Friday, March 4, 2011

7.4 Tx & Rx characters simultaneously

Hello Readers:

I have started this blog to show you Embedded C programming for 8051 family microcontroller using KEIL compiler. The KISS philosophy is used to write this tutorial. What is KISS? Keep It Simple, Stupid!

7. Serial Port Interface

This section teaches you how to send data and receive data from personal computer through serial port.

7.4 Tx & Rx characters simultaneously

The program receives as-well as transmits serial data through serial port. When key is pressed data will be sent and otherwise data will be received. The transmitting data will be in R-range-direction [R20 R21 R22 …] format and can be seen on UART#1 window. This is because usually embedded system sends data in certain format so that receiver unit can distinguish it from other data it may receive on same port. 

Start KEIL V4.01 and close projects, if any are open. Now start new project with Device -> Generic->8051 [all variants] for general 8051 family target chip. Add a new text file, name it Pgm_74.C and add it to above created project as a source file. It is time to add code to Pgm_74.C, so type below shown code in it.


Code explanation: This program is nothing but previous transmitter & receiver programs mixture. No flow chart is provided as it makes more confusing.

After typing the code, press F7 or click Project->Build Target for building the source code. If there are no typical errors file will build successively and shows zero errors and zero warnings.
Now enter into debug mode by pressing Ctrl+F5 or click Debug->Start/Stop Debug Session menu. Our program is sending character in ‘Rrd’ format [R20 R21 R22 …] to UART #1 continuously. So we want to watch the UART #1 while running this program for receiving values. To get UART #1 tab click View->Serial Windows->UART #1 text.

Run the program by pressing F5 or clicking Debug->Run. You can see the Character ‘R20 R21 …’ on UART #1 tab continuously. The receiving character simulation is not possible as such facility is not provided in this program.

If you generate HEX file of this program, burn it into your target chip’s memory using suitable uploader and connecting chip to PC with the help of serial cable you can watch sending/receiving characters on PC’s Hyper Terminal & on chips LCD module simultaneously. To stop running the program press red ‘x’ mark icon or click Debug->Stop.

To get back the compile mode press Ctrl+F5 or click Debug->Start/Stop Debug Session menu.  

<End of 7.4   Tx & Rx characters simultaneously >


...till next post bye-bye & take care.

No comments:

Post a Comment