After running the program, I put the chip into my programmer and read
the program and EEPROM data memory into the buffers, but the EEPROM data
has not changed. Can someone please tell me what I am doing wrong?
> From: Leon Heller <.....leonKILLspam@spam@LFHELLER.DEMON.CO.UK>
> Wanting to use the 16C84 EEPROM data memory, I inserted the following
> code into an existing 16C84 program, which is intended to write 12H into
> the first location, to try the technique out:
> ;PUT SOMETHING INTO EEPROM DATA MEMORY
> MOVLW 00H ;EEPROM ADDRESS TO WRITE TO
> MOVWF EEADR
> MOVLW 12H ;EEPROM DATA TO PUT THERE
> MOVWF EEDATA
> ;STUFF FROM PAGES 31-32 OF PIC16C84 DATA
> MOVLW 55H
> MOVWF EECON2
> MOVLW 0AAH
> MOVWF EECON2
> BSF EECON1,WR ;WR = 1
> BSF EECON1,WREN ;WREN = 2
For a start, set WREN before doing anything!
Maybe you've deleted code to save net bandwidth, but remember that
EECON1 and EECON2 are in bank 2 so you will need to change the above
MOVLW 00H ;EEPROM ADDRESS TO WRITE TO
MOVLW 12H ;EEPROM DATA TO PUT THERE
bsf status,RP0 ; Set bank 1
BSF EECON1,WREN ; Note: this is swapped...
BSF EECON1,WR ; ...over from your code!
bcf eecon1,wren ;Disable further writes (does not
; affect current write) if necessary
goto $-1 ; Loop until write completes
bcf status,RP0 ; Back to bank 0, if necessary
> After running the program, I put the chip into my programmer and read
> the program and EEPROM data memory into the buffers, but the EEPROM data
> has not changed. Can someone please tell me what I am doing wrong?
> Leon Heller, G1HSM | "Do not adjust your mind, there is
> E-mail leonKILLspamlfheller.demon.co.uk | a fault in reality": on a wall
> Phone: +44 (0)1734 471424 | many years ago in Oxford.
One must suggest more careful reading of the manual, since it's all
explained there; and excuse any errors of mine, because I don't have the
manual in front of me.
[who happens to be working on the exact same thing - EEPROM in the '84]
Hi Leon, you wrote:-
>Wanting to use the 16C84 EEPROM data memory, I inserted the following
>After running the program, I put the chip into my programmer and read
>the program and EEPROM data memory into the buffers, but the EEPROM data
>has not changed. Can someone please tell me what I am doing wrong?
>Leon Heller, G1HSM | "Do not adjust your mind, there is
>E-mail @spam@leonKILLspamlfheller.demon.co.uk | a fault in reality": on a wall
>Phone: +44 (0)1734 471424 | many years ago in Oxford.
Here is some code taken directly from a working program I wrote. It is
written in Parallax Assembler (PASMX) but you should get the idea.
This is a clip of the list output from the assembler and the first column is
line numbers followed by the assembler code words.
You can see from this which PASMX instructions map to multiple Mchip
In the great traddition of these things, the simpler lower level routines
are listed first. (n.b. :loop is a local label)
Sorry I didn't have time to translate it for you. I hope it is of some help.
(Contact me direct if there is anything else you need help with Leon -
remember the transputer and QL? - long time no see!)
All the best.
1060 ;Routine to write a byte to the EEPROM,
assumes EEADR and EEDATA have
1061 ;already been loaded with the required
values and EEwrenable has already
1062 ;been called to prime the safety
1063 031D- 138B EEwriteit clrb GIE
;must run with interrupts disabled
1064 031E- 1683 setb RP0
;these registers are in page 1
1065 031F- 3055 0089 mov EECON2,#55h
;Required sequence to
1066 0321- 30AA 0089 mov EECON2,#0AAh ;55, AA,
1067 0323- 1488 setb WR
1068 0324- 1E08 2B24 :loop jnb EEIF,:loop
;wait until write
1069 0326- 1108 clrb WREN
;safe once again !
1070 0327- 1208 clrb EEIF
;reset indicator for next
1071 0328- 1283 clrb RP0
1072 0329- 0009 reti
;reenable interrupts when all done
1074 032A- 1683 EEread setb RP0
;control register is
in Page 1.
1075 032B- 1408 setb RD
;initiate read operation
1076 032C- 1283 clrb RP0
1077 032D- 0008 ret
1079 032E- 1683 EEwrenable setb RP0
enable safety guard
1080 032F- 1508 setb WREN
1081 0330- 1283 clrb RP0
1082 0331- 0008 ret
1084 0332- 232E EEwrite call EEwrenable
1085 0333- 231D call EEwriteit
1086 0334- 0008 ret
1088 ;Get EEPROM data into RAM
1089 ;Enter with R1=source, W=destination,
R2=number of bytes to move
1090 0335- 0084 EEget mov FSR,W
;start addr of target
1091 0336- 0826 0089 :loop mov EEADR,R1
;point to byte to
1092 0338- 232A call EEread
;select read mode
1093 0339- 0808 0080 mov INDIRECT,EEDATA
non-volatile value to working reg
1094 033B- 0A84 inc FSR
;next indirect address
1095 033C- 0AA6 inc R1
1096 033D- 0BA7 2B36 djnz R2,:loop
1097 033F- 0008 ret
1099 ;Put RAM data into the EEPROM.
1100 ;Enter with R1=destination, W=sorce,
R2=number of bytes to move.
1101 0340- 0084 EEput mov FSR,W
1102 0341- 0826 0089 :loop mov EEADR,R1
;point to byte to store
1103 0343- 0800 0088 mov EEDATA,INDIRECT
;load ram value
to EE reg
1104 0345- 2332 call EEwrite
1105 0346- 0A84 inc FSR
;next indirect sorce address
1106 0347- 0AA6 inc R1
;next destination address
1107 0348- 0BA7 2B41 djnz R2,:loop
1108 034A- 0008 ret