I write and test my code for on-going two months. Nothing work and I have no idea what went wrong as I wrote the code according to data sheet. Maybe the HD44780 has it's variant which make the implementation slightly difference from one and other.
I have to search on-line and read other people source code to understand how the initialisation of lcd is done. After some research, I found that elm-chan website has the most detail guide on implementation and the most accurate one also. For the source code, I found that armandas is the best written source code so far. I do follow some of the way armandas naming and code structure. Also there is simplified but detail datasheet from spickles.
The main problem I faced is the initialisation part, so I am going to start with this. There are two types of initialisation process. First is setup with internal reset, second is initialisation with software. The internal reset procedure is relatively easy, and protostack even shows an initialisation example using solely dip switch. This is pretty amazing as no a single MCU is involved in this.
Second type is the initialisation by instruction.
The initialisation diagram is as follow:
I had highlighted the changes I made.
For the last 4 steps, the long delay is needed as weird character will come out. Usually weird character mean the time needed for the lcd to process data is not enough.
For the third step from last, I found that 0b00001000 is not the correct initialisation. Although most of the datasheet online, and even microchip application note have shown that 0b00001000 is the correct value. Nonetheless, I do encounter some problem when initializing the lcd. Maybe the HD44780 variant is different somehow.
In this configuration, I choose, 8 bits data transmission and 2 lines display.
..............................................................................................................................................
For the 16x2 lcd, a pointer to particular location in lcd is important. The HD44780 in (8 bits, 2 lines configuration) able to store 80 locations. But only the first 16 locations of the 1st line and 2nd line able to be displayed.
The DDRAM address mapping is as follow:
The numbering is at hexadecimal format.
To point to first row, third column, DDRAM is set at 0x02.
To point to second row, third colum, DDRAM is set at 0x42.
The pseudo code is easy
if first row, DDRAM = address_point_by_user;
if second row, DDRAM = address_point_by_user + 0x40;
..............................................................................................................................................
Microchip has two simple rules to follow when apply read and write operation to IO port which are "0" for output and "1" for input and the second rule is "read from port, write to latch".
In order to write to output, the IO direction is set to output and the write operation is written to latch as follow:
#define HD44780_initPinIO() {TRISBbits.RB4=0; TRISBbits.RB5=0; TRISD=0x00;}
#define HD44780_EN_PIN LATBbits.LATB5
#define HD44780_RS_PIN LATBbits.LATB4
#define HD44780_DATA_PORT LATD
..............................................................................................................................................
To keep the coding easy to use and easy to understand, only three functions are included in the hd44780.h which are
void HD44780_Init(void);
void HD44780_WriteString(const rom char *s);
void HD44780_GoToPoint(char row, char col);
HD44780_Init()-must be defined before the two other functions.
HD44780_WriteString(const rom char *s)-write words to display.
HD44780_GoToPoint(char row, char col)-go to particular location of lcd.
Nevertheless, hd44780.c file can be modified to cater the user's need as most functions are hidden in hd44780.c.
..............................................................................................................................................
Simple note:
One pulse - EN high, delay 50 us, EN low.
RS pin - 0 = COMMAND; 1 = DATA.
DDRAM location - Location at lcd display.
rom - c18 keyword to store data in flash.
..............................................................................................................................................
Output:
Most people would prefer the "hello world" message, but I decide to display 4 alphabet at 4 different locations. ^^
The source code can be found at github.
Second type is the initialisation by instruction.
The initialisation diagram is as follow:
I had highlighted the changes I made.
For the last 4 steps, the long delay is needed as weird character will come out. Usually weird character mean the time needed for the lcd to process data is not enough.
For the third step from last, I found that 0b00001000 is not the correct initialisation. Although most of the datasheet online, and even microchip application note have shown that 0b00001000 is the correct value. Nonetheless, I do encounter some problem when initializing the lcd. Maybe the HD44780 variant is different somehow.
In this configuration, I choose, 8 bits data transmission and 2 lines display.
..............................................................................................................................................
For the 16x2 lcd, a pointer to particular location in lcd is important. The HD44780 in (8 bits, 2 lines configuration) able to store 80 locations. But only the first 16 locations of the 1st line and 2nd line able to be displayed.
The DDRAM address mapping is as follow:
The numbering is at hexadecimal format.
To point to first row, third column, DDRAM is set at 0x02.
To point to second row, third colum, DDRAM is set at 0x42.
The pseudo code is easy
if first row, DDRAM = address_point_by_user;
if second row, DDRAM = address_point_by_user + 0x40;
..............................................................................................................................................
Microchip has two simple rules to follow when apply read and write operation to IO port which are "0" for output and "1" for input and the second rule is "read from port, write to latch".
In order to write to output, the IO direction is set to output and the write operation is written to latch as follow:
#define HD44780_initPinIO() {TRISBbits.RB4=0; TRISBbits.RB5=0; TRISD=0x00;}
#define HD44780_EN_PIN LATBbits.LATB5
#define HD44780_RS_PIN LATBbits.LATB4
#define HD44780_DATA_PORT LATD
..............................................................................................................................................
To keep the coding easy to use and easy to understand, only three functions are included in the hd44780.h which are
void HD44780_Init(void);
void HD44780_WriteString(const rom char *s);
void HD44780_GoToPoint(char row, char col);
HD44780_Init()-must be defined before the two other functions.
HD44780_WriteString(const rom char *s)-write words to display.
HD44780_GoToPoint(char row, char col)-go to particular location of lcd.
Nevertheless, hd44780.c file can be modified to cater the user's need as most functions are hidden in hd44780.c.
..............................................................................................................................................
Simple note:
One pulse - EN high, delay 50 us, EN low.
RS pin - 0 = COMMAND; 1 = DATA.
DDRAM location - Location at lcd display.
rom - c18 keyword to store data in flash.
..............................................................................................................................................
Output:
The source code can be found at github.
No comments:
Post a Comment