CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

USART receive problem

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
NeilOne
Guest







USART receive problem
PostPosted: Sat Jun 23, 2007 5:07 am     Reply with quote

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);

WriteUSART(i);
}
//while(!PIR1bits.TXIF)
//continue;
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Jun 23, 2007 9:15 am     Reply with quote

Your code looks like C18 code. This is the CCS compiler forum.
You should ask your questions in the Microchip C18 forum:
http://forum.microchip.com/tt.aspx?forumid=3
NeilOne
Guest







Thank you
PostPosted: Sat Jun 23, 2007 10:13 am     Reply with quote

PCM programmer wrote:
Your code looks like C18 code. This is the CCS compiler forum.
You should ask your questions in the Microchip C18 forum:


Thank uSmile
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group