16F628 on-chip eeprom problem

Started by Vladimir M Skrbic March 1, 2004
Hello everyone,

I'm new to the group and I'd like to ask a question. I've recently
moved all my projects from 16F84 to 16F628 mcu's. Yesterday I've
tried to write data to the internal (on-chip) eeprom of 16F628 using
PicBasic Pro with little (or no ;) sucess. Would anyone care to
explain why the same code works on 16F84 and 16F876/877 but not on
16F628? I used the most common method:

EEPROM 0, 127 ' Store 127 into eeprom location 0
...
[code]
...
READ 0, W ' Put contents of memory location 0 into W
...
[code]
...
WRITE 0, W ' Put contents in W into eeprom location 0
...
END

And neither of the commands work! I've tried all locations from
0 - 11 for example and no luck. What am I doing wrong? Any help is
appreciated! Thanks in advance.

--
Sincerest regards,
YZ7REA Vladimir M Skrbic
4N7ATV Repeater Administrator
YU7GHZ Radio Club President


Hi, I even made some assembler-macro's that can be
used for the '628. They work perfectly.

Kees.

;=========================================================================================
; EEprom macros for PIC 16F628
;=========================================================================================
EEPROM_READ MACRO CONFIG_ADDR
BSF STATUS, RP0 ; Bank1
MOVLW CONFIG_ADDR ;
MOVWF EEADR ; Address to read
BSF EECON1, RD ; perform EEPROM read
MOVF EEDATA, W ; store the data
BCF STATUS, RP0 ; Bank0
ENDM

EEPROM_WRITE MACRO CONFIG_ADDR, CONFIG_DATA
BSF STATUS, RP0 ; Bank1
MOVLW CONFIG_ADDR ;
MOVWF EEADR ; Address to write
MOVLW CONFIG_DATA ;
MOVWF EEDATA ; Data to write
BSF EECON1, WREN ; Enable Write
BCF INTCON, GIE ; Disable Interrupts
MOVLW 0x55 ; Write 0x55
MOVWF EECON2 ;
MOVLW 0xAA ; Write 0xAA
MOVWF EECON2 ;
BSF EECON1, WR ; set WR bit

BTFSC EECON1, WR ; still set?
GOTO $-1 ; wait until cleared

BCF EECON1, WREN ; Disable further Writes
BSF INTCON, GIE ; Enable Interrupts

BCF STATUS, RP0 ; Bank0
ENDM

EEPROM_VERIFY MACRO
BSF STATUS, RP0 ; Bank1
MOVF EEDATA, W ; last written value in 'W'
BSF EECON1, RD ; start read at current address
SUBWF EEDATA, W ; subtract W from EEDATA
BTFSS STATUS, Z ; ZERO flag set?
GOTO write_error ; No, there was a write-error
BCF STATUS, RP0 ; Bank0
ENDM --- rj_satterlee <> wrote:
> Hi Validmer-
>
> Well, it's a little more complicated than that.
> I've included the
> read and write routines to the eeprom memory that I
> use for the
> 16F628, which I got from the manual. It's assembly,
> but I think
> that it gives a pretty clear indication of the
> process. Seems
> to work well for me.
>
> Hope this helps.
>
> Cheers,
>
> Rich S.
>
> aka WB6VAL
>
> --- In , "Vladimir M Skrbic"
> <atomski@E...>
> wrote:
> > Hello everyone,
> >
> > I'm new to the group and I'd like to ask a
> question. I've recently
> > moved all my projects from 16F84 to 16F628 mcu's.
> Yesterday I've
> > tried to write data to the internal (on-chip)
> eeprom of 16F628 using
> > PicBasic Pro with little (or no ;) sucess. Would
> anyone care to
> > explain why the same code works on 16F84 and
> 16F876/877 but not on
> > 16F628? I used the most common method:
> >
> > EEPROM 0, 127 ' Store 127 into eeprom
> location 0
> > ...
> > [code]
> > ...
> > READ 0, W ' Put contents of memory
> location 0 into W
> > ...
> > [code]
> > ...
> > WRITE 0, W ' Put contents in W into eeprom
> location 0
> > ...
> > END
> >
> > And neither of the commands work! I've tried all
> locations from
> > 0 - 11 for example and no luck. What am I doing
> wrong? Any help is
> > appreciated! Thanks in advance.
> >
> > --
> > Sincerest regards,
> > YZ7REA Vladimir M Skrbic
> > 4N7ATV Repeater Administrator
> > YU7GHZ Radio Club President
;---------------------------------
>
> ; Read Eprom routine
> ; inputs: eprom_addr contains the address of the
> eprom memory to read
> ; outputs: eprom_data contains the data read from
> the eprom
>
;---------------------------------
> read_eprom
> movf eprom_addr, W ;get the address
> bsf STATUS, RP0 ;select bank 1
> movwf EEADR ;set address to read
> bsf EECON1, RD ;read the eprom
> movf EEDATA, W ;hold in w register
> bcf STATUS, RP0 ;select bank 0
> movwf eprom_data ;save the information
> return
;---------------------------------
> ; Write/verify Eprom routine
> ; inputs: eprom_addr contains the address of the
> eprom memory to read
> ; eprom_data contains the data to write to
> the eprom
> ; output: W = 0 ==> o.k., W <> 0 ==> error in write
> ; uses: eprom_intcon. Stores the state of the
> interrupt bit
> ; NOTE: this routine COULD hang if the eprom logic
> in the hardware
> ; fails to operate. Could put a check in for
> it. The max
> ; time for a byte to be programmed is 8 ms.
>
;---------------------------------
> write_eprom
> bcf PIR1, EEIF ;clear eprom write int flag
> movf eprom_addr, W ;get the address
> bsf STATUS, RP0 ;select bank 1
> movf INTCON, W ;get interrupt control
> bcf STATUS, RP0 ;select bank 0
> movwf eprom_intcon ;save GIE state
> movf eprom_addr, W ;get the address
> bsf STATUS, RP0 ;select bank 1 again
> movwf EEADR ;set address
> bcf STATUS, RP0 ;select bank 0
> movf eprom_data, W ;get the data
> bsf STATUS, RP0 ;select bank 1 again
> movwf EEDATA ;set the data bits
> bsf EECON1, WREN ;set the write enable
> bcf INTCON, GIE ;turn off interrupts
> movlw h'55'
> movwf EECON2 ;first set of eprom write
> movlw h'aa'
> movwf EECON2 ;second set of eprom write
> bsf EECON1, WR ;set the write bit (acutal
> write)
> bcf STATUS, RP0 ;select bank 0
> ; spin waiting for the write to complete
> movlw h'ff'
> write_eprom1
> btfss PIR1, EEIF ;test for write complete
> goto write_eprom1 ;branch if not finished
> ; finished the write
> ; now verify write
> movf EEDATA, W
> bsf EECON1, RD ;read data written
> ; value in W == data read?
> subwf EEDATA, W
> bcf STATUS, RP0 ;select bank 0
> ; reset the interrupt control bit to original value
> btfsc eprom_intcon, GIE ;branch if not enabled
> bsf INTCON,GIE ;enable general interrupts
> return ;if bad w <> 0 >
>


__________________________________




--- In , Kees Stenekes <knalkeez@y...> wrote:
> Hi, I even made some assembler-macro's that can be
> used for the '628. They work perfectly.
>
> Kees.
>
Kees, I've managed to solve my problem using PicBasic Pro, but thank
you very much for the reply...

Sincerest regards,
--
YZ7REA Vladimir M Skrbic
4N7ATV Repeater Administrator
YU7GHZ Radio Club President