hi all
i'm a beginner in pic microcontroller
i'm programming two pic18f4550 one sender and the other is a reciever which connected Rx to Tx to communicate
i wrote the program in mikroc c based on its library and tested on protus and worked
but in the real world nothing work at all
the sender code is :
char uart_rd;
void main() {
ADCON1 |= 0x0F; // Configure all ports with analog function as digital
CMCON |= 7; // Disable comparators
TRISC0_bit = 0;
TRISC2_bit = 0; RC2_bit = 1;
UART1_Init(9600); // Initialize UART module at 9600 bps
Delay_ms(100); // Wait for UART module to stabilize
SPEN_bit = 1;
TXEN_bit = 1;
while (1) { // Endless loop
Delay_ms(1000);
UART1_Write(0x01);
RC0_bit^=1;
Delay_ms(1000);
UART1_Write(0x02);
RC0_bit^=1;
}
}
the reciever code is :
char uart_rd;
void main() {
ADCON1 |= 0x0F; // Configure all ports with analog function as digital
CMCON |= 7; // Disable comparators
TRISD=0;
TRISC0_bit = 0;
TRISC2_bit = 0; RC5_bit = 0;
UART1_Init(9600); // Initialize UART module at 9600 bps
Delay_ms(100); // Wait for UART module to stabilize
SPEN_bit=1;
CREN_bit=1;
while (1) { // Endless loop
if (UART1_Data_Ready()) { // If data is received,
uart_rd = UART1_Read(); // read the received data,
if(uart_rd==0x01) RD5_bit^=1;
if(uart_rd==0x02) RD7_bit^=1;
if((uart_rd!=0x01) && (uart_rd!=0x02)) RD3_bit^=1;
}
}
}