Subversion Repositories svnkaklik

Rev

Details | Last modification | View Log

Rev Author Line No. Line
2 kaklik 1
#nolist
2
//#define  PTT PIN_A2                 // PTT control
3
//#define  TXo PIN_C0                 // To the transmitter modulator
4
#define  PERIODAH delay_us(222)     // Halfperiod H 222;78/1200     500;430/500
5
#define  TAILH delay_us(78)
6
#define  PERIODAL delay_us(412)     // Halfperiod L 412;345/1200    1000;880/500
7
#define  TAILL delay_us(345)
8
#byte    STATUS = 3                 // CPUs status register
9
 
10
byte SendData[16] = {'A'<<1, 'L'<<1, 'L'<<1, ' '<<1, ' '<<1, ' '<<1,  0x60,
11
                     'C'<<1, 'Z'<<1, '0'<<1, 'R'<<1, 'R'<<1, 'R'<<1, 0x61,
12
                     0x03, 0xF0};
13
 
14
boolean bit;
15
int fcslo, fcshi;    // variabloes for calculating FCS (CRC)
16
int stuff;           // stuff counter for extra 0
17
int flag_flag;       // if it is sending flag (7E)
18
int fcs_flag;        // if it is sending Frame Check Sequence
19
int i;               // for for
20
 
21
void flipout()       //flips the state of output pin a_1
22
{
23
	stuff = 0;        //since this is a 0, reset the stuff counter
24
	if (bit)
25
   {
26
     bit=FALSE;      //if the state of the pin was low, make it high.
27
   }
28
   else
29
   {
30
     bit=TRUE;	  	   //if the state of the pin was high make it low
31
   }
32
}
33
 
34
void fcsbit(byte tbyte)
35
{
36
#asm
37
   BCF    STATUS,0
38
   RRF    fcshi,F             // rotates the entire 16 bits
39
   RRF    fcslo,F			      // to the right
40
#endasm
41
   if (((STATUS & 0x01)^(tbyte)) ==0x01)
42
   {
43
         fcshi = fcshi^0x84;
44
         fcslo = fcslo^0x08;
45
   }
46
}
47
 
48
void SendBit ()
49
{
50
	if (bit)
51
   {
52
      output_high(TXo);
53
      PERIODAH;
54
      output_low(TXo);
55
      PERIODAH;
56
      output_high(TXo);
57
      PERIODAH;
58
      output_low(TXo);
59
      TAILH;
60
    }
61
    else
62
    {
63
      output_high(TXo);
64
      PERIODAL;
65
      output_low(TXo);
66
      TAILL;
67
    };
68
}
69
 
70
void SendByte (byte inbyte)
71
{
72
   int k, bt;
73
 
74
   for (k=0;k<8;k++)    //do the following for each of the 8 bits in the byte
75
   {
76
     bt = inbyte & 0x01;            //strip off the rightmost bit of the byte to be sent (inbyte)
77
     if ((fcs_flag == FALSE) & (flag_flag == FALSE)) fcsbit(bt);    //do FCS calc, but only if this
78
						                                                //is not a flag or fcs byte
79
     if (bt == 0)
80
     {
81
       flipout();
82
     }  			               // if this bit is a zero, flip the output state
83
     else
84
     {                          			      //otherwise if it is a 1, do the following:
85
       if (flag_flag == FALSE) stuff++;      //increment the count of consequtive 1's
86
       if ((flag_flag == FALSE) & (stuff == 5))
87
       {       //stuff an extra 0, if 5 1's in a row
88
         SendBit();
89
         flipout();               //flip the output state to stuff a 0
90
       }//end of if
91
     }//end of else
92
     // delay_us(850);				 //introduces a delay that creates 1200 baud
93
     SendBit();
94
     inbyte = inbyte>>1;          //go to the next bit in the byte
95
   }//end of for
96
}//end of SendByte
97
 
98
void SendPacket(char *data)
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(i=0; i<10; i++) 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(i=0; i<16; i++) SendByte(SendData[i]);      //send the packet bytes
118
 
119
   for(i=0; 0 != *data; i++)
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
#list