Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

NUBE with EEPROM Problems

Status
Not open for further replies.

PaulF

New Member
I am trying to convert a program from the net that was designed for the 16C84 and I want to use it on the 16F84A. I have everything working but the EEprom updating. I would appreciate some help as I am in the dark when it comes to EEprom. The writing section doesn't seem wright because it goes to bank one but I don't see a return to bank zero and interupts are disabled but not reenabled.
Code:
;----------- EEPROM MODULE AT PIC16F84A
;Rev 1.00
;d.27/07-95
; note: use timer

wadr equ 2Fh ; address in RAM 2F
value equ 2Eh ; Data in RAM 2E

WR_EEPROM ; write EEPROM (data in RAM 2E+adr in RAM 2E)
movfw wadr,W ; w=adr
movwf EEADR ; EEADR=w
movfw value,W ; w=data
movwf EEDATA ; EEDATA=w
; --- write sequnce
bsf STATUS,5 ; EEPROM write enable
bcf INTCON,GIE ; disable interupts
movlw 0x55 ; w=55h
movwf EECON2 ; EECON2=w
movlw 0xAA ; w=AAh
movwf EECON2 ; EECON2=w
bsf EECON1,WR ; EECON1=write
movlw .100 ; load time write
movwf xms ; move w to xms
call wait_xms ; wait in ms
; --- end
;return

RD_EEPROM ; address in RAM 2F
movfw wadr,W ; data in RAM 2E
movwf EEADR ; EEADR=w
bsf STATUS,5 ; bank 1
bsf EECON1,RD ; set RD bit
bcf STATUS,5 ; bank 0
movfw EEDATA,W ; w=data
movwf value ; data=w
; --- end
return
;-------------- END EEPROM MODULE
Code:
 
You are correct, it isn't right.

Here is how I would modify it,
Code:
WR_EEPROM       			; write EEPROM (data in RAM 2E+adr in RAM 2E)
                movfw   wadr,W          ; w=adr
                movwf   EEADR           ; EEADR=w
                movfw   value,W         ; w=data
                movwf   EEDATA          ; EEDATA=w
                bsf     STATUS,RP0      ; Bank 1
		bsf	EECON1,WREN	; Enable write
                bcf     INTCON,GIE      ; disable interupts
                movlw   0x55            ; w=55h
                movwf   EECON2          ; EECON2=w
                movlw   0xAA            ; w=AAh
                movwf   EECON2          ; EECON2=w
                bsf     EECON1,WR       ; EECON1=write
WaitWR		btfsc	EECON1,WR	; Wait for write to complete
		goto	WaitWR
		bcf	EECON1,WREN	;stop spurious writes
		bcf	STATUS,RP0	;back to bank 0
	;	bsf	INTCON,GIE	;enable interrupts if used.
		return 
                        
RD_EEPROM       ; address in RAM 2F
                movfw   wadr,W          ; data in RAM 2E
                movwf   EEADR           ; EEADR=w
                bsf     STATUS,RP0      ; bank 1
                bsf     EECON1,RD       ; set RD bit
                bcf     STATUS,RP0      ; bank 0
                movfw   EEDATA,W        ; w=data
                movwf   value           ; data=w
                return

I rem'd the interrupt enable as it is only needed if interrupts are used.

Mike.
 
Glad I could help.

This is one area where the normal advise to switch to a 16F628 because they are compatible and cheaper, doesn't work. The above code will not work on a 628 and changing it is probably beyond most beginners abilities.

Mike.
 
Pommie said:
Glad I could help.

This is one area where the normal advise to switch to a 16F628 because they are compatible and cheaper, doesn't work. The above code will not work on a 628 and changing it is probably beyond most beginners abilities.

Sorry, don't have time to look now (got to go out on a job), but what's the difference between an 84 and a 628 as far as EEPROM goes?.
 
Nigel Goodwin said:
Sorry, don't have time to look now (got to go out on a job), but what's the difference between an 84 and a 628 as far as EEPROM goes?.
As I said, it don't work. EEDATA is 08 on the 84 - 9A on the 628. +other things.

Are you telling me that after preaching how the 628 is the replacement for the 84, you didn't know this?

Mike.
 
Pommie said:
As I said, it don't work. EEDATA is 08 on the 84 - 9A on the 628. +other things.

What difference does that make?, the .INC file sets all those correctly. You obviously shouldn't be accessing registers, or bits, by number, but using the include files to do so.

