You should read section 10.3 of the 16F877A datasheet. Basically, you set the USART up for synchronous transmission. then when you write a character to TXBUF and set TXEN, the data will be clocked out. In synchronous mode, RC6 is the clock and RC7 is the data. When TXIF is set, you can write the next byte to TXREG. Fig 10.9When does USART Send or receive data ? When does communication begin and end ?
Receive is on the same data line (RC7), synchronous mode is half-duplex i.e. one way at a time. You clear TXEN and set SREN. The USART will change RC7 to input and generate 8 clocks to clock in data from a synchronous slave. After 8 bits have been received, RCIF is set and you read the received data from RXREG.
Synchronous and asynchronous modes are not usually mixed in an application. Synchronous mode is for synchronous peripherials that take clock and data (similar to SPI). Async is for communication with terminals and the like. Some terminals support both modes but rarely.
Stick with async for sending characters back and forth to the PC unless you really have a special need to do otherwise (and you won't).
Next, you should write then ReceiveChar function from my flow chart. Then you can test the communication by calling ReceiveChar to get characters from the PC and sending them back using UART_send_char. If it works, whatever you type on the terminal will show up back on the PC screen.
Last edited: