I included the preamble in the transmitter, and I think im on the right track on the receiver but im not sure.
Can anyone shed some light? It compiles fine, but it doesnt work what so ever. PortA should be high initially, but thats not happening?
TX Code:
Code: Select all
/*This Program recevies a USART signal via RF
from a handheld remote, that is then translated
to a binary output on PORTA
8MHz int. Osc
*/
void main() {
CMCON = 7; // turns of the analog comparators on the PORTA pins
// ensures pins are reading digital
TRISA = 0xFF; // set PORTA to be input
// Initialize USART module
Usart_Init(4800);
do {
Usart_write(49);
Usart_write(49);
Usart_write(65);
Usart_write(PORTA);
Usart_write(66);
Usart_write(35);
delay_ms(5);
} while (1);
}//~!
Receiver:
Code: Select all
unsigned short i, rxdata[3];
unsigned int rxnum;
void main() {
INTCON.GIE = 0; // Disable interrupts
cmcon = 7; //Declare Variables
VRCON = 0;
PORTA = PORTB.F4 = PORTB.F5 = 1; //Init. PORTA
PORTB = 0; //& PORTB
TRISA = 0x00;
TRISB = 0x00;
TRISB.F1 = 1;
rxnum = 0;
Usart_Init(2400); //Establish USART at 2400bps
while(1){
if(Usart_Data_Ready){
i = Usart_Read();
}
if( i == 65){
while( rxnum < 3){
if(Usart_Data_Ready){
rxdata[rxnum] = Usart_Read();
rxnum++;
}
if(rxdata[1] == 66 && rxdata[2] == 35){
PORTA = rxdata[0];}
}}
if ( PORTA == 239) {
PORTB.F4 = 0;
}
if ( PORTA == 223) {
PORTB.F5 = 0;
}
Delay_ms(100);
PORTA = 0XFF;
PORTB.F4 = PORTB.F5 = 1;
}
}