Need help USART programming in MikroC
I'm using microchip PIC18f452. I'm looking for a way to perform communication between my PIC and PC. I'm testing the communication by using the example code from mikroC as shown below. However, I found that the result I obtained in PC were different from what were expected. For example, if I set the data to be sent as number in dec, when I send 1, I would get 255(expected to get 1); when send 2, the result would be 242(expected to get 2) and so on. Can someone tell me why I cant get the expected result? It there any problem with this code? I'm looking for your kindly help, please.
Code :
unsigned short i;
void main() {
USART_init(19200); // initialize USART module
// (8 bit, 19200 baud rate, no parity bit...)
while (1) {
if (USART_Data_Ready()) { // if data is received
i = USART_Read(); // read the received data
USART_Write(i); // send data via USART
}
}
}