' ********************************************************************** ' ** Program: k51ppoe.BAS - Version : 1.1 - 04 March 2004 ** ' ** Compilee : BASCOM 8051 DEMO, (IDE and LIB V.2.0.11.0) ** ' ** Scheda : K51-AVR driven by GMB HR168 and GMM AC2 ** ' ** Firm: 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 HR168 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'. ' ' ' Rel. 1.1 04.03.04 - By Graziano Gaiba ' ' ' !!!!!!!!!!!!!!!!!!!!!!! ATTENTION !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ' In menu Options/Compiler/Misc set: ' - Byte End(hex) at least A0 ' ' The file compiled is smaller than 2048 bytes, so it can be compiled ' with free demo version of BASCOM 8051. ' '*********************************************************************** ' '****************** Compiler directives ************************** ' $regfile = "89c51AC2.dat" $romstart = &H0 ' start address of code for FLASH $ramstart = &H0 ' start address of external RAM $ramsize = &H100 ' 256 bytes of external RAM $crystal = 14745600 ' Microcontroller clock $baud = 19200 ' RS-232 baud rate '$large ' 16 bit addressing for jumps ' (Not for demo version) $map ' Generates address map Config Sda = P2.1 ' I2C serial DATA Config Scl = P2.0 ' I2C serial CLK ' '********************* Constants declaration *************************** ' Dim Saa1064 As Const &H38 ' Slave address SAA1064 Dim Wsaa1064 As Const &H70 ' Slave address SAA1064 in Write Dim Rsaa1064 As Const &H71 ' Slave address SAA1064 in Read '****************** Addresses list for Saa1064 ************************* Dim Ctb As Const 0 ' Address Control byte Dim Dig1 As Const 1 ' Address Digit 1 Dim Dig2 As Const 2 ' Address Digit 2 Dim Dig3 As Const 3 ' Address Digit 3 Dim Dig4 As Const 4 ' Address Digit 4 '*********************************************************************** ' ********************************************************************** ' Comment the declaration of the component not used, uncomment the other ' declaration ' 'Dim Pcf8574 As Const &H3C ' Slave address PCF8574A 'Dim Wpcf8574 As Const &H78 ' Slave address PCF8574A in Write 'Dim Rpcf8574 As Const &H79 ' Slave address PCF8574A in Read Dim Pcf8574 As Const &H24 ' Slave address PCF8574P Dim Wpcf8574 As Const &H48 ' Slave address PCF8574P in Write Dim Rpcf8574 As Const &H49 ' Slave address PCF8574P in Read ' '*********************** Variables declaration ************************* ' Dim Pout As Byte ' value for output signals Dim X As Byte ' general purpose Dim Valore As Byte ' counter ' '********************* Procedures declaration ************************** ' Declare Sub Iniz ' Peripherals initialization ' '*************************** Main program ****************************** ' Main: ' Delay for signals settling Waitms 1 Call Iniz ' initializations Do Valore = 1 ' starting value For X = 1 To 7 ' cycle initialization Pout = Not Valore ' complement the value I2csend Wpcf8574 , Pout ' set the outputs Rotate Valore , Left ' left shift of bits Waitms 255 ' delay Next X For X = 1 To 7 ' cycle initialization Pout = Not Valore ' complement the value I2csend Wpcf8574 , Pout ' set the outputs Rotate Valore , 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 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 '