; File: 93C46B.A51 Date: 02/29/2000 ; ; /* (c) Copyright BLUE EARTH RESEARCH, MANKATO, MN 2000 */ ; /* All rights reserved. */ ; $ PW(99) PL(60) DATE(02-29-00) $ DEBUG ERRORPRINT XREF ; ******************************************************* ; * 93C46B SERIAL EEPROM DRIVER * ; ******************************************************* ; ----------------------------------------------------- ; | Written By: Thomas Bachmann | ; | Blue Earth Research, Mankato, MN 56001 | ; ----------------------------------------------------- ; ------------------------------------------------------------ ; ; NOTES: ; ; This file is an update to the original 93C46.A51 file ; used to read and write the serial EEPROM on the Micro-485. ; ; The updated driver will work on both the old and the new ; devices. ; ; ------------------------------------------------------------ LastByte DATA 20H ; Last byte written to PB Command DATA 1FH ; Command to execute HiByte DATA 1EH ; Hi byte to/from EEPROM LoByte DATA 1DH ; Lo byte to/from EEPROM n EQU R0 ; Bit Counter register EEZ2 BIT 7 ; Not used EECS BIT 6 ; EEPROM chip select EESK BIT 5 ; EEPROM clock EEI BIT 4 ; EEPROM data in EEO EQU P3.3 ; EEPROM data out PortB XDATA 0FD01H ; 82C55A Port B Address ReDe EQU 0110B ; Leave serial port enabled CSEG AT 7D00H EEProm: PUSH ACC ; Save registers PUSH PSW PUSH DPL PUSH DPH MOV DPTR,#PortB ; Access Port B only MOV LastByte,#ReDe ; Through "LastByte" ORL PSW,#000$11$000B ; Select rb 3 CLR EESK ; Clock must be MOV A,LastByte ; low to start MOVX @DPTR,A CLR EECS ; Get ready MOV A,LastByte MOVX @DPTR,A SETB EECS ; Select EEPROM MOV A,LastByte MOVX @DPTR,A SETB EEI ; Start bit is 1st ACALL Toggle MOV A,Command MOV n,#8 ; Send 8 bits Clock8: RLC A ; Get next one MOV EEI,C ACALL Toggle ; Clockit DJNZ n,Clock8 RL A ; Realign bits JB ACC.7,MaybeRead ; READ or ERASE ? JB ACC.6,Write ; WRITE ? CheckOther: JB ACC.5,Done ; EWEN or ERAL ? JNB ACC.4,Done ; EWDS ? ; Write to a single address or all addresses Write: MOV n,#16 MOV A,HiByte ; Get Hi byte First MoreWrite: RLC A ; Get next bit MOV EEI,C ACALL Toggle ; Clockit CJNE n,#9,SkipLo MOV A,LoByte ; Get Lo byte Next SkipLo: DJNZ n,MoreWrite SJMP Done MaybeRead: JB ACC.6,Done ; ERASE ? MOV n,#16 ; Loop 16 times MoreRead: ACALL Toggle ; Clock in data bit MOV C,EEO ; Get data bit RLC A ; Shift into ACC CJNE n,#9,SkipHi MOV HiByte,A ; Store HiByte SkipHi: DJNZ n,MoreRead MOV LoByte,A ; Store LoByte Done: SETB EEI ; Release I/O MOV A,LastByte MOVX @DPTR,A CLR EECS ; Start self clocking MOV A,LastByte MOVX @DPTR,A SETB EECS MOV A,LastByte MOVX @DPTR,A JNB EEO,$ ; Still Busy ? CLR EECS ; Deselect EEPROM MOV A,LastByte MOVX @DPTR,A SETB EESK MOV A,LastByte MOVX @DPTR,A POP DPH ; Restore registers POP DPL POP PSW POP ACC RET ; ------- Subroutine for Clocking a bit --------- Toggle: PUSH ACC MOV A,LastByte ; First set the data pin MOVX @DPTR,A SETB EESK ; then toggle the clock MOV A,LastByte MOVX @DPTR,A CLR EESK MOV A,LastByte MOVX @DPTR,A POP ACC RET END ; Following is the HEX file derived from the assembled source ; file. This can be used for directly loading the program via ; MONITOR-51 and almost any terminal program. :107D0000C0E0C0D0C082C08390FD0175200643D082 :107D100018C205E520F0C206E520F0D206E520F005 :107D2000D204B186E51F7808339204B186D8F923CE :107D300020E71B20E60620E52830E4257810E51E24 :107D4000339204B186B80902E51DD8F4801320E609 :107D5000107810B186A2B333B80902F51ED8F4F535 :107D60001DD204E520F0C206E520F0D206E520F0A1 :107D700030B3FDC206E520F0D205E520F0D083D077 :107D800082D0D0D0E022C0E0E520F0D205E520F09E :087D9000C205E520F0D0E0225D :00000001FF