info:lcd_4_bit_interfacing
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
info:lcd_4_bit_interfacing [2011/01/15 08:53] – tomgee | info:lcd_4_bit_interfacing [2011/01/16 11:29] (current) – tomgee | ||
---|---|---|---|
Line 14: | Line 14: | ||
The busy flag will only be valid after the above reset sequence. Usually we do not use busy flag in 4-bit mode as we have to write code for reading two nibbles from the LCD. Instead we simply put a delay usually 300 to 600uS. This delay might vary depending on the LCD. It depends on the LCD module. So if you feel any problem running the LCD, simply try to increase the delay. This usually works. 400uS is a good typical value. | The busy flag will only be valid after the above reset sequence. Usually we do not use busy flag in 4-bit mode as we have to write code for reading two nibbles from the LCD. Instead we simply put a delay usually 300 to 600uS. This delay might vary depending on the LCD. It depends on the LCD module. So if you feel any problem running the LCD, simply try to increase the delay. This usually works. 400uS is a good typical value. | ||
+ | |||
+ | ==== Sending data/ | ||
+ | |||
+ | Here' the common steps to send data/ | ||
+ | |||
+ | |||
+ | The steps are: | ||
+ | |||
+ | 1. Load high 4-bits on 4 LCD data pins | ||
+ | 2. Send to the LCD port | ||
+ | 3. Toggle enable signal | ||
+ | 4. Load lower 4-bits on 4 LCD data pins | ||
+ | 5. Send to LCD port | ||
+ | 6. Toggle enable signal | ||
+ | |||
+ | ==== C code to perform the above ==== | ||
+ | ;In this 4-bit tutorial the LCD is connected to | ||
+ | ;the controller in following way... | ||
+ | ;D4 - P3.0 | ||
+ | ;D5 - P3.1 | ||
+ | ;D6 - P3.2 | ||
+ | ;D7 - P3.3 | ||
+ | ;EN - P3.7 | ||
+ | ;RS - P3.5 | ||
+ | |||
+ | //The pins used are same as explained earlier | ||
+ | # | ||
+ | |||
+ | //LCD Registers addresses | ||
+ | # | ||
+ | # | ||
+ | |||
+ | 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(); | ||
+ | lcd_cmd(0x28); | ||
+ | lcd_cmd(0x0C); | ||
+ | lcd_cmd(0x06); | ||
+ | lcd_cmd(0x80); | ||
+ | } | ||
+ | |||
+ | ==== Sending Command/ | ||
+ | |||
+ | 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); | ||
+ | |||
+ | delayus(200); | ||
+ | delayus(200); | ||
+ | } |
info/lcd_4_bit_interfacing.1295099616.txt.gz · Last modified: 2011/01/15 08:53 by tomgee