I have a Keil C code for using 16x2 LCD in 4-bit mode. the code is working fine.........
Problem: If "RS", "E" control pins (on LCD) are on a different port than the Data port, the code works fine....... But if the Data and Control Pins are on the Same Port, there's nothing appearing on the LCD.
please suggest any reason (and remedy if possible) for this.........
Controller: P89V51RD2 80c51 core 8-bit CPU with 64KB Flash, 1Kb RAM from NXP(Philips). LCD Module: Hitachi HD44780 controller based 16x2 Alphanumeric Green Backlit LCD.
#define lcd_port P3
//LCD Registers addresses #define LCD_EN 0x80 #define LCD_RS 0x20
void delay_ms(unsigned int x) { unsigned int i,j; for(j=0; j<=x; j++) { for(i=0; i<=1000; i++); } }
void lcd_reset() { lcd_port = 0xFF; delayms(20); lcd_port = 0x03+LCD_EN; lcd_port = 0x03; delayms(10); lcd_port = 0x03+LCD_EN; lcd_port = 0x03; delayms(1); lcd_port = 0x03+LCD_EN; lcd_port = 0x03; delayms(1); lcd_port = 0x02+LCD_EN; lcd_port = 0x02; delayms(1); }
void lcd_init () { lcd_reset(); // Call LCD reset lcd_cmd(0x28); // 4-bit mode - 2 line - 5x7 font. lcd_cmd(0x0C); // Display no cursor - no blink. lcd_cmd(0x06); // Automatic Increment - No Display shift. lcd_cmd(0x80); // Address DDRAM with 0 offset 80h. }
void lcd_cmd (char cmd) { lcd_port = ((cmd >> 4) & 0x0F)|LCD_EN; lcd_port = ((cmd >> 4) & 0x0F);
lcd_port = (cmd & 0x0F)|LCD_EN; lcd_port = (cmd & 0x0F);
delayus(200); delayus(200); }
void lcd_data (unsigned char dat) { lcd_port = (((dat >> 4) & 0x0F)|LCD_EN|LCD_RS); lcd_port = (((dat >> 4) & 0x0F)|LCD_RS);
lcd_port = ((dat & 0x0F)|LCD_EN|LCD_RS); lcd_port = ((dat & 0x0F)|LCD_RS);
Andy,
Please stay calm :-)
The instructions for posting source code really are quite clearly stated: www.danlhenry.com/.../keil_code.png well 'stated' but not 'read' or, at least not 'followed'
I'm perfectly calm, just want the OP to get help, which requires reading and following www.danlhenry.com/.../keil_code.png
Erik
Hmmm.... if your ability to judge "working code" is as good as your ability notice illegible source code, I think that assertion must be open to considerable doubt...
Since you did not give use the pinout lets look at 1 function WITH the pre and \pre tags
void lcd_data (unsigned char dat) { lcd_port = (((dat >> 4) & 0x0F)|LCD_EN|LCD_RS); // Write High Nibble lcd_port = (((dat >> 4) & 0x0F)|LCD_RS); lcd_port = ((dat & 0x0F)|LCD_EN|LCD_RS); // Write Low Nibble lcd_port = ((dat & 0x0F)|LCD_RS); delayus(200); // wait 400 uSec delayus(200); } I ASSUME the data is the lower nibble