Thursday, February 24, 2011

7.2 Sending Three Characters

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.2 Sending Three Characters


This program sends three letters to PC through serial port. One can see this repeatedly sending character on Terminal program. To get Terminal Program in Windows click as follows:

Start Menu->All Programs -> Accessories -> Communications  -> HyperTerminal 

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_72.C and add it to above created project as a source file. It is time to add code to Pgm_72.C, so type below shown code in it.


Code explanation: This program is similar to previous program, PGM_71.C only extended to send three characters. Note that carriage [0x0D] and Line Feed [0x0A] are added after each ‘YES’. This makes it more readable and same is observed in UART#1 window while simulating it. No flow chart diagram is provided as it makes unnecessarily 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 characters ‘Y’, ‘E’, ‘S’ with carriage and line feed 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 Characters are arranged as ‘YES’ and printed each time on new line on UART #1 tab continuously. 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 character ‘YES’ on PC’s Hyper Terminal. 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.2   Sending Three Characters >
 
...till next post bye-bye & take care.

No comments:

Post a Comment