Subversion Repositories svnkaklik

Compare Revisions

No changes between revisions

Regard whitespace Rev 7 → Rev 10

/roboti/solarni/2006/scamnum_specularis/AX25.c
0,0 → 1,139
//#define PTT PIN_A2 // PTT control
//#define TXo PIN_C0 // To the transmitter modulator
//#define PERIODAH delay_us(218) // Halfperiod H 222;78/1200 500;430/500
//#define TAILH delay_us(74)
//#define PERIODAL delay_us(408) // Halfperiod L 412;345/1200 1000;880/500
//#define TAILL delay_us(341)
#define PERIODAH delay_us(222) // Halfperiod H 222;78/1200 500;430/500
#define TAILH delay_us(78)
#define PERIODAL delay_us(412) // Halfperiod L 412;345/1200 1000;880/500
#define TAILL delay_us(345)
#byte STATUS = 3 // CPUs status register
 
byte SendData[16] = {'A'<<1, 'L'<<1, 'L'<<1, ' '<<1, ' '<<1, ' '<<1, 0x60,
'C'<<1, 'Z'<<1, '0'<<1, 'R'<<1, 'R'<<1, 'R'<<1, 0x61,
0x03, 0xF0};
 
boolean bit;
int fcslo, fcshi; // variabloes for calculating FCS (CRC)
int stuff; // stuff counter for extra 0
int flag_flag; // if it is sending flag (7E)
int fcs_flag; // if it is sending Frame Check Sequence
int i; // for for
 
void flipout() //flips the state of output pin a_1
{
stuff = 0; //since this is a 0, reset the stuff counter
if (bit)
{
bit=FALSE; //if the state of the pin was low, make it high.
}
else
{
bit=TRUE; //if the state of the pin was high make it low
}
}
 
void fcsbit(byte tbyte)
{
#asm
BCF STATUS,0
RRF fcshi,F // rotates the entire 16 bits
RRF fcslo,F // to the right
#endasm
if (((STATUS & 0x01)^(tbyte)) ==0x01)
{
fcshi = fcshi^0x84;
fcslo = fcslo^0x08;
}
}
 
void SendBit ()
{
if (bit)
{
output_low(TXo);
PERIODAH;
output_high(TXo);
PERIODAH;
output_low(TXo);
PERIODAH;
output_high(TXo);
TAILH;
}
else
{
output_low(TXo);
PERIODAL;
output_high(TXo);
TAILL;
};
}
 
void SendByte (byte inbyte)
{
int k, bt;
 
for (k=0;k<8;k++) //do the following for each of the 8 bits in the byte
{
bt = inbyte & 0x01; //strip off the rightmost bit of the byte to be sent (inbyte)
if ((fcs_flag == FALSE) & (flag_flag == FALSE)) fcsbit(bt); //do FCS calc, but only if this
//is not a flag or fcs byte
if (bt == 0)
{
flipout();
} // if this bit is a zero, flip the output state
else
{ //otherwise if it is a 1, do the following:
if (flag_flag == FALSE) stuff++; //increment the count of consequtive 1's
if ((flag_flag == FALSE) & (stuff == 5))
{ //stuff an extra 0, if 5 1's in a row
SendBit();
flipout(); //flip the output state to stuff a 0
}//end of if
}//end of else
// delay_us(850); //introduces a delay that creates 1200 baud
SendBit();
inbyte = inbyte>>1; //go to the next bit in the byte
}//end of for
}//end of SendByte
 
void SendPacket(char *data)
{
bit=FALSE;
 
fcslo=fcshi=0xFF; //The 2 FCS Bytes are initialized to FF
stuff = 0; //The variable stuff counts the number of 1's in a row. When it gets to 5
// it is time to stuff a 0.
 
// output_low(PTT); // Blinking LED
// delay_ms(1000);
// output_high(PTT);
 
flag_flag = TRUE; //The variable flag is true if you are transmitted flags (7E's) false otherwise.
fcs_flag = FALSE; //The variable fcsflag is true if you are transmitting FCS bytes, false otherwise.
 
for(i=0; i<10; i++) SendByte(0x7E); //Sends flag bytes. Adjust length for txdelay
//each flag takes approx 6.7 ms
flag_flag = FALSE; //done sending flags
 
for(i=0; i<16; i++) SendByte(SendData[i]); //send the packet bytes
 
for(i=0; 0 != *data; i++)
{
SendByte(*data); //send the packet bytes
data++;
};
 
fcs_flag = TRUE; //about to send the FCS bytes
fcslo =fcslo^0xff; //must XOR them with FF before sending
fcshi = fcshi^0xff;
SendByte(fcslo); //send the low byte of fcs
SendByte(fcshi); //send the high byte of fcs
fcs_flag = FALSE; //done sending FCS
flag_flag = TRUE; //about to send flags
SendByte(0x7e); // Send a flag to end packet
}
 
 
 
/roboti/solarni/2006/scamnum_specularis/menic.BAK
0,0 → 1,200
// *************************************
// * Scamnum Specularis ** 20. 9. 2006 *
// *************************************
 
#include ".\menic.h"
 
#define TXo PIN_B5 // To the transmitter modulator
#include ".\AX25.c" // Podprogram pro prenos telemetrie
char AXstring[40]; // Buffer pro prenos telemetrie
 
#define REFSTART 95 // Hodnota odpovidajici 1,2V pri nezatizenych clancich
#define DUTY1 2 // Delka sepnuti PWM v us pro sero
#define DUTY2 19 // Delka sepnuti PWM v us pro jednu zarovku 500W
 
// Tabulka hodnot prevodniku pro ruzna napajeci napeti
// 80 3,99V
// 90 3,54V
// 100 3,20V
// 105 3,04V
// 107 2,99V
// 110 2,91v
// 200 1,61V
 
#define PIEZO PIN_A6 // Jeden pol piezo reproduktoru
#define LED PIN_A7 // LED / druhy pol piezo reproduktoru
#define MENIC PIN_B3 // Spinani tranzistoru menice
#define REFPWR PIN_B1 // Napajeni zdroje referencniho napeti
#define MOTOR PIN_B2 // Spinani tranzistoru motoru
#define SW1 PIN_B6 // DIPswitch 1
#define SW2 PIN_B7 // DIPswitch 2
#define NAPETI 4 // Cislo kanalu DA prevodniku pro mereni napeti
#define PWM 0 // Cislo kanalu DA prevodniku pro nastaveni PWM
#define ROZJEZD 1 // Cislo kanalu DA prevodniku pro nastaveni rozjezdu
 
#byte SSPBUF = 0x13 // Adresy registru jednotky SSP
#byte SSPCON1 = 0x14
#byte SSPSTAT = 0x94
 
// Vzorky pro generovani PWM pomoci SSP
unsigned int8 const Pattern[8] = {0x02,0x06,0x0e,0x1e,0x3e,0x7e,0xfe,0xff};
unsigned int8 MotorPattern;
 
#INT_SSP
void IntSSP()
{
SSPBUF=MotorPattern; // znovu vysli stejnou hodnotu
}
 
void pip() // pipnuti a bliknuti
{
int1 beep;
int i;
 
for(i=0; i<250; i++)
{
output_bit(PIEZO, beep);
beep=~beep;
output_bit(LED, beep);
delay_us(100);
};
output_high(PIEZO);
output_high(LED);
}
 
void cvak() // pouze cvaknuti piezoelementem bez bliknuti
{
output_bit(PIEZO,~input(PIEZO));
}
 
