.DISPLAY " EEPROM " .EJECT ; generates a new page in the output listing. ;+--------------------------------------------------------------------------+ ;| EEPROM 93C46 128 x 8 | ;| | ;| WRITTEN BY : Jean-Francois GATTO | ;| DATE : 16/09/91 | ;| REVISION : V01.00 | ;| | ;| SOFTWARE DESCRIPTION : These routines read or write EEPROM registers. | ;| PC4 is configured in input with pull-up and | ;| PC5, PC6 and PC7 are configured in push-pull | ;| output. | ;| | ;| READ instruction reads the content of the | ;| addressed register. | ;| EWEN instruction enables the writing. | ;| WRITE instruction writes the addressed register| ;| EWDS instruction disables the writing. | ;| | ;| 128 x 8 = 1 Kb | ;| | ;| 1 +-----------+ 8 | ;| PC7 ( CS )--------| CS VCC |------| VCC | ;| 2 | | 7 | ;| PC6 ( SK )--------| SK |---- | ;| 3 | | 6 | ;| PC5 ( DO )--------| DI ORG |----+ | ;| 4 | | 5 | | ;| PC4 ( DI )--------| DO GND |----+--| 0V | ;| +-----------+ | ;| | ;| EXAMPLE : ;***** program ***** | ;| .ORG 880h | ;| LDI DDRC,11100000b | ;| LDI ORC,11100000b | ;| LDI DRC,00000000b | ;| LDI DATA,24h | ;| LDI ADDRESS,10h | ;| CALL EWEN | ;| CALL WRITE | ;| CALL EWDS | ;| - do... | ;| CALL READ | ;| - do... | ;| .END | ;| ;***** subroutine ***** | ;| .INPUT " EEPROM.ASM " | ;| | ;+--------------------------------------------------------------------------+ .EJECT ; generates a new page in the output listing. ;+--------------------------------------------------------------------------+ ;| EWEN | ;| | ;| INTERNAL PARAMETERS : SAVE_A register saves the accumulator. | ;| CS is the bit 7 of DRC. | ;| SK is the bit 6 of DRC. | ;| DO is the bit 5 of DRC. | ;| DI is the bit 4 of DRC. | ;| | ;| WORST EXECUTION SPEED : 160 cycles | ;| WORST EXECUTION TIME : Tcyc x 160 = 260 us at 8 Mhz | ;| BYTE : 38 bytes | ;+--------------------------------------------------------------------------+ EWEN ; Save the contexte. LD SAVE_A,A ; save the accumulator. ; Send the EWEN instruction in order to enable the EEPROM. SET CS,DRC ; select the EEPROM. SET DO,DRC ; \ SET SK,DRC ; | start bit. RES SK,DRC ; / RES DO,DRC ; \ SET SK,DRC ; | RES SK,DRC ; | EWEN code. SET SK,DRC ; | RES SK,DRC ; / ; Send the address. SET DO,DRC ; \ LDI A,07h ; | EWEN0 SET SK,DRC ; | address = 11XXXXXb. RES SK,DRC ; | DEC A ; | JRNZ EWEN0 ; / ; Exit the subroutine and restore the contexte. RES DO,DRC RES CS,DRC LD A,SAVE_A ; restore the accumulator. RET .EJECT ; generates a new page in the output listing. ;+--------------------------------------------------------------------------+ ;| EWDS | ;| | ;| INTERNAL PARAMETERS : SAVE_A register saves the accumulator. | ;| CS is the bit 7 of DRC. | ;| SK is the bit 6 of DRC. | ;| DO is the bit 5 of DRC. | ;| DI is the bit 4 of DRC. | ;| | ;| WORST EXECUTION SPEED : 152 cycles | ;| WORST EXECUTION TIME : Tcyc x 152 = 247 us at 8 Mhz | ;| BYTE : 34 bytes | ;+--------------------------------------------------------------------------+ EWDS ; Save the contexte. LD SAVE_A,A ; save the accumulator. ; Send the EWDS instruction in order to disable the EEPROM. SET CS,DRC ; select the EEPROM. SET DO,DRC ; \ SET SK,DRC ; | start bit. RES SK,DRC ; / RES DO,DRC ; \ SET SK,DRC ; | RES SK,DRC ; | EWDS code. SET SK,DRC ; | RES SK,DRC ; / ; Send the address. LDI A,07h ; \ EWDS0 SET SK,DRC ; | RES SK,DRC ; | adress = 00XXXXXb. DEC A ; | JRNZ EWDS0 ; / ; Exit the subroutine and restore the contexte. RES CS,DRC LD A,SAVE_A ; restore the accumulator. RET .EJECT ; generates a new page in the output listing. ;+--------------------------------------------------------------------------+ ;| WRITE | ;| | ;| INPUT PARAMETERS : ADDRESS register contains the address. | ;| DATA register contains the data in write mode. | ;| CS is the bit 7 of DRC. | ;| SK is the bit 6 of DRC. | ;| DO is the bit 5 of DRC. | ;| DI is the bit 4 of DRC. | ;| | ;| INTERNAL PARAMETERS : SAVE_A register saves the accumulator. | ;| COUNTER register contains the bit number. | ;| | ;| WORST EXECUTION SPEED : 448 cycles | ;| WORST EXECUTION TIME : Tcyc x 448 = 728 us at 8 Mhz + programing time | ;| BYTE : 97 bytes | ;+--------------------------------------------------------------------------+ WRITE ; Save the contexte. LD SAVE_A,A ; save the accumulator. ; Send the WRITE instruction. SET CS,DRC ; select the EEPROM. SET DO,DRC ; \ SET SK,DRC ; | start bit. RES SK,DRC ; / RES DO,DRC ; \ SET SK,DRC ; | RES SK,DRC ; | WRITE code. SET DO,DRC ; | SET SK,DRC ; | RES SK,DRC ; / ; Send the address. RES DO,DRC LDI COUNTER,07h LD A,ADDRESS SLA A ; shift the address ( 7 bits ). WRIT0 RLC A JRNC WRIT1 SET DO,DRC ; \ JP WRIT2 ; | WRIT1 RES DO,DRC ; | send the address. WRIT2 SET SK,DRC ; | RES SK,DRC ; / DEC COUNTER JRNZ WRIT0 ; Send the data. RES DO,DRC LDI COUNTER,08h LD A,DATA WRIT3 RLC A JRNC WRIT4 SET DO,DRC ; \ JP WRIT5 ; | WRIT4 RES DO,DRC ; | send the data. WRIT5 SET SK,DRC ; | RES SK,DRC ; / DEC COUNTER JRNZ WRIT3 ; Wait for the end of the programming time ( it is not mandatory, you ; can jump over this part). RES DO,DRC RES CS,DRC SET CS,DRC WRIT6 SET SK,DRC RES SK,DRC RES DI,DRC ; PC4 is reconfigured in pull-up. JRS DI,DRC,WRIT6 ; wait for busy bit. WRIT7 SET SK,DRC RES SK,DRC RES DI,DRC ; PC4 is reconfigured in pull-up. JRR DI,DRC,WRIT7 ; wait for ready bit. ; Exit the subroutine and restore the contexte. RES CS,DRC LD A,SAVE_A ; restore the accumulator. RET .EJECT ; generates a new page in the output listing. ;+--------------------------------------------------------------------------+ ;| READ | ;| | ;| INPUT PARAMETERS : ADDRESS register contains the address. | ;| CS is the bit 7 of DRC. | ;| SK is the bit 6 of DRC. | ;| DO is the bit 5 of DRC. | ;| DI is the bit 4 of DRC. | ;| | ;| INTERNAL PARAMETERS : SAVE_A register saves the accumulator. | ;| COUNTER register contains the bit number. | ;| | ;| OUTPUT PARAMETERS : DATA register contains the data in read mode. | ;| | ;| WORST EXECUTION SPEED : 558 cycles | ;| WORST EXECUTION TIME : Tcyc x 558 = 906 us at 8 Mhz | ;| BYTE : 79 bytes | ;+--------------------------------------------------------------------------+ READ ; Save the contexte. LD SAVE_A,A ; save the accumulator. ; Send the READ instruction. SET CS,DRC ; select the EEPROM. SET DO,DRC ; \ SET SK,DRC ; | start bit. RES SK,DRC ; / SET SK,DRC ; \ RES SK,DRC ; | RES DO,DRC ; | READ code. SET SK,DRC ; | RES SK,DRC ; / ; Send the address. LDI COUNTER,07h LD A,ADDRESS SLA A ; shift the address ( 7 bits ). READ0 RLC A JRNC READ1 SET DO,DRC ; \ JP READ2 ; | READ1 RES DO,DRC ; | send the address. READ2 SET SK,DRC ; | RES SK,DRC ; / DEC COUNTER JRNZ READ0 ; Receive the data. RES DO,DRC LDI COUNTER,08h CLR A READ3 SLA A SET SK,DRC RES SK,DRC RES DI,DRC ; PC4 is reconfigured in pull-up. JRS DI,DRC,READ4 ; \ RES 0,A ; | receive the data. JP READ5 ; | READ4 SET 0,A ; / READ5 DEC COUNTER JRZ READ6 JP READ3 READ6 LD DATA,A ; Exit the subroutine and restore the contexte. RES CS,DRC LD A,SAVE_A ; restore the accumulator. RET