//#define PTT PIN_A2 // PTT control//#define TXo PIN_C0 // To the transmitter modulator#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 registerbyte 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 0int flag_flag; // if it is sending flag (7E)int fcs_flag; // if it is sending Frame Check Sequencevoid flipout() //flips the state of output pin a_1{stuff = 0; //since this is a 0, reset the stuff counterif (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){#asmBCF STATUS,0RRF fcshi,F // rotates the entire 16 bitsRRF fcslo,F // to the right#endasmif (((STATUS & 0x01)^(tbyte)) ==0x01){fcshi = fcshi^0x84;fcslo = fcslo^0x08;}}void SendBit (){if (bit){output_high(TXo);PERIODAH;output_low(TXo);PERIODAH;output_high(TXo);PERIODAH;output_low(TXo);TAILH;}else{output_high(TXo);PERIODAL;output_low(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 byteif (bt == 0){flipout();} // if this bit is a zero, flip the output stateelse{ //otherwise if it is a 1, do the following:if (flag_flag == FALSE) stuff++; //increment the count of consequtive 1'sif ((flag_flag == FALSE) & (stuff == 5)){ //stuff an extra 0, if 5 1's in a rowSendBit();flipout(); //flip the output state to stuff a 0}//end of if}//end of else// delay_us(850); //introduces a delay that creates 1200 baudSendBit();inbyte = inbyte>>1; //go to the next bit in the byte}//end of for}//end of SendBytevoid SendPacket(char *data){int ii; // for forbit=FALSE;fcslo=fcshi=0xFF; //The 2 FCS Bytes are initialized to FFstuff = 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(ii=0; ii<10; ii++) SendByte(0x7E); //Sends flag bytes. Adjust length for txdelay//each flag takes approx 6.7 msflag_flag = FALSE; //done sending flagsfor(ii=0; ii<16; ii++) SendByte(SendData[ii]); //send the packet bytesfor(ii=0; 0 != *data; ii++){SendByte(*data); //send the packet bytesdata++;};fcs_flag = TRUE; //about to send the FCS bytesfcslo =fcslo^0xff; //must XOR them with FF before sendingfcshi = fcshi^0xff;SendByte(fcslo); //send the low byte of fcsSendByte(fcshi); //send the high byte of fcsfcs_flag = FALSE; //done sending FCSflag_flag = TRUE; //about to send flagsSendByte(0x7e); // Send a flag to end packet}