void main()
{
int8 n;
int8 perioda;
int8 razeni;
int8 uclanku;
 
setup_timer_0(RTCC_INTERNAL);setup_wdt(WDT_1152MS);
setup_timer_1(T1_DISABLED);
setup_adc_ports(ADC_CLOCK_INTERNAL|sAN0|sAN1|sAN4|VSS_VDD);
setup_adc(ADC_CLOCK_INTERNAL);
setup_spi(FALSE);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
 
output_low(MENIC); // Vsechno zastav
output_low(MOTOR);
output_low(REFPWR);
output_high(LED);
output_high(PIEZO);
 
set_adc_channel(NAPETI); // Vyber AD kanal pro pomerne mereni napeti
set_pwm1_duty(0); // Spust PWM, ale zatim s trvalou 0 na vystupu
setup_ccp1(CCP_PWM);
setup_timer_2(T2_DIV_BY_1,100,1); // perioda
 
setup_oscillator(OSC_4MHZ|OSC_INTRC); // rozjed PIC (zvysi se odber)
 
// jsme v depu?
set_pwm1_duty(DUTY1); // PWM pro zatizeni clanku pri malem osvetleni
n=0;
do
{
output_low(REFPWR); // Vypni napajeni napetove reference, aby se setrilo
delay_ms(100);
if (4==n++) {cvak(); n=0;}; // Kazdy 4. pruchod cvakni
output_high(REFPWR); // Zapni napajeni napetove reference
delay_ms(1); // Pockej na ustaleni napeti
} while (read_adc()>REFSTART); // Odkryl starter clanky?
output_low(REFPWR); // Vypni napajeni napetove reference, aby se setrilo
 
// port_b_pullups(TRUE); // Zapni pullupy, aby slo cist DIPswitch
// do
// {
// Precti trimry
set_adc_channel(PWM); // Zjisteni nastaveni PWM
delay_us(100); // Pockej na prepnuti kanalu A/D prevodniku
perioda=(read_adc()>>1)+40; // rozsah: 40 az 167
 
set_adc_channel(ROZJEZD); // Zjisteni nastaveni rozjezdu
delay_us(100); // Pockej na prepnuti kanalu A/D prevodniku
razeni=read_adc()>>1; // rozsah: 0 az 127
 
// Rozjeti menice
set_pwm1_duty(0); // Zastav PWM, aby slo nastavit jinou frekvenci
setup_timer_2(T2_DIV_BY_1,perioda,1); // perioda
set_pwm1_duty(DUTY2); // PWM pro zatizeni clanku pri jedne 500W zarovce
 
pip(); // potvrzeni odstartovani / servisni mod
delay_ms(500);
 
// } while (input(SW1)); // Je zapnut servisni mod? SW1(OFF)=ANO
// port_b_pullups(FALSE); // Vypni pullupy, aby se setrilo energii
 
// Regulace nabíjení
output_high(REFPWR); // Prepni AD na mereni napeti clanku
set_adc_channel(NAPETI); // Prepni Zmer napeti clanku
delay_us(50); // Pockej na prepnuti kanalu A/D prevodniku
for(n=1;n<=10;n++)
{
// Zmer napeti (aktualni zatizeni clanku)
uclanku=read_adc();
// Uprav parametry menice
if (uclanku>105)
{
perioda++;
}
else
{
perioda--;
}
set_pwm1_duty(0); // Zastav PWM, aby slo nastavit jinou frekvenci
setup_timer_2(T2_DIV_BY_1,perioda,1); // perioda
set_pwm1_duty(DUTY2); // PWM pro zatizeni clanku pri jedne 500W zarovce
delay_ms(100);
}
output_low(REFPWR);
// posli telemetrii
sprintf(AXstring,"p=%u r=%u u=%u", perioda, razeni, uclanku); // Convert DATA to String.
SendPacket(&AXstring[0]);
 
delay_ms(13000); // Pockame 14s
 
// rozjezd
SSPSTAT = 0; // inicializace SPI jednotky
SSPCON1 = 0x22; // SPI OSC/64
MotorPattern=0x02; // prvni data pro vyslani
SSPBUF=MotorPattern;
enable_interrupts(global);
enable_interrupts(INT_SSP); // az budou vyslana, prijde interrupt od SSP
 
for(n=0; n<=7; n++) // razeni osmi rychlostnich stupnu
{
MotorPattern=Pattern[n];
delay_ms(razeni); // Pockej na dalsi razeni
};
SSPSTAT = 0;
SSPCON1 = 0; // SPI stop
disable_interrupts(INT_SSP); // zastav preruseni od SSP
 
// jedem co to da
output_high(MOTOR);
 
/*
if (TRUE) // Venkovni jizda?
{
delay_ms(5000); // Venku muzeme jet 5s
set_pwm1_duty(0); // Zastav menic
// output_low(MOTOR); // Zastav motor
while(TRUE) restart_wdt(); // Cekej porad
};
delay_ms(3000);
*/
delay_ms(1300); // Nemeli bysme jet dele nez 1,3s :-)
output_low(MOTOR); // Zastav motor
// Menic je stale zapnut a zatezuje clanky
 
while(TRUE); // Cekej, dokud se neztrati svetlo,
// nebo prijde WatchDog
 
}
/roboti/solarni/2006/scamnum_specularis/menic.HEX
0,0 → 1,108
:1000000000308A00BA290000FF00030E8301A1001E
:100010007F08A0000A08A8008A01A00E0408A20018
:100020007708A3007808A4007908A5007A08A6003C
:100030007B08A700831383128C308400801D222844
:100040008C193528220884002308F7002408F800BA
:100050002508F9002608FA002708FB0028088A006E
:10006000210E8300FF0E7F0E09008A1143280A101B
:100070008A100A118207023406340E341E343E34CC
:100080007E34FE34FF34680893008C118A112228D4
:100090006F308400000803195D280130F800BF307C
:1000A000F7006400F70B5128F80B4F284230F70097
:1000B000F70B58286400800B4D2800348316051771
:1000C0008312051F65280513662805178316051377
:1000D00083128A115A2AEF016F08F93C031C8B28FE
:1000E0006E1874280513752805178316051301303B
:1000F0008312EE066E187E2885137F2885178316D7
:10010000851364001F30F700F70B842800000000FF
:100110008312EF0A6C2883160513831205178316C2
:100120008513831285178A11A32A69088400700831
:100130008000840A8001E90A00347108F801700225
:100140000318A5287008F700B128F7010830F2005D
:10015000F00DF70D710877020318F700F80DF20B98
:10016000A828003478086E08F0006430F1009D2063
:100170007708EE0078083030031DC528EF1CCC2826
:10018000EF19CC286F1A2030C828EF116F126F14A6
:10019000F8077808F00095206E08F0000A30F100AA
:1001A0009D207708EE0078083030031DDD28EF1918
:1001B000E1286F1CE1286F1A2030F8077808F0005A
:1001C00095203030EE076E08F00095200034BC0119
:1001D000391CEC283910ED2839140034391C1A293F
:1001E000831686128312861264004730F700F70BDD
:1001F000F7280000831686128312861664004730A3
:10020000F700F70B0129000083168612831286126D
:1002100064004730F700F70B0B29000083168612A5
:100220008312861664001830F700F70B15290000BA
:1002300000002D29831686128312861264008530F1
:10024000F700F70B212983168612831286166400A5
:100250006F30F700F70B2A2900000034F101710814
:10026000073C031C762970080139F200BE08031907
:100270003B2900303C290130F300BD080319422915
:100280000030432901307305003A031956297208DA
:10029000F3000310BB0CBA0C030801397306013CD0
:1002A000031D56298430BB060830BA06F208031D28
:1002B0005B29E7207129BD080319BC0ABD08031991
:1002C0006329003064290130F3003C08053C031920
:1002D0006B2900306C290130730503197129EE2058
:1002E000E720EE200310F00CF10A2F29003439101A
:1002F000FF30BB00BA00BC010130BD00BE01BF0130
:100300003F08093C031C89297E30F0002E21BF0ADA
:100310008029BD01BF013F080F3C031C98292930EB
:100320003F0784000008EF00F0002E21BF0A8B2950
:10033000BF016E08840000080319A7296E08840015
:100340000008EF00F0002E21EE0ABF0A99290130C3
:10035000BE00FF30BA06BB063A08F0002E213B086B
:10036000F0002E21BE010130BD007E30F0002E21B4
:100370008A110C2B84011F30830583161F129F12D4
:100380001B0880399B0007309C0082308312A90033
:100390009830AA00AB004030AC00AD00AE00603039
:1003A000AF008630B000B430B1006030B200A4308D
:1003B000B300B400B5006130B6000330B700F030D0
:1003C000B800E90183160108C03981000E30F7003A
:1003D000073083128101813084000008F03907382A
:1003E000800064000008F739F719F03977048000BD
:1003F000900183161F129F121B088039D3389B006F
:100400001F1383121F179F1783169F1383121F1426
:10041000941283160611861406120030831294007B
:100420008316940007309C00050864000230F70032
:10043000F70B182A00001C0883120D1383169D0168
:1004400086118312861183160611831206118316F4
:1004500086108312861083168513831285178316E0
:100460000513831205172030F8001F08C7397804D8
:100470009F00950183168611831286110C30970018
:100480000030F80004389200643083169200623025
:100490008F00023083129500EA01831686108312C2
:1004A00086106430EF0048206A08EA0A043C031D05
:1004B0005B2A5E28EA0183168610831286140130B7
:1004C000EF0048201F151F19632A1E085F3C031CFC
:1004D0004D2A83168610831286100030F8001F08FC
:1004E000C73978049F0064001F30F700F70B762AA5
:1004F000000000001F151F197B2A1E08F7000310BB
:10050000F70C7708283EEB000830F8001F08C739C1
:1005100078049F0064001F30F700F70B8D2A00005D
:1005200000001F151F19922A03101E0CEC009501E4
:100530000030F800043892006B08831692001330E4
:10054000831295006B280230EE00FA30EF0048204D
:10055000EE0BA52A83168610831286142030F8002D
:100560001F08C73978049F0064000F30F700F70BAD
:10057000B72A00000130EA006A080A3C031CDC2AA2
:100580001F151F19C12A1E08ED006D08693C0318CC
:10059000CB2AEB0ACC2AEB0395010030F800043893
:1005A00092006B088316920013308312950064301A
:1005B000EF004820EA0ABC2A8316861083128610B0
:1005C0004030E9007030F00095203D30F00095207B
:1005D0006B08EE001B30EF00B2202030F0009520B9
:1005E0007230F00095203D30F00095206C08EE0050
:1005F0001B30EF00B2202030F00095207530F00065
:1006000095203D30F00095206D08EE001B30EF0086
:10061000B2204030EE0077293430EE00FA30EF009F
:100620004820EE0B0E2B8316940122308312940087
:100630000230E80068089300C0308B0483168C15E4
:100640008312EA016A08073C031C2F2B6A08372033
:10065000F800E8006C08EF004820EA0A222B831615
:1006600094018312940183168C11061183120615CE
:100670000A30EE008230EF004820EE0B3A2B831652
:0A068000061183120611432B6300DC
:04400E003C27FC3F10
:00000001FF
;PIC16F88
/roboti/solarni/2006/scamnum_specularis/menic.LST
0,0 → 1,1125
CCS PCM C Compiler, Version 3.245, 27853 12-IX-06 23:20
 
