PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Anschluss für i2c-Lcd selbst festelegen



funkheld
29.08.2010, 17:25
Wie kann ich hier die Anchlusspins am PCF8574 selber festlegen und wo?

Gruss



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:
*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:
*BASIC: i2csend pcf8574_LCD,_temp1
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]

PicNick
30.08.2010, 06:38
Meinst du, was du machen musst, um das LCD anders als hier festgelegt anzuschliessen ?
;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

Die Sache ist in solchen Befehlen versteckt :



[_Init_LCD]
ldi r16, &hc0
Ldi _temp1, &h03
Ldi _temp1, &h02
Ldi _temp1, &h28
Ldi _temp1, &h08
Ldi _temp1, &h0c
Ldi _temp1, &h01
[_Write_lcd]
Cbr _temp1,&HF0 ; E1, E2, RW, RS low


Und dann noch insofern, als davon ausgegangen wird, dass
D4-D7 an P0-P3 hängt.

z.B:
ldi r16, &hc0 ; initialisierung
ist ja gleich
ldi r16, &B1100000 ; die Bits P7 ------- P0
also:
ldi r16, P7=1, P6=1, P5-P0 = 0
anders:
ldi r16, E1=1, E2=1 der Rest=0

Wenn ich dich überhaupt richtig verstanden habe.

Man kann leichter konkret helfen, wenn du sagst, WAS von den Pins du anders anschliessen willst.

funkheld
30.08.2010, 09:42
So wollte ich die festlegen:



#define LD4 0 // Pin to Data Bus 4
#define LD5 1 // Pin to Data Bus 5
#define LD6 2 // Pin to Data Bus 6
#define LD7 3 // Pin to Data Bus 7

#define LRS 6 // Pin to RS Pin (Register Select)
#define LRW 5 // Pin to Read/Write Pin
#define LEN 4 // Pin to Enable Pin

Richard
30.08.2010, 11:18
Wie kann ich hier die Anchlusspins am PCF8574 selber festlegen und wo?


Irgendwie bin ich jetzt etwas irritiert, Was hat ein Busexpander PCF8574
mit einem LCD zu schaffen?

