HD44780 - LCD
On today's article we are going to use an lcd 16x2 with Hitachi HD44780 LCD controller.wikipedia image |
It is necessary before we proceed with schematics and code to explain the basics of these lcds.
Pins
lcd display 16x2 |
- Vss - Ground
- Vdd - 5 volts
- Vee - contrast adjustment
- RS - register select
- RW - read or write
- E - enable
- D0-D7: is the data/command pins
- Vdd - backlight anode (optional)
- Vss - backlight cathode (optional)
The first 3 pins is just for power.
The fourth pin RS, is the register select pin. If this is set (RS=1) it means that the data register is selected and the display is now waiting for data. But if RS is unset (RS=0) the command register is selected and the Lcd is waiting for commands to be appeared between D0-D7 pins. That pin it is very important because throughout our projects is very common to send both data and commands.
The fifth pin RW,is the read/write register. When is set (RW=1) we can read from the lcd (rare but is it possible), and when is unset (RW=0) we can write to lcd.
The sixth pin E, enable, it is used as a flag for the lcd to show that the data/command on the D0-D7 pins is valid, and the data/command will be latched into lcd controller as soon as this pin change from high to low. For example if i want to write 10001001, i should move to PORTC the value 10001001, and the data will be valid only when a high to low pulse appears to Enable pin.
The seventh is the data/command pins D0-D7. The valid commands is available in the datasheet of the display, and the data it will be ascii code of the character. For example if i want to write the letter "A" on the display i should apply to the D0-D7 pins the code 0x41 which the ascii equivalent code of "A".
Initialization
The initialization it can be happen by following the flow chart below:
Every part of the flow chart is a command we can send to the display based on the table below:
Keep in mind that in order to send a command (or data) we have to follow the flowchart below:
Here is the initialization code:
- Lcd_Init
- ;RB4 --> RS
- ;RB5 --> RW
- ;RB6 --> E
- ;RC0-RC7 --> D0-D7
- ;wait for the LCD display to boot up
- call Delay100ms
- ;ready for command
- bcf PORTB, 4
- ;1. Clear Display and Home the Cursor
- ;movlw b'00000001'
- movwf PORTC
- bsf PORTB, 6
- call Delay1ms
- bcf PORTB, 6
- call Delay1ms
- ;2. Return Cursor and LCD to Home Position
- movlw b'00000010'
- movwf PORTC
- bsf PORTB, 6
- call Delay1ms
- bcf PORTB, 6
- call Delay1ms
- ;3. Set Cursor Move Direction
- ;0-0-0-0-0-1-ID-S
- ;ID - Increment the Cursor After Each Byte Written to Display if Set
- ;S - Shift Display when Byte Written to Display
- movlw b'00000110'
- movwf PORTC
- bsf PORTB, 6
- call Delay1ms
- bcf PORTB, 6
- call Delay1ms
- ;4. Enable Display/Cursor
- ;0-0-0-0-1-D-C-B
- ;D - Turn Display On(1)/Off(0)
- ;C - Turn Cursor On(1)/Off(0)
- ;B - Cursor Blink On(1)/Off(0)
- movlw b'00001111'
- movwf PORTC
- bsf PORTB, 6
- call Delay1ms
- bcf PORTB, 6
- call Delay1ms
- ;5. Move Cursor/Shift Display
- ;0-0-0-1-SC-RL-x-x
- ;SC - Display Shift On(1)/Off(0)
- ;RL - Direction of Shift Right(1)/Left(0)
- movlw b'00010100'
- movwf PORTC
- bsf PORTB, 6
- call Delay1ms
- bcf PORTB, 6
- call Delay1ms
- ;6. Set Interface Length
- ;0-0-1-DL-N-F-*-*
- ;DL - Set Data Interface Length 8(1)/4(0)
- ;N - Number of Display Lines 1(0)/2(1)
- ;F - Character Font 5x10(1)/5x7(0)
- movlw b'00111100'
- movwf PORTC
- bsf PORTB, 6
- call Delay1ms
- bcf PORTB, 6
- call Delay1ms
- ;7.
- bcf PORTB, 5
- movlw 0x80
- movwf PORTC
- bsf PORTB, 6
- call Delay1ms
- bcf PORTB, 6
- call Delay1ms
- return
Schematic
So based on the explanation above, we created the following schematic:Message
And after the initialization ends, we are now ready to write the message we want on the screen:
- ...
- SPACE_l EQU 0x20
- A_l EQU 0x41
- B_l EQU 0x42
- C_l EQU 0x43
- D_l EQU 0x44
- E_l EQU 0x45
- F_l EQU 0x46
- G_l EQU 0x47
- H_l EQU 0x48
- I_l EQU 0x49
- J_l EQU 0x4A
- K_l EQU 0x4B
- L_l EQU 0x4C
- M_l EQU 0x4D
- N_l EQU 0x4E
- O_l EQU 0x4F
- P_l EQU 0x50
- Q_l EQU 0x51
- R_l EQU 0x52
- S_l EQU 0x53
- T_l EQU 0x54
- U_l EQU 0x55
- V_l EQU 0x56
- W_l EQU 0x57
- X_l EQU 0x58
- Y_l EQU 0x59
- Z_l EQU 0x5A
- ...
- ;write data
- bsf PORTB, 4
- movlw H_l
- movwf PORTC
- bsf PORTB, 6
- call Delay100us
- bcf PORTB, 6
- movlw E_l
- movwf PORTC
- bsf PORTB, 6
- call Delay100us
- bcf PORTB, 6
- movlw L_l
- movwf PORTC
- bsf PORTB, 6
- call Delay100us
- bcf PORTB, 6
- movlw L_l
- movwf PORTC
- bsf PORTB, 6
- call Delay100us
- bcf PORTB, 6
- movlw O_l
- movwf PORTC
- bsf PORTB, 6
- call Delay100us
- bcf PORTB, 6
- ;move cursor to line 2
- bcf PORTB, 4 ;write command
- bcf PORTB, 5
- movlw 0xC0
- movwf PORTC
- bsf PORTB, 6
- call Delay1ms
- bcf PORTB, 6
- call Delay1ms
- ;write data
- bsf PORTB, 4
- movlw J_l
- movwf PORTC
- bsf PORTB, 6
- call Delay100us
- bcf PORTB, 6
- movlw A_l
- movwf PORTC
- bsf PORTB, 6
- call Delay100us
- bcf PORTB, 6
- movlw C_l
- movwf PORTC
- bsf PORTB, 6
- call Delay100us
- bcf PORTB, 6
- movlw K_l
- movwf PORTC
- bsf PORTB, 6
- call Delay100us
- bcf PORTB, 6
- movlw SPACE_l
- movwf PORTC
- bsf PORTB, 6
- call Delay100us
- bcf PORTB, 6
- movlw S_l
- movwf PORTC
- bsf PORTB, 6
- call Delay100us
- bcf PORTB, 6
- movlw P_l
- movwf PORTC
- bsf PORTB, 6
- call Delay100us
- bcf PORTB, 6
- movlw A_l
- movwf PORTC
- bsf PORTB, 6
- call Delay100us
- bcf PORTB, 6
- movlw R_l
- movwf PORTC
- bsf PORTB, 6
- call Delay100us
- bcf PORTB, 6
- movlw R_l
- movwf PORTC
- bsf PORTB, 6
- call Delay100us
- bcf PORTB, 6
- movlw O_l
- movwf PORTC
- bsf PORTB, 6
- call Delay100us
- bcf PORTB, 6
- movlw W_l
- movwf PORTC
- bsf PORTB, 6
- call Delay100us
- bcf PORTB, 6
- loop
- goto loop
All the files can be found here...
Thank you...
No comments:
Post a Comment