
|
INFO - FAQ - CC2-Forum - CCPro-Forum |
|
> Hallo MICRO-Fans! > Hier ein Beispiel von mir mit 2 PCF8574 mit LCD Ausgabe und LED Ausgabe: > > > '************************************************************* > ' * > ' C-Control/MICRO I2C_LCD_Ausgabe1.BAS * > ' JPM 18.08.2004 jxx2344305@aol.com * > ' Aufgabe: Laufled und Anzeige der internen Uhrzeit * > ' * > ' - Porterweiterung für MICRO ueber den I2C-Bus * > ' - Ansteuerung zwei PCF8574 * > ' Adr.1=LCD R=64 W=65 * > ' Adr.3=8 LEDs mit Vorwiderstand 2,2K nach +5V R=68 W=69 * > ' - SDA am Port 5 (kann geändert werden) * > ' - SCL am Port 6 (kann geändert werden) * > ' * > '************************************************************* > ' > ' LCD Beschaltung für Adr. 1 > 'PCF 1 A0 --- I2C Addresse: Gnd > 'PCF 2 A1 --- I2C Addresse: Gnd > 'PCF 3 A2 --- I2C Addresse: Gnd > 'PCF 4 P0 --- LCD 11 DB4 > 'PCF 5 P1 --- LCD 12 DB5 > 'PCF 6 P2 --- LCD 13 DB6 > 'PCF 7 P3 --- LCD 14 DB7 > 'PCF 8 Gnd --- Gnd > 'PCF 9 P4 --- LCD 5 R/W > 'PCF 10 P5 --- LCD 4 RS > 'PCF 11 P6 --- LCD 6 EN > 'PCF 12 P7 --- frei > 'PCF 13 INT --- frei > 'PCF 14 SCL --- MICRO Port 6 > 'PCF 15 SDA --- MICRO Port 5 > 'PCF 16 Vcc --- + 5 Volt > > '************************************************************* > ' --- Definitionen -------------------- > define SDA port[5] > define SCL port[6] > '-------------------------- > '---- Variablen ----------- > '-------------------------- > define Daten 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 Zaehler byte[2] > define N byte[3] > define lcd_param byte[4] > define lcd_buf byte[5] > define w1 byte[6] > define char_num byte[7] > '------------------------------------------------------------- > SDA = 1 > SCL = 1 > '_____________________________________________________________ > > ' --- Programmoperationen ------------- > > > gosub LCD_INIT '1.Adresse PCF8574 > gosub message1 > gosub stop > > #Loop > gosub Start 'I2C-Start > Daten = 68 '3.Adresse PCF8574 > gosub I2C_Write > Daten = &HFD 'LED2 > gosub I2C_Write > pause 50 > Daten = &HFB 'LED3 > gosub I2C_Write > pause 50 > Daten = &HF7 'LED4 > gosub I2C_Write > pause 50 > Daten = &HEF 'LED5 > gosub I2C_Write > pause 50 > Daten = &HDF 'LED6 > gosub I2C_Write > pause 50 > Daten = &HBF 'LED7 > gosub I2C_Write > pause 50 > Daten = &H7F 'LED8 > gosub I2C_Write > pause 50 > > Daten = &HBF 'LED7 > gosub I2C_Write > Pause 10 > Daten = &HDF 'LED6 > gosub I2C_Write > pause 10 > Daten = &HEF 'LED5 > gosub I2C_Write > pause 10 > Daten = &HF7 'LED4 > gosub I2C_Write > pause 5 > Daten = &HFB 'LED3 > gosub I2C_Write > pause 5 > > gosub Stop 'I2C_Stop > > gosub lcd_init > w1=hour > gosub ausgabe > lcd_param = &H3a > gosub lcd_writechar > w1=minute > gosub ausgabe > lcd_param = &H3a > gosub lcd_writechar > w1=second > gosub ausgabe > gosub stop > goto loop > > #Start > SDA=0:SCL=1: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 > > #pulse_SCL > SCL=0:SCL=1:SCL=0:SDA=0:return > > '--------------------------------------- > '---- LCD TREIBER ROUTINEN ------------- > '--------------------------------------- > > #LCD_INIT > ' alle ports 0 > gosub Start > Daten = 64 '1.Adresse PCF8574 > gosub I2C_Write > Daten = OFF > gosub I2C_Write > > ' 8-Bit-Modus aktivieren > lcd_param=&H38 : gosub LCD_WRITECMD > > ' mit 8-Bit-Command in 4-Bit-Modus umschalten > daten=&B00000010 > gosub I2C_Write > daten=daten or 64 '1 an E > gosub I2C_Write > daten=daten and 2 '0 an E > gosub I2C_Write > > ' ab jetzt 4-Bit-Modus > lcd_param = &H28 : gosub LCD_WRITECMD > lcd_param = &H0C : gosub LCD_WRITECMD > > ' Display loeschen > #LCD_CLS > lcd_param = &H02 : gosub LCD_WRITECMD > lcd_param = &H01 : gosub LCD_WRITECMD > return > ' Zeilenwechsel > #LCD_GOTOLINE > if lcd_param = 1 then lcd_param = &H80 > if lcd_param = 2 then lcd_param = &HC0 > goto LCD_WRITECMD > > ' LCD-Kommando > #LCD_WRITECMD > lcd_buf = OFF > goto LCD_WRITE > > ' Zeichenausgabe > #LCD_WRITECHAR > > lcd_buf = &B00100000 > > ' Kommando oder Zeichen an Display senden > #LCD_WRITE > daten = lcd_buf or (lcd_param shr 4) ' Hi-Nibble > gosub I2C_Write > daten=daten or 64 '1 an E > gosub I2C_Write > daten=daten and 2 '0 an E > gosub I2C_Write > > daten = lcd_buf or (lcd_param and &H0F) ' Lo-Nibble > gosub I2C_Write > daten=daten or 64 '1 an E > gosub I2C_Write > daten=daten and 2 '0 an E > gosub I2C_Write > > return > > > '---------------------------------------------------------------------- > #Ausgabe 'zweistellige Zahl IN: w1=Ausgabewert > > lcd_param = (w1 / 10) + 48 > > gosub lcd_writechar > lcd_param = (w1 mod 10) + 48 > gosub lcd_writechar > return > > #Ausgabe3 'dreistellige Zahl > lcd_param = (w1 / 100) + 48 > gosub lcd_writechar > w1 = w1 mod 100 > gosub Ausgabe 'zweistellige Zahl > return > '-------------------------------------------------------- > #message1 > char_num =255: lcd_param = 1 : gosub lcd_gotoline > #read_loop1 > char_num = char_num+1 > '------- tabelle bis FF lesen ----------- > looktab startup1, char_num, lcd_param > if lcd_param = &HFF then goto new_line_m1 > gosub lcd_writechar: goto read_loop1 > '------- zweiten teil lesen -------------- > #new_line_m1 > lcd_param = 2 : gosub lcd_gotoline > #read_loop2 > char_num = char_num+1 > looktab startup1, char_num, lcd_param > if lcd_param = &HFF then return > gosub lcd_writechar: goto read_loop2 > '------------------------------------------------------------------- > '-------------- EINSCHALTTEXT ------------ MICRO I2C_LCD_Ausgabe1 -- > table startup1 > &H20 &H20 &H4d &H49 &h43 &H52 &H4f &HFF > '-------------------------------------------- > &h49 &H32 &H43 > &H5f &H4c &H43 &H44 &H5f &H41 &H75 &H73 &H67 &H61 &H62 &H65 &H31 &HFF > tabend > > '----------------------------------- > > end > Hallo Jan Peter, habe da eine kürzere und einfachere I2C_Write Routine die nur mit ein paar Bytes (58) auskommt: define i byte 'Indexzähler define zum_i2c byte 'Byte zum I2C-Device define sda port [1] define scl port [2] #PUTBYTE for i = 0 to 8 '1 Byte senden.MSB first if (zum_i2c and &H80) =&H80 then sda=1 else sda=0 'Datenbit senden tog scl : tog scl 'Clock zum Speichern im I2C-Device zum_i2c=zum_i2c shl 1 'Nächstes Bit next i Probier´s doch mal ! Liebe Grüße aus Wien |
| Antwort schreiben |