Filename: D:\KAKL\roboti\solarni\2006\scamnum\menic.lst
 
ROM used: 837 words (20%)
Largest free fragment is 2048
RAM used: 85 (49%) at main() level
91 (52%) worst case
Stack: 4 worst case (3 in main + 1 for interrupts)
 
*
0000: MOVLW 00
0001: MOVWF 0A
0002: GOTO 1BA
0003: NOP
0004: MOVWF 7F
0005: SWAPF 03,W
0006: CLRF 03
0007: MOVWF 21
0008: MOVF 7F,W
0009: MOVWF 20
000A: MOVF 0A,W
000B: MOVWF 28
000C: CLRF 0A
000D: SWAPF 20,F
000E: MOVF 04,W
000F: MOVWF 22
0010: MOVF 77,W
0011: MOVWF 23
0012: MOVF 78,W
0013: MOVWF 24
0014: MOVF 79,W
0015: MOVWF 25
0016: MOVF 7A,W
0017: MOVWF 26
0018: MOVF 7B,W
0019: MOVWF 27
001A: BCF 03.7
001B: BCF 03.5
001C: MOVLW 8C
001D: MOVWF 04
001E: BTFSS 00.3
001F: GOTO 022
0020: BTFSC 0C.3
0021: GOTO 035
0022: MOVF 22,W
0023: MOVWF 04
0024: MOVF 23,W
0025: MOVWF 77
0026: MOVF 24,W
0027: MOVWF 78
0028: MOVF 25,W
0029: MOVWF 79
002A: MOVF 26,W
002B: MOVWF 7A
002C: MOVF 27,W
002D: MOVWF 7B
002E: MOVF 28,W
002F: MOVWF 0A
0030: SWAPF 21,W
0031: MOVWF 03
0032: SWAPF 7F,F
0033: SWAPF 7F,W
0034: RETFIE
0035: BCF 0A.3
0036: GOTO 043
.................... // *************************************
.................... // * Scamnum Specularis ** 20. 9. 2006 *
.................... // *************************************
....................
.................... #include ".\menic.h"
.................... #include <16F88.h>
.................... //////// Standard Header file for the PIC16F88 device ////////////////
.................... #device PIC16F88
.................... #list
....................
....................
.................... #device adc=8
....................
.................... #fuses WDT,INTRC_IO, NOPUT, MCLR, NOBROWNOUT, NOLVP, NOCPD, \
.................... NOWRT, DEBUG, NOPROTECT, NOFCMEN, NOIESO, CCPB3
....................
.................... #use delay(clock=3900000,RESTART_WDT)
*
0048: MOVLW 6F
0049: MOVWF 04
004A: MOVF 00,W
004B: BTFSC 03.2
004C: GOTO 05D
004D: MOVLW 01
004E: MOVWF 78
004F: MOVLW BF
0050: MOVWF 77
0051: CLRWDT
0052: DECFSZ 77,F
0053: GOTO 051
0054: DECFSZ 78,F
0055: GOTO 04F
0056: MOVLW 42
0057: MOVWF 77
0058: DECFSZ 77,F
0059: GOTO 058
005A: CLRWDT
005B: DECFSZ 00,F
005C: GOTO 04D
005D: RETLW 00
....................
....................
....................
.................... #define TXo PIN_B5 // To the transmitter modulator
.................... #include ".\AX25.c" // Podprogram pro prenos telemetrie
.................... //#define PTT PIN_A2 // PTT control
.................... //#define TXo PIN_C0 // To the transmitter modulator
.................... //#define PERIODAH delay_us(218) // Halfperiod H 222;78/1200 500;430/500
.................... //#define TAILH delay_us(74)
.................... //#define PERIODAL delay_us(408) // Halfperiod L 412;345/1200 1000;880/500
.................... //#define TAILL delay_us(341)
.................... #define PERIODAH delay_us(222) // Halfperiod H 222;78/1200 500;430/500
.................... #define TAILH delay_us(78)
.................... #define PERIODAL delay_us(412) // Halfperiod L 412;345/1200 1000;880/500
.................... #define TAILL delay_us(345)
.................... #byte STATUS = 3 // CPUs status register
....................
.................... byte SendData[16] = {'A'<<1, 'L'<<1, 'L'<<1, ' '<<1, ' '<<1, ' '<<1, 0x60,
.................... 'C'<<1, 'Z'<<1, '0'<<1, 'R'<<1, 'R'<<1, 'R'<<1, 0x61,
.................... 0x03, 0xF0};
*
01C5: MOVLW 82
01C6: BCF 03.5
01C7: MOVWF 29
01C8: MOVLW 98
01C9: MOVWF 2A
01CA: MOVWF 2B
01CB: MOVLW 40
01CC: MOVWF 2C
01CD: MOVWF 2D
01CE: MOVWF 2E
01CF: MOVLW 60
01D0: MOVWF 2F
01D1: MOVLW 86
01D2: MOVWF 30
01D3: MOVLW B4
01D4: MOVWF 31
01D5: MOVLW 60
01D6: MOVWF 32
01D7: MOVLW A4
01D8: MOVWF 33
01D9: MOVWF 34
01DA: MOVWF 35
01DB: MOVLW 61
01DC: MOVWF 36
01DD: MOVLW 03
01DE: MOVWF 37
01DF: MOVLW F0
01E0: MOVWF 38
....................
.................... boolean bit;
.................... int fcslo, fcshi; // variabloes for calculating FCS (CRC)
.................... int stuff; // stuff counter for extra 0
.................... int flag_flag; // if it is sending flag (7E)
.................... int fcs_flag; // if it is sending Frame Check Sequence
.................... int i; // for for
....................
.................... void flipout() //flips the state of output pin a_1
.................... {
.................... stuff = 0; //since this is a 0, reset the stuff counter
*
00E7: CLRF 3C
.................... if (bit)
00E8: BTFSS 39.0
00E9: GOTO 0EC
.................... {
.................... bit=FALSE; //if the state of the pin was low, make it high.
00EA: BCF 39.0
.................... }
.................... else
00EB: GOTO 0ED
.................... {
.................... bit=TRUE; //if the state of the pin was high make it low
00EC: BSF 39.0
.................... }
.................... }
00ED: RETLW 00
....................
.................... void fcsbit(byte tbyte)
.................... {
.................... #asm
.................... BCF STATUS,0
*
0149: BCF 03.0
.................... RRF fcshi,F // rotates the entire 16 bits
014A: RRF 3B,F
.................... RRF fcslo,F // to the right
014B: RRF 3A,F
.................... #endasm
.................... if (((STATUS & 0x01)^(tbyte)) ==0x01)
014C: MOVF 03,W
014D: ANDLW 01
014E: XORWF 73,W
014F: SUBLW 01
0150: BTFSS 03.2
0151: GOTO 156
.................... {
.................... fcshi = fcshi^0x84;
0152: MOVLW 84
0153: XORWF 3B,F
.................... fcslo = fcslo^0x08;
0154: MOVLW 08
0155: XORWF 3A,F
.................... }
.................... }
....................
.................... void SendBit ()
.................... {
.................... if (bit)
*
00EE: BTFSS 39.0
00EF: GOTO 11A
.................... {
.................... output_low(TXo);
00F0: BSF 03.5
00F1: BCF 06.5
00F2: BCF 03.5
00F3: BCF 06.5
.................... PERIODAH;
00F4: CLRWDT
00F5: MOVLW 47
00F6: MOVWF 77
00F7: DECFSZ 77,F
00F8: GOTO 0F7
00F9: NOP
.................... output_high(TXo);
00FA: BSF 03.5
00FB: BCF 06.5
00FC: BCF 03.5
00FD: BSF 06.5
.................... PERIODAH;
00FE: CLRWDT
00FF: MOVLW 47
0100: MOVWF 77
0101: DECFSZ 77,F
0102: GOTO 101
0103: NOP
.................... output_low(TXo);
0104: BSF 03.5
0105: BCF 06.5
0106: BCF 03.5
0107: BCF 06.5
.................... PERIODAH;
0108: CLRWDT
0109: MOVLW 47
010A: MOVWF 77
010B: DECFSZ 77,F
010C: GOTO 10B
010D: NOP
.................... output_high(TXo);
010E: BSF 03.5
010F: BCF 06.5
0110: BCF 03.5
0111: BSF 06.5
.................... TAILH;
0112: CLRWDT
0113: MOVLW 18
0114: MOVWF 77
0115: DECFSZ 77,F
0116: GOTO 115
0117: NOP
0118: NOP
.................... }
.................... else
0119: GOTO 12D
.................... {
.................... output_low(TXo);
011A: BSF 03.5
011B: BCF 06.5
011C: BCF 03.5
011D: BCF 06.5
.................... PERIODAL;
011E: CLRWDT
011F: MOVLW 85
0120: MOVWF 77
0121: DECFSZ 77,F
0122: GOTO 121
.................... output_high(TXo);
0123: BSF 03.5
0124: BCF 06.5
0125: BCF 03.5
0126: BSF 06.5
.................... TAILL;
0127: CLRWDT
0128: MOVLW 6F
0129: MOVWF 77
012A: DECFSZ 77,F
012B: GOTO 12A
012C: NOP
.................... };
.................... }
012D: RETLW 00
....................
.................... void SendByte (byte inbyte)
.................... {
.................... int k, bt;
....................
.................... for (k=0;k<8;k++) //do the following for each of the 8 bits in the byte
012E: CLRF 71
012F: MOVF 71,W
0130: SUBLW 07
0131: BTFSS 03.0
0132: GOTO 176
.................... {
.................... bt = inbyte & 0x01; //strip off the rightmost bit of the byte to be sent (inbyte)
0133: MOVF 70,W
0134: ANDLW 01
0135: MOVWF 72
.................... if ((fcs_flag == FALSE) & (flag_flag == FALSE)) fcsbit(bt); //do FCS calc, but only if this
0136: MOVF 3E,F
0137: BTFSC 03.2
0138: GOTO 13B
0139: MOVLW 00
013A: GOTO 13C
013B: MOVLW 01
013C: MOVWF 73
013D: MOVF 3D,F
013E: BTFSC 03.2
013F: GOTO 142
0140: MOVLW 00
0141: GOTO 143
0142: MOVLW 01
0143: ANDWF 73,W
0144: XORLW 00
0145: BTFSC 03.2
0146: GOTO 156
0147: MOVF 72,W
0148: MOVWF 73
.................... //is not a flag or fcs byte
.................... if (bt == 0)
*
0156: MOVF 72,F
0157: BTFSS 03.2
0158: GOTO 15B
.................... {
.................... flipout();
0159: CALL 0E7
.................... } // if this bit is a zero, flip the output state
.................... else
015A: GOTO 171
.................... { //otherwise if it is a 1, do the following:
.................... if (flag_flag == FALSE) stuff++; //increment the count of consequtive 1's
015B: MOVF 3D,F
015C: BTFSC 03.2
015D: INCF 3C,F
.................... if ((flag_flag == FALSE) & (stuff == 5))
015E: MOVF 3D,F
015F: BTFSC 03.2
0160: GOTO 163
0161: MOVLW 00
0162: GOTO 164
0163: MOVLW 01
0164: MOVWF 73
0165: MOVF 3C,W
0166: SUBLW 05
0167: BTFSC 03.2
0168: GOTO 16B
0169: MOVLW 00
016A: GOTO 16C
016B: MOVLW 01
016C: ANDWF 73,W
016D: BTFSC 03.2
016E: GOTO 171
.................... { //stuff an extra 0, if 5 1's in a row
.................... SendBit();
016F: CALL 0EE
.................... flipout(); //flip the output state to stuff a 0
0170: CALL 0E7
.................... }//end of if
.................... }//end of else
.................... // delay_us(850); //introduces a delay that creates 1200 baud
.................... SendBit();
0171: CALL 0EE
.................... inbyte = inbyte>>1; //go to the next bit in the byte
0172: BCF 03.0
0173: RRF 70,F
.................... }//end of for
0174: INCF 71,F
0175: GOTO 12F
.................... }//end of SendByte
0176: RETLW 00
....................
.................... void SendPacket(char *data)
.................... {
.................... bit=FALSE;
0177: BCF 39.0
....................
.................... fcslo=fcshi=0xFF; //The 2 FCS Bytes are initialized to FF
0178: MOVLW FF
0179: MOVWF 3B
017A: MOVWF 3A
.................... stuff = 0; //The variable stuff counts the number of 1's in a row. When it gets to 5
017B: CLRF 3C
.................... // it is time to stuff a 0.
....................
.................... // output_low(PTT); // Blinking LED
.................... // delay_ms(1000);
.................... // output_high(PTT);
....................
.................... flag_flag = TRUE; //The variable flag is true if you are transmitted flags (7E's) false otherwise.
017C: MOVLW 01
017D: MOVWF 3D
.................... fcs_flag = FALSE; //The variable fcsflag is true if you are transmitting FCS bytes, false otherwise.
017E: CLRF 3E
....................
.................... for(i=0; i<10; i++) SendByte(0x7E); //Sends flag bytes. Adjust length for txdelay
017F: CLRF 3F
0180: MOVF 3F,W
0181: SUBLW 09
0182: BTFSS 03.0
0183: GOTO 189
0184: MOVLW 7E
0185: MOVWF 70
0186: CALL 12E
0187: INCF 3F,F
0188: GOTO 180
.................... //each flag takes approx 6.7 ms
.................... flag_flag = FALSE; //done sending flags
0189: CLRF 3D
....................
.................... for(i=0; i<16; i++) SendByte(SendData[i]); //send the packet bytes
018A: CLRF 3F
018B: MOVF 3F,W
018C: SUBLW 0F
018D: BTFSS 03.0
018E: GOTO 198
018F: MOVLW 29
0190: ADDWF 3F,W
0191: MOVWF 04
0192: MOVF 00,W
0193: MOVWF 6F
0194: MOVWF 70
0195: CALL 12E
0196: INCF 3F,F
0197: GOTO 18B
....................
.................... for(i=0; 0 != *data; i++)
0198: CLRF 3F
0199: MOVF 6E,W
019A: MOVWF 04
019B: MOVF 00,W
019C: BTFSC 03.2
019D: GOTO 1A7
.................... {
.................... SendByte(*data); //send the packet bytes
019E: MOVF 6E,W
019F: MOVWF 04
01A0: MOVF 00,W
01A1: MOVWF 6F
01A2: MOVWF 70
01A3: CALL 12E
.................... data++;
01A4: INCF 6E,F
.................... };
01A5: INCF 3F,F
01A6: GOTO 199
....................
.................... fcs_flag = TRUE; //about to send the FCS bytes
01A7: MOVLW 01
01A8: MOVWF 3E
.................... fcslo =fcslo^0xff; //must XOR them with FF before sending
01A9: MOVLW FF
01AA: XORWF 3A,F
.................... fcshi = fcshi^0xff;
01AB: XORWF 3B,F
.................... SendByte(fcslo); //send the low byte of fcs
01AC: MOVF 3A,W
01AD: MOVWF 70
01AE: CALL 12E
.................... SendByte(fcshi); //send the high byte of fcs
01AF: MOVF 3B,W
01B0: MOVWF 70
01B1: CALL 12E
.................... fcs_flag = FALSE; //done sending FCS
01B2: CLRF 3E
.................... flag_flag = TRUE; //about to send flags
01B3: MOVLW 01
01B4: MOVWF 3D
.................... SendByte(0x7e); // Send a flag to end packet
01B5: MOVLW 7E
01B6: MOVWF 70
01B7: CALL 12E
.................... }
01B8: BCF 0A.3
01B9: GOTO 30C (RETURN)
....................
....................
....................
....................
.................... char AXstring[40]; // Buffer pro prenos telemetrie
....................
.................... #define REFSTART 95 // Hodnota odpovidajici 1,2V pri nezatizenych clancich
.................... #define DUTY1 2 // Delka sepnuti PWM v us pro sero
.................... #define DUTY2 19 // Delka sepnuti PWM v us pro jednu zarovku 500W
....................
.................... // Tabulka hodnot prevodniku pro ruzna napajeci napeti
.................... // 80 3,99V
.................... // 90 3,54V
.................... // 100 3,20V
.................... // 105 3,04V
.................... // 107 2,99V
.................... // 110 2,91v
.................... // 200 1,61V
....................
.................... #define PIEZO PIN_A6 // Jeden pol piezo reproduktoru
.................... #define LED PIN_A7 // LED / druhy pol piezo reproduktoru
.................... #define MENIC PIN_B3 // Spinani tranzistoru menice
.................... #define REFPWR PIN_B1 // Napajeni zdroje referencniho napeti
.................... #define MOTOR PIN_B2 // Spinani tranzistoru motoru
.................... #define SW1 PIN_B6 // DIPswitch 1
.................... #define SW2 PIN_B7 // DIPswitch 2
.................... #define NAPETI 4 // Cislo kanalu DA prevodniku pro mereni napeti
.................... #define PWM 0 // Cislo kanalu DA prevodniku pro nastaveni PWM
.................... #define ROZJEZD 1 // Cislo kanalu DA prevodniku pro nastaveni rozjezdu
....................
.................... #byte SSPBUF = 0x13 // Adresy registru jednotky SSP
.................... #byte SSPCON1 = 0x14
.................... #byte SSPSTAT = 0x94
....................
.................... // Vzorky pro generovani PWM pomoci SSP
.................... unsigned int8 const Pattern[8] = {0x02,0x06,0x0e,0x1e,0x3e,0x7e,0xfe,0xff};
.................... unsigned int8 MotorPattern;
....................
.................... #INT_SSP
.................... void IntSSP()
.................... {
.................... SSPBUF=MotorPattern; // znovu vysli stejnou hodnotu
*
0043: MOVF 68,W
0044: MOVWF 13
.................... }
....................
0045: BCF 0C.3
0046: BCF 0A.3
0047: GOTO 022
.................... void pip() // pipnuti a bliknuti
.................... {
.................... int1 beep;
.................... int i;
....................
.................... for(i=0; i<250; i++)
*
006B: CLRF 6F
006C: MOVF 6F,W
006D: SUBLW F9
006E: BTFSS 03.0
006F: GOTO 08B
.................... {
.................... output_bit(PIEZO, beep);
0070: BTFSC 6E.0
0071: GOTO 074
0072: BCF 05.6
0073: GOTO 075
0074: BSF 05.6
0075: BSF 03.5
0076: BCF 05.6
.................... beep=~beep;
0077: MOVLW 01
0078: BCF 03.5
0079: XORWF 6E,F
.................... output_bit(LED, beep);
007A: BTFSC 6E.0
007B: GOTO 07E
007C: BCF 05.7
007D: GOTO 07F
007E: BSF 05.7
007F: BSF 03.5
0080: BCF 05.7
.................... delay_us(100);
0081: CLRWDT
0082: MOVLW 1F
0083: MOVWF 77
0084: DECFSZ 77,F
0085: GOTO 084
0086: NOP
0087: NOP
.................... };
0088: BCF 03.5
0089: INCF 6F,F
008A: GOTO 06C
.................... output_high(PIEZO);
008B: BSF 03.5
008C: BCF 05.6
008D: BCF 03.5
008E: BSF 05.6
.................... output_high(LED);
008F: BSF 03.5
0090: BCF 05.7
0091: BCF 03.5
0092: BSF 05.7
.................... }
0093: BCF 0A.3
0094: GOTO 2A3 (RETURN)
....................
.................... void cvak() // pouze cvaknuti piezoelementem bez bliknuti
.................... {
.................... output_bit(PIEZO,~input(PIEZO));
*
005E: BSF 03.5
005F: BSF 05.6
0060: BCF 03.5
0061: BTFSS 05.6
0062: GOTO 065
0063: BCF 05.6
0064: GOTO 066
0065: BSF 05.6
0066: BSF 03.5
0067: BCF 05.6
.................... }
0068: BCF 03.5
0069: BCF 0A.3
006A: GOTO 25A (RETURN)
....................
.................... void main()
.................... {
*
01BA: CLRF 04
01BB: MOVLW 1F
01BC: ANDWF 03,F
01BD: BSF 03.5
01BE: BCF 1F.4
01BF: BCF 1F.5
01C0: MOVF 1B,W
01C1: ANDLW 80
01C2: MOVWF 1B
01C3: MOVLW 07
01C4: MOVWF 1C
.................... int8 n;
.................... int8 perioda;
.................... int8 razeni;
.................... int8 uclanku;
....................
.................... setup_timer_0(RTCC_INTERNAL);setup_wdt(WDT_1152MS);
*
01E2: BSF 03.5
01E3: MOVF 01,W
01E4: ANDLW C0
01E5: MOVWF 01
01E6: MOVLW 0E
01E7: MOVWF 77
01E8: MOVLW 07
01E9: BCF 03.5
01EA: CLRF 01
01EB: MOVLW 81
01EC: MOVWF 04
01ED: MOVF 00,W
01EE: ANDLW F0
01EF: IORLW 07
01F0: MOVWF 00
01F1: CLRWDT
01F2: MOVF 00,W
01F3: ANDLW F7
01F4: BTFSC 77.3
01F5: ANDLW F0
01F6: IORWF 77,W
01F7: MOVWF 00
.................... setup_timer_1(T1_DISABLED);
01F8: CLRF 10
.................... setup_adc_ports(ADC_CLOCK_INTERNAL|sAN0|sAN1|sAN4|VSS_VDD);
01F9: BSF 03.5
01FA: BCF 1F.4
01FB: BCF 1F.5
01FC: MOVF 1B,W
01FD: ANDLW 80
01FE: IORLW D3
01FF: MOVWF 1B
.................... setup_adc(ADC_CLOCK_INTERNAL);
0200: BCF 1F.6
0201: BCF 03.5
0202: BSF 1F.6
0203: BSF 1F.7
0204: BSF 03.5
0205: BCF 1F.7
0206: BCF 03.5
0207: BSF 1F.0
.................... setup_spi(FALSE);
0208: BCF 14.5
0209: BSF 03.5
020A: BCF 06.2
020B: BSF 06.1
020C: BCF 06.4
020D: MOVLW 00
020E: BCF 03.5
020F: MOVWF 14
0210: BSF 03.5
0211: MOVWF 14
.................... setup_comparator(NC_NC_NC_NC);
0212: MOVLW 07
0213: MOVWF 1C
0214: MOVF 05,W
0215: CLRWDT
0216: MOVLW 02
0217: MOVWF 77
0218: DECFSZ 77,F
0219: GOTO 218
021A: NOP
021B: MOVF 1C,W
021C: BCF 03.5
021D: BCF 0D.6
.................... setup_vref(FALSE);
021E: BSF 03.5
021F: CLRF 1D
....................
.................... output_low(MENIC); // Vsechno zastav
0220: BCF 06.3
0221: BCF 03.5
0222: BCF 06.3
.................... output_low(MOTOR);
0223: BSF 03.5
0224: BCF 06.2
0225: BCF 03.5
0226: BCF 06.2
.................... output_low(REFPWR);
0227: BSF 03.5
0228: BCF 06.1
0229: BCF 03.5
022A: BCF 06.1
.................... output_high(LED);
022B: BSF 03.5
022C: BCF 05.7
022D: BCF 03.5
022E: BSF 05.7
.................... output_high(PIEZO);
022F: BSF 03.5
0230: BCF 05.6
0231: BCF 03.5
0232: BSF 05.6
....................
.................... set_adc_channel(NAPETI); // Vyber AD kanal pro pomerne mereni napeti
0233: MOVLW 20
0234: MOVWF 78
0235: MOVF 1F,W
0236: ANDLW C7
0237: IORWF 78,W
0238: MOVWF 1F
.................... set_pwm1_duty(0); // Spust PWM, ale zatim s trvalou 0 na vystupu
0239: CLRF 15
.................... setup_ccp1(CCP_PWM);
023A: BSF 03.5
023B: BCF 06.3
023C: BCF 03.5
023D: BCF 06.3
023E: MOVLW 0C
023F: MOVWF 17
.................... setup_timer_2(T2_DIV_BY_1,100,1); // perioda
0240: MOVLW 00
0241: MOVWF 78
0242: IORLW 04
0243: MOVWF 12
0244: MOVLW 64
0245: BSF 03.5
0246: MOVWF 12
....................
.................... setup_oscillator(OSC_4MHZ|OSC_INTRC); // rozjed PIC (zvysi se odber)
0247: MOVLW 62
0248: MOVWF 0F
....................
.................... // jsme v depu?
.................... set_pwm1_duty(DUTY1); // PWM pro zatizeni clanku pri malem osvetleni
0249: MOVLW 02
024A: BCF 03.5
024B: MOVWF 15
.................... n=0;
024C: CLRF 6A
.................... do
.................... {
.................... output_low(REFPWR); // Vypni napajeni napetove reference, aby se setrilo
024D: BSF 03.5
024E: BCF 06.1
024F: BCF 03.5
0250: BCF 06.1
.................... delay_ms(100);
0251: MOVLW 64
0252: MOVWF 6F
0253: CALL 048
.................... if (4==n++) {cvak(); n=0;}; // Kazdy 4. pruchod cvakni
0254: MOVF 6A,W
0255: INCF 6A,F
0256: SUBLW 04
0257: BTFSS 03.2
0258: GOTO 25B
0259: GOTO 05E
025A: CLRF 6A
.................... output_high(REFPWR); // Zapni napajeni napetove reference
025B: BSF 03.5
025C: BCF 06.1
025D: BCF 03.5
025E: BSF 06.1
.................... delay_ms(1); // Pockej na ustaleni napeti
025F: MOVLW 01
0260: MOVWF 6F
0261: CALL 048
.................... } while (read_adc()>REFSTART); // Odkryl starter clanky?
0262: BSF 1F.2
0263: BTFSC 1F.2
0264: GOTO 263
0265: MOVF 1E,W
0266: SUBLW 5F
0267: BTFSS 03.0
0268: GOTO 24D
.................... output_low(REFPWR); // Vypni napajeni napetove reference, aby se setrilo
0269: BSF 03.5
026A: BCF 06.1
026B: BCF 03.5
026C: BCF 06.1
....................
.................... // port_b_pullups(TRUE); // Zapni pullupy, aby slo cist DIPswitch
.................... // do
.................... // {
.................... // Precti trimry
.................... set_adc_channel(PWM); // Zjisteni nastaveni PWM
026D: MOVLW 00
026E: MOVWF 78
026F: MOVF 1F,W
0270: ANDLW C7
0271: IORWF 78,W
0272: MOVWF 1F
.................... delay_us(100); // Pockej na prepnuti kanalu A/D prevodniku
0273: CLRWDT
0274: MOVLW 1F
0275: MOVWF 77
0276: DECFSZ 77,F
0277: GOTO 276
0278: NOP
0279: NOP
.................... perioda=(read_adc()>>1)+40; // rozsah: 40 az 167
027A: BSF 1F.2
027B: BTFSC 1F.2
027C: GOTO 27B
027D: MOVF 1E,W
027E: MOVWF 77
027F: BCF 03.0
0280: RRF 77,F
0281: MOVF 77,W
0282: ADDLW 28
0283: MOVWF 6B
....................
.................... set_adc_channel(ROZJEZD); // Zjisteni nastaveni rozjezdu
0284: MOVLW 08
0285: MOVWF 78
0286: MOVF 1F,W
0287: ANDLW C7
0288: IORWF 78,W
0289: MOVWF 1F
.................... delay_us(100); // Pockej na prepnuti kanalu A/D prevodniku
028A: CLRWDT
028B: MOVLW 1F
028C: MOVWF 77
028D: DECFSZ 77,F
028E: GOTO 28D
028F: NOP
0290: NOP
.................... razeni=read_adc()>>1; // rozsah: 0 az 127
0291: BSF 1F.2
0292: BTFSC 1F.2
0293: GOTO 292
0294: BCF 03.0
0295: RRF 1E,W
0296: MOVWF 6C
....................
.................... // Rozjeti menice
.................... set_pwm1_duty(0); // Zastav PWM, aby slo nastavit jinou frekvenci
0297: CLRF 15
.................... setup_timer_2(T2_DIV_BY_1,perioda,1); // perioda
0298: MOVLW 00
0299: MOVWF 78
029A: IORLW 04
029B: MOVWF 12
029C: MOVF 6B,W
029D: BSF 03.5
029E: MOVWF 12
.................... set_pwm1_duty(DUTY2); // PWM pro zatizeni clanku pri jedne 500W zarovce
029F: MOVLW 13
02A0: BCF 03.5
02A1: MOVWF 15
....................
.................... pip(); // potvrzeni odstartovani / servisni mod
02A2: GOTO 06B
.................... delay_ms(500);
02A3: MOVLW 02
02A4: MOVWF 6E
02A5: MOVLW FA
02A6: MOVWF 6F
02A7: CALL 048
02A8: DECFSZ 6E,F
02A9: GOTO 2A5
....................
.................... // } while (input(SW1)); // Je zapnut servisni mod? SW1(OFF)=ANO
.................... // port_b_pullups(FALSE); // Vypni pullupy, aby se setrilo energii
....................
.................... // Regulace nabíjení
.................... output_high(REFPWR); // Prepni AD na mereni napeti clanku
02AA: BSF 03.5
02AB: BCF 06.1
02AC: BCF 03.5
02AD: BSF 06.1
.................... set_adc_channel(NAPETI); // Prepni Zmer napeti clanku
02AE: MOVLW 20
02AF: MOVWF 78
02B0: MOVF 1F,W
02B1: ANDLW C7
02B2: IORWF 78,W
02B3: MOVWF 1F
.................... delay_us(50); // Pockej na prepnuti kanalu A/D prevodniku
02B4: CLRWDT
02B5: MOVLW 0F
02B6: MOVWF 77
02B7: DECFSZ 77,F
02B8: GOTO 2B7
02B9: NOP
.................... for(n=1;n<=10;n++)
02BA: MOVLW 01
02BB: MOVWF 6A
02BC: MOVF 6A,W
02BD: SUBLW 0A
02BE: BTFSS 03.0
02BF: GOTO 2DC
.................... {
.................... // Zmer napeti (aktualni zatizeni clanku)
.................... uclanku=read_adc();
02C0: BSF 1F.2
02C1: BTFSC 1F.2
02C2: GOTO 2C1
02C3: MOVF 1E,W
02C4: MOVWF 6D
.................... // Uprav parametry menice
.................... if (uclanku>105)
02C5: MOVF 6D,W
02C6: SUBLW 69
02C7: BTFSC 03.0
02C8: GOTO 2CB
.................... {
.................... perioda++;
02C9: INCF 6B,F
.................... }
.................... else
02CA: GOTO 2CC
.................... {
.................... perioda--;
02CB: DECF 6B,F
.................... }
.................... set_pwm1_duty(0); // Zastav PWM, aby slo nastavit jinou frekvenci
02CC: CLRF 15
.................... setup_timer_2(T2_DIV_BY_1,perioda,1); // perioda
02CD: MOVLW 00
02CE: MOVWF 78
02CF: IORLW 04
02D0: MOVWF 12
02D1: MOVF 6B,W
02D2: BSF 03.5
02D3: MOVWF 12
.................... set_pwm1_duty(DUTY2); // PWM pro zatizeni clanku pri jedne 500W zarovce
02D4: MOVLW 13
02D5: BCF 03.5
02D6: MOVWF 15
.................... delay_ms(100);
02D7: MOVLW 64
02D8: MOVWF 6F
02D9: CALL 048
.................... }
02DA: INCF 6A,F
02DB: GOTO 2BC
.................... output_low(REFPWR);
02DC: BSF 03.5
02DD: BCF 06.1
02DE: BCF 03.5
02DF: BCF 06.1
.................... // posli telemetrii
.................... sprintf(AXstring,"p=%u r=%u u=%u", perioda, razeni, uclanku); // Convert DATA to String.
*
01E1: CLRF 69
*
02E0: MOVLW 40
02E1: MOVWF 69
02E2: MOVLW 70
02E3: MOVWF 70
02E4: CALL 095
02E5: MOVLW 3D
02E6: MOVWF 70
02E7: CALL 095
02E8: MOVF 6B,W
02E9: MOVWF 6E
02EA: MOVLW 1B
02EB: MOVWF 6F
02EC: CALL 0B2
02ED: MOVLW 20
02EE: MOVWF 70
02EF: CALL 095
02F0: MOVLW 72
02F1: MOVWF 70
02F2: CALL 095
02F3: MOVLW 3D
02F4: MOVWF 70
02F5: CALL 095
02F6: MOVF 6C,W
02F7: MOVWF 6E
02F8: MOVLW 1B
02F9: MOVWF 6F
02FA: CALL 0B2
02FB: MOVLW 20
02FC: MOVWF 70
02FD: CALL 095
02FE: MOVLW 75
02FF: MOVWF 70
0300: CALL 095
0301: MOVLW 3D
0302: MOVWF 70
0303: CALL 095
0304: MOVF 6D,W
0305: MOVWF 6E
0306: MOVLW 1B
0307: MOVWF 6F
0308: CALL 0B2
.................... SendPacket(&AXstring[0]);
0309: MOVLW 40
030A: MOVWF 6E
030B: GOTO 177
....................
.................... delay_ms(13000); // Pockame 14s
030C: MOVLW 34
030D: MOVWF 6E
030E: MOVLW FA
030F: MOVWF 6F
0310: CALL 048
0311: DECFSZ 6E,F
0312: GOTO 30E
....................
.................... // rozjezd
.................... SSPSTAT = 0; // inicializace SPI jednotky
0313: BSF 03.5
0314: CLRF 14
.................... SSPCON1 = 0x22; // SPI OSC/64
0315: MOVLW 22
0316: BCF 03.5
0317: MOVWF 14
.................... MotorPattern=0x02; // prvni data pro vyslani
0318: MOVLW 02
0319: MOVWF 68
.................... SSPBUF=MotorPattern;
031A: MOVF 68,W
031B: MOVWF 13
.................... enable_interrupts(global);
031C: MOVLW C0
031D: IORWF 0B,F
.................... enable_interrupts(INT_SSP); // az budou vyslana, prijde interrupt od SSP
031E: BSF 03.5
031F: BSF 0C.3
....................
.................... for(n=0; n<=7; n++) // razeni osmi rychlostnich stupnu
0320: BCF 03.5
0321: CLRF 6A
0322: MOVF 6A,W
0323: SUBLW 07
0324: BTFSS 03.0
0325: GOTO 32F
.................... {
.................... MotorPattern=Pattern[n];
0326: MOVF 6A,W
0327: CALL 037
0328: MOVWF 78
0329: MOVWF 68
.................... delay_ms(razeni); // Pockej na dalsi razeni
032A: MOVF 6C,W
032B: MOVWF 6F
032C: CALL 048
.................... };
032D: INCF 6A,F
032E: GOTO 322
.................... SSPSTAT = 0;
032F: BSF 03.5
0330: CLRF 14
.................... SSPCON1 = 0; // SPI stop
0331: BCF 03.5
0332: CLRF 14
.................... disable_interrupts(INT_SSP); // zastav preruseni od SSP
0333: BSF 03.5
0334: BCF 0C.3
....................
.................... // jedem co to da
.................... output_high(MOTOR);
0335: BCF 06.2
0336: BCF 03.5
0337: BSF 06.2
....................
.................... /*
.................... if (TRUE) // Venkovni jizda?
.................... {
.................... delay_ms(5000); // Venku muzeme jet 5s
.................... set_pwm1_duty(0); // Zastav menic
.................... // output_low(MOTOR); // Zastav motor
.................... while(TRUE) restart_wdt(); // Cekej porad
.................... };
.................... delay_ms(3000);
.................... */
.................... delay_ms(1300); // Nemeli bysme jet dele nez 1,3s :-)
0338: MOVLW 0A
0339: MOVWF 6E
033A: MOVLW 82
033B: MOVWF 6F
033C: CALL 048
033D: DECFSZ 6E,F
033E: GOTO 33A
.................... output_low(MOTOR); // Zastav motor
033F: BSF 03.5
0340: BCF 06.2
0341: BCF 03.5
0342: BCF 06.2
.................... // Menic je stale zapnut a zatezuje clanky
....................
.................... while(TRUE); // Cekej, dokud se neztrati svetlo,
0343: GOTO 343
.................... // nebo prijde WatchDog
....................
.................... }
0344: SLEEP
 
