Blindversuch, kann es leider nicht testen
ist 1:1 die lcd_i2c.lib funktionalität , aber eben für PCA
PCF8674 Pin 0- 7 ==> PCA P0.0-7
Code:
copyright = Kent Andersson
www = none
email = kent@smmab.se
comment = I2C LCD driver
libversion = 1.02
date = 31 march 2002
statement = You are free to use this code any way you like, if you are able to optimize
statement = it better, please send me an update on my e-mail.
history = No known bugs.
;define a constant named PCF8574_LCD pointing to the I2C address
;dimension _lcd_e as byte to control the E-lines (4 lines LCD:s)
;_lcd_e should have one of the following values
;128 to enable E1, 64 to enable E2, 192 to enable both E1 and E2 (cls, deflcdchar)
;Connect the following pins from PCF8574 to LCD
;
;P0 - D4
;P1 - D5
;P2 - D6
;P3 - D7
;P4 - RS
;P5 - RW (not used, set to 0 to ground for write)
;P6 - E2 (on 1 or 2 line display nc)
;P7 - E1
[_Init_LCD]
_Init_LCD:
;------------------------------------------------------------------------
; initialize PCA
;------------------------------------------------------------------------
*BASIC: i2cstart
*BASIC: i2cwbyte pcf8574_LCD
*BASIC: i2cwbyte &H06 ;command (write register 6)
*BASIC: i2cwbyte &H00 ; val register 6 00 -> all Output
*BASIC: i2cwbyte &HE8 ; val register 7 E8 -> 0, 1, 2 Output 3,4,5,6,7 input
*BASIC: i2cstop
;------------------------------------------------------------------------
*BASIC: waitms 50
ldi r16,&hc0 ; this is to make the initialization on both halfs of a 4-line LCD
Ldi _temp1, &h03 ; at init-time I call all routines before _lcd_e is loaded into r16
Rcall _Send_to_LCD
*BASIC: waitms 4
Rcall _Send_to_LCD
Rcall _Send_to_LCD
Ldi _temp1, &h02
Rcall _Send_to_LCD
Ldi _temp1, &h28
Rcall _Write_lcd_byte ;RS flag should to be 0, so jump directly to write byte
Ldi _temp1, &h08
Rcall _Write_lcd_byte
Ldi _temp1, &h0c
Rcall _Write_lcd_byte
Ldi _temp1, &h01
Rjmp _Write_lcd_byte
[END]
[_Write_lcd]
_Write_lcd:
*lds r16,{_lcd_e}
sbr r16,&h10 ;set RS flag (4 high bits is used as control)
rjmp _write_lcd_byte
_Lcd_Control:
*lds r16,{_lcd_e}
_write_lcd_byte:
push r24
Swap _temp1
Rcall _Write_lcd_Nibble
pop r24
_Write_lcd_nibble:
Cbr _temp1,&HF0 ; E1, E2, RW, RS low
_Send_to_LCD:
push r26
push r27
ldi r25,3
_send_3_times:
; -----------------------------------send to PCA
*BASIC: i2cstart
*BASIC: i2cwbyte pcf8574_LCD
*BASIC: i2cwbyte &H02 ;command (write register 2)
*BASIC: i2cwbyte _temp1 ; val register 2
*BASIC: i2cstop
eor _temp1,R16 ; Xor E1 and/or E2 to set them
; @genus(250)
ldi r26,0
_LCD_delay:
dec R26
brne _LCD_delay
Dec R25
Brne _send_3_times
eor _temp1,R16 ; Xor to restore to initial state (even number of times)
pop r27
pop r26
ret
[END]
Wie gesagt: so wie es ist, nur auf PCA
Lesezeichen