Wednesday, January 12, 2011

3.1Sending Characters [1 line]

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!


3. LCD Interface

This section teaches you how to control LCD connected to output port of a microcontroller chip.

3.1 Sending Characters [1 line]


This program displays “Hi!” on LCD screen continuously. Here LCD is configured for two lines but using only one line. Note that R/W [Read/Write] pin is connected permanently to ground [in hardware] as always write operation is used in this program. 

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



 
Code explanation:
Line 16: This command configures LCD for 2 line 5x7 dot matrix.
Line 18: This command says display ON, cursor blinking.
Line 20: This command clears the display.
Line 22: This command shifts cursor to right.
Line 24: This command takes cursor to line1, position 6.
Line 26: This command sends ‘H’ letter to LCD.
Line 28: This command sends ‘i’ letter to LCD.
Line 30: This command sends ‘!’ letter to LCD.
Line 35: This lcdcmd() function sends parameter commands to LCD.
Line 46: This lcddata() function sends parameter data to LCD.
Line 57: This MSDelay() function supplies delay between each command execution.

Below is the flow chart diagram of program PGM_31.C.

  

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 “Hi” characters to Port 1 continuously. So we want to watch the Port 1 pins while running this program for changing values. To get Port 1 tab click Peripherals->I/O Ports->Port 1 text.

Run the program by pressing F5 or clicking Debug->Run. You can see the hexa  values of ‘H’,’I’ & ‘!’ characters on Port 1 tab continuously in binary form. If you generate HEX file of this program, burn it into your target chip’s memory using suitable uploader and connecting LCD to Port 1 you can have message “Hi” on  LCD screen. 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 3.1   Sending Characters [1 line] >
 

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