Configuration Fuses:
Word 1: 273C WDT NOPUT MCLR NOBROWNOUT NOLVP NOCPD NOWRT DEBUG CCPB3 NOPROTECT INTRC_IO
Word 2: 3FFC NOFCMEN NOIESO
/roboti/solarni/2006/scamnum_specularis/menic.PJT
0,0 → 1,56
[PROJECT]
Target=menic.HEX
Development_Mode=
Processor=0x688F
ToolSuite=CCS
 
[Directories]
Include=C:\Program Files\PICC\devices\
Library=
LinkerScript=
 
[Target Data]
FileList=D:\KAKL\roboti\solarni\2006\scamnum\menic.c
BuildTool=C-COMPILER
OptionString=+FM
AdditionalOptionString=
BuildRequired=1
 
[menic.c]
Type=4
Path=
FileList=
BuildTool=
OptionString=
AdditionalOptionString=
 
[mru-list]
1=menic.c
 
[Windows]
0=0000 menic.c 0 0 796 451 3 0
 
[Opened Files]
1=D:\KAKL\roboti\solarni\2006\scamnum\menic.c
2=D:\KAKL\roboti\solarni\2006\scamnum\menic.h
3=C:\Program Files\PICC\devices\16F88.h
4=D:\KAKL\roboti\solarni\2006\scamnum\AX25.c
5=
[debugperif]
selected=Analog/Digital Conv
[debugram]
autoread=1
[debugeedata]
autoread=1
[debugbreak]
count=0
[pcwdebug]
watchcol0=75
[debugwatch]
count=0
[debugexpr]
expr=
sideeffects=0
[Units]
Count=1
1=D:\KAKL\roboti\solarni\2006\scamnum\menic.c (main)
/roboti/solarni/2006/scamnum_specularis/menic.SYM
0,0 → 1,100
003 STATUS
013 SSPBUF
014 SSPCON1
015-016 CCP_1
015 CCP_1_LOW
016 CCP_1_HIGH
020 @INTERRUPT_AREA
021 @INTERRUPT_AREA
022 @INTERRUPT_AREA
023 @INTERRUPT_AREA
024 @INTERRUPT_AREA
025 @INTERRUPT_AREA
026 @INTERRUPT_AREA
027 @INTERRUPT_AREA
028 @INTERRUPT_AREA
029-038 SendData
039.0 bit
03A fcslo
03B fcshi
03C stuff
03D flag_flag
03E fcs_flag
03F i
040-067 AXstring
068 MotorPattern
069 @sprintf_string
06A main.n
06B main.perioda
06C main.razeni
06D main.uclanku
06E SendPacket.data
06E @PRINTF_U_324.P1
06E.0 pip.beep
06E main.@SCRATCH
06F pip.i
06F @PRINTF_U_324.P1
06F @delay_ms1.P2
06F SendPacket.@SCRATCH
06F main.@SCRATCH
070 @DIV88.P1
070 @SPRINTF.P2
070 SendByte.inbyte
071 SendByte.k
071 @DIV88.P1
072 SendByte.bt
072 @DIV88.@SCRATCH
073 fcsbit.tbyte
073 SendByte.@SCRATCH
074 fcsbit.@SCRATCH
075 fcsbit.@SCRATCH
077 @SCRATCH
078 @SCRATCH
078 _RETURN_
079 @SCRATCH
07A @SCRATCH
07B @SCRATCH
094 SSPSTAT
09C.6 C1OUT
09C.7 C2OUT
 
