Celé to popsat určitě nedokážu, tak prostě vyzkoušej níže uvedený testovací program, který jsem našel na zahraničním PICAXE fóru (program jsem upravil pro PICAXE 08M2) [adresu jsem tam nastavil $4E, ale v originálních poznámkách je uvedeno, že běžnější adresa je $40]:
Kód: Vybrat vše
' Picaxe sample code to drive a HD44780 based LCD display
' through i2c commands using a PCF8574 based I/O expander
' i.e. the cheap arduino displays and adapters sold on Ebay
' tested with picaxe 28x2
'port mapping on my i2c adapter:
'display pin 14 (DB7) -> PCF8574.P3
'display pin 13 (DB6) -> PCF8574.P2
'display pin 12 (DB5) -> PCF8574.P1
'display pin 11 (DB4) -> PCF8574.P0
'display pin 4 (RS) -> PCF8574.P6 = 64 low for instructions / high for character data
'display pin 6 (E) -> PCF8574.P4 = 16 enable
' LCD_ID can be $40, $42, $44, $46, $48, $4A, $4C or $4E
' depending on whether lines A0-A2 (pins 1-3) of PCF8574 are tied high or low
' check with continuity tester - my adapter was sold as 0x27 (all lines tied to +V),
' but its real address is 0x20 (all lines tied to ground)
symbol LCD_ID = $4E ' 0x27 << 1
symbol message=0 ' start of EEPROM display data
EEPROM message,("Congratulations Its working! ")
symbol counter = b4 ' loop counter
symbol pointer = b5 ' data pointer
symbol D_Rs = b6 ' display's Rs line = P6 on PCF8574
symbol D_Enable = 16 ' display's Enable line = P4 on PCF8574
main:
' maximum frequency to drive display without including additional pause statements
setfreq m8
' setup i2c for display - display adapter
hi2csetup i2cmaster, LCD_ID, i2cslow, i2cbyte
gosub InitDisplay
gosub DisplayMessage
end
' Initiation procedure for the LCD
' initialization sequence per page 46 of HD44780 datasheet
' the actual codes can be found in table 6 on page 24/25 of the same datasheet
InitDisplay:
pause 200 ' Wait 200 ms for LCD to reset (just in case)
' -------------------------------------------------------------------
' The first 3 hi2cout commands force software re-initialization '
' in case power supply issues prevent proper internal initialization '
' -------------------------------------------------------------------'
hi2cout 3,(19,3)
pause 5 ' Wait 5 ms
hi2cout 3,(19,3) ' Send data again
hi2cout 3,(19,3) ' Send data again
' ------------------------------------------------------------------------------
' 2 critical steps - do not skip these when using PCF8574 or other I/O expander '
' ------------------------------------------------------------------------------'
' Set to 4-bit operation.
hi2cout 2,(18,2)
' set function = 4-bit operation + 2 lines + 5x8 font
b0=32+0+8+0
gosub wrins
' ---------------------------------------------------------------------------------
' The following 3 items can be skipped if program code handles the screen properly '
' ---------------------------------------------------------------------------------'
' display control = turn display off + cursor off + no blinking
b0=8+0+0+0
gosub wrins
' clear display and DDRAM pointer
b0=1
gosub wrins
' set entry mode = increment + no shift (during data load)
b0=4+2+0
gosub wrins
return
' --------- end of initialization sequence per page 46 --------------------------
' sample routines
DisplayMessage:
' display control: turn on screen + turn on cursor + blink cursor
b0 = 8+4+2+1
gosub wrins
' display line 1
pointer=message
for counter=1 to 16
read pointer,b0
gosub wrchr
inc pointer
next counter
' cursor positioning
' HD44780 has 2x40 characters of display RAM to store messages
' b0 = 128 + charpos -- charpos line 1 = 0-39 -- charpos line 2 = 64-103
b0 = 192 ' move cursor to start address of 2nd line
gosub wrins
' display line 2
for counter=1 to 16
read pointer,b0
gosub wrchr
inc pointer
next counter
return
' ---------- pseudo print command ------------------------------------
' to print text messages directly from your program,
' you can use the following code:
for counter = 0 to 15
lookup counter,(" this is a test "),b0
gosub wrchr
next counter
' --------- additional basic instructions ---------------------------------
' return home - puts cursor and memory pointer to start of line 1
' will shift display if necessary
b0 = 2 : gosub wrins
pause 2 ' this can take a bit of time
' scroll memory buffer contents
b0 = 16 + 8 + 0 ' shift display (not cursor) to the left
b0 = 16 + 8 + 4 ' shift display (not cursor) to the right
gosub wrins ' 1 character position per call to wrins
' --------- low level subroutines ---------------------------------
wrins:
D_Rs=0 ' instruction
goto chrout
wrchr:
D_Rs=64 ' character
chrout:
b1 = b0 / 16 ' high nibble
gosub send_nibble
b1 = b0 & 15 ' low nibble
send_nibble:
b1 = b1 | D_Rs
b2 = b1 | D_Enable
;HI2cOut [LCD_ID],b1,(b2,b1) ; for X2 parts only
HI2cOut b1,(b2,b1)
return
' the form HI2cOut b1,(b2,b1) is allowed here if only one hi2c device is used
' to use more than one hi2c device seems to require the [LCD_ID],... format
' and would therefore be restricted to 'x2' picaxe parts