INFO - FAQ - CC2-Forum - CCPro-Forum |
Hello, now seeing more of your code I have an 1 more Idea: There's an example for the M-Unit 2.0 ( IIC_PCF8574_2.bas, see sniplet below) that says, that if you want to read from a 8574 Port, you must set all ports HIGH before, to be able to pull down to low later. I cannot see in your code that you did so, so maybe it helps (replace print#, get.. with your subroutines and ignore the LCD Statements, it shows only the principle): sniplet: ' In diesem Beispiel wird der Portstatus abgefragt und im LCD binär angezeigt. ' Wichtig ist, dass vorher der PCF8574 initialisiert wurde (alle Ports Output HI) ' dann liegen alle Ports hochohmig auf HI und können LO gezogen werden. ' Ist ein Port auf LO geschaltet, können sie ihn nicht nach HI ziehen, ' Das ist deshalb so, weil der PCF 8574 kein Datenrichtungsregister hat, ' und die Ports (auch beim Lesen des Eingangswertes) immer als Ausgang ' geschaltet sind ' ' ACHTUNG ' Achten Sie unbedingt darauf, dass das LCD initialisiert ist, wenn es ' angesteckt ist (auch wenn sie es nicht benutzen). ' Es teilt sich einen Teil seines Busses mit dem IIC-BUS ' print"#ON_LCD#"; ' print"#INIT#"; ' print"#OFF#"; '----------------------------------------------------------------------- '-------------------------- '------ I/O PORTS --------- '-------------------------- '-------------------------- '---- SYSTEM MEMORY ------- '-------------------------- define DEV1READ &B01001111 define DEV1WRITE &B01001110 define PCFDATA byte[1] define COUNTER byte[2] define x byte[64] define y bit[255] define z port [144] define f byteport[18] #INIT print"#ON_LCD#"; print"#INIT#"; print"PCF8574 IIC-TEST"; print"#L207#"; print"READ"; print"#OFF#"; pause 50 print"#ON_IIC#"; print"#START"; put DEV1WRITE put &B11111111 print"#STOP#"; print"#OFF#"; '----------------------------------------------------- '-- PCF 8574 DATEN LESEN ---- '----------------------------------------------------- #LOOP print"#ON_IIC#"; 'UPLEITUNG ZUM IIC-MODULE '-------- DATEN VON PCF8574 LESEN ------------------ print"#START#"; put DEV1READ get PCFDATA print "#STOP#"; '--------------------------------------------------- print"#OFF#"; 'UMLEITUNG ABSCHALTEN 'led=on:pause 3:led=off:pause 3 '----------------------------------------------------- '-- PCF 8574 DATEN AM LCD ANZEIGEN ---- '----------------------------------------------------- print"#ON_LCD#"; 'UMLEITUNG ZUM LCD MODULE print"#L101#"; print"STATUS: "; if (PCFDATA and &H80)=0 then print "0"; else print "1"; if (PCFDATA and &H40)=0 then print "0"; else print "1"; if (PCFDATA and &H20)=0 then print "0"; else print "1"; if (PCFDATA and &H10)=0 then print "0"; else print "1"; if (PCFDATA and &H08)=0 then print "0"; else print "1"; if (PCFDATA and &H04)=0 then print "0"; else print "1"; if (PCFDATA and &H02)=0 then print "0"; else print "1"; if (PCFDATA and &H01)=0 then print "0"; else print "1"; print"#OFF#"; goto LOOP > > > Hello, > > > > hard to say what's wrong with THIS program, (I do not have the book [1]), but you can get addittional help and tips, when you check the documentation of M-Unit 2.0, even if you don't have it. It provides a port module (Conrad# 198848) where you can see in the documentation if you use the 8574 properly (pins etc.) > > > > Also there are demo programs available for the use of this module, so you could use this demos and replace the print# / i2c start / i2c stop - statements inside by subroutines (gosub) that do the same. So you see if your 8574 Hardware is responding properly. > > > > Carsten > > > > > Please, who can help me to program a PCF8574. What is wrong in the program given below. I like to turn a stepper connnected to P4-P7 (of the PCF8574) when a switch) connected to P3 is depressed. P0/P3 are connected with a pull-up to 5V . By pressing the switch P3 will be connected with a pull-up to 5 V > > > > > > define .......etc > > > > > > SDA=on > > > SCL=on > > > zaehler=&B00001000 > > > > > > #loop > > > 'reading ON/OFF of P3 > > > gosub start > > > datenW=65 > > > gosub I2C_write > > > gosub I2C_read > > > gosub Noack > > > gosub Stop > > > if datenR=&B00001111 then gosub motor else goto loop > > > goto loop > > > > > > #motor > > > zaehler =zaehler shl 1 > > > gosub start > > > datenW=64 > > > gosub I2C_write > > > datenW=Zaehler > > > gosub I2C_write > > > gosub stop > > > if zaehler=&B10000000 then zaehler=&B00001000 > > > return > > > > > > #start > > > please refer to [1] > > > > > > #stop > > > please refer to [1] > > > > > > #I2C_write > > > please refer to [1] > > > read instead of daten : datenW > > > > > > #I2C_read > > > please refer to [1] > > > read instead of daten: datenR > > > > > > #Ack > > > please refer to [1] > > > > > > #Noack > > > please refer to [1] > > > > > > [1] Messen, Steueren, Regeln mit dem C-Control/BASIC System von Kainka (page 163 u.w.) > > > > > > thank you very much > > > > Hallo Carsten,, > > Thank you for your answer > > Question1 > Regarding [1] : please refer to the answer I have given to Achim > > Questikn2 > Next to other documentation I have also " studied " the documentation of the M -unit-2, but without any result > > Question3 > It is not a hardware problem, as there is nothing wrong with the I2C-bus PCF8574. The problem is the software. If you replace the #loop by: > > #loop > goto motor > return > > then the stepper runs merrily. > > The problem in #loop is reading the position of the switch (ON or OFF) connected (in this case) to P3 of the PCF8574 > > I hope you can help me > > kind regards rien van harmelen > > Kind regards > > > > |
Antwort schreiben |