0048 @delay_ms1
00E7 flipout
0149 fcsbit
00EE SendBit
012E SendByte
0177 SendPacket
0037 @const57
0043 IntSSP
006B pip
005E cvak
01BA main
0095 @SPRINTF
009D @DIV88
00B2 @PRINTF_U_324
01BA @cinit
 
Project Files:
D:\KAKL\roboti\solarni\2006\scamnum\menic.c
D:\KAKL\roboti\solarni\2006\scamnum\menic.h
C:\Program Files\PICC\devices\16F88.h
D:\KAKL\roboti\solarni\2006\scamnum\AX25.c
 
Units:
D:\KAKL\roboti\solarni\2006\scamnum\menic.c (main)
 
Compiler Settings:
Processor: PIC16F88
Pointer Size: 8
ADC Range: 0-255
Opt Level: 9
Short,Int,Long: 1,8,16
 
Output Files:
Errors: D:\KAKL\roboti\solarni\2006\scamnum\menic.err
INHX8: D:\KAKL\roboti\solarni\2006\scamnum\menic.hex
Symbols: D:\KAKL\roboti\solarni\2006\scamnum\menic.sym
List: D:\KAKL\roboti\solarni\2006\scamnum\menic.lst
Debug/COFF: D:\KAKL\roboti\solarni\2006\scamnum\menic.cof
Call Tree: D:\KAKL\roboti\solarni\2006\scamnum\menic.tre
Statistics: D:\KAKL\roboti\solarni\2006\scamnum\menic.sta
/roboti/solarni/2006/scamnum_specularis/menic.c
0,0 → 1,200
// *************************************
// * Scamnum Specularis ** 20. 9. 2006 *
// *************************************
 
