;EEPROM routines for WORD access to a 93c66 from 8051 core MPU ; ;Higher Functions: ;EER reads one word ;WEN enables write ;WDS disables write ;EEW writes one word ;EER - read one 16-bit word from address *b* into EET2:EET1 ;Entry b = address ; NV_CS and NV_SK = 0 ;Uses EET0 to hold address ; EET2:EET1 to hold data ; a, b destroyed ;Calls EEA (issue command and address) ; EED (read byte) EER: mov a,#0C0h ;start bit and read command acall EEA ;issue command and address acall EED ;read MSB mov EET2,a acall EED ;read LSB mov EET1,a sjmp EEW1 ;drop NV_CS and return ;WEN - enable write ;Entry NV_CS and NV_SK = 0 ;Uses EET0 to hold parameter (C0h for write enable) ; a, b destroyed ;Calls WDS (jump into) WEN: mov b,#0c0h ;control parameter to enable write sjmp WDS1 ;continue in WDS ;WDS - disable write ;Entry NV_CS and NV_SK = 0 ;Uses EET0 to hold parameter (00h for write disable) ; a, b destroyed ;Calls EEA (issue command and parameter) WDS: mov b,#00h ;control parameter to disable write WDS1: mov a,#80h ;start bit and control command acall EEA ;issue command and parameter (as address) sjmp EEW1 ;drop NV_CS and return ;EEW - write one 16-bit word at address *b* from EET2:EET1 ;Entry b = address ; EET2:EET1 data to be written ; NV_CS and NV_SK = 0 ;Uses EET0 to hold address ; a, b destroyed ;Calls EEA (issue command and address) ; EEB (write byte) EEW: mov a,#0A0h ;start bit and write command acall EEA ;issue command and address mov a,EET2 ;write MSB acall EEB mov a,EET1 ;write LSB acall EEB clr NV_CS ;terminate write operation nop setb NV_CS ;commence waiting for completion jnb NV_DO,$ ;until NV_DO goes high EEW1: clr NV_CS ;disable chip ret ;EEPROM primitives ;EEA - send 3 bit command and 8 bit address ;Entry A = command (bits 7-5) ; b = address ; NV_CS and NV_SK = 0 ;Uses EET0 to hold address ; a, b destroyed ;Calls EEB (fall thru) ; EEC EEA: mov EET0,b ;hold address for later mov b,#3 ;command lth acall EEC ;send command mov a,EET0 ;now send 8 bit address ;EEB - send byte from *a* ;Entry A = byte to send ; b = don't care ; NV_CS in unknown state ; NV_SK = 0 ;Uses a, b destroyed ;Calls EEC (fall thru) EEB: mov b,#8 ;EEC - send *b* bits from *a* ;Entry A = bits to send, left justified ; b = number of bits ; NV_CS in unknown state ; NV_SK = 0 ;Uses a, b destroyed ;Calls none EEC: setb NV_CS ;enable chip EEC1: rlc a ; move bit into CY mov NV_DI, c ; output bit nop ; delay min 400 nS setb NV_SK ; raise clock nop ; delay min 400 nS clr NV_SK ; drop clock djnz b, EEC1 ; next bit ret ;EED - read 8 bits into *a* ;Entry A = don't care ; b = don't care ; NV_CS in unknown state ; NV_SK = 0 ;Exit A = assembled byte ;Uses a, b destroyed ;Calls none EED: mov b, #8 ; init loop / delay min one uS setb NV_CS ; enable chip EED1: setb NV_SK ; raise clock nop ; delay min one uS mov c,NV_DO ; read serial data output rlc a ; shift in bit / delay min one uS clr NV_SK ; drop clock djnz b, EED1 ; next bit / delay min one uS ret