Subversion Repositories svnkaklik

Rev

Go to most recent revision | Details | Last modification | View Log

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