Are you telling me that after preaching how the 628 is the replacement for the 84, you didn't know this?

Not as I recall, and as far as I can remember the 84-628 migration document didn't mention it, but it was ten years or so ago since I last say it. But as it makes no difference, it probably wouldn't mention it anyway?.
 
Nigel Goodwin said:
What difference does that make?, the .INC file sets all those correctly. You obviously shouldn't be accessing registers, or bits, by number, but using the include files to do so.
.

And the bank switching will just happen.:rolleyes:

You should apply that philosophy to your config values.

Mike.
P.S. I still haven't seen this mystical migration document.
 
Last edited:
Pommie said:
And the bank switching will just happen.:rolleyes:

You should apply that philosophy to your config values.

Mike.
P.S. I still haven't seen this mystical migration document.

It's so long ago you were probably too young! :p

It certainly no longer seems to be available on the MicroChip website though?, if I ever find a copy I'll send it you - but it's probably far too many computers ago to be on my current HDD, or on the backups from the previous two or three (and I don't have any backups now from older machines).
 
We all have our styles of programming, I'm trying to adopt a style for the kit tutorial and online book that won't teach bad habbits that we ALL have.

I remember when I first joined Electro-Tech I was using the SPASM (Tech-Tools) assembler. That got me some flack :)
I still miss it like a bad habit. It was similar to the 8051 instruction set but for a PIC, Parallax wrote it initially.
 
Sorry Bill,

While style is fine, when I post something that is good advice to a beginners and a guru questions it (without reason) and then when shown that they are actually wrong they still defend their situation I get a little pissed.

Nigel knows he is wrong, I know he is wrong, you know he is wrong and anyone that knows pics knows he is wrong.

I really hate it when someone criticises me when I am correct.

Mike.
 
Pommie said:
Sorry Bill,

While style is fine, when I post something that is good advice to a beginners and a guru questions it (without reason) and then when shown that they are actually wrong they still defend their situation I get a little pissed.

Nigel knows he is wrong, I know he is wrong, you know he is wrong and anyone that knows pics knows he is wrong.

I clearly said in my original post that i was going out at that instant, so politely inquired as to what the difference was, as I didn't have time to download the manuals and check.

I then, again politely, queried your reply, why are you getting so over excited?.

Regardless of what you don't remember, the 84 was replaced by the 628, the 84 was declared obselete, there was a migration document, and there was very little difference between them.
 
Nigel Goodwin said:
I clearly said in my original post that i was going out at that instant, so politely inquired as to what the difference was, as I didn't have time to download the manuals and check.

I then, again politely, queried your reply, why are you getting so over excited?.

Regardless of what you don't remember, the 84 was replaced by the 628, the 84 was declared obselete, there was a migration document, and there was very little difference between them.

You did indeed state that you were going out. I was then kind enough to answer your questions.

What I don't understand is why you are defending the 628 replacing the 84 when the EEPROM registers are in completely different banks!!

And, the other thing I don't understand is why you had to post on this thread when there was no need? I haven't posted anything wrong. Do you have some sort of problem with me?

Mike.
 
Pommie said:
You did indeed state that you were going out. I was then kind enough to answer your questions.

What I don't understand is why you are defending the 628 replacing the 84 when the EEPROM registers are in completely different banks!!

And, the other thing I don't understand is why you had to post on this thread when there was no need? I haven't posted anything wrong. Do you have some sort of problem with me?

No problem with you, like I said I simply asked (because I didn't have time to check), and you replied, and I then queried your answer. Now I'm back inside, I've had time to download the datasheets and see what you are on about, as you say, different banks.
 
Pommie said:
So, you agree that the 628 is not a good replacement for the 84?

No, it's the official replacement from MicroChip, it was released as it's replacement and the 84 discontinued. Since the long off days when that happened, because of all the idiots still wanting to use it, they appear to have re-released it at a huge price increase.

Good business if you can get, never mind selling modern components and fighting with other manufacturers by cutting prices - sell customers an old obselete device and charge them lots more money for it! - we could all do with some of that! :p
 
I think it was at Electronica 2002 when I asked someone at Microchip why they charge so much for the 16F84, when the 16F627 does more. The answer was that they charge that much because they can.

Some applications don't have code flexibility. Users are stuck with the code for one reason or another. There is no danger that the users could use another company's microcontrollers, as that would take a complete rewrite of the code.
So Microchip can charge what they like.

There is competition for new projects, so Microchip offer a range of cheaper microcontrollers.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top