Hi all,
I recently tried connecting the UART of my PIC16F877A to a PC to send some ASCII characters after successfully testing my MAX232.
I simulated the program in MPLAB SIM where it seems to work fine. When it comes to actual hardware though I ran into some trouble with the terminal screen filling up with seemingly random characters.
I felt it must be a Baud rate error and changed the Baud rate a couple of times but to no avail.
Here is my code:
NOTE: I just configured the reception. I am not actually receiving anything
Here's the random characters I captured off the terminal.
Thanks!
I recently tried connecting the UART of my PIC16F877A to a PC to send some ASCII characters after successfully testing my MAX232.
I simulated the program in MPLAB SIM where it seems to work fine. When it comes to actual hardware though I ran into some trouble with the terminal screen filling up with seemingly random characters.
I felt it must be a Baud rate error and changed the Baud rate a couple of times but to no avail.
Here is my code:
Rich (BB code):
//main.c
//To set up a UART transmit connection between a PC and PIC16F877A
#include<htc.h>
#define _XTAL_FREQ 20000000
#define BAUD 9600
#define BRGR (_XTAL_FREQ)/(16*(129+1))
__CONFIG(FOSC_HS & CPD_OFF & CP_OFF & WDTE_OFF & BOREN_OFF & PWRTE_OFF & DEBUG_ON & LVP_OFF);
void UART_Init()
{
//SET UP TX
SPBRG=BRGR; //Baud rate set at 9600 B/s and 20 MHz crystal
BRGH=1; //High speed Baud rate generator selected
SPEN=1; //Serial Port Enabled
SYNC=0; //No Sync Transmission
TX9=0; //8 Bit transmission
TXEN=1; //TXIF set; no data in TXREG
//SET UP RX
RX9=0; //8 Bit reception
}
void UART_Write(unsigned char byte)
{
while(!TXIF); //if Transmit buffer is empty
TXREG=byte; //write to 8 bit tx buffer
__delay_us(10); //wait for some time
}
void main()
{
UART_Init();
while(1)
{
UART_Write('0');
}
}
Here's the random characters I captured off the terminal.
I admit I might have messed it all up in the code somewhere. Please help me find it.RRÒRÒRÒRÒRÒRÒRÒRÒRÒRÒRÒRÒRÒRÒRÒRÒRÒVÒVÒRÖRÒVÒVÖVÖVÖVÖVÖVÖVÖVÒVÒVÖRÖVÒVÒRÖVÒRÒRÒRÒRÒRÒRÒRÒRÒRÒRÒRÒRÒRÒRÒRÒRÒRÒRÒRÒRÒRÒVÒRÖVÒVÖRÖRÖVÖVÖVÖVÖVÖVÖVÖRÒVÖVÒRÒRÖVÒRÒRÒRÒRÒRÒRÒRÒRÒRÒRÒRÒRÒRÒRÒRÒRÒRÒRÒRÒRÒRÖRÒRÒV
Thanks!