Hi,
I am currently using PIC16F873A, MPLAB 8.46, UIC00B programmer/debugger and HI TECH compiler.
I am trying to send data to PC through UART, but the data display on Putty is different from the one that I sent.
As you can see from attachment, there are 3 characters (in fact, the data that I have sent are 173, 174 and 175 respectively).
Can anyone help on this? Thanks!
while(1) //Infinite loop
{
unsigned char data = 175;
UART_init();
uart_send(data);
}
void uart_send(unsigned char data)
{
while(TXIF==0); //only send the new data after
TXREG=data; //the previous data finish sent
}
void UART_init(void)
{
#define BAUDRATE 115200 //bps
#ifndef _XTAL_FREQ
#define _XTAL_FREQ 4000000 //MHz
#endif
TRISC6 = 1; //TX pin
TRISC7 = 1; //RX pin
SPBRG = ((_XTAL_FREQ/16)/BAUDRATE) - 1;
BRGH = 1; //Fast Baudrate
SYNC = 0; //Asynchronous
TXEN = 1;
TX9 = 0; // 8-bit transmission
CREN = 1; // Enable reception
SPEN = 1; // Enable serial port pins
RX9 = 0; // 8-bit reception
}