Subversion Repositories svnkaklik

Rev

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

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