read
LIST p=16F88
include "P16F88.inc"
__config _CONFIG1, _WDT_OFF & _INTRC_IO & _MCLR_ON & _LVP_OFF
errorlevel -302
NEW equ h'74' ;EEPROM locations
OLD equ h'75'
read
banksel EEADR ;Select Bank of EEADR
movf NEW, W
movwf EEADR ; Data Memory Address to
banksel EECON1 ; Select Bank of EECON1
bcf EECON1, EEPGD ; Point to Data memory
bsf EECON1, RD ; EE Read
banksel EEDATA ; Select Bank of EEDATA
movf EEADR, W
return
;_________________________________________________
write
banksel EECON1 ; Select Bank of EECON1
btfsc EECON1, WR ; Wait for write
goto $-1 ; to complete
banksel EEADR ; Select Bank of EEADR
movf NEW, W
movwf EEADR ;DATA Address to write
movf NEW, W ;
movwf EEDATA ; DATA Value to write
banksel EECON1 ; Select Bank of EECON1
bcf EECON1, EEPGD ; Point to DATA memory
bsf EECON1, WREN ; Enable writes
bcf INTCON, GIE ; Disable INTs.
movlw 55h
movwf EECON2 ; Write 55h
movlw h'AA'
movwf EECON2 ; Write AAh
bsf EECON1, WR ; Set WR bit to begin write
bsf INTCON, GIE ; Enable INTs.
bcf EECON1, WREN ; Disable writes
return
banksel EEADR
movf NEW, W
movwf EEADR ;DATA Address to write
movf NEW, W ;
movwf EEDATA ; DATA Value to write
read
banksel EEADR ; Select Bank of EEADR
movlw NEW
movwf EEADR ; Data Memory Address to read
banksel EECON1 ; Select Bank of EECON1
bcf EECON1, EEPGD; Point to Data memory
bsf EECON1, RD ; EE Read
banksel EEADR ; Select Bank of EEDATA
movf EEDATA, W ; W = EEDATA
return
;_________________________________________________
write
banksel EECON1 ; Select Bank of EECON1
btfsc EECON1, WR ; Wait for write
goto $-1 ; to complete
banksel EEADR ; Select Bank of EEADR
movlw NEW
movwf EEADR ; Data Memory Address to write
movfw NEW
movwf EEDATA ; Data Memory Value to write
banksel EECON1 ; Select Bank of EECON1
bcf EECON1, EEPGD ; Point to DATA memory
bsf EECON1, WREN ; Enable writes
bcf INTCON, GIE ; Disable INTs.
movlw 55h ;
movwf EECON2 ; Write 55h
movlw h'AA' ;
movwf EECON2 ; Write AAh
bsf EECON1, WR ; Set WR bit to begin write
bsf INTCON, GIE ; Enable INTs.
bcf EECON1, WREN ; Disable writes
return
banksel EEADR ; Select Bank of EEADR
movlw NEW
movwf EEADR ; Data Memory Address to write
movfw NEW
movwf EEDATA ; Data Memory Value to write
banksel EEADR ; Select Bank of EEADR
movlw NEW
movwf EEADR ; Data Memory Address to write
[COLOR=Red]movlw 0x96 ; dummy data to test write[/COLOR]
movwf EEDATA ; Data Memory Value to write
If you post all your code we can run it and work out why it isn't working. Also, how do you know it isn't working? Are you reading the EEPROM with a programmer? Setting a breakpoint after the read?
Mike.
Good question Pommie, I don't really know, I get the right value in EEDATA, and go through the write sequence, then unplug, then replug, and reset the connection. I don't really know how to work with the breakpoint, and I do read the EEPROM with the programmer in debug or released mode. I suppose that could be the problem right there.... me screwing it up as usual...
Hi Geko, I do get the right value in EEDATA (say 0x33), then I go through the write sequence, then I unplug the programmer (Firefly) and vary the AD input, then replug the firefly, then reconnect with the MPLAB, then I get the new AD value in EEDATA (say 0x25), not the old one. I haven't tried the reset button on the firefly, or breakpoints as Pommie suggested, mostly because I don't really know how to work with breakpoints.
Hi Geko, I do get the right value in EEDATA (say 0x33), then I go through the write sequence,
You know it gets written, or you assume it gets written?Hi Geko, what I do is I write a value into the EEPROM,
then unplug the chip. Now I replug the chip, and reconnect with the MPLAB, this resets all the registers to FF,
"then you go to the program" where? how? what?then I go to the program, and my first command is the read.
I haven't written anything yet. That's when I don't get the value I wrote previously but the value coming out of AD if I varied the pot.
Don't bet on itbut I'm near the end, and only this has to be fixed, then I'm done.
bsf EECON1, WR ;start writing
btfsc EECON1, WR ;wait for writing completion
goto $-1
read
banksel EEADR ; Select Bank of EEADR
movlw NEW
movwf EEADR ; Data Memory Address to read
banksel EECON1 ; Select Bank of EECON1
bcf EECON1, EEPGD; Point to Data memory
bsf EECON1, RD ; EE Read
banksel EEADR ; Select Bank of EEDATA
movf EEDATA, W ; W = EEDATA
return
write
banksel EEADR ; Select Bank of EEADR
movlw NEW
movwf EEADR ; Data Memory Address to write
movfw NEW
movwf EEDATA ; Data Memory Value to write
banksel EECON1 ; Select Bank of EECON1
bcf EECON1, EEPGD ; Point to DATA memory
bsf EECON1, WREN ; Enable writes
movlw 55h
movwf EECON2 ; Write 55h
movlw h'AA'
movwf EECON2 ; Write AAh
bsf EECON1, WR ; Set WR bit to begin write
btfsc EECON1, WR ; Wait for any write
goto $-1
bcf EECON1, WREN ; Disable writes
return
Are you saying that when you program the code into PIC you also initialise the EEPROM?RD: The read sequence picks up the value, so it has to be written. It writes when I write the program, then it stays in, and never changes, even after subsequent writes.
You make this hard work! You still haven't said what registers? EEPROM, SFR, GPR? I guess you mean EEPROM, if so either it's not ever writing to them, or it's getting erased, or the write routine is writing OxFF into it.RD: When I power up the chip, all registers are set to FF.
Unlikely unless you're running it out of spec' - to fast - to low voltage. RTFD(atasheet)Perhaps the clock is too fast for the EEPROM.
I'm still trying to get the EEPROM to return the proper value each time I go through a write. So far, I only get the proper value on first write, that's when I go through the programming write. After that the value doesn't change when I go through the steps. Geko says the code is fine, so I'm looking for something else that might affect the write. Perhaps it's just me as usual that doesn't use the MPLAB correctly. I am writing in debug, and release mode. I have not tried the chip out of firefly. Maybe I should do that, and see how it works.
Does the varible "NEW" stay the same each time you run the pgm?
Did you notice that you are useing "NEW" for the address and data, or did I read that wrong?
If I am wrong don't zing me too bad, I'm still learning too.
Mike.
Did you notice that you are useing "NEW" for the address and data, or did I read that wrong?
Hi Mike,
The code is actually writing the content of location 0x74 (movfw) to the EEPROM at location 0x74 (movlw).
@Robert
The fact that someone who is commissioned to write a commercial program comes on here asking newbie questions really scares me.I just hope this isn't any kind of crytical component.
Mike.
LIST p=16F88
include "P16F88.inc"
__config _CONFIG1, _WDT_OFF & _INTRC_IO & _MCLR_ON & _LVP_OFF
errorlevel -302
Cblock 0x20
TIMER1, TIMER2, VALUE, LEDON, STARTDELAY,
W0, W1, W2, W3, W4, W5, count, LBYTE,
endc
HBYTE equ h'7F'
NEW equ h'74' ; EEPROM data
OLD equ h'75'
banksel TRISA ;bank 1
movlw 0x42 ;1MHz clock
movwf OSCCON
movlw 0x07 ;turn comparators off
movwf CMCON
movlw B'11111111'
movwf TRISB ;all input.
movlw B'00000010' ;all RA ports all outputs except A/D (RA1) input
movwf ANSEL
movwf TRISA
movlw B'00000000'
movwf OPTION_REG ;make all PORTB pins 1
banksel PORTA
goto start
read
banksel EEADR ; Select Bank of EEADR
movlw NEW
movwf EEADR ; Data Memory Address to read
banksel EECON1 ; Select Bank of EECON1
bcf EECON1, EEPGD; Point to Data memory
bsf EECON1, RD ; EE Read
banksel EEADR ; Select Bank of EEDATA
movf EEDATA, W ; W = EEDATA
return
write
banksel EEADR ; Select Bank of EEADR
movlw NEW
movwf EEADR ; Data Memory Address to write
movfw NEW
movwf EEDATA ; Data Memory Value to write
banksel EECON1 ; Select Bank of EECON1
bcf EECON1, EEPGD ; Point to DATA memory
bsf EECON1, WREN ; Enable writes
movlw 55h
movwf EECON2 ; Write 55h
movlw h'AA'
movwf EECON2 ; Write AAh
bsf EECON1, WR ; Set WR bit to begin write
btfsc EECON1, WR ; Wait for any write
goto $-1
bcf EECON1, WREN ; Disable writes
return
start
call read
movwf OLD
incf OLD,f
movfw OLD
movwf NEW
call write
hang
goto hang
end
LIST p=16F88
include "P16F88.inc"
__config _CONFIG1, _WDT_OFF & _INTRC_IO & _MCLR_ON & _LVP_OFF
errorlevel -302
Cblock 0x20
TIMER1, TIMER2, VALUE, LEDON, STARTDELAY,
W0, W1, W2, W3, W4, W5, count, LBYTE,
endc
HBYTE equ h'7F'
NEW equ h'74' ; EEPROM data
OLD equ h'75'
banksel TRISA ;bank 1
movlw 0x42 ;1MHz clock
movwf OSCCON
movlw 0x07 ;turn comparators off
movwf CMCON
movlw B'11111111'
movwf TRISB ;all input.
movlw B'00000010' ;all RA ports all outputs except A/D (RA1) input
movwf ANSEL
movwf TRISA
movlw B'00000000'
movwf OPTION_REG ;make all PORTB pins 1
banksel PORTA
goto start
read
banksel EEADR ; Select Bank of EEADR
movlw NEW
movwf EEADR ; Data Memory Address to read
banksel EECON1 ; Select Bank of EECON1
bcf EECON1, EEPGD; Point to Data memory
bsf EECON1, RD ; EE Read
banksel EEADR ; Select Bank of EEDATA
movf EEDATA, W ; W = EEDATA
return
write
banksel EEADR ; Select Bank of EEADR
movlw NEW
movwf EEADR ; Data Memory Address to write
movfw NEW
movwf EEDATA ; Data Memory Value to write
banksel EECON1 ; Select Bank of EECON1
bcf EECON1, EEPGD ; Point to DATA memory
bsf EECON1, WREN ; Enable writes
movlw 55h
movwf EECON2 ; Write 55h
movlw h'AA'
movwf EECON2 ; Write AAh
bsf EECON1, WR ; Set WR bit to begin write
btfsc EECON1, WR ; Wait for any write
goto $-1
bcf EECON1, WREN ; Disable writes
return
start
call read
movwf OLD
incf OLD,f
movfw OLD
movwf NEW
call write
nop
nop
call read
hang
goto hang
end
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?