'---------------------------------------------------------------------------------------- ' Name: I2CL_EEPROM_DEMO_002.TIG ' Type: TIGER-BASIC Source Code ' Purpose: This is an example program used for demonstration how to write and ' read data to and from an I2C EEPROM, using the new I2CL functions ' ' (C) - Copyright Wilke Technology, P.O.Box 1727, D-52018 Aachen, Germany '---------------------------------------------------------------------------------------- ' ' Thank you for using BASIC Tigers in your products. If you have questions, ideas ' or special needs, please contact your next distributor or the Tiger support team ' and visit our web site: ' ' Wilke Technology GmbH ' The Tiger Support Team ' P.O.Box 1727, D-52018 Aachen, Germany ' Krefelder Str. 147, D-52070 Aachen, Germany ' ' email: support@wilke-technology.com (english) ' email: support@wilke.de (german) ' Phone: +49 (241) 918 900 Mo to Fr, 7:00 to 16:00 (GMT) ' Fax: +49 (241) 918 9068 ' ' New information, new drivers and free downloads see: ' ' www.wilke-technology.com (english) ' www.wilke.de (german) ' ' Sincerely, ' ' Your Tiger Support Team ' '---------------------------------------------------------------------------------------- ' ' This example was compiled for running on a Plug & Play Lab. Use Compiler 5.01n or ' later, TAC files version 1.13g or later. ' ' The program increments in an endless loop the values in the addresses 10,000 to 10,003 ' of an 32k EEPROM (M24256) by 5. If the value exceeds 250, it is set back to 0. ' Therefore inside the loop the program reads a value from address ADR of the EEPROM, ' increments it and writes the new value back. Then it reads the value again. ' ' Connect the EEPROMs clock line to pin L80 and the EEPROMs data line to pin L81 of the ' Plug & Play Lab and connect also a pull-up resistor to each line, ' connect VCC and GND to the EEPROM ' ' !----------+-------- Vcc = +5V ' ! ! ' ! ! ' !---! !---! ' ! ! ! ! ' !------------------! ! R ! ! R ! ' ! BASIC-Tiger ! ! ! ! ! ' ! TINY-Tiger ! !---! !---! ' ! ECONO-Tiger ! ! ! ' ! ! ! ! ' ! SCL = CLOCK !-------+-------------------- I2C-Bus ' ! (L80) ! ! ' ! ! ! ' ! ! ! ' ! SDA = DATA !------------------+--------- I2C-Bus ' ! (L81) ! ' ! ! ' ! ! ' ! ! ' ! ! ' !------------------! ' ' ' For more information about the new I2CL functions please look at the file ' I2CL_DEMO_001. All functions and parameters are described in detail there. ' '---------------------------------------------------------------------------------------- USER_VAR_STRICT ' Variables must be declared BYTE Value, FLG, EVER ' Global variables WORD Adr STRING Read$, Write$, I2C$, Result$ TASK MAIN ' Begin task MAIN ' load LCD-device driver (BASIC-Tiger) INSTALL_DEVICE #1, "LCD1.TDD" ' Install LCD driver ' load LCD-device driver (TINY-Tiger) ' INSTALL DEVICE #1, "LCD1.TDD", 0, 0, 0, 0, 0, 0, 80h, 8 ' (Port, Clock_Pin, Data_Pin, Speed_Reduction: 1=no ... 20=slower ) I2CL_SETUP ( 8, 0, 1, 20) ' Setup the ports used to comunicate ' with the EEPROM USING "UH<2><2> 0.0.0.0.2" ' Display numbers in HEX Read$ = "" ' DevSel for read operations Write$ = "" ' DevSel for write operations FOR EVER = 0 TO 0 STEP 0 ' Endless loop FOR ADR = 10000 TO 10003 ' Loop through EEPROM addresses PRINT #1,"<1>"; ' Clear display '-----------------------------------------------' ' Read value from address ' '-----------------------------------------------' I2C$ = Write$ ' Build string for writing BYTE addr. to bus (HI + LO byte) I2C$ = NTOS$(I2C$,1,-2,ADR) ' Build string for writing BYTE addr. to bus (HI + LO byte) I2CL_START (0) ' Set START condition on bus FLG = I2CL_WRITE (I2C$) ' Write DevSel + memory addr. to bus for addr. selection I2CL_START (0) ' Set START condition on bus FLG = I2CL_WRITE (Read$) ' Write DevSel to bus for read operation Result$ = I2CL_READ$ (1) ' READ 1 byte = addr. content from I2C-Bus I2CL_STOP (0) ' Set STOP condition on bus Value = ASC (Result$) ' Set "Value" to the value read from bus USING "UD<5><1> 0.0.0.0.5UD<3><1> 0.0.0.0.3" ' Format string for numbers PRINT_USING #1,"RE Addr ";ADR;": ";Value ' Print read value on LCD WAIT_DURATION 100 ' Wait 100 ms IF Value > 250 THEN ' If Value > 250 Value = 0 ' Set Value to 0 ELSE ' If Value <=250 Value = Value + 5 ' Increment "Value" by 5 ENDIF ' '-----------------------------------------------' ' Write new value to address ' '-----------------------------------------------' I2C$ = Write$ + " " + CHR$(Value) ' Build string for writing to bus I2C$ = NTOS$(I2C$,1,-2,ADR) ' Build string for writing to bus I2CL_START (0) ' Set START condition on bus FLG = I2CL_WRITE (I2C$) ' Write DevSel, memory addr. & data to bus I2CL_STOP (0) ' Set STOP condition on bus USING "UD<5><1> 0.0.0.0.5UD<3><1> 0.0.0.0.3" ' Format string for numbers PRINT_USING #1,"WR Addr ";ADR;": ";Value ' Print written value on LCD WAIT_DURATION 100 ' Wait 100 ms '-----------------------------------------------' ' Read value from address again ' '-----------------------------------------------' I2C$ = Write$ ' Build string for writing BYTE addr. to bus (HI + LO byte) I2C$ = NTOS$(I2C$,1,-2,ADR) ' Build string for writing BYTE addr. to bus (HI + LO byte) I2CL_START (0) ' Set START condition on bus FLG = I2CL_WRITE (I2C$) ' Write DevSel + memory addr. to bus for addr. selection I2CL_START (0) ' Set START condition on bus FLG = I2CL_WRITE (Read$) ' Write DevSel to bus for read operation Result$ = I2CL_READ$ (1) ' READ 1 byte = addr. content from I2C-Bus I2CL_STOP (0) ' Set STOP condition on bus Value = ASC (Result$) ' Set "Value" to the value read from bus USING "UD<5><1> 0.0.0.0.5UD<3><1> 0.0.0.0.3" ' Format string for numbers PRINT_USING #1,"RE Addr ";ADR;": ";Value ' Print read value on LCD WAIT_DURATION 3000 ' Wait 3000 ms NEXT ' Next EEPROM addr NEXT ' End of endless loop END ' End of task MAIN