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.

Problem with onboard EEPROM on 16f628A

Status
Not open for further replies.

clueless123

New Member
I am trying to use the onboard EEPROM of a 16f628A, and no matter
what address I specify, only the first byte is being modified. My .asm
file is appended at the end.

In my program, I am trying to modify location 0x03, but only 0x00 is
getting modified. Could somebody please clue me in?

Thank you.

; This file is a basic code template for assembly code generation *
; on the PICmicro PIC16F628A. This file contains the basic code *
; building blocks to build upon. *
; *
; If interrupts are not used all code presented between the ORG *
; 0x004 directive and the label main can be removed. In addition *
; the variable assignments for 'w_temp' and 'status_temp' can *
; be removed. *
; *
; Refer to the MPASM User's Guide for additional information on *
; features of the assembler (Document DS33014). *
; *
; Refer to the respective PICmicro data sheet for additional *
; information on the instruction set. *
; *
;**********************************************************************
; *
; Filename: xxx.asm *
; Date: *
; File Version: *
; *
; Author: *
; Company: *
; *
; *
;**********************************************************************
; *
; Files required: *
; *
; *
; *
;**********************************************************************
; *
; Notes: *
; *
; *
; *
; *
;**********************************************************************

list p=16f628A ; list directive to define processor
#include <p16F628A.inc> ; processor specific variable definitions

errorlevel -302 ; suppress message 302 from list file

__CONFIG _CP_OFF & _DATA_CP_OFF & _LVP_OFF & _BOREN_OFF & _MCLRE_OFF & _WDT_OFF & _PWRTE_ON & _INTOSC_OSC_NOCLKOUT

; '__CONFIG' directive is used to embed configuration word within .asm file.
; The lables following the directive are located in the respective .inc file.
; See data sheet for additional information on configuration word settings.




;***** VARIABLE DEFINITIONS
w_temp EQU 0x71 ; variable used for context saving
status_temp EQU 0x72 ; variable used for context saving





;**********************************************************************
ORG 0x000 ; processor reset vector
goto main ; go to beginning of program


ORG 0x004 ; interrupt vector location
movwf w_temp ; save off current W register contents
movf STATUS,w ; move status register into W register
movwf status_temp ; save off contents of STATUS register

; isr code can go here or be located as a call subroutine elsewhere


movf status_temp,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,f
swapf w_temp,w ; restore pre-isr W register contents
retfie ; return from interrupt


main

; remaining code goes here

bsf STATUS, RP0 ; read from the onboard EEPROM
movlw 0x03
movfw EEADR
bsf EECON1, RD
incf EEDATA, 1

bsf EECON1, WREN ; now increment this value by 1
bcf INTCON, GIE
movlw 0x55
movwf EECON2
movlw 0xAA
movwf EECON2
bsf EECON1,WR
bsf INTCON, GIE

Stop goto Stop ;endless loop


; initialize eeprom locations

ORG 0x2100
DE 0x00, 0x01, 0x02, 0x03


END ; directive 'end of program'
 
I'm still unable to get my code to work. Now I have created a
write eeprom subroutine but it still does not write the desired value
into the desired location. I am sure it is a minor error of some kind.

Could somebody clue me in? My code is below:

; This file is a basic code template for assembly code generation *
; on the PICmicro PIC16F628A. This file contains the basic code *
; building blocks to build upon. *
; *
; If interrupts are not used all code presented between the ORG *
; 0x004 directive and the label main can be removed. In addition *
; the variable assignments for 'w_temp' and 'status_temp' can *
; be removed. *
; *
; Refer to the MPASM User's Guide for additional information on *
; features of the assembler (Document DS33014). *
; *
; Refer to the respective PICmicro data sheet for additional *
; information on the instruction set. *
; *
;**********************************************************************
; *
; Filename: xxx.asm *
; Date: *
; File Version: *
; *
; Author: *
; Company: *
; *
; *
;**********************************************************************
; *
; Files required: *
; *
; *
; *
;**********************************************************************
; *
; Notes: *
; *
; *
; *
; *
;**********************************************************************

list p=16f628A ; list directive to define processor
#include <p16F628A.inc> ; processor specific variable definitions

errorlevel -302 ; suppress message 302 from list file

__CONFIG _CP_OFF & _DATA_CP_OFF & _LVP_OFF & _BOREN_OFF & _MCLRE_OFF & _WDT_OFF & _PWRTE_ON & _INTOSC_OSC_NOCLKOUT

; '__CONFIG' directive is used to embed configuration word within .asm file.
; The lables following the directive are located in the respective .inc file.
; See data sheet for additional information on configuration word settings.

cblock 0x20 ;start of general purpose registers
eeprom_addr
eeprom_value
endc



;***** VARIABLE DEFINITIONS
w_temp EQU 0x71 ; variable used for context saving
status_temp EQU 0x72 ; variable used for context saving





;**********************************************************************
ORG 0x000 ; processor reset vector
goto main ; go to beginning of program


ORG 0x004 ; interrupt vector location
movwf w_temp ; save off current W register contents
movf STATUS,w ; move status register into W register
movwf status_temp ; save off contents of STATUS register

; isr code can go here or be located as a call subroutine elsewhere


movf status_temp,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,f
swapf w_temp,w ; restore pre-isr W register contents
retfie ; return from interrupt


main

; remaining code goes here

movlw 0x70
movwf EEADR
movlw 0xAA
movwf EEDATA
call Write_EEPROM

Stop goto Stop ;endless loop


Read_EEPROM ; put address in w; result is returned in w
bsf STATUS, RP0 ; read from the onboard EEPROM
movwf EEADR
bsf EECON1, RD
movfw EEDATA
bcf STATUS, RP0
return

Write_EEPROM ; put value in eeprom_value and address in eeprom_addr
bsf STATUS, RP0
bsf EECON1, WREN
bcf INTCON, GIE
movlw 0x55
movwf EECON2
movlw 0xAA
movwf EECON2
bsf EECON1, WR
bsf INTCON, GIE
return


; initialize eeprom locations

ORG 0x2100
DE 0x00, 0x01, 0x02, 0x03


END ; directive 'end of program'
 
Write_EEPROM ; put value in eeprom_value and address in eeprom_addr
bsf STATUS, RP0
bsf EECON1, WREN
bcf INTCON, GIE
movlw 0x55
movwf EECON2
movlw 0xAA
movwf EECON2
bsf EECON1, WR
bsf INTCON, GIE
return

Try to put a loop until the write is finish and switch back your bank to 0 like this :

Write_EEPROM ; put value in eeprom_value and address in eeprom_addr
bsf STATUS, RP0
bsf EECON1, WREN
bcf INTCON, GIE
movlw 0x55
movwf EECON2
movlw 0xAA
movwf EECON2
bsf EECON1, WR
btfsc eecon1,wr
goto $-1
bcf eecon1,wren ;disable eeprom write
bcf status,rp0
bsf INTCON, GIE
return
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top