
|
INFO - FAQ - CC2-Forum - CCPro-Forum |
|
Hello, I have posted 2 programs for you to try. You may need to change the EEPROM I2C ADDRESS in the software to make it work with your I2C EEPROM, look under ** CONSTANTS **. Greetings, H.J. Windt 'READ WRITE BYTE for EEPROM AT24C64A v1.0 for CCIUM2.0 with CCIAB2.0' '**************** I/O PORTS ****************' define lcd_backlight_off port[16] '*******************************************' '**************** A/D PORTS ****************' '*******************************************' '**************** D/A PORTS ****************' '*******************************************' '**************** VARIABLES ****************' define configuration byte[1] define iic_nack bit[7] define iic_nack_count byte[2] define eeprom_data_address word[2] define eeprom_data byte[5] define temp byte[6] '*******************************************' '**************** CONSTANTS ****************' define eeprom_i2c_address 162 define eeprom_data_address_max 8191 '*******************************************' '****************** SETUP ******************' put 0 : print"#ON_LCD#";"#INIT#";"#CLR#";"#OFF#";:lcd_backlight_off = 1 '*******************************************' '***************** PROGRAM *****************' #start print"Enter :" print"0 to write byte" print"1 to read byte" print"> "; : input temp on temp goto enter_data, get_data #enter_data print"Enter EEPROM data address" print"> "; : input eeprom_data_address if (eeprom_data_address > eeprom_data_address_max) or (eeprom_data_address < 0) then goto start print"Enter Byte to be saved" print"> "; : input eeprom_data gosub write_byte goto start #get_data print"Enter EEPROM data address" print"> "; : input eeprom_data_address if (eeprom_data_address > eeprom_data_address_max) or (eeprom_data_address < 0) then goto start gosub read_byte print"Byte = "; eeprom_data goto start '*******************************************' '*************** SUBROUTINES ***************' #write_byte print"#ON_IIC#"; print"#START#"; put eeprom_i2c_address put eeprom_data_address / 256 put eeprom_data_address mod 256 put eeprom_data print"#STOP#"; print"#OFF#"; gosub check_iic_nack if iic_nack_count > 3 then goto eeprom_iic_error if iic_nack then goto write_byte return #read_byte print"#ON_IIC#"; print"#START#"; put eeprom_i2c_address put eeprom_data_address / 256 put eeprom_data_address mod 256 print"#STOP#"; print"#OFF#"; gosub check_iic_nack if iic_nack then goto pass_read_byte print"#ON_IIC#"; print"#START#"; put eeprom_i2c_address + 1 get eeprom_data print"#STOP#"; print"#OFF#"; gosub check_iic_nack #pass_read_byte if iic_nack_count > 3 then goto eeprom_iic_error if iic_nack then goto read_byte return #check_iic_nack print"#ON_CONFIG#"; get configuration if not iic_nack then goto pass_iic_nack_clear iic_nack = 0 put configuration iic_nack = 1 iic_nack_count = iic_nack_count + 1 print"#OFF#"; return #pass_iic_nack_clear iic_nack_count = 0 print"#OFF#"; return '*******************************************' '********* CALIBRATION SUBROUTINES *********' '*******************************************' '****************** DATA *******************' '*******************************************' '************* ERROR MESSAGES **************' #eeprom_iic_error print"IIC ERROR : EEPROM NACK!" return '*******************************************' ################################################################################## ################################################################################## ################################################################################## 'DATA LOGGER for EEPROM AT24C64A v1.4 for CCIUM2.0 with CCIAB2.0' '**************** I/O PORTS ****************' define lcd_backlight_off port[16] '*******************************************' '**************** A/D PORTS ****************' '*******************************************' '**************** D/A PORTS ****************' '*******************************************' '**************** VARIABLES ****************' define configuration byte[1] define iic_nack bit[7] define iic_nack_count byte[2] define temp byte[3] define loop byte[5] define dd byte[6] define mm byte[7] define yy byte[8] define impulse_counts word[5] define eeprom_data_address word[6] '*******************************************' '**************** CONSTANTS ****************' define eeprom_i2c_address 162 define eeprom_data_address_max 8191 define bytes_to_save 5 '*******************************************' '****************** SETUP ******************' put 0 : print"#ON_LCD#";"#INIT#";"#CLR#";"#OFF#"; : lcd_backlight_off = on '*******************************************' '***************** PROGRAM *****************' #start print"Enter :" print"0 = CLEAR I2C EEPROM" print"1 = WRITE DATA" print"2 = DUMP DATA" print"> "; input temp on temp gosub clear_i2c_eeprom, enter_data, dump_data_from_i2c_eeprom goto start #enter_data print"Enter Day (1-31)" print"> "; : input dd print"Enter Month (1-12)" print"> "; : input mm print"Enter Year (0-99)" print"> "; : input yy print"Enter Number of Impulses (0-32767)" print"> "; : input impulse_counts gosub write_data_to_i2c_eeprom return '*******************************************' '*************** SUBROUTINES ***************' #write_data_to_i2c_eeprom eeprom_data_address = bytes_to_save + 1 #check_for_empty_page if eeprom_data_address > eeprom_data_address_max then goto eeprom_full print"#ON_IIC#"; print"#START#"; put eeprom_i2c_address put eeprom_data_address / 256 put eeprom_data_address mod 256 print"#STOP#"; print"#OFF#"; gosub check_iic_nack if iic_nack then goto pass_check_for_empty_page print"#ON_IIC#"; print"#START#"; put eeprom_i2c_address + 1 get temp print"#STOP#"; print"#OFF#"; gosub check_iic_nack #pass_check_for_empty_page if iic_nack_count > 3 then gosub eeprom_i2c_nack if iic_nack then goto check_for_empty_page if temp = 0 then eeprom_data_address = eeprom_data_address + (bytes_to_save + 1) if temp = 0 then goto check_for_empty_page eeprom_data_address = eeprom_data_address - bytes_to_save for loop = 1 to (bytes_to_save + 1) #write_data_loop print"#ON_IIC#"; print"#START#"; put eeprom_i2c_address put eeprom_data_address / 256 put eeprom_data_address mod 256 if loop = 1 then put dd if loop = 2 then put mm if loop = 3 then put yy if loop = 4 then put impulse_counts / 256 if loop = 5 then put impulse_counts mod 256 if loop = 6 then put 0 print"#STOP#"; print"#OFF#"; pause 1 gosub check_iic_nack if iic_nack_count > 3 then gosub eeprom_i2c_nack if iic_nack then goto write_data_loop eeprom_data_address = eeprom_data_address + 1 next print"MESSAGE: DONE" return #eeprom_full print"WARNING: I2C EEPROM FULL!"; pause 100 return #dump_data_from_i2c_eeprom print"********************" eeprom_data_address = bytes_to_save + 1 #check_for_data if eeprom_data_address > eeprom_data_address_max then goto eeprom_dump_end print"#ON_IIC#"; print"#START#"; put eeprom_i2c_address put eeprom_data_address / 256 put eeprom_data_address mod 256 print"#STOP#"; print"#OFF#"; gosub check_iic_nack if iic_nack then goto pass_check_for_data print"#ON_IIC#"; print"#START#"; put eeprom_i2c_address + 1 get temp print"#STOP#"; print"#OFF#"; gosub check_iic_nack #pass_check_for_data if iic_nack_count > 3 then gosub eeprom_i2c_nack if iic_nack then goto check_for_data if temp > 0 then goto eeprom_dump_end eeprom_data_address = eeprom_data_address - bytes_to_save #read_data for loop = 1 to bytes_to_save #read_data_loop print"#ON_IIC#"; print"#START#"; put eeprom_i2c_address put eeprom_data_address / 256 put eeprom_data_address mod 256 print"#STOP#"; print"#OFF#"; gosub check_iic_nack if iic_nack then goto pass_read_data print"#ON_IIC#"; print"#START#"; put eeprom_i2c_address + 1 get temp if loop = 1 then dd = temp if loop = 2 then mm = temp if loop = 3 then yy = temp if loop = 4 then impulse_counts = temp * 256 if loop = 5 then impulse_counts = impulse_counts + temp print"#STOP#"; print"#OFF#"; gosub check_iic_nack #pass_read_data if iic_nack_count > 3 then gosub eeprom_i2c_nack if iic_nack then goto read_data_loop eeprom_data_address = eeprom_data_address + 1 next eeprom_data_address = eeprom_data_address + bytes_to_save + 1 print dd;"/";mm;"/";yy;" -> ";impulse_counts goto check_for_data #eeprom_dump_end if eeprom_data_address = bytes_to_save + 1 then print"MESSAGE: NO DATA STORED" print"********************" print"MESSAGE: I2C EEPROM DUMP DONE" return #clear_i2c_eeprom print"MESSAGE: Clearing I2C EEPROM, Please Wait..." eeprom_data_address = bytes_to_save + 1 #reset_i2c_eeprom_loop if eeprom_data_address > eeprom_data_address_max then goto clear_i2c_eeprom_done print"#ON_IIC#"; print"#START#"; put eeprom_i2c_address put eeprom_data_address / 256 put eeprom_data_address mod 256 put 255 print"#STOP#"; print"#OFF#"; gosub check_iic_nack if iic_nack_count > 3 then gosub eeprom_i2c_nack if iic_nack then goto reset_i2c_eeprom_loop eeprom_data_address = eeprom_data_address + (bytes_to_save + 1) goto reset_i2c_eeprom_loop #clear_i2c_eeprom_done print"MESSAGE: Done" return #check_iic_nack print"#ON_CONFIG#"; get configuration if not iic_nack then goto pass_iic_nack_clear iic_nack = 0 put configuration iic_nack = 1 iic_nack_count = iic_nack_count + 1 print"#OFF#"; return #pass_iic_nack_clear iic_nack_count = 0 print"#OFF#"; return '*******************************************' '******* INITIALIZATION SUBROUTINES ********' '*******************************************' '********* CALIBRATION SUBROUTINES *********' '*******************************************' '****************** DATA *******************' '*******************************************' '************* ERROR MESSAGES **************' #eeprom_i2c_nack print"I2C ERROR : EEPROM IIC NACK"; pause 100 return '*******************************************' |
| Antwort schreiben |