PDA

View Full Version : Can't get a 12F629 to blink a led



Sharky
- 26th June 2005, 14:26
Hi,

What is wrong with this code, I know that is has to be very simple but I can not get it to work! :(


@ DEVICE pic12F629, INTRC_OSC_NOCLKOUT ; System Clock Options
@ DEVICE pic12F629, WDT_ON ; Watchdog Timer
@ DEVICE pic12F629, PWRT_ON ; Power-On Timer
@ DEVICE pic12F629, MCLR_OFF ; Master Clear Options (Internal)
@ DEVICE pic12F629, BOD_OFF ; Brown-Out Detect
@ DEVICE pic12F629, CPD_OFF ; Data Memory Code Protect
@ DEVICE pic12F629, PROTECT_OFF

DEFINE OSCCAL_1K 1' Set OSCCAL for 1k
cmcon = 7 ' Comparator OFF

loop:
High GPIO.0 ' Turn on LED connected to PORT0
Pause 500 ' Delay for .5 seconds

Low GPIO.0 ' Turn off LED connected to PORTB.0
Pause 500 ' Delay for .5 seconds

GoTo loop ' Go back to loop and blink LED forever

I have tried to download a hexfile for the 12F629 that blinks GPIO.0 and 1 that is working just fine, but when I try the above code it don't work.

An the worst thing is that when i have tried to run the above code my PIC dies, in other words it is not possible to program it again :confused:

Regards
Sharky

Bruce
- 26th June 2005, 18:24
Does the code that works include DEFINE OSCCAL_1K 1..?

This define places a call to program location 03ffh. If your device programmer has erased this location, then using this define will cause a continuous loop.

I.E. call 03ffh, wrap around back to 0, land on call 03ffh again, etc,,

Location 03ff has a retlw xx instruction. xx is the factory oscillator calibration value returned by the retlw instruction.

I read one of my 12F629's with my programmer. This is what's read from location 03ff.

03ff- 3494

34 is the retlw instruction. This should always be the same. 94 is the factory oscillator calibration value (for this particular 12F629) returned in w when call 03ffh is issued.

If your programmer has erased this, you have a few options.

1. Remove the DEFINE OSCCAL_1K 1, and use the default value that's already in osccal. That eliminates to continuous loop if the retlw xx at location 03ffh has been erased.

2. Replace DEFINE OSCCAL_1K 1 with osccal = xx (xx is the value to load into the osccal register). You'll need to experiment to find the optimum value if you didn't read & record the value before programming/erasing your 12F629.

3. Use the PBP pokecode command to replace the retlw xx at location 03ffh.
Assuming 94h is the calibration value you find works best, then pokecode @$3ff, $94 would place retlw 94 at location 03ffh, and you could then use DEFINE OSCCAL_1K 1 again.

Your code above works fine as-is on the 12F629 I programmed, but I have my programmer (meLabs serial programmer) setup to not erase or re-program the calibration value at 03ffh.

I'm not sure what would cause it to not be re-programmable unless your programmer is over-riding config fuse settings in your .hex file and setting code protection. Then you have to erase the part before re-programming.

What programmer are you using?

Can you read the 12F629 to verify location 03ffh is blank or has the retlw xx?

Can you erase the PIC?

Sharky
- 26th June 2005, 22:35
Hi Bruce,

Right now I use the K8048 from Velleman. I like the programmer but I really don't like the software called ProgPic2.

The code that works is a HEX file that I have downloaded from the web,
just to check if the programmer and the PIC was working,
so I don't know if it uses include DEFINE OSCCAL_1K.

After I have tried to program my own code (the code shown in my previous post) It seems that the PIC dies totally. It's not possible to read it or erase it, the software just tell me that there is no device placed in the programmer.

I will try to upgrade one of my home made JDM pic-programmers so it will have an 8-pin socket and then try to program the PIC with IC-Prog software.

But I still just don't understand that the downloaded HEX file work perfectly, I can program it into the 12F629, erase the PIC and then program it again. It is first when I use my own program that the 12F629 dies. :eek:

Thank U very much for your help :)

Regards
Gert

Sharky
- 27th June 2005, 11:28
Now I solved the problems.

The first thing was my JDM programming device, when I use:

@ DEVICE pic12F629, INTRC_OSC_NOCLKOUT
@ DEVICE pic12F629, MCLR_OFF
It is not possible to program the PIC again with my JDM or Velleman programmer.

I solved the problem by reading this: http://feng3.cool.ne.jp/en/vddctrl.html and by using a few components and a solderiron. :cool:

And Bruce thanks for the OSCCAL learning, I have used your suggestions to get the pic up and running again.

Thanks! :)

Regards
Gert