PAGE WRITE<br />The IS24CXX is capable of page-WRITE (8-byte for 24C01/<br />02 and 16-byte for 24C04/08/16) operation. A page-WRITE<br />is initiated in the same manner as a byte write, but instead<br />of terminating the internal write cycle after the first data word<br />is transferred, the master device can transmit up to N more<br />bytes (N=7 for 24C01/02 and N=15 for 24C04/08/16). After<br />the receipt of each data word, the IS24CXX responds<br />immediately with an ACKnowledge on SDA line, and the<br />three lower (24C01/24C02) or four lower (24C04/24C08/<br />24C16) order data word address bits are internally<br />incremented by one, while the higher order bits of the data<br />word address remain constant. If the master device should<br />transmit more than N+1 (N=7 for 24C01/02 and N=15 for<br />24C04/08/16) words, prior to issuing the STOP condition,<br />the address counter will “roll over,” and the previously<br />written data will be overwritten. Once all N+1 (N=7 for<br />24C01/02 and N=15 for 24C04/08/16) bytes are received<br />and the STOP condition has been sent by the Master, the<br />internal programming cycle begins. At this point, all received<br />data is written to the IS24CXX in a single write cycle. All<br />inputs are disabled until completion of the internal WRITE<br />cycle.<br /><br />以上的規格說24C01和24C02都是 0x07<br />雖然我取 0x03也行,但程序要進行換行,運行的時間比0x07長了點<br /><br />EEPROM_24C01 EQU 0x03 ;4 bytes row structrue<br />EEPROM_24C01A EQU 0x07 ;8 bytes row structrue<br />EEPROM_24C02 EQU 0x07 ;8 bytes row structrue<br />EEPROM_24C04 EQU 0x0f ;16 bytes row structrue<br />EEPROM_24C08 EQU 0x0f ;16 bytes row structrue<br />EEPROM_24C16 EQU 0x0f ;16 bytes row structrue<br /><br />;=========================================================================================<br />; EEPROMWrite<br />;=========================================================================================<br />EEPROMWrite: <br /> ldi zI2CRepeat ,I2CFAILTIMES&0fh<br />?DeviceNoStabile:<br /> ldi zI2CAck ,00h <br /> sbim zI2CRepeat ,01h<br /> baz Exit_EEPROMWrite<br /> andim SDA_PINCR ,SDA^0x0f ;check bus<br /> andim SCL_PINCR ,SCL^0x0f <br /> nop <br /> nop<br /> nop<br /> lda SDA_PIN ,0 <br /> sta zI2CAck ,0 <br /> andim zI2CAck ,SDA <br /> baz ?DeviceIsBusy ;ready if sda pull high<br /> lda SCL_PIN ,0 <br /> sta zI2CAck ,0 <br /> andim zI2CAck ,SCL<br /> if SCL_PULL==SCL_PULLUP_TO_VDD<br /> bnz ?DeviceIsReady ;if scl pull high<br /> else <br /> baz ?DeviceIsReady ;if scl pull down<br /> endif <br />?DeviceIsBusy: <br /> call IICStop<br /> call Delay10ms<br /> jmp ?DeviceNoStabile<br />?DeviceIsReady: <br />?EEPROMWriteOneByte:<br /> call IICInit<br /> ;*** clear writeProtect<br /> // andim WP_PIN ,WP^0x0f <br /> call IICStart ;start<br /> orim zI2CDevAddr ,DEV_WRITE ;write device addr<br /> sta zI2CByteData+0 ,0<br /> ldi zI2CByteData+1 ,DEV_COMMAND <br /> call IICWriteByte <br /> baz $+2<br /> jmp ?DeviceIsBusy<br /> lda zI2CByteAddr+0 ,0 ;write byte addr<br /> sta zI2CByteData+0 ,0<br /> lda zI2CByteAddr+1 ,0<br /> sta zI2CByteData+1 ,0<br /> call IICWriteByte <br /> baz $+2<br /> jmp ?DeviceIsBusy<br />?WriteUserData: <br /> lda zI2CDPL ,0 ;prt->currentRAM <br /> sta rzDPL ,0<br /> lda zI2CDPM ,0<br /> sta rzDPM ,0<br /> lda zI2CDPH ,0<br /> sta rzDPH ,0<br /> lda rzINX ,0<br /> sta zI2CByteData+0 ,0<br /> adim rzDPL ,01h<br /> eor rzDPL ,0<br /> adcm rzDPM ,0<br /> lda rzINX ,0<br /> sta zI2CByteData+1 ,0<br /> call IICWriteByte ;write one byte<br /> baz ?successWrite<br /> jmp ?DeviceIsBusy<br />?successWrite: ;if success,then<br /> sbim zI2CCounter ,01h ;counter-- <br /> baz ?Finish_WriteEEPROM ;exit if counter=0<br />?syncUser: <br /> adim zI2CDPL ,0x02 ;nextRAM <- ptr<br /> eor zI2CDPL ,0 <br /> adcm zI2CDPM ,0 <br />?syncDevice: <br /> adim zI2CByteAddr+0 ,0x01<br /> eor zI2CByteAddr+0 ,0<br /> adcm zI2CByteAddr+1 ,0<br /> or zI2CByteAddr+0 ,0<br /> baz ?writeNextPage<br /> ;shift row meet 24C01 data structrue<br /> ldi zWk0 ,EEPROM_24C01 <br /> and zI2CByteAddr+0 ,0<br /> baz ?writeNextRow<br /> ?writeCurrentRow:<br /> jmp ?WriteUserData <br /> ?writeNextPage:<br /> adim zI2CDevAddr ,0x02 <br /> ?writeNextRow: <br /> andim zI2CDevAddr ,1110b <br /> call IICStop <br /> call Delay10ms ;continue to<br /> jmp EEPROMWrite ;write next page<br />?Finish_WriteEEPROM: <br /> call IICStop <br /> call Delay10ms <br /> ldi zI2CAck ,01h ;mark success flag<br />Exit_EEPROMWrite: <br /> ;*** set writeProtect <br /> // orim WP_PIN ,WP <br /> lda zI2CAck ,0<br /> rtni ;to disable writing
|