![](/uploads/1/2/5/5/125513405/583885662.jpeg)
![Pic16f628a Eeprom Write Pic16f628a Eeprom Write](/uploads/1/2/5/5/125513405/103115577.jpg)
Interfacing of PIC12F675 with (i2c based) 24LC64 EEPROM (code + Proteus simulation) This post provides the code for interfacing 24LC64 EEPROM with PIC12F675 microcontroller. This 24LC64 EEPROM has i2c based interface and PIC12F675 doesn’t have any built in i2c modules, so software i2c module is created in the code. This code is written in C.
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'
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'
![Arduino eeprom write Arduino eeprom write](/uploads/1/2/5/5/125513405/308116298.png)
I got to thinking about how Hydrogen on Demand will be unique, and I need a way to saving a value of how long a delay should be between the time the lower sensor goes low and how long after the upper sensor goes high to keep from overfilling the cell with electrolyte. I was thinking of using an EEPROM to store that data that would be read and moved to the delay counter that is used when the Refill section of my code is running. I would probably read a switch that tells on an input that would tell my pic to read the other input that would increment the W Register to the desired delay. When the switch to increment the W register goes low it would write the W register to the EEPROM. I'm already thinking of what code to write for the subroutine to set the value to the W Register, but what Registers would be used in the onboard EEPROM and what commands would be used to read and write to the EEPROM registers??
Edit:
I thought about leaving putting the value in code, but I would like to be able to change that value without having to recompile and reprogram the PIC with a new HEX file if I ever change HOD cells and require a different refill time to sufficiently fill the cell to above the Upper Water Level Sensor.
Edit:
I thought about leaving putting the value in code, but I would like to be able to change that value without having to recompile and reprogram the PIC with a new HEX file if I ever change HOD cells and require a different refill time to sufficiently fill the cell to above the Upper Water Level Sensor.
![](/uploads/1/2/5/5/125513405/583885662.jpeg)