I need just help in second part of the circuit ( programming of pic16f628a) ; this circuit is remote control based on UART mode to send "F, B, R, L, and S" from pic16f628a to pic16f628a this is the ferst part programming which works correctly with transmitter part but I know it has some errors
transmitter code
Code:
void main() {
TRISA = 0xFF; //set all pin of port A as an input
PORTA = 0x00;
TRISB = 0x00; //set all pin of port B as an output
PORTB = 0x00;
CMCON = 0x07;
UART1_Init(9600); // initialize UART module
Delay_ms(100);
while (1) {
if (PORTA.F0 == 0) { //if push button is pressed
Delay_ms(20);
if(PORTA.F0 == 0) { //send forword signal
UART1_Write('F');
Delay_ms(500);
}
}
if (PORTA.F1 == 0) { //if push button is pressed
Delay_ms(20);
if(PORTA.F1 == 0) {
UART1_Write('B');
Delay_ms(500);
}
}
if (PORTA.F2 == 0) { //if push button is pressed
Delay_ms(20);
if(PORTA.F2 == 0) {
UART1_Write('R');
Delay_ms(500);
}
}
if (PORTA.F3 == 0) { //if push button is pressed
Delay_ms(20);
if(PORTA.F3 == 0) {
UART1_Write('L');
Delay_ms(500);
}
}
if (PORTA.F4 == 0) { //if push button is pressed
Delay_ms(20);
if(PORTA.F4 == 0) {
UART1_Write('S');
Delay_ms(500);
}
}
}
}
code of receiver part when I tried to do it with two characters
void main() {
unsigned int receiver;
PORTA = 0x00;
TRISA = 0x00;
PORTB = 0x00;
TRISB = 0xFF; //set all pin of port B as an output
CMCON = 0x07;
UART1_Init(9600); // initialize UART module
Delay_ms(100);
while (1) {
if (UART1_Data_Ready() == 1) { // if data is received
UART1_Read_Text(receiver, "F", 500); // reads text until 'F' is found
; portA.F0 = 1;
Delay_ms(1000);
portA.F0 = 0;
break;
}
}
if (UART1_Data_Ready() == 1) { // if data is received
UART1_Read_Text(receiver, "B", 500); // reads text until 'B' is found
; portA.F1 = 1;
Delay_ms(1000);
portA.F1 = 0;
Break;
}
}