mikesmixes777
New Member
Hi,
I am trying to do a small program to get the USART to work. I want to write the letter "A" out on the RS232 port. I have downloaded a sample hex file and loaded into the PIC to test the RS-232 comms to my pc. All is working except my version of code. I am getting funny asterix symbols out the comms port.
Have I left something out of the code. I have set up the registers as per the datasheet and I am only transmitting at the moment.
Thanks
Mike
I am trying to do a small program to get the USART to work. I want to write the letter "A" out on the RS232 port. I have downloaded a sample hex file and loaded into the PIC to test the RS-232 comms to my pc. All is working except my version of code. I am getting funny asterix symbols out the comms port.
Have I left something out of the code. I have set up the registers as per the datasheet and I am only transmitting at the moment.
Code:
#include <p18cxxx.h>
void init_usart(void) // Initialise the USART
{
TXSTA=0x24; // Asynch,8bits,tx enb
RCSTA=0x90;
SPBRG=0x12; // BaudRate=9600 @ 20Mhz as Table
RCSTAbits.SPEN=1; // Enable Serial Port
}
void write_usart(void) //Write to the USART
{
while(TXSTAbits.TRMT==1)
TXREG='A';
}
void main (void)
{
TRISC=0x80; //Set RC7=Input, RC0:6 as Output
init_usart(); // Initialise the USART
write_usart();
}
Thanks
Mike