Searching \ for '[PIC]: Newbie trouble writing to EEPROM on 16F873' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/begin.htm?key=eeprom
Search entire site for: 'Newbie trouble writing to EEPROM on 16F873'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: Newbie trouble writing to EEPROM on 16F873 '
2002\04\21@005137 by John Brown

picon face
[Opps! I forgot to put the [PIC]: at the start of the subject line when I first sent this. Sorry!]

I am having trouble writing to the EEPROM in a on 16F873.

Using the "RomZAP Bootloader III" I put in the following code to read a value from an analog input, then display the value on some LEDs and store the value in EEPROM. The program does all this except it only does it once - ie it doesn't go around the LOOP. It seems to hang on the last instruction before "goto LOOP".

NOTE: if I remove all the code from EWRITE onwards the LOOP works perfectly.

NOTE2: the code after EWRITE routine is more or less straight out of the 16F87x datasheet, except I have modified it so it just writes the value which is in W to EEPROM address 0x00. Also, I have not enable interrupts so I have commented out the relevant bits as required.

(I will more EWRITE out to be a subroutine, but I have put it in the main loop for now in order to just get it going...)

Any suggestions greatly appreciated!

John



       org 0x0003

       bsf     STATUS,RP0      ; select register bank 1
       bcf     STATUS,RP1      ;

       movlw   H'00'
       movwf   TRISC           ; set PORTC [7-0] all outputs
       clrf    ADCON1          ; set PORTA [7-0) all analogue inputs

       bcf     STATUS, RP0     ; select register bank 0

       movlw   B'01000001'     ; bits [7-6] = select Fosc/8; bits [5-3] select analogue input from RA0/AN0
       movwf   ADCON0          ;     bit [0] = activate A2D converter


LOOP    bsf     ADCON0,GO       ; start A2D conversion
Adwait  nop                     ; wait for conversion to complete
       btfsc   ADCON0,GO       ;
       goto    Adwait          ;

       movf    ADRESH,W

       MOVWF   PORTC

EWRITE  bsf     STATUS, RP1
       bsf     STATUS, RP0     ; select register bank 3
Ewait   btfsc   EECON1, WR      ; wait for any previous write_
       goto    $-1             ;   to finish
       bcf     STATUS, RP0     ; select register bank 2
;       movf    VALUE, W        ; set EEDATA to value you want to write_
       movwf   EEDATA          ;   to EEPROM
;       movf    ADDR, W ; set EEADR to the EEPROM address_
       movlw   0x00
       movwf   EEADR           ;   that you want to write to
       bsf     STATUS, RP0     ; select register bank 3
       bcf     EECON1, EEPGD   ; Point to data memory
       bsf     EECON1, WREN    ; Enable writes
;       bcf     INTCON, GIE     ; Only disable interrupts if already enabled_
;                               ;   otherwise discard
       movlw   0x55            ; Write 55h to_
       movwf   EECON2          ;   EECON2
       movlw   0xAA            ; Write AAh to_
       movwf   EECON2          ;   EECON2
       bsf     EECON1, WR      ; Start write operation
;       bsf     INTCON, GIE     ; Only disable interrupts if already enabled_
;                               ;   otherwise discard
       bcf     EECON1, WREN    ; Disable writes

       goto LOOP


_______________________________________________________________________
John Brown
PhD (Clinical Psychology) candidate
                                     Email:  spam_OUTjohn.brownTakeThisOuTspamanu.edu.au
School of Psychology                  Phone:  (02) 6125-3827
Room 124, Building 39, Psychology     Fax:    (02) 6125-0499
The Australian National University    Mobile: 0429 455 504
ACTON ACT 0200   Web: http://www.anu.edu.au/psychology/staff/BrownJ.htm

--
http://www.piclist.com hint: To leave the PICList
.....piclist-unsubscribe-requestKILLspamspam@spam@mitvma.mit.edu


2002\04\21@080415 by Glen Wiley

picon face
John,

Is the write to EE succeeding?  You can tell by using your programmer
to read the part and examining the EE.

I found that on the 16F872 I had to set EEADRH to 0 in order for my
EE access to work.  This was not spelled out in the datasheet, but
the register is identified.

On Sun, Apr 21, 2002 at 02:48:12PM +1000, John Brown wrote:
{Quote hidden}

<snip>

--
Glen Wiley

Those who can - code.

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestspamKILLspammitvma.mit.edu


2002\04\21@095610 by Olin Lathrop

face picon face
> I am having trouble writing to the EEPROM in a on 16F873.
> ...
>
>         org 0x0003

That's a strange place to start.  The reset location is 0, and the interrupt
location is 4.

>         bsf     STATUS,RP0      ; select register bank 1
>         bcf     STATUS,RP1      ;

All this manual setting of bank bits makes me nervous.  Looking up the
registers you used and verifying you set the right banks is a waste of time
when the assembler can do most of this for you.


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

--
http://www.piclist.com hint: To leave the PICList
.....piclist-unsubscribe-requestKILLspamspam.....mitvma.mit.edu


2002\04\21@185910 by Tony Nixon

flavicon
picon face
John Brown wrote:
{Quote hidden}

RAM bank select is still pointing to RAM page 3 before "goto LOOP"

You are writing to the EEPROM about 100 times per second which is
probably unnessary. Thats about 2 1/2 hours available time before the
location could end its life.

ROMzap initialises the PORT & TRIS registers from the boot code, so it's
not needed in your user code unless you need to specifically change
them.

--
Best regards

Tony

