Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

EEPROM Crashes chip

Status
Not open for further replies.

kentken

New Member
I am using a 16F872, I need to store a number into EEPROM when turned off.

When I enable this part of the program, the chip crashes. I have writen it just like the data sheet showed. Any Ideas??

Thanks
Kent
 

Nigel Goodwin

Super Moderator
Most Helpful Member
The code examples given usually work fine, try posting your code so we can see what you are doing.

One point, how many subroutines are you calling?, you may be exceeding the stack depth.
 

kentken

New Member
Well, here it is:

READ_ROM_EEPROM
BSF STATUS,RP1 ;
BCF STATUS,RP0 ; Select bank 2
CLRF EEADR^0x0100 ; Start Loc
BSF STATUS,RP0 ; Select bank 3
BCF EECON1^0x0180,EEPGD
BSF EECON1^0x0180,RD
BCF STATUS,RP0 ; Select bank 2
MOVF EEDATA^0x0100,W
MOVWF STROKE_COUNT ; From EEPROM
INCF EEADR^0x0100,F ; Point to next Loc in EEPROM
BSF STATUS,RP0 ; Select bank 3
BCF EECON1^0x0180,EEPGD
BSF EECON1^0x0180,RD
BCF STATUS,RP0 ; Select bank 2
MOVF EEDATA^0x0100,W
MOVWF STROKE_LED ; From EEPROM
INCF EEADR^0x0100,F ; Point to next Loc in EEPROM
BSF STATUS,RP0 ; Select bank 3
BCF EECON1^0x0180,EEPGD
BSF EECON1^0x0180,RD
BCF STATUS,RP0 ; Select bank 2
MOVF EEDATA^0x0100,W
MOVWF TOTAL_1 ; From EEPROM
INCF EEADR^0x0100,F ; Point to next Loc in EEPROM
BSF STATUS,RP0 ; Select bank 3
BCF EECON1^0x0180,EEPGD
BSF EECON1^0x0180,RD
BCF STATUS,RP0 ; Select bank 2
MOVF EEDATA^0x0100,W
MOVWF TOTAL_2 ; From EEPROM
RETURN

SAVE_EEPROM
BSF STATUS,RP1 ;
BCF STATUS,RP0 ; Select bank 2
CLRF EEADR^0x0100 ; Start Loc
MOVF STROKE_COUNT,W
MOVWF EEDATA^0x0100 ; Load EEPROM
CALL SEND_TO_EEPROM
BCF STATUS,RP0 ; Select bank 2
INCF EEADR^0x0100,F ; Point to next Loc in EEPROM
MOVF STROKE_LED,W
MOVWF EEDATA^0x0100 ; Load EEPROM
CALL SEND_TO_EEPROM
BCF STATUS,RP0 ; Select bank 2
INCF EEADR^0x0100,F ; Point to next Loc in EEPROM
MOVF TOTAL_1,W
MOVWF EEDATA^0x0100 ; Load EEPROM
CALL SEND_TO_EEPROM
BCF STATUS,RP0 ; Select bank 2
INCF EEADR^0x0100,F ; Point to next Loc in EEPROM
MOVF TOTAL_2,W
MOVWF EEDATA^0x0100 ; Load EEPROM
CALL SEND_TO_EEPROM
RETURN

;**********************************

SEND_TO_EEPROM
BSF STATUS,RP0 ; Bank 3
BSF STATUS,RP1 ;
BCF EECON1^0x0180,EEPGD
BSF EECON1^0x0180,WREN
BCF INTCON,GIE ;
MOVLW 0x055
MOVWF EECON2^0x0180
MOVLW 0x0AA
MOVWF EECON2^0x0180
BSF EECON1^0x0180,WR
BTFSC EECON1^0x0180,WR ; Done?
GOTO $-1 ;-1 LINE
BCF EECON1^0x0180,WREN
BSF INTCON,GIE ;
RETURN



Thanks
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Top