Reborn121
Newbie level 5
- Joined
- Jun 29, 2010
- Messages
- 8
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Location
- united states
- Activity points
- 1,340
i have some code i am trying to get working here...there are probably a few things wrong with it but i cant seem to get it together...please help!...the program is suppose to erase EEPROM, then read a value from EEADR and store in EEBYT and output the value to port 3, then suppose to write a byte to EEPROM and thats it....please point me in the right direction...thanks
Code:
size EQU 9
EEBYT EQU 00h
EEADR EQU 20h
CS EQU p1.0
SK EQU p1.1
DI EQU p1.2
DO EQU p1.3
clr CS ; low
clr SK ; low
setb DI ; high
setb DO ; high
call ewen ;enable write
call eral ;erase device
call ewds ;disable writing
mov c,EEADR ;move EEADR into c
mov EEBYT,c ;move c into EEBYT
mov p3,EEBYT ;move EEBYT to port 3
;write byte to EEPROM
mov EEADR, #7fh ; address
mov EEBYT, #55h ; data
mov a, EEBYT
call write ;call write routine
write:
setb CS
mov dpl, #101b
mov b, #3
call outdata
mov dpl, EEADR
mov b, #size ; bit count
call outdata
mov dpl, EEBYT
mov b, #8
call outdata
clr CS ; drop CS
eral:
setb CS ; raise CS
mov dptr, #(10010b SHL (size-2))
mov b, #(size+3)
call outdata
clr CS ; drop CS
ret
ewen:
setb CS ; raise CS
mov dptr, #(10011b SHL (size-2))
mov b, #(size+3)
call outdata
clr CS ; drop CS
ret
ewds:
setb CS
mov dptr, #(10000b SHL (size-2))
mov b, #(size+3)
call outdata
clr CS
ret
outdata:
push b
mov a, b ; get bit count
mov a, dpl
call shout
pop b
ret
shout:
out:
clr SK ; drop clock
rlc a ; move bit into CY
mov DI, c ; output bit
nop ; delay min 400 nS
setb SK ; raise clock
djnz b, out ; next bit / delay min one u
clr SK ; drop clock
ret
END