'
'
' schema:
'
' +---------------------------------------------------------------+
' | |
' | LCD DISPLAY Hitachi HD44780 Standard |
' | |
' | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
' +-+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+-+
' | | | | | | | | | | | | | | | |
' GND V+ CNT RS RW E D0 D1 D2 D3 D4 D5 D6 D7 LV+ LGND
' | | | | | | | | | | | | | | | |
' = +5 | | = | | | | |
' | +-+ | | | | | | |
' | < | | | | | | |
' | 10K ><+ +------------------+ | | | |
' | < | | | | | |
' +-----+ | | | | | |
' | | | | | |
' | | | | | |
' | | | | | |
' | | | | | |
' to Picaxe I2C | | | | | |
' ^ ^ | | | | | |
' +5 | | ++ | | | | |
' | | | | | | | | | | | |
' +-+---+---+---+---+---+---+---+-+ | | | |
' | V+ SDA SCD INT P7 P6 P5 P4| | | | |
' | | | | | |
' D PCF8574 port expander | | | | |
' | | | | | |
' | A0 A1 A2 P0 P1 P2 P3 GND| | | | |
' +-+---+---+---+---+---+---+---+-+ | | | |
' | | | | | | | | | | | |
' +---+---+ | | | +------------------------+
' | | | +------------------------+
' gnd | +------------------------+
' +------------------------+
'
'
'
'
' name - 8574 bit - LCD
' ------ -------- ---------------
SYMBOL DB4 = 0 ; LCD Data Line 4 (pin 11)
SYMBOL DB5 = 1 ; LCD Data Line 5 (pin 12)
SYMBOL DB6 = 2 ; LCD Data Line 6 (pin 13)
SYMBOL DB7 = 3 ; LCD Data Line 7 (pin 14)
'SYMBOL RS = 4 ; 0 = Command 1 = Data (pin 4)
SYMBOL RS =6 ; 0 = Command 1 = Data P6
; 5 free (to pin 15 for lcd bk light, for ex.)
; 6 free
'SYMBOL E = 7 ; 0 = Idle 1 = Active (pin 6)
SYMBOL E = 4 ; 0 = Idle 1 = Active P4
SYMBOL RW = 5 ;read = 1 write = 0 on P5 / keep it low for write
SYMBOL Addr8574 = $4E ; this is the 8574 I2C address
; A2=A1=A0=1 <-> x100 111x
SYMBOL RSCMDmask = %00000000 ; Select Command register
'SYMBOL RSDATmask = %00010000 ; Select Data register = High P4 on 8574
SYMBOL RSDATmask = %01000000 ; Select Data register = High P6 on 8574
'SYMBOL Emask = %11100000 ; Enable = P7 on 8574
SYMBOL Emask = %00010000 ; Enable = P4 on 8574
SYMBOL temp = b11
SYMBOL aByte = b12
SYMBOL rsbit = b13
SYMBOL index = b14
main:
GOSUB InitialiseLcd ; Initialise the LCD
mainloop:
aByte = $01 'clear
GOSUB SendCmdByte
aByte = 2 * 8 | $40 ; Program User Defined Character 2
GOSUB SendCmdByte
aByte = %00110 : GOSUB SendDataByte ; ##
aByte = %10110 : GOSUB SendDataByte ; # ##
aByte = %11111 : GOSUB SendDataByte ; #####
aByte = %00101 : GOSUB SendDataByte ; # #
aByte = %00100 : GOSUB SendDataByte ; #
aByte = %00100 : GOSUB SendDataByte ; #
aByte = %01010 : GOSUB SendDataByte ; # #
aByte = %10001 : GOSUB SendDataByte ; # #
aByte = 2 ; put User Defined Character 2
GOSUB SendCmdByte ' goto home
table 10, ("Let's make")
table 20, ("ROBOT")
for b0 = 10 to 19
readtable b0,aByte
GOSUB SendDataByte
next b0
aByte = $80 | $40 ; Put cursor at start of Line 2
GOSUB SendCmdByte
wait 1
for b0 = 20 to 24
readtable b0,aByte
GOSUB SendDataByte
next b0
wait 3
aByte = $80 | $0C ; Put cursor at start of Line 2
GOSUB SendCmdByte
aByte = 2 ; Display User Defined Character 2
GOSUB SendDataByte
wait 9
aByte = 1
GOSUB SendCmdByte
goto mainloop
' INITIALIZE LCD
' -----------------------------------------------------------------
'
InitialiseLcd:
' initialize I2C
i2cslave Addr8574, i2cslow, i2cbyte
for index = 0 TO 5
read index,aByte
gosub SendInitCmdByte
next
' Nibble commands - To initialise 4-bit mode
eeprom 0,( $33 ) ; %0011---- %0011---- 8-bit / 8-bit
eeprom 1,( $32 ) ; %0011---- %0010---- 8-bit / 4-bit
' Byte commands - To configure the LCD
;
; Display Format
; 4bit mode, 2 lines, 5x7
;
; 001LNF00
eeprom 2,( $28 ) ; %00101000
; L : 0 = 4-bit Mode 1 = 8-bit Mode
; N : 0 = 1 Line 1 = 2 Lines
; F : 0 = 5x7 Pixels 1 = N/A
;
; Setup Display
; Display ON, Cursor On, Cursor Steady
;
; 00001DCB
eeprom 3,( $0E ) ; %00001110
; D : 0 = Display Off 1 = Display On
; C : 0 = Cursor Off 1 = Cursor On
; B : 0 = Cursor Steady 1 = Cursor Flash
;
; Setup Cursor/Display
; Inc Cursor Cursor Move
;
; 000001IS
eeprom 4,( $06 ) ; %00000110 %000001IS Cursor Move
; I : 0 = Dec Cursor 1 = Inc Cursor
; S : 0 = Cursor Move 1 = Display Shift
eeprom 5,( $01 ) ; Clear Screen
return
' SEND INIT CMD BYTE - SEND CMD BYTE - SEND DATA BYTE
' -----------------------------------------------------------------
'
SendInitCmdByte:
pause 15 ; Delay 15mS at 4MHz
SendCmdByte:
rsbit = RSCMDmask ; Send to Command register
SendDataByte:
'
' put MSB OUT FIRTS
' via I2C
'
'temp = aByte >> 4 | rsbit x2 command
temp = aByte /16
temp = temp | rsbit
gosub DirectSendCmd
'
' put LSB
'
temp = aByte & $0F | rsbit
rsbit = RSDATmask ; Send to Data register next
DirectSendCmd:
temp = temp xor Emask ' E=1
writei2c (temp) ' send to 8574 via I2C
temp = temp xor Emask ' E=0
writei2c (temp)
return