;Stazeno z www.HW.cz
; Autorem tohoto SW je Zdenek Janis
Medusa@brajan.cz
; Unit na komunikaci s EEPROM AT93C46
;
;*****************************************************************************
; Dle hardware nastav:
;
; CS - vyber obvodu
EE_CS BIT P2.4
;
; SK - hidinovy vstup
EE_SK BIT P2.3
;
; DI - data input
EE_DI BIT P2.2
;
; DO - data output
EE_DO BIT P2.1
;
; ORG - organizace 16/8bit
EE_ORG BIT P2.0
;
;*****************************************************************************
;
; Inicializace EEPROMky
EE_Init: ; Inicializace EEPROM pro 8bitovou komunikaci
clr EE_CS ; CS
clr EE_ORG ; 8bitova organizace
clr EE_DI ; IN EEPROM
clr EE_SK ; CLK
setb EE_DO ; OUT EEPROM
ret
;*****************************************************************************
; Cteni jednoho bajtu z EEPROMky
; OC: 110
EE_Read: ; v R0 adresa, v A vysledek cteni
; Uloz registry
push 000h ; R0
acall EE_StartBit ; Posli Start Bit
; Zaslani operacniho codu do EEPROM (110)
setb C
acall EE_WrBit
acall EE_WrBit
clr C
acall EE_WrBit
; Zaslani adresy, A6, A5, A4, A3, A2, A1, A0
mov A, R0 ; A:= Adresa bunky pro zapis do EEPROM
rl A ; Posun o jeden bit do leva (7bit neni potreba)
mov R0, #007d ; Pocet odesilanych bitu pro adresu
EE_ReAdd: ;
rlc A ; presun bit do C
acall EE_WrBit ; a posli jej EEPROM
djnz R0, EE_ReAdd ; Posilej dalsi bit
; cteni dat z EEPROMky
clr A
mov R0, #009d ; Pocet prijmanych bitu
EE_ReDat: ;
acall EE_ReBit
rlc A ; Test bitu
djnz R0, EE_ReDat ; Posilej dalsi bit
; Ukonci proceduru cteni
acall EE_StopBit ; Posli Stop Bit
; Obnov registry
pop 000h ; R0
ret
;*****************************************************************************
; Zapis jeden bajt do EEPROMky
; OC: 101
EE_Write: ; v R0 adresa, v A data pro zapis
; Uloz registry
push ACC ; A
push 000h ; R0
acall EE_StartBit ; Posli Start Bit
; Zaslani operacniho codu do EEPROM (101)
setb C
acall EE_WrBit
clr C
acall EE_WrBit
setb C
acall EE_WrBit
; Zaslani adresy, A6, A5, A4, A3, A2, A1, A0
push ACC ; Uloz data pro EEPROM
mov A, R0 ; A:= Adresa bunky pro zapis do
EEPROM
rl A ; Posun o jeden bit do leva (7bit neni
potreba)
mov R0, #007d ; Pocet odesilanych bitu pro adresu
EE_WrAdd: ;
rlc A ; presun bit do C
acall EE_WrBit ; a posli jej EEPROM
djnz R0, EE_WrAdd ; Posilej dalsi bit
; Zaslani dat EEPROMce
pop ACC ; Obnov data pro EEPROM
mov R0, #008d ; Pocet odesilanych bitu pro data
EE_WrDat: ;
rlc A ; Test bitu
acall EE_WrBit
djnz R0, EE_WrDat ; Posilej dalsi bit
; Cekej na dokonceni internich operaci zapisu
EEPROMky
acall EE_Done ;
acall EE_StopBit ; Posli Stop Bit
; Obnov registry
pop 000h ; R0
pop ACC ; A
ret
;*****************************************************************************
; Smazani jedne bunky (vyplni ji $FF)
; OC: 111
EE_Erase: ; v R0 adresa mazane bunky v EEPROM
; Uloz registry
push ACC ; A
push 000h ; R0
acall EE_StartBit ; Posli Start Bit
; Zaslani operacniho codu do EEPROM (111)
setb C
acall EE_WrBit
acall EE_WrBit
acall EE_WrBit
; Zaslani adresy, A6, A5, A4, A3, A2, A1, A0
mov A, R0 ; A:= Adresa bunky pro smazani
rl A ; Posun o jeden bit do leva (7bit neni potreba)
mov R0, #007d ; Pocet odesilanych bitu pro adresu
EE_ErAdd: ;
rlc A ; presun bit do C
acall EE_WrBit ; a posli jej EEPROM
djnz R0, EE_ErAdd ; Posilej dalsi bit
; Cekej na dokonceni internich operaci zapisu
EEPROMky
acall EE_Done ;
acall EE_StopBit ; Posli Stop Bit
; Obnov registry
pop 000h ; R0
pop ACC ; A
ret
;*****************************************************************************
; Povoleni zapisovych a mazacich operaci
; OC: 100,11
EE_EWEN: ; Write enable must precede all programming.
; Start bit
acall EE_StartBit
; Operacni code (100)
setb C
acall EE_WrBit
clr C
acall EE_WrBit
acall EE_WrBit
; Pod Operacni code (11)
setb C
acall EE_WrBit
acall EE_WrBit
; Zbytek - libovolne hodnoty: 5x (00000)
clr C
acall EE_WrBit
acall EE_WrBit
acall EE_WrBit
acall EE_WrBit
acall EE_WrBit
; Stop bit
acall EE_StopBit
ret
;*****************************************************************************
; Zakaz mazacich a zapisovych operaci
; OC: 100,00
EE_EWDS: ; Disable all programming instuctions.
; Start bit
acall EE_StartBit
; Operacni code (100)
setb C
acall EE_WrBit
clr C
acall EE_WrBit
acall EE_WrBit
; Pod Operacni code (00)
clr C
acall EE_WrBit
acall EE_WrBit
; Zbytek - libovolne hodnoty: 5x (00000)
clr C
acall EE_WrBit
acall EE_WrBit
acall EE_WrBit
acall EE_WrBit
acall EE_WrBit
; Stop bit
acall EE_StopBit
ret
;*****************************************************************************
; Smaz celou pamet EEPROM
; OC: 100,10
EE_ERAL: ; Erases all memory locatons.
; Start bit
acall EE_StartBit
; Operacni code (100)
setb C
acall EE_WrBit
clr C
acall EE_WrBit
acall EE_WrBit
; Pod Operacni code (10)
setb C
acall EE_WrBit
clr C
acall EE_WrBit
; Zbytek - libovolne hodnoty: 5x (00000)
clr C
acall EE_WrBit
acall EE_WrBit
acall EE_WrBit
acall EE_WrBit
acall EE_WrBit
; Cekej na dokonceni internich operaci mazani
EEPROMky
acall EE_Done
acall EE_StopBit ; Stop Bit
ret
;*****************************************************************************
; Zapis do vsech budek EEPROM
; OC: 100,01
EE_WRAL: ; v A zapisovana data
; Uloz registry
push ACC ; A
push 000h ; R0
; Start bit
acall EE_StartBit
; Operacni code (100)
setb C
acall EE_WrBit
clr C
acall EE_WrBit
acall EE_WrBit
; Pod Operacni code (01)
clr C
acall EE_WrBit
setb C
acall EE_WrBit
; Zbytek - libovolne hodnoty: 5x (00000)
clr C
acall EE_WrBit
acall EE_WrBit
acall EE_WrBit
acall EE_WrBit
acall EE_WrBit
mov R0, #008d ; Pocet odesilanych bitu pro
data
EE_WaDat: ;
rlc A ; Test bitu
acall EE_WrBit
djnz R0, EE_WaDat ; Posilej dalsi bit
; Cekej na dokonceni internich operaci zapisu
EEPROMky
acall EE_Done
acall EE_StopBit ; Stop Bit
; Obnov registry
pop 000h ; R0
pop ACC ; A
ret
;*****************************************************************************
;*****************************************************************************
EE_StartBit: ; Aktivace zbernice EEPROM
setb EE_DO ; Tento pin priprav na cteni
clr EE_SK ; Hodiny low
clr EE_DI ; Data input low
setb EE_CS ; Aktivuj EEPROM
ret
EE_StopBit: ; Deaktivace zbernice EEPROM
clr EE_CS ; Deaktivace EEPROM
clr EE_DI ; Definuj hodnoty pro EEPROM
clr EE_SK ; ...
setb EE_DO ; ...
ret
EE_WrBit: ; Zapis bitu dle C(arry) do EEPROM
clr EE_SK ; Nuluj hodiny
mov EE_DI, C; Nastav DI:= C
setb EE_SK ; Prejdi u hodin na Log. 1.
nop
clr EE_SK ; Dokonci hodinovy impuls
clr EE_DI ; Nastav standartni hodnoty
ret
EE_ReBit: ; Cteni bitu z EEPROM, vysledek v
C(arry)...
setb EE_DO ; Pin pro cteni
clr EE_DI ; Data pro EEPROM nejsou potreba
clr EE_SK ; Nuluj hodiny
mov C, EE_DO; Nacti bit
setb EE_SK ; Nabezna hrana hodin
nop
clr EE_SK ; Sestupna hrana hodin
ret
EE_Done: ; Ceka na dokonceni vnitrni operace EEPROM
setb EE_DO ; Pin na cteni
clr EE_DI ; Data nejsou potreba...
clr EE_SK ; Hodiny na Log. 0.
clr EE_CS ; Sestupna hrana - EEPROM chceck status
nop
setb EE_CS ; Zacatek EEPROM chceck status
EE_Check:
nop
jnb EE_DO, EE_Check ; Cekej na Log. 1
nop
ret
;Stazeno z www.HW.cz
; Autorem tohoto SW je Zdenek Janis
Medusa@brajan.cz
|