I tried posting something before but it failed
It's working fine on proteus, but not on the breadboard. Maybe i'm not starting some register?
ty in advance
Code: Select all
unsigned int i;
void main() {
PORTB = 0;
TRISB = 0b11110000;
TRISC = 0b11000011;
RCSTA.CREN = 1; // enable reception.
RCSTA.SPEN = 1; //Serial port enable
UART1_Init(9600); // initialize USART module
// (8 bit, 9600 baud rate, no parity bit...)
while (1)
{
if (PORTB.F4 == 1 ){ //if push button is unpressed
UART1_Write(0b11111100);
Delay_ms(100);
if (UART1_Data_Ready()) {
PORTC.F4 = 1;
i = UART1_Read(); // read the received data
PORTB = i;
Delay_ms(100); //light LEDs on RB0 - RB3
}
}
if (PORTB.F4 == 0 ) { //if push button is pressed
UART1_Write(0b00001111);
Delay_ms(100);
if (UART1_Data_Ready()) {
i = UART1_Read(); // read the received data
PORTB = i;
Delay_ms(100); //light LEDs on RB4- RB7
}
}
}
}