' ********************************************************************** ' ** Program : gmbi2ce.bas - Version : 1.2 ** ' ** Compiler : BASCOM 8051 DEMO, (IDE and LIB V.2.0.11.0) ** ' ** Board : GMB HR168 with GMM ACZero ** ' ** Corporate: 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 ** ' ** ** ' ** Written by: Graziano Gaiba 02.02.2005 ** ' ********************************************************************** ' ' These demos allow to communicate to I2C BUS devices connected to CN8. ' According to the Mini Module installed, it is possible to read or write bytes ' at any slave address and location address input by console. In detail, when ' reading the byte read is visualized and when writing the byte input is sent. ' ' ' Rel. 1.1 03.03.04 - By Graziano Gaiba ' ' Rel. 1.2 02.02.05 - By Graziano Gaiba ' ' Modified to work with GMM ACZero ' ' ' !!!!!!!!!!!!!!!!!!!!!!! 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 = "8951cc03.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 ' ' Config Sda = P2.1 ' I2C serial DATA Config Scl = P2.0 ' I2C serial CLK ' ' '****************** Variables declaration ********************** ' Dim Valore As Byte , I As Byte ' Generic use Dim Slave As Byte ' Slave address Dim Buf(30) As Byte ' Data to send and receive Dim Inviare As Byte ' Number of data to send Dim Ricevere As Byte ' Number of data to receive ' ' '************************** Main program ****************************** ' Main: Waitms 1 ' Delay for signals settling ' Initialize demo Disable Interrupts ' Disabiles interrupts Auxr = &H0C ' Selects Eram on external data area Eecon = &H00 ' Disables Eeprom of Micro Adcf = &H00 ' Sets port 1 as input Do Print Chr(12) Print "Demo I2C BUS on CN8 of GMB HR168" Print Print "1) Write" Print "2) Read" Print Print "Select: " Do Valore = Inkey Loop Until Valore = "1" Or Valore = "2" Print Input "Slave address (in decimal): " , Slave Input "Number of data to receive: " , Ricevere Input "Number of data to send: " , Inviare If Inviare <> 0 Then For I = 1 To Inviare Print "data " ; I ; ") "; Input Buf(i) Next I End If Select Case Valore Case "1" : I2csend Slave , Buf(1) , Inviare Case "2": I2creceive Slave , Buf(1) , Inviare , Ricevere End Select If Ricevere <> 0 Then Print "Data received:" For I = 1 To Ricevere Print "data " ; I ; ") " ; Buf(i) Next I End If Print "Hit a key to continue..." Do Valore = Inkey Loop Until Valore <> 0 Loop End ' '************************ Program end *************************** '