Tuesday, May 4, 2010

Alpha numeric LCD interface with micro-controller

In This Project the main components used will be as follows:
1. LCD, alpha numeraic, 4 line 40 characters
2. Microcontroller At89s52, any other from this list can be used(8051, at89s51,at20c8051,etc)
LCD:
The LCD is a large alpha numeric type lcd of 4 lines and 40 characters means (4*40). The PIN configrurations is as follows:
P2.0 through P2.4: LCD DB[4:7] ;Bi-directional data/command pins. Alphanumeric characters are sent in ASCII format.
P2.5: LCD RS; Register Select -> Command Register is selectedRS = 1 -> Data Register is selected
P2.6: LCD E1 Enable (Latch data) for first controller
P2.4: LCD E2 Enable (Latch data) for second controller
E: Used to latch the data present on the data pins. A high-to-low edge is needed to latch the data
R/W: Read or Write 0 -> Write, 1 -> Read
8 data pins D7:D0
VEE : contrast control, a variable resistor of 10k between VCC and ground is used to control VEE voltages for contrast.

Display Data RAM (DDRAM) of LCD
Display data RAM (DDRAM) is where you send the characters (ASCII code) you want to see on the LCD screen. It stores display data represented in 8-bit character codes. Its capacity is 80 characters (bytes).
Busy Flag (BF) of LCD
When the busy flag is 1, the LCD is in the internal operation mode, and the next instruction will not be accepted. When RS = 0 and R/W = 1 the busy flag is output to DB7 (MSB of LCD data bus).
Please note that : The next instruction must be written after ensuring that the busy flag is 0.
LCD Commands
The LCD’s internal controller accept several commands and modify the display accordingly on getting the commands. These commands would be like these:
– Clear screen– Return home– Shift display right/left etc.

The other Instruction s are as follows, which are used when and where required in the code or program. the code is in decimal and then hexadecimal.

  1. Function set (8-bit interface, 2 lines, 5*7 Pixels) Decimal=56, HEX =38
  2. Function set (8-bit interface, 1 line, 5*7 Pixels) 48 ,30
  3. Function set (4-bit interface, 2 lines, 5*7 Pixels) 40, 28
  4. Function set (4-bit interface, 1 line, 5*7 Pixels) 32, 20
  5. Scroll display one character right (all lines) 28 ,1E
  6. Scroll display one character left (all lines) 24, 18
  7. Home (move cursor to top/left character position) 2, 02
  8. Move cursor one character left 16, 10
  9. Move cursor one character right 20, 14
  10. Turn on visible underline cursor 14 ,0E
  11. Turn on visible blinking-block cursor 15 ,0F
  12. Make cursor invisible 12 ,0C
  13. Blank the display (without clearing) 8 ,08
  14. Restore the display (with cursor hidden) 12 ,0C
  15. Clear Screen 1 01
  16. Set cursor position (DDRAM address) 128 + addr ,80+ addr
  17. Set pointer in character-generator RAM (CG RAM address) 64 + addr, 40+ addr

Program for LCD 4line and 40characters in keil c51 is as follows:

// 02/01/2010an example program in c
// for lcd of four line and 40 characters on each line
#include //at89x51.h for registers of 8051
#include// intrins.h for nop
unsigned int delayy;sbit lcd_en1 = P2^6;
sbit lcd_rs = P2^5;sbit lcd_en2 = P2^4;sbit lcd_d7 = P2^3;//4 bit connection
sbit lcd_d6 = P2^2;sbit lcd_d5 = P2^1;sbit lcd_d4 = P2^0;
void delay(n);
void initializelcd(void);
void lcd_send_byte(unsigned char godata,bit w,bit e);
void gotoxy(unsigned char x, unsigned char y,bit ec);
void printlcd(unsigned char *ch,bit el);
void clrlcd(bit ed);
void main(){
delay(10); initializelcd(); delay(10000); gotoxy(0,0,0);
delay(15000); clrlcd(0); delay(1000);
printlcd("Welcome Date = 27/5/2007 Time = 11:59pm",0); delay(5000);
gotoxy(0,1,0); delay(9000);
printlcd("Testing of a four line lcd",0); delay(10000);
gotoxy(0,0,1); delay(9000);
printlcd("Developed By Dr. Rana",1); delay(10000);
gotoxy(0,1,1); delay(9000);
printlcd(" Pakistan. ",1); delay(15000);
while(1) { ; } }
void initializelcd(void)
{ delay(16000); lcd_en1 = 1;lcd_en2 = 1;
lcd_send_byte(0x38,0,0); delay(1000);
lcd_en1 = 0;lcd_en2 = 0;
delay(1000); lcd_en1 = 1;lcd_en2 = 1;
lcd_send_byte(0x38,0,0); delay(1000);
lcd_en1 = 0;lcd_en2 = 0; delay(1000);
lcd_en1 = 1;lcd_en2 = 1; lcd_send_byte(0x38,0,0);
delay(1000); lcd_en1 = 0;lcd_en2 = 0;
delay(1000); lcd_en1 = 1;lcd_en2 = 1; lcd_send_byte(0x20,0,0);
delay(1000); lcd_en1 = 0;lcd_en2 = 0;
delay(1000); lcd_en1 = 1;lcd_en2 = 1; lcd_send_byte(0x0c,0,0);
delay(500); lcd_send_byte(0x01,0,0);
delay(500); lcd_send_byte(0x06,0,0);
delay(500); lcd_send_byte(0x1c,0,0);
delay(500); lcd_send_byte(0x01,0,0);
delay(500); lcd_en1 = 0;lcd_en2 = 0;
}


Source: http://microcontroller51.blogspot.com/2010/01/alpha-numeric-lcd-interface-with-micro.html

No comments:

Post a Comment