mikesmixes
New Member
Hi,
I am trying to configure the EUSART in a PIC18F2620....
See attached code.
The problem is that I recieve the correct characters but also the incorrect characters...
like happy faces and W's and > when all I should be receiving is T's.
Even when writing a String, there were incorrect characters withing the String.
Thanks.
Mike
I am trying to configure the EUSART in a PIC18F2620....
See attached code.
The problem is that I recieve the correct characters but also the incorrect characters...
like happy faces and W's and > when all I should be receiving is T's.
Even when writing a String, there were incorrect characters withing the String.
Thanks.
Mike
Code:
//Library includes
#include <p18f2620.h>
#include <usart.h>
//My includes
#include "Main.h"
#pragma config OSC = HS //Oscilator = High Speed
#pragma config WDT = OFF //Watch Dog timer = ON
#pragma config PWRT = OFF //Power up timer OFF
#pragma config LVP = OFF //Low Voltage Programming = OFF
void InitializeBoard()
{
TRISCbits.TRISC1 = 0; //LED to show button pressed
}
void ConfigureUSART()
{
// configure USART Fosc=25Mhz, BR=19200, 8bits,
OpenUSART( USART_TX_INT_OFF &
USART_RX_INT_OFF &
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
USART_CONT_RX &
USART_BRGH_HIGH,
80 );
//Enhanced USART Configuration
baudUSART (BAUD_IDLE_CLK_LOW &
BAUD_8_BIT_RATE &
BAUD_WAKEUP_ON &
BAUD_AUTO_OFF);
}
void main(void)
{
int busy = 0; //USART Busy
int buttonState = 0; //Last button state to detect falling edge
int send = 0; //Send request
InitializeBoard();
ConfigureUSART();
while(1)
{
PORTCbits.RC1 = !PORTBbits.RB5; //Set state of LED
if( PORTBbits.RB5 < buttonState ) //Detect falling edge
{
send = 1;
}
busy = BusyUSART();
if(!BusyUSART() && send ) //Send required and USART available
{
// putrsUSART( "Test String, button pressed\n" );
WriteUSART('T'); //Send just one char
send = 0; //reset send request
}
buttonState = PORTBbits.RB5; //Set last state of button
}
}