lloydi12345
Member level 4
Hi, I am new on serial programming using UART and this is my first attempt to program it. I used to program on ASM but now I wanna give it a shot on mikroC. I hope someone can tell me where my mistake is. RD0 - RD3 is supposed to light and RD4 - RD7 is supposed to be off whenever my push button is unpressed. When the push button is pressed, it does the opposite.
Code:
unsigned int i;
void main() {
PORTD = 0;
TRISB = 1;
TRISD = 0;
UART1_Init(9600); // initialize USART module
// (8 bit, 9600 baud rate, no parity bit...)
if (PORTB = 0x01 ){ //if push button is unpressed
UART1_Write(0b00001111);
Delay_ms(100);
while (1) {
if (UART1_Data_Ready()) {
i = UART1_Read(); // read the received data
PORTD = i;
Delay_ms(100); //light LEDs on RB0 - RB3
}
}
}
else { //if push button is pressed
UART1_Write(0b11110000);
Delay_ms(100);
while (1) {
if (UART1_Data_Ready()) {
i = UART1_Read(); // read the received data
PORTD = i;
Delay_ms(100); //light LEDs on RB4- RB7
}
}
}
}