PDA

View Full Version : PIC16F84A EEPROM problems



The Master
- 10th June 2007, 22:56
Hi, ive been searching google for about 3 hours now but still not found the answer.

My code needs to read/write a single byte on EEPROM. When i use the read command i get a weird value returned (usually 127, i have no idea where that comes from) and when i use write the chip resets ifself.

I'm new to using EEPROM but it looked simple till i tried to use it

Heres a cut down sample of my program

taddress var byte
taddress=20
write 0,taddress

skimask
- 10th June 2007, 23:10
Heres a cut down sample of my program

taddress var byte
taddress=20
write 0,taddress

That code snip really doesn't tell us anything. Post the whole thing. You've got a DEFINE wrong somewhere, maybe some conflicting interrupts, who knows...
Maybe change the handle from 'The Master' to 'Maybe the Master in the Future, but for now, I can't get a simple EEPROM write to work'...

fazan83
- 11th June 2007, 05:27
That code snip really doesn't tell us anything. Post the whole thing. You've got a DEFINE wrong somewhere, maybe some conflicting interrupts, who knows...
Maybe change the handle from 'The Master' to 'Maybe the Master in the Future, but for now, I can't get a simple EEPROM write to work'...

Maybe he is master in other field.

The Master
- 11th June 2007, 07:58
Maybe he is master in other field.

too right :P thats my name on other forums. just keeping it the same. im good at VB6 etc

ive not defined anything so far and ive not got any interrupts. the example i saw on the net didnt say to define anything

http://www.microengineeringlabs.com/resources/samples/pbc/ee.bas

everything else in the program works fine. all the serin/serout if then elses etc. its just read/write that dont work

The Master
- 11th June 2007, 20:08
righty. now im at home i can give you th full code. i made an new test program and it still doesnt work



trisa=%00000000
trisb=%00000000

t1 var byte

high portb.0
pause 100
low portb.0
pause 100


high portb.3
pause 100
low portb.3
pause 100

read 0,t1

portb=t1

end


it has 8 LEDs connected to portb. 2 of them flash on startup to prove the chip is working then it should read a value from EEPROM[0] and display it using the LEDs.

i set the EEPROM values in the programmer software before programming. if i read everything back from the chip then i can see it definately has set the EEPROM.

no matter what value i put in the EEPROM the LEDs always tell me the value is %11111110

skimask
- 11th June 2007, 20:14
Instead of END, try STOP, or a read/portb/goto loop, see what happens.
Do you have anything across Vss & Vdd?

The Master
- 11th June 2007, 20:17
Instead of END, try STOP, or a read/portb/goto loop, see what happens.
Do you have anything across Vss & Vdd?

i tried the loop



loop:
read 0,t1
portb=t1
goto loop


still same result.

what might i have accross vss and vdd? do you mean power or components? i have power because the LEDs work. i also have a capacitor before the regulator or the chip wont work

skimask
- 11th June 2007, 20:24
what might i have accross vss and vdd? do you mean power or components? i have power because the LEDs work. i also have a capacitor before the regulator or the chip wont work

How about a little something, like a .1uf across Vdd and Vss on the PIC itself?

The Master
- 11th June 2007, 20:26
How about a little something, like a .1uf across Vdd and Vss on the PIC itself?

hmm, do i really need that? the origional diagram i had a few years back shows 1 there but i tried removing it and it didnt appear to affect anything.

ill try and find one. its not something i have laying around :P

mister_e
- 11th June 2007, 20:34
Try..


@ __CONFIG _XT_OSC & _WDT_OFF & _CP_OFF

PORTB = 0
TRISB = 0

DATA 0,1,2,4,8,16,32,64,128

Addr var byte

for Addr=0 to 8
read Addr, PORTB
PAUSE 500
NEXT

STOP

and make sure you have MCLR pin tied to VCC via a resistor. Cap always have to be there. 0.1, 0.22, 0.47 or whatever else in that range.

The Master
- 11th June 2007, 20:44
ok, i copied that exactly. it wouldnt compile because of the top line so i removed it and set the fuses in the programmer software. i borrowed one of those caps from another circuit and its still not working. im getting the exact same result

Edit: MCLR is connected to vdd with a 10K resistor

mister_e
- 11th June 2007, 20:48
OK, so what happen if you change the loop to

for Addr=0 to 7
PORTB = DCD ADDR
PAUSE 500
NEXT

If it doesn't work... or you have a faulty crystal, or your crystal capacitor are bad, or the PSU is bad, or the PIC is bad... OR everything previously listed ;)

