Code:
' I2CREAD and I2WRITE Commands with External EEPROM on 12-bit core
'
' Write to the first 36 locations of External I2C EEPROM
' Read from eeprom and output sequentaly then as strings
' Tested on 12F675 using 24LC01B EEPROM
@ __config _INTRC_OSC_NOCLKOUT & _PWRTE_ON & _WDT_ON & _MCLRE_ON & _CP_OFF & _BODEN_OFF
DEFINE OSC 4
DEFINE DEBUG_REG GPIO
DEFINE DEBUG_BIT 2
DEFINE DEBUGIN_BIT 5
DEFINE DEBUG_BAUD 2400
DEFINE DEBUG_MODE 0
DEFINE SHIFT_PAUSEUS 1000
EECON1 = 7 'Probably not needed here, enables internal eeprom
CMCON = 7 'Disable comparators
ADCON0.0 = 0 'Disable A/D converters
ANSEL = 0 'Disables Analog Select
DPIN var GPIO.0 'Assign Data pin
CPIN var GPIO.1 'Assign Clock pin
' a nice place to store things
B0 var byte
B1 var byte
B2 var byte
B3 VAR BYTE
GPIO = 0 ' set port latches low
TRISIO = 0 ' set ports as outputs
pause 1000 ' Waste time while serial LCD initiailizes
For B2 = 0 To 35 ' counter for lookup table
lookup b2,["A","B","C","D","E","F","G","H","I","J","K","L","M",_
"N","O","P","Q","R","S","T","U","V","W","X","Y","Z","0","1","2",_
"3","4","5","6","7","8","9"],B0 ' store each char in b0 1 at a time
I2CWRITE DPIN,CPIN,$A0,B2,[ b0] 'write to 24C01 eeprom 1 character
Pause 20
Next B2 'next character write to eeprom
DEBUG 254,1 'clear LCD of any leftover data
loop:
DEBUG 254,1 'clears away the leftovers each loop
For B3 = 0 To 35 ' counter for reading 35 characters
I2CREAD DPIN,CPIN,$A0,b3,[B1] ' read each character 1 at a time
pause 500 ' time to see each character on the LCD
DEBUG 254,2,"CHAR ",B1," " ' display the characters 1 at a time
'
Next B3 ' get next character
I2CREAD DPIN,CPIN,$A0,0,[STR B1\20] ' read a string of 20 characters
DEBUG 254,2,STR B1\20 ' display those 20 characters
I2CREAD DPIN,CPIN,$A0,16,[STR B1\16]' get the last 16 characters
DEBUG 254,$C0,STR B1\16," " ' display those 16 characters
DEBUG 254,$94,"I2C EEPROM DEMO" ' display this program's purpose
DEBUG 254,$D4,"USING ARRAY & STRING"
PAUSE 1500 ' time to read the LCD
'NEXT B3 ' go do it all again
Goto loop
end
POKECODE @$3FF, $4C 'read your PIC before erasing and put the cal. data here
Bookmarks