We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
i am writing a program for an 8051...the program is suppose to erase device memory then read a value from variable EEADR and store in EEBYT and output the value to port 3...finally it is suppose to write a byte to EEPROM with address in EEADR and value in EEBYT...i am using the 8051 IDE to compile this and it compiles fine but i cant figure out how to actually check the routines and see if it is running properly...does anyone know how to check this for me or see any errors in the program? Also, since i am not reading anything from the EEPROM i did not put in any routine to read from it. Thanks for any help!
SK equ p1.0 ;serial clock DI equ p1.1 ;data input DO equ p1.2 ;data output CS equ p1.3 ;chip select EEADR data 50h ;EEADR in 50h EEBYT data 60h ;EEBYT in 60h DSEG AT 20H ORG 20H ; stack start stack: DS 20H ; stack length CSEG ORG 0000H ; start program in 0000H jmp start ; jump to start routine USING 0 ; using register bank 0 start: mov sp, #(stack-1) ; initialize stack pointer clr CS ; clear CS clr SK ; clear serial clock setb DI ; set data input setb DO ; set data output mov EEADR, #55h ; move value 55h into EEADR mov EEBYT,EEADR ;move EEADR to EEBYT mov p3,EEBYT ;move EEBYT to port 3 call ewen ; call enable write routine call eral ; call erase all routine call EWDS ; call disable writing routine mov EEADR, #7fh ; address for byte mov EEBYT, #45h ; byte value call write ; call write routine ;routine to enable write operations EWEN: setb CS ; set chip select mov dptr, #(10011b SHL 7) ;shift left mov b, #12 ; move 12 into b call send ; call send routine clr CS ; clear chip select ret ; return ;routine to erase device eral: setb CS ; set chip select mov dptr, #(10010b SHL 7) ; shift left mov b, #12 ; move 12 into b call send ; call send routine clr CS ; clear chip select ret ; return ;routine to write a byte to EEPROM write: setb CS ; set chip select mov dpl, #101b ; move 5 to dpl mov b, #3 ; move 3 to b call send ; call send routine mov dpl, EEADR ; move EEADR to dpl mov b, #9 ; number of bits call send ; call send routine mov dpl, EEBYT ; move EEBYT into dpl mov b, #8 ; move 8 into b call send ; call send routine clr CS ; clear chip select ret ; return ; routine to send data send: push b ; push b onto stack mov a, b ; bit count into a clr c ; clear bit c subb a, #8 ; subtract 8 from a jc less1 ; jump if less than 8 jz equal ; jump if equals eight mov b, a ; move a into b clr c ; clear bit subb a, #8 ; subtract 8 from a jc less2 ; jump if less than eight jnz great ; jump if greater than eight mov a, dph ; move dph into a jmp call ; jump to call less2: push b ; push b onto stack mov a, dph ; move dph into a shift: rr a ; rotate a to right djnz b, shift ; jump if b not zero to shift pop b ; pop b from stack call: call send2 ; call send2 routine mov b, #8 ; move 8 into b equal: mov a, dpl ; move dpl into a jmp call2 ; jump to call2 less1: push b ; push b onto stack mov a, dpl ; move dpl into a shift2: rr a ; rotate a to right djnz b, shift2 ; jump if b not zero to shift2 pop b ; pop b from stack call2: call send2 ; call send2 routine great: pop b ;pop b from stack ret ;return send2: out: clr SK ; clear serial clock rlc a ; move bit mov DI, c ; move c into data input nop ; delay min 400 nS setb SK ; set serial clock djnz b, out ; next bit / delay min one uS clr SK ; clear clock ret ;return ewds: setb CS ; CS equals 1 mov dptr, #(10000b SHL 7) mov b, #12 ;move 12 into b call send ;call send routine clr CS ; clear chip select ret ;return