#include ".\menic.h"
 
#define TXo PIN_B5 // To the transmitter modulator
#include ".\AX25.c" // Podprogram pro prenos telemetrie
char AXstring[40]; // Buffer pro prenos telemetrie
 
#define REFSTART 95 // Hodnota odpovidajici 1,2V pri nezatizenych clancich
#define DUTY1 2 // Delka sepnuti PWM v us pro sero
#define DUTY2 19 // Delka sepnuti PWM v us pro jednu zarovku 500W
 
// Tabulka hodnot prevodniku pro ruzna napajeci napeti
// 80 3,99V
// 90 3,54V
// 100 3,20V
// 105 3,04V
// 107 2,99V
// 110 2,91v
// 200 1,61V
 
#define PIEZO PIN_A6 // Jeden pol piezo reproduktoru
#define LED PIN_A7 // LED / druhy pol piezo reproduktoru
#define MENIC PIN_B3 // Spinani tranzistoru menice
#define REFPWR PIN_B1 // Napajeni zdroje referencniho napeti
#define MOTOR PIN_B2 // Spinani tranzistoru motoru
#define SW1 PIN_B6 // DIPswitch 1
#define SW2 PIN_B7 // DIPswitch 2
#define NAPETI 4 // Cislo kanalu DA prevodniku pro mereni napeti
#define PWM 0 // Cislo kanalu DA prevodniku pro nastaveni PWM
#define ROZJEZD 1 // Cislo kanalu DA prevodniku pro nastaveni rozjezdu
 
