Rev Author Line No. Line
417 kakl 1 //#define PTT PIN_A2 // PTT control
2 //#define TXo PIN_C0 // To the transmitter modulator
3 #define PERIODAH delay_us(222) // Halfperiod H 222;78/1200 500;430/500
4 #define TAILH delay_us(78)
5 #define PERIODAL delay_us(412) // Halfperiod L 412;345/1200 1000;880/500
6 #define TAILL delay_us(345)
7 #byte STATUS = 3 // CPUs status register
8  
9 byte SendData[16] = {'A'<<1, 'L'<<1, 'L'<<1, ' '<<1, ' '<<1, ' '<<1, 0x60,
10 'C'<<1, 'Z'<<1, '0'<<1, 'R'<<1, 'R'<<1, 'R'<<1, 0x61,
11 0x03, 0xF0};
12  
13 boolean bit;
14 int fcslo, fcshi; // variabloes for calculating FCS (CRC)
15 int stuff; // stuff counter for extra 0
16 int flag_flag; // if it is sending flag (7E)
17 int fcs_flag; // if it is sending Frame Check Sequence
18  
19 void flipout() //flips the state of output pin a_1
20 {
21 stuff = 0; //since this is a 0, reset the stuff counter
22 if (bit)
23 {
24 bit=FALSE; //if the state of the pin was low, make it high.
25 }
26 else
27 {
28 bit=TRUE; //if the state of the pin was high make it low
29 }
30 }
31  
32 void fcsbit(byte tbyte)
33 {
34 #asm
35 BCF STATUS,0
36 RRF fcshi,F // rotates the entire 16 bits
37 RRF fcslo,F // to the right
38 #endasm
39 if (((STATUS & 0x01)^(tbyte)) ==0x01)
40 {
41 fcshi = fcshi^0x84;
42 fcslo = fcslo^0x08;
43 }
44 }
45  
46 void SendBit ()
47 {
48 if (bit)
49 {
50 output_high(TXo);
51 PERIODAH;
52 output_low(TXo);
53 PERIODAH;
54 output_high(TXo);
55 PERIODAH;
56 output_low(TXo);
57 TAILH;
58 }
59 else
60 {
61 output_high(TXo);
62 PERIODAL;
63 output_low(TXo);
64 TAILL;
65 };
66 }
67  
68 void SendByte (byte inbyte)
69 {
70 int k, bt;
71  
72 for (k=0;k<8;k++) //do the following for each of the 8 bits in the byte
73 {
74 bt = inbyte & 0x01; //strip off the rightmost bit of the byte to be sent (inbyte)
75 if ((fcs_flag == FALSE) & (flag_flag == FALSE)) fcsbit(bt); //do FCS calc, but only if this
76 //is not a flag or fcs byte
77 if (bt == 0)
78 {
79 flipout();
80 } // if this bit is a zero, flip the output state
81 else
82 { //otherwise if it is a 1, do the following:
83 if (flag_flag == FALSE) stuff++; //increment the count of consequtive 1's
84 if ((flag_flag == FALSE) & (stuff == 5))
85 { //stuff an extra 0, if 5 1's in a row
86 SendBit();
87 flipout(); //flip the output state to stuff a 0
88 }//end of if
89 }//end of else
90 // delay_us(850); //introduces a delay that creates 1200 baud
91 SendBit();
92 inbyte = inbyte>>1; //go to the next bit in the byte
93 }//end of for
94 }//end of SendByte
95  
96 void SendPacket(char *data)
97 {
98 int ii; // for for
99  
100 bit=FALSE;
101  
102 fcslo=fcshi=0xFF; //The 2 FCS Bytes are initialized to FF
103 stuff = 0; //The variable stuff counts the number of 1's in a row. When it gets to 5
104 // it is time to stuff a 0.
105  
106 // output_low(PTT); // Blinking LED
107 // delay_ms(1000);
108 // output_high(PTT);
109  
110 flag_flag = TRUE; //The variable flag is true if you are transmitted flags (7E's) false otherwise.
111 fcs_flag = FALSE; //The variable fcsflag is true if you are transmitting FCS bytes, false otherwise.
112  
113 for(ii=0; ii<10; ii++) SendByte(0x7E); //Sends flag bytes. Adjust length for txdelay
114 //each flag takes approx 6.7 ms
115 flag_flag = FALSE; //done sending flags
116  
117 for(ii=0; ii<16; ii++) SendByte(SendData[ii]); //send the packet bytes
118  
119 for(ii=0; 0 != *data; ii++)
120 {
121 SendByte(*data); //send the packet bytes
122 data++;
123 };
124  
125 fcs_flag = TRUE; //about to send the FCS bytes
126 fcslo =fcslo^0xff; //must XOR them with FF before sending
127 fcshi = fcshi^0xff;
128 SendByte(fcslo); //send the low byte of fcs
129 SendByte(fcshi); //send the high byte of fcs
130 fcs_flag = FALSE; //done sending FCS
131 flag_flag = TRUE; //about to send flags
132 SendByte(0x7e); // Send a flag to end packet
133 }
134  
135  
136