I use 18f4520, wanna use USART to communicate data with PC. MCU could transmit data to PC, but couldn't receive data from PC. The source code is as follows. Anyone kowns the reason?? Thank u for your answering:)
#include <p18f4520.h>
#include <sw_i2c.h>
#include <delays.h>
#include <usart.h>
#pragma config OSC = HS
#pragma config PWRT = OFF
#pragma config BOREN = OFF
#pragma config WDT = OFF
#pragma config MCLRE = ON
#pragma config PBADEN = OFF
#pragma config LVP = OFF
void init(void)
{
CMCON=0b00000111; // Close Comparator
TRISA=0b00010000; // Configure PORTA I/O
TRISB=0b00000001; // Configure PORTB I/O
TRISC=0b00000000; // Configure PORTC I/O
TRISD=0b00000000; // Configure PORTD I/O
TRISE=0b00001000; // Configure PORTE I/O
ADCON1=0b00001111; // Enable digital I/O
SPBRG=64; // Transmission choices for the Baud Rate 4800bps(SPBRG=(20000000/ 4800/64)-1)
BAUDCONbits.BRG16=0; // Choice 8-bit baud rate generator
TXSTAbits.BRGH=0; // High Baud Rate
TXSTAbits.SYNC=0; // Asynchronous mode
RCSTAbits.SPEN=1; // Enable Serial Transmit
TXSTAbits.TX9=0; // 8-bit Transmission
TXSTAbits.TXEN=1; // Enable Transmission
}
void main( void )
{
char i = 'Q';
char wr[]={"world"};
char ra[7];
init();
WriteUSART(i); // Display a ‘Q’ to the USART
putsUSART(wr); // Display a word to the USART
while (!DataRdyUSART());//!PIR1bits.RCIF);//
while(1)
{
i = ReadUSART();//getcUSART();
// TransmitData();
//getsUSART(display_1line, 10);
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum