' ********************************************************************** ' ** Program: k51ppoe.BAS - Version : 1.1 - 28 January 2004 ** ' ** Compiler : Bascom AVR IDE - LIB 1.11.7.4 ** ' ** Scheda : K51-AVR driven by GMB HR84 and GMM AM08 ** ' ** Society: grifo(r) ITALIAN TECHNOLOGY ** ' ** Via Dell' Artigiano 8/6 40016 San Giorgio di Piano (BO) ** ' ** Tel.+39 051 892 052 Fax +39 051 893 661 ** ' ** http://www.grifo.com http://www.grifo.it ** ' ** sales@grifo.it tech@grifo.it grifo@grifo.it ** ' ** ** ' ** Written by: Graziano Gaiba ** ' ********************************************************************** ' ' This demo allows to drive an I2C BUS peripheral on board of K51-AVR, PCF8574, ' through mini-BLOCK module GMB HR84 and grifo(r) mini module. ' PCF 8574 is an I/O expander that allows to drive 8 TTL digital lines, both as ' input and as output, all the operations of read and write are performed ' through synchronous serial interface I2C BUS. ' This demo activates in sequence one line at a time, creating the classic bit ' shift to the right and to the left, and writes 'out' on the 7 segments ' display of K51-AVR, near the characters 'out'. ' ' ' 28.01.04 - Rel 1.1 By Graziano Gaiba per GMM AM08 ' ' Compiled file is smaller than 2048 bytes, so it can becompliled with free ' demo of BASCOM AVR. ' ' ' !!!!!!!!!!!!!!!!!!!!!!!!!!! IMPORTANT !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ' In menu Options | Compiler | Chip, set: ' ' Chip: M8 ' HW Stack: at least 64 ' Soft Stack: at least 32 ' Framesize: at least 64 ' ' ' ****************** Compiler directives ************************** ' $regfile = "m8def.dat" $crystal = 7372800 $baud = 19200 Config Sda = Portc.4 ' I2C serial DATA Config Scl = Portc.5 ' I2C serial CLK ' '********************* Constants declaration *************************** ' Const Saa1064 = &H38 ' Slave address SAA1064 Const Wsaa1064 = &H70 ' Slave address SAA1064 in Write Const Rsaa1064 = &H71 ' Slave address SAA1064 in Read '****************** Addresses list for Saa1064 ************************* Const Ctb = 0 ' Address Control byte Const Dig1 = 1 ' Address Digit 1 Const Dig2 = 2 ' Address Digit 2 Const Dig3 = 3 ' Address Digit 3 Const Dig4 = 4 ' Address Digit 4 ' ********************************************************************** ' Comment the declaration of the component not used, uncomment the other ' declaration ' '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 ' '*********************** Variables declaration ************************* ' Dim Pout As Byte ' Value to set in output Dim X As Byte ' Generic use Dim Dato As Byte ' Counter ' '********************* Procedures declaration ************************** ' Declare Sub Iniz() ' Peripherals initialization ' '*************************** Main program ****************************** ' Main: ' Delay for signals settling Print Chr(12) Print "Demo output of 8 TTL signals of PCF8574." Print Print "One TTL signal shifts from left to right and viceversa." Call Iniz() ' initializations Do Dato = 1 ' starting value For X = 1 To 7 ' cycle initialization Pout = Not Dato ' complement the value I2csend Wpcf8574 , Pout ' set the outputs Rotate Dato , Left ' left shift of bits Waitms 255 ' delay Next X For X = 1 To 7 ' cycle initialization Pout = Not Dato ' complement the value I2csend Wpcf8574 , Pout ' set the outputs Rotate Dato , Right ' right shift of the bits Waitms 255 ' delay Next X Loop End ' '*************************** Programma end ****************************** ' ' '**************************** Procedures ******************************** ' ' ********************** Peripherals initialization ******************** ' This procedure performs all the system initializations. ' Parameters: ' Input : nothing ' Output : nothing ' ************************************************************************ ' Sub Iniz() ' Inizializzazione periferiche Local Valore As Byte Do I2creceive Rsaa1064 , Valore ' Read the status register Loop Until Valore = 0 ' Wait for SAA1064 to turn on I2cstart ' Start sequence for I2CBUS I2cwbyte Wsaa1064 ' Communicate the Slave address I2cwbyte Ctb ' Point to control register 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 indifferent I2cwbyte 92 ' set DY1 "o" I2cwbyte 28 ' set DY2 "u" I2cwbyte 120 ' set DY3 "t" I2cwbyte 0 ' set DY4 off I2cstop End Sub '