INFO - FAQ - CC2-Forum - CCPro-Forum |
Hallo MICRO-Fans! Jetzt geht auch die Eingabe mit PCF8574 Hier ein Beispiel: '************************************** ' ' C-Control/MICRO I2CPCF8574RW1.BAS ' 18.8.2004 JPM jxx2344305@aol.com ' Aufgabe: ' ' - Porterweiterung ueber den I2C-Bus ' - Ansteuerung eines PCF8574 für Aus- und Eingabe ' - SDA am Port 5 ' - SCL am Port 6 '************************************** ' --- Definitionen -------------------- define Taster port[3] define LED port[4] define SDA port[5] 'gn define SCL port[6] 'br '-------------------------- '---- Variablen ----------- '-------------------------- define DatenW byte[1] define B1 bit[1] define B2 bit[2] define B3 bit[3] define B4 bit[4] define B5 bit[5] define B6 bit[6] define B7 bit[7] define B8 bit[8] define DatenR byte[2] define BR1 bit[9] define BR2 bit[10] define BR3 bit[11] define BR4 bit[12] define BR5 bit[13] define BR6 bit[14] define BR7 bit[15] define BR8 bit[16] define Zaehler byte[3] define N byte[4] '------------------------------------------------------------- SDA = 1 SCL = 1 baud 9600 led=on '_____________________________________________________________ ' --- Programmoperationen ------------- #Loop for Zaehler = 0 to 255 gosub Start DatenW = 64 '1.Adresse PCF8574 gosub I2C_Write DatenW = Zaehler gosub I2C_Write gosub Stop pause 50 gosub Start DatenW = 65 '1.PCF8574, Lesen gosub I2C_Write gosub I2C_Read print DatenR gosub NoAck gosub Stop next goto Loop 'Endlosschleife #Start SDA=0:SCL=0:return #Stop SCL=1:SDA=1:return #I2C_WRITE if B8=ON then SDA=ON gosub pulse_SCL if B7=ON then SDA=ON gosub pulse_SCL if B6=ON then SDA=ON gosub pulse_SCL if B5=ON then SDA=ON gosub pulse_SCL if B4=ON then SDA=ON gosub pulse_SCL if B3=ON then SDA=ON gosub pulse_SCL if B2=ON then SDA=ON gosub pulse_SCL if B1=ON then SDA=ON gosub pulse_SCL gosub pulse_SCL ' 9. Impuls ACK vom Slave return #I2C_Read DatenR = 0 SCL=0 deact SDA ' SDA = Eingang SCL=1 if SDA=ON then BR8=ON SCL =0 SCL=1 if SDA=ON then BR7=ON SCL =0 SCL=1 if SDA=ON then BR6=ON SCL =0 SCL=1 if SDA=ON then BR5=ON SCL =0 SCL=1 if SDA=ON then BR4=ON SCL =0 SCL=1 if SDA=ON then BR3=ON SCL =0 SCL=1 if SDA=ON then BR2=ON SCL =0 SCL=1 if SDA=ON then BR1=ON SCL =0 return #Ack SDA = 0:gosub pulse_SCL:return #NoAck SDA=1:gosub pulse_SCL:SDA=1:return #pulse_SCL SCL=0:SCL=1:SCL=0:SDA=0:return end |
Antwort schreiben |