#byte SSPBUF = 0x13 // Adresy registru jednotky SSP
#byte SSPCON1 = 0x14
#byte SSPSTAT = 0x94
 
// Vzorky pro generovani PWM pomoci SSP
unsigned int8 const Pattern[8] = {0x02,0x06,0x0e,0x1e,0x3e,0x7e,0xfe,0xff};
unsigned int8 MotorPattern;
 
#INT_SSP
void IntSSP()
{
SSPBUF=MotorPattern; // znovu vysli stejnou hodnotu
}
 
void pip() // pipnuti a bliknuti
{
int1 beep;
int i;
 
for(i=0; i<250; i++)
{
output_bit(PIEZO, beep);
beep=~beep;
output_bit(LED, beep);
delay_us(100);
};
output_high(PIEZO);
output_high(LED);
}
 
void cvak() // pouze cvaknuti piezoelementem bez bliknuti
{
output_bit(PIEZO,~input(PIEZO));
}
 
void main()
{
int8 n;
int8 perioda;
int8 razeni;
int8 uclanku;
 
setup_timer_0(RTCC_INTERNAL);setup_wdt(WDT_1152MS);
setup_timer_1(T1_DISABLED);
setup_adc_ports(ADC_CLOCK_INTERNAL|sAN0|sAN1|sAN4|VSS_VDD);
setup_adc(ADC_CLOCK_INTERNAL);
setup_spi(FALSE);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
 
output_low(MENIC); // Vsechno zastav
output_low(MOTOR);
output_low(REFPWR);
output_high(LED);
output_high(PIEZO);
 
set_adc_channel(NAPETI); // Vyber AD kanal pro pomerne mereni napeti
set_pwm1_duty(0); // Spust PWM, ale zatim s trvalou 0 na vystupu
setup_ccp1(CCP_PWM);
setup_timer_2(T2_DIV_BY_1,100,1); // perioda
 
setup_oscillator(OSC_4MHZ|OSC_INTRC); // rozjed PIC (zvysi se odber)
 
// jsme v depu?
set_pwm1_duty(DUTY1); // PWM pro zatizeni clanku pri malem osvetleni
n=0;
do
{
output_low(REFPWR); // Vypni napajeni napetove reference, aby se setrilo
delay_ms(100);
if (4==n++) {cvak(); n=0;}; // Kazdy 4. pruchod cvakni
output_high(REFPWR); // Zapni napajeni napetove reference
delay_ms(1); // Pockej na ustaleni napeti
} while (read_adc()>REFSTART); // Odkryl starter clanky?
output_low(REFPWR); // Vypni napajeni napetove reference, aby se setrilo
 
// port_b_pullups(TRUE); // Zapni pullupy, aby slo cist DIPswitch
// do
// {
// Precti trimry
set_adc_channel(PWM); // Zjisteni nastaveni PWM
delay_us(100); // Pockej na prepnuti kanalu A/D prevodniku
perioda=(read_adc()>>1)+40; // rozsah: 40 az 167
 
set_adc_channel(ROZJEZD); // Zjisteni nastaveni rozjezdu
delay_us(100); // Pockej na prepnuti kanalu A/D prevodniku
razeni=read_adc()>>1; // rozsah: 0 az 127
 
// Rozjeti menice
set_pwm1_duty(0); // Zastav PWM, aby slo nastavit jinou frekvenci
setup_timer_2(T2_DIV_BY_1,perioda,1); // perioda
set_pwm1_duty(DUTY2); // PWM pro zatizeni clanku pri jedne 500W zarovce
 
pip(); // potvrzeni odstartovani / servisni mod
delay_ms(500);
 
// } while (input(SW1)); // Je zapnut servisni mod? SW1(OFF)=ANO
// port_b_pullups(FALSE); // Vypni pullupy, aby se setrilo energii
 
// Regulace nabíjení
output_high(REFPWR); // Prepni AD na mereni napeti clanku
set_adc_channel(NAPETI); // Prepni Zmer napeti clanku
delay_us(50); // Pockej na prepnuti kanalu A/D prevodniku
for(n=1;n<=10;n++)
{
// Zmer napeti (aktualni zatizeni clanku)
uclanku=read_adc();
// Uprav parametry menice
if (uclanku>105)
{
perioda++;
}
else
{
perioda--;
}
set_pwm1_duty(0); // Zastav PWM, aby slo nastavit jinou frekvenci
setup_timer_2(T2_DIV_BY_1,perioda,1); // perioda
set_pwm1_duty(DUTY2); // PWM pro zatizeni clanku pri jedne 500W zarovce
delay_ms(100);
}
output_low(REFPWR);
// posli telemetrii
sprintf(AXstring,"p=%u r=%u u=%u", perioda, razeni, uclanku); // Convert DATA to String.
SendPacket(&AXstring[0]);
 
delay_ms(13000); // Pockame 14s
 
// rozjezd
SSPSTAT = 0; // inicializace SPI jednotky
SSPCON1 = 0x22; // SPI OSC/64
MotorPattern=0x02; // prvni data pro vyslani
SSPBUF=MotorPattern;
enable_interrupts(global);
enable_interrupts(INT_SSP); // az budou vyslana, prijde interrupt od SSP
 
for(n=0; n<=7; n++) // razeni osmi rychlostnich stupnu
{
MotorPattern=Pattern[n];
delay_ms(razeni); // Pockej na dalsi razeni
};
SSPSTAT = 0;
SSPCON1 = 0; // SPI stop
disable_interrupts(INT_SSP); // zastav preruseni od SSP
 
// jedem co to da
output_high(MOTOR);
 
/*
if (TRUE) // Venkovni jizda?
{
delay_ms(5000); // Venku muzeme jet 5s
set_pwm1_duty(0); // Zastav menic
// output_low(MOTOR); // Zastav motor
while(TRUE) restart_wdt(); // Cekej porad
};
delay_ms(3000);
*/
delay_ms(1300); // Nemeli bysme jet dele nez 1,3s :-)
output_low(MOTOR); // Zastav motor
// Menic je stale zapnut a zatezuje clanky
 
while(TRUE); // Cekej, dokud se neztrati svetlo,
// nebo prijde WatchDog
 
}
/roboti/solarni/2006/scamnum_specularis/menic.cof
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/roboti/solarni/2006/scamnum_specularis/menic.err
0,0 → 1,2
No Errors
0 Errors, 0 Warnings.
/roboti/solarni/2006/scamnum_specularis/menic.h
0,0 → 1,9
#include <16F88.h>
 