mICros
http://www.bubblesoftonline.com
EraseMEsalesspam_OUTspamTakeThisOuTbubblesoftonline.com

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestspamspam_OUTmitvma.mit.edu


2002\04\21@190103 by Tony Nixon

flavicon
picon face
Olin Lathrop wrote:
>
> > I am having trouble writing to the EEPROM in a on 16F873.
> > ...
> >
> >         org 0x0003
>
> That's a strange place to start.  The reset location is 0, and the interrupt
> location is 4.

ROMzap has a bootloader vector at 0x0000

       movlw high(Boot)
       movwf PCLATH
       goto Boot

I'm thinking of changing this setup for RZ ver 4.


>
> >         bsf     STATUS,RP0      ; select register bank 1
> >         bcf     STATUS,RP1      ;
>
> All this manual setting of bank bits makes me nervous.  Looking up the
> registers you used and verifying you set the right banks is a waste of time
> when the assembler can do most of this for you.
>

...and in this case was the problem.

--
Best regards

Tony

mICros
http://www.bubblesoftonline.com
@spam@salesKILLspamspambubblesoftonline.com

--
http://www.piclist.com hint: To leave the PICList
KILLspampiclist-unsubscribe-requestKILLspamspammitvma.mit.edu


2002\04\21@190519 by John Brown

picon face
>Is the write to EE succeeding?

Yes, but then it hangs without going on around the loop.

>I found that on the 16F872 I had to set EEADRH to 0 in order for my
>EE access to work.  This was not spelled out in the datasheet, but
>the register is identified.

Hmm, OK I'll look into that. Thanks.

John




{Quote hidden}

_______________________________________________________________________
John Brown
PhD (Clinical Psychology) candidate
                                      Email:  spamBeGonejohn.brownspamBeGonespamanu.edu.au
School of Psychology                  Phone:  (02) 6125-3827
Room 124, Building 39, Psychology     Fax:    (02) 6125-0499
The Australian National University    Mobile: 0429 455 504
ACTON ACT 0200   Web: http://www.anu.edu.au/psychology/staff/BrownJ.htm

--
http://www.piclist.com hint: To leave the PICList
TakeThisOuTpiclist-unsubscribe-requestEraseMEspamspam_OUTmitvma.mit.edu


2002\04\21@193534 by John Brown

picon face
> >         bsf     STATUS,RP0      ; select register bank 1
> >         bcf     STATUS,RP1      ;
>
>All this manual setting of bank bits makes me nervous.  Looking up the
>registers you used and verifying you set the right banks is a waste of time
>when the assembler can do most of this for you.

Err, really! I wasn't aware of that! I'll have to have a closer look at
what the assembler does and doesn't do. Thanks,

John


_______________________________________________________________________
John Brown
PhD (Clinical Psychology) candidate
                                      Email:  RemoveMEjohn.brownspamTakeThisOuTanu.edu.au
School of Psychology                  Phone:  (02) 6125-3827
Room 124, Building 39, Psychology     Fax:    (02) 6125-0499
The Australian National University    Mobile: 0429 455 504
ACTON ACT 0200   Web: http://www.anu.edu.au/psychology/staff/BrownJ.htm

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestEraseMEspam.....mitvma.mit.edu


2002\04\21@193541 by John Brown

picon face
>RAM bank select is still pointing to RAM page 3 before "goto LOOP"

ah! Yes so it is...

>You are writing to the EEPROM about 100 times per second which is
>probably unnessary. Thats about 2 1/2 hours available time before the
>location could end its life.

Yes, I am kind of aware of that. Having failed at an earlier attempt (for
the same reason) I was just trying to write the simplest bit code to get it
working before separating it off into a routine that I only call when
necessary - which I will now do. I hadn't actually done the maths and am
surprised that it is so short a time before failure, but I guess it is a
lot of writes!

Thanks,

John


_______________________________________________________________________
John Brown
PhD (Clinical Psychology) candidate
                                      Email:  EraseMEjohn.brownspamanu.edu.au
School of Psychology                  Phone:  (02) 6125-3827
Room 124, Building 39, Psychology     Fax:    (02) 6125-0499
The Australian National University    Mobile: 0429 455 504
ACTON ACT 0200   Web: http://www.anu.edu.au/psychology/staff/BrownJ.htm

--
http://www.piclist.com hint: To leave the PICList
RemoveMEpiclist-unsubscribe-requestEraseMEspamEraseMEmitvma.mit.edu


2002\04\21@195641 by Olin Lathrop

face picon face
> > >         bsf     STATUS,RP0      ; select register bank 1
> > >         bcf     STATUS,RP1      ;
> >
> >All this manual setting of bank bits makes me nervous.  Looking up the
> >registers you used and verifying you set the right banks is a waste of
time
> >when the assembler can do most of this for you.
>
> Err, really! I wasn't aware of that! I'll have to have a closer look at
> what the assembler does and doesn't do. Thanks,

Well it can't do it for you directly, but you can use some assembler
features to help you out.  See my DBANKIF and related macros in
STD.INS.ASPIC at http://www.embedinc.com/pic.  DBANKIF uses assembler
directives to compute the bank a register is in, and assembler variables to
track the current bank settings.  With these it can compute which, if any,
RPn bit diddling instructions are required.  This system is not totally
foolproof, but it goes a long way and you never have to look up what bank a
special function is in.


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

--
http://www.piclist.com hint: To leave the PICList
RemoveMEpiclist-unsubscribe-requestspam_OUTspamKILLspammitvma.mit.edu


More... (looser matching)
- Last day of these posts
- In 2002 , 2003 only
- Today
- New search...