Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

how to write/read from USART?

Status
Not open for further replies.

tuanvoi

New Member
Hi all,

I've read the data sheet for my PIC18F4550. It explains me everything (i.e. how turn on USART, how to set mode "synchronous, a synchronous"...). However, one part that I think is not clearly explained is how to read/write the Tx/Rx pins. Could you please help me with this write/read from the pins Rx/Tx (I prefer MPLAB C compiler)? For example, If I want to write '1' to the Tx, how do I use the method? Or how do I read from pin Rx?

Thank you!

Tom
 
Last edited:
In my Uc, there is a Data Buffer which you use in order to send data through TX (by writing that buffer) and to accept data through RX - data is accepted to RX every time you transmitting a byte.
 
You know, i'm writing
UDBUF = 0x03, and it transmit 0x03.
I wait for the transmit flag to get High to know that it has finished so i can trasmit my next byte.

while (TRNSMT_FLAG != HIGH);
 
When the Rx receives an 8bit data which is saved in register 'RCREG'. How do I read (what method) so that I can convert it back to binary.

And also how do I write to Tx 'TXREG' register?

Please correct me if I'm wrong. If I want to assign 00000001 to TXREG. I will write TXREG = 00000001, is this corect?

And on the receiver side Rx, how to I read the '00000001'? Thank you.
 
Last edited:
When the RX register gets full (ie. receives the transmited byte), the RCIF flag will be set. You can set up an interrupt to let you know when RCREG is full.

Then you can set up something like
x=RCREG;

Are you using interrupts or are you polling the RCIF to see if data is has been received ?
 
When the RX register gets full (ie. receives the transmited byte), the RCIF flag will be set. You can set up an interrupt to let you know when RCREG is full.

Then you can set up something like
x=RCREG;

Are you using interrupts or are you polling the RCIF to see if data is has been received ?

I'm using RCIF because I only send 1 byte just for a try first. Thanks
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top