#device adc=8
 
#fuses WDT,INTRC_IO, NOPUT, MCLR, NOBROWNOUT, NOLVP, NOCPD, \
NOWRT, DEBUG, NOPROTECT, NOFCMEN, NOIESO, CCPB3
 
#use delay(clock=3900000,RESTART_WDT)
 
/roboti/solarni/2006/scamnum_specularis/menic.sta
0,0 → 1,42
 
ROM used: 837 (20%)
837 (20%) including unused fragments
 
1 Average locations per line
5 Average locations per statement
 
RAM used: 85 (49%) at main() level
91 (52%) worst case
 
Lines Stmts % Files
----- ----- --- -----
201 92 58 D:\KAKL\roboti\solarni\2006\scamnum\menic.c
10 0 0 D:\KAKL\roboti\solarni\2006\scamnum\menic.h
279 0 0 C:\Program Files\PICC\devices\16F88.h
140 67 27 D:\KAKL\roboti\solarni\2006\scamnum\AX25.c
----- -----
1260 318 Total
 
Page ROM % RAM Functions:
---- --- --- --- ----------
0 22 3 1 @delay_ms1
0 7 1 0 flipout
0 64 8 0 SendBit
0 73 9 4 SendByte
0 67 8 2 SendPacket
0 12 1 0 @const57
0 5 1 0 IntSSP
0 42 5 2 pip
0 13 2 0 cvak
0 395 47 6 main
0 8 1 1 @SPRINTF
0 21 3 3 @DIV88
0 53 6 2 @PRINTF_U_324
 
Segment Used Free
--------- ---- ----
00000-00003 4 0
00004-00036 51 0
00037-007FF 782 1211
00800-00FFF 0 2048
 
/roboti/solarni/2006/scamnum_specularis/menic.tre
0,0 → 1,77
ÀÄmenic
ÃÄmain 0/395 Ram=6
³ ÃÄ??0??
³ ÃÄ@delay_ms1 0/22 Ram=1
³ ÃÄcvak 0/13 Ram=0
³ ÃÄ@delay_ms1 0/22 Ram=1
³ ÃÄpip 0/42 Ram=2
³ ÃÄ@delay_ms1 0/22 Ram=1
³ ÃÄ@delay_ms1 0/22 Ram=1
³ ÃÄ@SPRINTF 0/8 Ram=1
³ ÃÄ@SPRINTF 0/8 Ram=1
³ ÃÄ@PRINTF_U_324 0/53 Ram=2
³ ³ ÃÄ@DIV88 0/21 Ram=3
³ ³ ÃÄ@SPRINTF 0/8 Ram=1
³ ³ ÃÄ@DIV88 0/21 Ram=3
³ ³ ÃÄ@SPRINTF 0/8 Ram=1
³ ³ ÀÄ@SPRINTF 0/8 Ram=1
³ ÃÄ@SPRINTF 0/8 Ram=1
³ ÃÄ@SPRINTF 0/8 Ram=1
³ ÃÄ@SPRINTF 0/8 Ram=1
³ ÃÄ@PRINTF_U_324 0/53 Ram=2
³ ³ ÃÄ@DIV88 0/21 Ram=3
³ ³ ÃÄ@SPRINTF 0/8 Ram=1
³ ³ ÃÄ@DIV88 0/21 Ram=3
³ ³ ÃÄ@SPRINTF 0/8 Ram=1
³ ³ ÀÄ@SPRINTF 0/8 Ram=1
³ ÃÄ@SPRINTF 0/8 Ram=1
³ ÃÄ@SPRINTF 0/8 Ram=1
³ ÃÄ@SPRINTF 0/8 Ram=1
³ ÃÄ@PRINTF_U_324 0/53 Ram=2
³ ³ ÃÄ@DIV88 0/21 Ram=3
³ ³ ÃÄ@SPRINTF 0/8 Ram=1
³ ³ ÃÄ@DIV88 0/21 Ram=3
³ ³ ÃÄ@SPRINTF 0/8 Ram=1
³ ³ ÀÄ@SPRINTF 0/8 Ram=1
³ ÃÄSendPacket 0/67 Ram=2
³ ³ ÃÄSendByte 0/73 Ram=4
³ ³ ³ ÃÄfcsbit (Inline) Ram=3
³ ³ ³ ÃÄflipout 0/7 Ram=0
³ ³ ³ ÃÄSendBit 0/64 Ram=0
³ ³ ³ ÃÄflipout 0/7 Ram=0
³ ³ ³ ÀÄSendBit 0/64 Ram=0
³ ³ ÃÄSendByte 0/73 Ram=4
³ ³ ³ ÃÄfcsbit (Inline) Ram=3
³ ³ ³ ÃÄflipout 0/7 Ram=0
³ ³ ³ ÃÄSendBit 0/64 Ram=0
³ ³ ³ ÃÄflipout 0/7 Ram=0
³ ³ ³ ÀÄSendBit 0/64 Ram=0
³ ³ ÃÄSendByte 0/73 Ram=4
³ ³ ³ ÃÄfcsbit (Inline) Ram=3
³ ³ ³ ÃÄflipout 0/7 Ram=0
³ ³ ³ ÃÄSendBit 0/64 Ram=0
³ ³ ³ ÃÄflipout 0/7 Ram=0
³ ³ ³ ÀÄSendBit 0/64 Ram=0
³ ³ ÃÄSendByte 0/73 Ram=4
³ ³ ³ ÃÄfcsbit (Inline) Ram=3
³ ³ ³ ÃÄflipout 0/7 Ram=0
³ ³ ³ ÃÄSendBit 0/64 Ram=0
³ ³ ³ ÃÄflipout 0/7 Ram=0
³ ³ ³ ÀÄSendBit 0/64 Ram=0
³ ³ ÃÄSendByte 0/73 Ram=4
³ ³ ³ ÃÄfcsbit (Inline) Ram=3
³ ³ ³ ÃÄflipout 0/7 Ram=0
³ ³ ³ ÃÄSendBit 0/64 Ram=0
³ ³ ³ ÃÄflipout 0/7 Ram=0
³ ³ ³ ÀÄSendBit 0/64 Ram=0
³ ³ ÀÄSendByte 0/73 Ram=4
³ ³ ÃÄfcsbit (Inline) Ram=3
³ ³ ÃÄflipout 0/7 Ram=0
³ ³ ÃÄSendBit 0/64 Ram=0
³ ³ ÃÄflipout 0/7 Ram=0
³ ³ ÀÄSendBit 0/64 Ram=0
³ ÃÄ@delay_ms1 0/22 Ram=1
³ ÃÄ@const57 0/12 Ram=0
³ ÃÄ@delay_ms1 0/22 Ram=1
³ ÀÄ@delay_ms1 0/22 Ram=1
ÀÄIntSSP 0/5 Ram=0