Hi Guys I have write to eeprom but when I power up it wont starts from last saved value its starting from "0000".I cannot solve the problem please take a look.
Thanks
Thanks
Code:
list p=16f628a
#include <P16F628A.inc>
errorlevel -302
__config 0x3D18
D0 equ 21h
D1 equ 22h
D10 equ 23h
D100 equ 24h
SCcount equ 25h
Eadd equ 70h ;common to all four banks
Edat equ 71h ;common to all four banks
org 0x00
movlw 0x07
movwf CMCON
goto Main
;**********************************************
;multiplexing & increment stuff in the four SSD
;**********************************************
Scan ----
----
return
Incr ----
----
return
;**********************
;eeprom write routine
;**********************
Ewrite bsf STATUS,RP1 ;B1
movf Edat,W
movwf EEDATA
movf Eadd,W
movwf EEADR
bsf EECON1,WREN
movlw 55h
movwf EECON2
movlw 0AAh
movwf EECON2
bsf EECON1,WR
btfsc EECON1,WR
goto $-1
clrf STATUS ;B0
return
;**********************
;eeprom read routine
;**********************
EEread bsf STATUS,RP1 ;B1
movwf EEADR
bsf EECON1,RD
btfsc EECON1,RD
goto $-1
movf EEDATA,W
clrf STATUS ;B0
return
;******************************
;main program startd from here
;******************************
Main bsf STATUS,RP0 ;B1
movlw 01h ;make RB0 input button
movwf TRISB
clrf TRISA
bcf OPTION_REG,NOT_RBPU
bcf STATUS,RP0 ;B0
clrf Eadd
clrf Edat
clrf D0
clrf D1
clrf D10
clrf D100
;*************************************************************
;read the saved value first & put into four digits in the SSD
;*************************************************************
clrw
call EEread
movwf D0
movlw 01h
call EEread
movwf D1
movlw 02h
call EEread
movwf D10
movlw 03h
call EEread
movwf D100
;****************************
;has the save button pressed?
;****************************
Main1 movlw .100 ;100 scans
movwf SCcount
call Scan
decfsz SCcount,f
goto $-2
call Incr
btfsc PORTB,0 ;check the save button
goto Main1
;****************************************
;yes then write the four digits to EEPROM
;****************************************
clrw
movwf Eadd
movf D0,W
movwf Edat
call Ewrite
movlw 01h
movwf Eadd
movf D1,W
movwf Edat
call Ewrite
movlw 02h
movwf Eadd
movf D10,W
movwf Edat
call Ewrite
movlw 03h
movwf Eadd
movf D100,W
movwf Edat
call Ewrite
call Scan
btfss PORTB,0
goto $-2
goto Main1
end