-
Display über i2c
Hallo,
ein 16*2 Standarddisplay soll über I2c und einen PCA9555D gesteuert werden.
Leider hilft die lcd_i2c.lib nur bedingt weiter, da Anpassungen wegen des PCAs nötig sind. Kann mir da jemand weiterhelfen, Assembler ist nicht gerade mein Steckenpferd ;-)
-
Ich hab' diese .lib garnicht. Ist die zum dowloaden for free ?
-
-
Gut, ich hab' mal geguckt.
Die LCD-I2C. LIb ist ja ergreifend einfach, er repliziert ja das LCD-Byte von Bascom einfach auf die Pins des PCF.
Es ist also nur der I2C - Sende befehl aufzubohren um die kontroll-bytes des PCA.
Wieweit die KEY_I2C sache mit dem Interrupt da hineinintegriert werden kann, hab ich mir aber noch nicht überlegt. Brauchst du das auch ?
-
Hallo Robert,
danke für deine Unterstützung. "Ergreifend einfach" hört sich gut an. Der grössere Unterschied zwischen den ICs ist eigentlich nur, daß der PCA9555D ein zusätzliches Command-Byte braucht. Mir reicht das Display völlig. Die Key_i2c Sache kann also wegfallen...
Günter
-
Ja, jetzt müßt ich noch wissen, an welche Pins du konkret deine LCD angeschlossen hast
-
Hallo Robert,
IC: Display:
P0.0-> D0
P0.1-> D1
P0.2-> D2
P0.3-> D3
P0.4-> D4
P0.5-> D5
P0.6-> D6
P0.7-> D7
P1.0-> E
P1.1-> R/W
P1.2-> RS
-
Uiui, das ist ein's drauf. Die Library und das Beispiel ist für 4 Bit-Anschluss ausgelegt.
Jetzt muß ich mal sehen, wie das mit Bascom und 8 Bit LCD eigentlich ist.
Ich hoffe, es brennt dir nicht unter den Nägeln, ich tu, was ich kann.
EDIT: scheint eher eine anspruchslose Sache zu sein. Da scheint mir besser, man macht gleich eine neue Lib. Ich muß noch finden, wo Bascom seine 8-Bit LCD funktions versteckt hat.
-
Hallo Robert,
8 Bit muß nicht sein! Es ist zwar so verdrahtet, aber was spricht dagegen es einfach 4 Bittig anzusteuern?
-
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