Simply my program is to read PORTA, when any bit goes high it transmits an appropriate number, eventually via RF, but now just with a wire.
On the receiving end, each number will have a corresponding binary number output on PORTA.
I have the PORTA receiver always high(0xFF), when the appropriate number is received, a particular bit is turned low.
I dont have much skill in C or any programming, can anyone help?
Receiver
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*/
unsigned short i;
void main() {
INTCON.GIE = 0; // Disable interrupts
cmcon = 7; //Declare Variables
VRCON = 0;
PORTA = 1; //Init. PORTA
PORTB = 0; //& PORTB
TRISA = 0x00;
TRISB = 0xFF;
Usart_Init(2400); //Establish USART at 2400bps
while(1){
if (Usart_Data_Ready()){
i= Usart_Read();
if (i == 1){
PORTA = 0xFE;}
else if (i == 2){
PORTA = 0xFD;}
else if (i == 3){
PORTA = 0xFB;}
else if (i == 4){
PORTA = 0xF7;}
else if (i == 5){
PORTA = 0xEF;}
else if (i == 6){
PORTA = 0xDF;}
else if (i == 7){
PORTA = 0xBF;}
else if (i == 8){
PORTA = 0x7F;}
else PORTA = 0xFF;
}
}}
Transmitter
Code: Select all
unsigned short i;
void main() {
INTCON.GIE = 0; // Disable interrupts
cmcon = 7;
VRCON = 0;
PORTA = 0;
PORTB = 0;
TRISA = 0xFF;
TRISB = 0x00;
Usart_Init(2400); //Establish USART at 2400bps
while (1){
if (PORTA.F0){
i=1;}
else if (PORTA.F1){
i=2;}
else if (PORTA.F2){
i=3;}
else if (PORTA.F3){
i=4;}
else if (PORTA.F4){
i=5;}
else if (PORTA.F5){
i = 6;}
else if (PORTA.F6){
i = 7;}
else if (PORTA.F7){
i = 8;}
Usart_Write(i);
}
}