So I am trying to interface 4x20 LCD with KS0066 driver with ATmega1284p. I have read the datasheet and tried to code for initialization, blinking cursor and a simple character display on the first position of the LCD. I am not able to find any readymade code for such display, and as per the datasheet, HD44780 and KS0066 are having different init sequences. I am posting my hardware connection and code below. Please let me know if there is anything wrong with it. All I am able to get is a hint of LCD getting initialized (as the original poster said - the LCD is having 4 light lines from 2 dark and 2 light line setting). Nothing beyond that.
Also, please check out the attached datasheet of KS0066 driver for information. I've tried the init sequence of HD44780 too but result is the same.
H/W Connection:
RS pin connected to PA2
R/W pin connected to GND
EN pin connected to PA3
DB4 - PA4
DB5 - PA5
DB6 - PA6
DB7 - PA7
Crystal of 11.0592MHz
Code:
#include <avr/io.h> #define F_CPU 11059200UL #include <util/delay.h> #define ms(ms_time) _delay_ms(ms_time) #define us(us_time) _delay_us(us_time) uint16_t ms_time,us_time; // LCD Definitions #define LCD_DDR DDRA #define LCD_PORT PORTA #define LCD_RS PA2 #define LCD_EN PA3 #define LCD_Data_Mask 0xF0 #define EN_SET (LCD_PORT |= (1 << LCD_EN)) #define EN_CLEAR (LCD_PORT &= ~(1 << LCD_EN)) #define RS_SET (LCD_PORT |= (1 << LCD_RS)) #define RS_CLEAR (LCD_PORT &= ~(1 << LCD_RS)) void LCD_Init(void); void LCD_Init(void) { LCD_DDR |= ((1 << LCD_RS) | (1 << LCD_EN)); LCD_DDR |= LCD_Data_Mask; RS_CLEAR; EN_CLEAR; /* LCD_PORT |= (LCD_Data_Mask & 0x30); // Sequence of HD44780 LCD_PORT |= (1 << LCD_EN); us(2); LCD_PORT &= ~(1 << LCD_EN); ms(10); LCD_PORT |= (LCD_Data_Mask & 0x30); LCD_PORT |= (1 << LCD_EN); us(2); LCD_PORT &= ~(1 << LCD_EN); ms(1); LCD_PORT |= (LCD_Data_Mask & 0x30); LCD_PORT |= (1 << LCD_EN); us(2); LCD_PORT &= ~(1 << LCD_EN); us(100);*/ // Please go through the pg.29 of attached PDF for the init sequence LCD_PORT |= (LCD_Data_Mask & 0x20); EN_SET; us(2); EN_CLEAR; ms(1); LCD_PORT |= (LCD_Data_Mask & 0x20); EN_SET; us(2); EN_CLEAR; us(2); LCD_PORT |= (LCD_Data_Mask & 0x80); EN_SET; us(2); EN_CLEAR; ms(1); LCD_PORT |= (LCD_Data_Mask & 0x00); EN_SET; us(2); EN_CLEAR; us(2); LCD_PORT |= (LCD_Data_Mask & 0xF0); EN_SET; us(2); EN_CLEAR; ms(1); LCD_PORT |= (LCD_Data_Mask & 0x00); EN_SET; us(2); EN_CLEAR; us(2); LCD_PORT |= (LCD_Data_Mask & 0x10); EN_SET; us(2); EN_CLEAR; ms(10); LCD_PORT |= (LCD_Data_Mask & 0x00); EN_SET; us(2); EN_CLEAR; us(2); LCD_PORT |= (LCD_Data_Mask & 0x60); EN_SET; us(2); EN_CLEAR; ms(1); LCD_PORT |= (LCD_Data_Mask & 0x80); // Setting DDRAM address EN_SET; us(2); EN_CLEAR; us(2); LCD_PORT |= (LCD_Data_Mask & 0x00); EN_SET; us(2); EN_CLEAR; ms(1); RS_SET; // Trying to print 'H' LCD_PORT |= (LCD_Data_Mask & 0x40); EN_SET; us(2); EN_CLEAR; us(2); LCD_PORT |= (LCD_Data_Mask & 0x80); EN_SET; us(2); EN_CLEAR; ms(1); } int main(void) { ms(2000); // delay inserted to clearly observe the change from 2 dark 2 light lines on LCD to all light lines LCD_Init(); while (1); }
Any help is highly appreciated. Thank you.