' ********************************************************************** ' * File: k51ppo.bas - Rel. 1.1 con Bascom AVR IDE e LIB 1.11.7.4 * ' * Schede: GMB HR84 + GMM AM08 + K51-AVR * ' * * ' * GRIFO(R) via Dell'Artigiano 8/6 40016 S. Giorgio di Piano (BO) * ' * Tel. +39 051 892052 Fax. +39 051 893661 * ' * http://www.grifo.com http://www.grifo.it * ' * sales@grifo.it tech@grifo.it grifo@grifo.it * ' * by Graziano Gaiba del 27.01.04 * ' ********************************************************************** ' ' Questo demo permette di pilotare una periferica I2C BUS a bordo della K51-AVR, ' PCF8574, attraverso il modulo mini-BLOCK GMB HR84 ed un mini modulo grifo(r). ' Il PCF874 e' un I/O expander che permette di pilotare 8 linee digitali TTL sia ' in ingresso che in uscita, tutte le operazioni di lettura e scrittura ' avvengono tramite l'interfaccia seriale sincrona I2C BUS. ' Il demo attiva alternativamente una linea alla volta, creando il classico ' scorrimento di un bit a destra e a sinistra, e scrive 'out' sui display a 7 ' segmenti della K51-AVR per indicare il funzionamento del demo. ' ' ' 27.01.04 - Rel 1.1 By Graziano Gaiba per GMM AM08 ' ' Il file compilato non supera i 2048 bytes, quindi puo' essere ' compilato con il demo gratuito di BASCOM AVR. ' ' ' !!!!!!!!!!!!!!!!!!!!!!!!!!! IMPORTANTE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ' Nel menu Options | Compiler | Chip, impostare: ' ' Chip: M8 ' HW Stack: almeno 64 ' Soft Stack: almeno 32 ' Framesize: almeno 64 ' ' '****************** Direttive del compilatore ************************** ' $regfile = "m8def.dat" $crystal = 7372800 $baud = 19200 Config Sda = Portc.4 Config Scl = Portc.5 ' ' ****************** Dichiarazione delle costanti *********************** ' Const Saa1064 = &H38 ' Slave address SAA1064 Const Wsaa1064 = &H70 ' Slave address SAA1064 in Write Const Rsaa1064 = &H71 ' Slave address SAA1064 in Read ' ***************** Elenco indirizzi per Saa1064 *********************** Const Ctb = 0 ' Ind. Control byte Const Dig1 = 1 ' Ind. Digit 1 Const Dig2 = 2 ' Ind. Digit 2 Const Dig3 = 3 ' Ind. Digit 3 Const Dig4 = 4 ' Ind. Digit 4 ' ********************************************************************** ' Commentare la dichiarazione del componente non usato ' 'Const Pcf8574 = &H3C ' Slave address PCF8574A 'Const Wpcf8574 = &H78 ' Slave address PCF8574A in Write 'Const Rpcf8574 = &H79 ' Slave address PCF8574A in Read Const Pcf8574 = &H24 ' Slave address PCF8574P Const Wpcf8574 = &H48 ' Slave address PCF8574P in Write Const Rpcf8574 = &H49 ' Slave address PCF8574P in Read ' '****************** Dichiarazione delle variabili ********************** ' Dim Pout As Byte ' valore per le linee di uscita Dim X As Byte ' uso generico Dim dato As Byte ' valore di conteggio ' '****************** Dichiarazione delle procedure ********************** ' Declare Sub Iniz() ' Inizializzazione periferiche ' '************************* Programma main ****************************** ' Main: Print Chr(12) Print "Demo di otto uscite TTL del PCF8574" Print Print "Sulle otto uscite TTL scorre un bit da destra a sinistra e vicecersa." Call Iniz() ' inizializzazioni Do Dato = 1 ' valore di partenza For X = 1 To 7 ' inizializzo il ciclo Pout = Not Dato ' complemento in valore I2cstart I2cwbyte Wpcf8574 I2cwbyte Pout I2cstop ' I2csend Wpcf8574 , Pout ' setto le uscite Rotate Dato , Left ' shift dei bit a sinistra Waitms 255 ' ritardo Next X For X = 1 To 7 ' inizializzo il ciclo Pout = Not Dato ' complemento in valore I2cstart I2cwbyte Wpcf8574 I2cwbyte Pout I2cstop ' I2csend Wpcf8574 , Pout ' setto le uscite Rotate Dato , Right ' shift dei bit a destra Waitms 255 ' ritardo Next X Loop End ' '************************ Fine del programma *************************** ' ' '**************************** Procedure ******************************** ' ' ******************* Inizializzazione delle periferiche ***************** ' Questa procedura esegue tutte le inizializzazioni del sistema. ' Parametri: ' Ingresso : nulla ' Uscita : nulla ' ************************************************************************ ' Sub Iniz ' Inizializzazione periferiche Local Valore As Byte Do I2creceive Rsaa1064 , Valore ' leggo il registro di stato Loop Until Valore = 0 ' attendo accensione SAA1064 I2cstart ' sequenza di Start per I2CBUS I2cwbyte Wsaa1064 ' comunico lo Slave address I2cwbyte Ctb ' Punto al registro di controllo I2cwbyte &B00100111 ' bit0 =1 dynamic mode ' bit1 =1 digit 1+3 not blanked ' bit2 =1 digit 2+4 not blanked ' bit3 =0 no test segment ' bit4 =0 no 3mA segment current ' bit5 =1 6mA segment current ' bit6 =0 no 12mA segment current ' bit7 =0 indifferente I2cwbyte 92 ' scrive DY1 "o" I2cwbyte 28 ' scrive DY2 "u" I2cwbyte 120 ' scrive DY3 "t" I2cwbyte 0 ' scrive DY4 off I2cstop End Sub '