Ansonsten lassen sich die Pin`s für ein LCD unter Optionen/compiler/LCD
festlegen.

Gruß Richard

PicNick
30.08.2010, 11:42
Hast du ein 1-bzw 2-zeiliges Display ? (weil du E2 offenbar nicht brauchst)

Ich hab versucht, bei den relevanten die Bits/Pins entsprechend zu tauschen.
Die geänderten Zeilen hab' ich markiert und die ursprünglichen Zeilen als Kommentar stehen lassen.

Ehrlich gesagt, bei ein paar trickreichen Commands blick' ich im moment nicht ganz durch. Daher logo keine Gewähr



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
;
; ================= original ======
;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

; ================= FUNKHELD ======
;P0 - D4
;P1 - D5
;P2 - D6
;P3 - D7
;P4 - E1
;P5 - RW (not used, set to 0 to ground for write)
;P6 - RS
;P7 - nc


[_Init_LCD]
_Init_LCD:
*BASIC: waitms 50
;-----------------------------------------------------------------
;ldi r16,&hc0 ; this is to make the initialization on both halfs of a 4-line LCD E1 + E2
;------------------------picnick-----------------------------------------
ldi r16,&h10 ; 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 RW + 8
Rcall _Write_lcd_byte ;RS flag should to be 0, so jump directly to write byte
;-----------------------------------------------------------------
;Ldi _temp1, &h08
;------------------------picnick-----------------------------------------
Ldi _temp1, &h40
;-----------------------------------------------------------------
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) RS
;------------------------picnick-----------------------------------------
sbr r16,&h40 ;set RS flag (4 high bits is used as control) RS 0x40
;-----------------------------------------------------------------
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:
*BASIC: i2csend pcf8574_LCD,_temp1
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]


Ich hab nicht gesehen, ob und wie der Herr Andersson
"_temp1" festlegt ?

Du weisst eh, dass du irgendwo
CONST PCF8574_LCD = i2c-addresse
und
DIM _lcd_e AS BYTE ' das Byte, das du schreiben willst
definieren musst ?
('tschuldige, wenn das eine überflüssige Frage ist )



Lass mich hören, ob das funzt oder ob das LCD verdampft ist *g*




@Richard offenbar will funkheld das LCD über den PCF betreiben und nicht 8 Pins verbraten. Scheint mir nicht aussergewöhnlich. Aber dadurch sind die Bascom -Einstellungen natürlich sinnlos

Richard
30.08.2010, 12:42
@Richard offenbar will funkheld das LCD über den PCF betreiben und nicht 8 Pins verbraten. Scheint mir nicht aussergewöhnlich. Aber dadurch sind die Bascom -Einstellungen natürlich sinnlos

Nicht nur die Einstellungen, die ganzen I²C Bascom Routinen..da ist es doch
weniger Aufwand man nimmt einen Mega 8 (als I²C slave, und hängt das Display normal daran. Oder gleich ein I²C Display. Ob hier (so) immer das Timing richtig klappt.......?

Ich kann relativ faul sein und suche mir immer den Weg das geringsten
Widerstandes (Arbeit). :-)

Gruß Richard

funkheld
30.08.2010, 13:39
Irgendwie bin ich jetzt etwas irritiert, Was hat ein Busexpander PCF8574
mit einem LCD zu schaffen?


Vielleicht ist das Neuland für dich.
Ich steuere das nomale LCD-Display(2*20) mit i2c(SDA und SCL) über den PCF8574.

Alle 7 Datenleitungen gehen an den PCF8574.

Gruss

funkheld
30.08.2010, 13:43
...immer das Timing richtig klappt.....


Null problemo.... O:) , das Ding läuft wie Schmitz Katze....mit Winavr-und mit Bascom routinen.

Warum zweifeln, baue es mal selber nach.
Man nehme 1 Pfung Mehl, 3 Eier, etwas Wasser und....und....
O:)

funkheld
30.08.2010, 13:46
Ich kann relativ faul sein und suche mir immer den Weg das geringsten
Widerstandes (Arbeit).


Bekommst du Hartz 4...und stehts um 12 Uhr auf...und...

Man das ist hier ist ein Hobby, wenn du zu faul bist, dann lass es sein. O:)

funkheld
30.08.2010, 14:07
Es läuft nocht nicht mit deinem Code.
Wenn ich es so anklemme wie es im original angegeben ist funktioniert es mit Bascom :



$regfile = "m32def.dat"
$framesize = 32
$swstack = 32
$hwstack = 64
$crystal = 16000000
$baud = 19200

$lib "Lcd_i2c.lib"

Config I2cdelay = 1
Config Sda = Portc.1
Config Scl = Portc.0

Const Pcf8574_lcd = 114

Dim _lcd_e As Byte

Enable Interrupts

_lcd_e = 128

Dim A As Byte

Cls
Lcd "hallo...i2c"

Wait 1

Locate 2 , 1
Lcd "shiften."

Wait 1

For A = 1 To 10
Shiftlcd Right '
Waitms 250
Next

For A = 1 To 10
Shiftlcd Left
Waitms 250
Next

End

funkheld
30.08.2010, 14:44
Wahrscheinlich weil Bascom RW auf masse haben möchte.

Warum man das gemacht hat, versteh ich nicht.

PicNick
30.08.2010, 15:17
naja, da muss mir da wohl mehr reinknien.
Eins ist aber schon:
Durch die andere Belegung müsstest du
_lcd_e = 16
schreiben (du hast ja Enable auf pin 4 statt auf Pin 7)


PS: sei nicht immer so ruppig. Richard hat dich ja nicht angegriffen