EDIT: config fuses..
http://www.picbasic.co.uk/forum/showthread.php?t=543

skimask
- 11th June 2007, 20:52
hmm, do i really need that? the origional diagram i had a few years back shows 1 there but i tried removing it and it didnt appear to affect anything.

ill try and find one. its not something i have laying around :P

That was then, this is now... Just bad design practice NOT to use one, I don't think you'll find anybody who will dispute that fact. Just because it worked once, doesn't mean it'll work like that every time...however, conversely, you'll have a hard time finding a PIC that won't run because one is installed (vs. one without a cap installed).

The Master
- 11th June 2007, 20:55
[QUOTE=mister_e;39699]OK, so what happen if you change the loop to

for Addr=0 to 7
PORTB = DCD ADDR
PAUSE 500
NEXT

that works. the LEDs are chasing as expected. what does this mean then?

mister_e
- 11th June 2007, 20:58
Probably the PIC EEPROM is bad OR there's a setting in your device programmer software that you overlooked.

What i mean is that some Device programmer software allow to program OR NOT the PIC EEPROM. Sure it's something like that.

The Master
- 11th June 2007, 21:08
Probably the PIC EEPROM is bad OR there's a setting in your device programmer software that you overlooked.

What i mean is that some Device programmer software allow to program OR NOT the PIC EEPROM. Sure it's something like that.

right. ive just tested it on another chip so its not that. theres 1 more fuse value you didnt mention so i changed that. the programmer app has an EEPROM override button so i tried that too and still as before.

this is confusing. random thought, could this possibly be anything like those chips where you have to access the *internal* EEPROM asif it was *external*?

another thing is that the datasheet for this chip says EEPROM stuff has to be written in a certain way but it only gives examples of assembly code so i dont understand it

mister_e
- 11th June 2007, 21:11
compile the first example the send me the generated .HEX file (in a .ZIP)

Everything work as expected here.

Which PIC programmer and software do you use?

EDIT: Which PBP version ?

The Master
- 11th June 2007, 21:15
compile the first example the send me the generated .HEX file (in a .ZIP)

Everything work as expected here.

Which PIC programmer and software do you use?


ok, this is the first example without the first line (or it wont compile)

the programmer i think is DIY K149 or 3149B-E
the programmer software is micropro25

Edit: Microcode studio 2.2.11 / PICBASIC PRO 2.45

mister_e
- 11th June 2007, 21:22
OK, assuming you have copy/pasted the whole first example, something is bad with your compiler... i guess. If i use the .HEX file you sent, nothing work. So i would suggest you to re-install PBP.

The Master
- 11th June 2007, 21:25
OK, assuming you have copy/pasted the whole first example, something is bad with your compiler... i guess. If i use the .HEX file you sent, nothing work. So i would suggest you to re-install PBP.

is there a certain way to install it cos last time i installed microcode studio then copy/pasted the picbasic folder into C:\ and it picked it up itself

Edit: i copy/pasted the whole code except the first line. the first line "@ __CONFIG _XT_OSC & _WDT_OFF & _CP_OFF" causes an error while compiling "opcode expected instead of '__config'"

mister_e
- 11th June 2007, 21:34
This error is because i use MPASM to compile the code, for PM syntax, you need to have a look at the link i posted above for the config fuses.

I'm reading the .HEX file you sent... may i assume you didn't selected the right PIC in the MicroCode studio drop list? I suspect a 16F877 :D which is the default one...

You should have your PBP installation Disk, just reinstall over and make sure MicroCode see the right PBP installation path... but first make sure you selected the right PIC in the drop list.

The Master
- 11th June 2007, 21:41
OMFG!

just before you posted that i was looking at the asm file and wondering why it said
INCLUDE "16F877.INC"

i never saw that dropdown box! what a retard! lol.

well, i programmed it again (this time with the correct chip selected) and your example code makes some lights turn on then all of them which i guess is what its supposed to.

cant believe i spent hours on google yesterday and all day today talking to you guys and it was all because of a dropdown box. im gonna go to bed now, ive had enough today. lol

thanks for all your help and sorry for wasting your time :D

mister_e
- 11th June 2007, 21:45
http://www.mister-e.org/Pics/woohoo
http://www.mister-e.org/Pics/ROFL Don't worry... this may happen.

Even Skimask do some mistake :D

skimask
- 11th June 2007, 23:20
Even Skimask do some mistake :D

Every day...sometimes twice...