PDA

View Full Version : PIC12F629 flash led



pmafer
- 7th November 2013, 11:26
Hello all.

I'm seeking help to put a simple led flashing on 12F629.

I've try all kinds of configs and get always same result... nothing blinks.

Anybody knows id 629 have any particularity thah i don't see?

i'm using internal 4 mhz osc and 1k resistor on mclr and picall programmer.

led on gpio.0

Can anyone give some ideias?

ps. i've read datasheet and manual... ;)

thanks
Paul

HenrikOlsson
- 7th November 2013, 11:51
Hi,
Post your code, complete with the CONFIG-settings you're using.

/Henrik.

AvionicsMaster1
- 7th November 2013, 15:55
Probably oughta add a schematic also.

pmafer
- 7th November 2013, 20:46
Hello again.
tks for your aswers!

code follows:

Define OSCCAL_1K 1
DEFINE OSC 4

CMCON = 7
OPTION_REG.7= 0
GPIO = %00000000
TRISIO = %00000001


Start:

HIGH GPIO.0
PAUSE 1000
LOW GPIO.0
PAUSE 1000

GOTO Start
END




Hi,
Post your code, complete with the CONFIG-settings you're using.

/Henrik.

Demon
- 8th November 2013, 01:54
Shouldn't DEFINE be uppercase?

Robert

Aussie Barry
- 8th November 2013, 02:09
You have set GPIO.0 as an input with your TRISIO = %00000001 statement.

Try using TRISIO = 0 instead and see how it goes.

Also, I am not sure of your purpose for the OSCCAL statement. IMO, it shouldn't be necessary for such a simple LED flash program.

Cheers
Barry
VK2XBP

longpole001
- 8th November 2013, 09:24
dont know if you fixed the input to an output as barry suggested but i think that the problem

you can remove the pullup option as they are turn off anyway if outputs
the calibration setting in osccal seems to be cleared during an erase on this chip
so setting the register if you need to it adjust may be needed , but other wise id not worry if it just blink a led
i would also recommend a more up to date IC such as 12F683 as the new designed chips have very similar instruction / register setups which make it easy to go to other new chips when learning a PIC

hope it helps

Cheers

Sheldon



#CONFIG
__config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_OFF

#ENDCONFIG

OSCCAL = %100000 ' 4MhZ - Set calibration register to Center Freq - Note Erasing the device also clears the calibration value for internal osc

CMCON = 0 ' Comparators not used
TRISIO = %00000000 ' set all GPIO as outputs - Note Master clear pin GPIO is not used
OPTION_REG.7 = 0 ' Set Week Pullups globle off . Note when GPIO SET AS output Week pullups is automaticly turned off


DEFINE OSC 4 ' Timing reference for pause , pauseus commands

Start:

toggle GPIO.0
pause 1000 ' pause of 1sec

goto Start

End

HenrikOlsson
- 8th November 2013, 10:34
Hi,

I don't see any real issues with the original code which would prevent it from working.

Yes, the TRIS-setting is indeed backwards and setting it correctly is always good practice but HIGH/LOW takes care of it for you so it shouldn't be a showstopper in this particular case.

The situation with define/DEFINE/DefINe/defiNE has been covered many times by now. The actual keyword (DEFINE) is NOT case sensitive, what comes after the keyword IS and that looks alright to me although the OSCCAL shouldn't be needed AFAIK. So, not a problem with that either. Comparator (which has a Connection on GPIO.0) is turned off correctly so not an issue with that either. I can't see any real problem.

My vote is on a hardware issue, perhaps your programmer doesn't release MCLR after programming - if you keep it attached that is.

Which version of PBP are you using?

/Henrik.

AvionicsMaster1
- 8th November 2013, 14:18
I have been schooled by the wizard and Henrik is correct on deFINE.

I agree OSSCAL is unneccessary but you do need to set the ports to digital with the ANSEL = 0. You really don't need the OPTION_REG statement for just a simple program. TRISIO should just read TRISIO = 0 to set all pins, except GPIO.3 (pin 4), as outputs. HIGH/LOW will do that but it looks cleaner setting it in the TRISIO. At least IMHO.

DEFINE OSC 4
ANSEL=0
CMCON = 7
OPTION_REG.7= 0
GPIO = 0
TRISIO = 0
Start:

HIGH GPIO.0
PAUSE 1000
LOW GPIO.0
PAUSE 1000

GOTO Start
END

I would also submit you need a 300ish ohm resistor in series with the LED and not much higher. If you lack the resistor you can hook it directly up to the PIC as the PIC will protect itself and only source about 20ish mA. I don't remember exactly what the PIC will source or sink but you can find it in the datasheet. GPIO.0 is pin 7 on the 12F629 and should have the unmarked(Anode) end of the LED hooked to it with the marked end (Cathode) to ground/common/return or whatever you want to call it.

Make sure pin 4 MCLR is tied to the voltage source, +5 VDC, with a 10kish resistor. If you're not hooked to +5VDC then you'll have to adjust the size of the resistor in series with the LED.

It should work.

HenrikOlsson
- 8th November 2013, 14:56
Hi,
The 12F629 doesn't have an ADC, there is no ANSEL register available.

Since my last post I've breadboarded a 12F629 and tried Pauls code as posted, it works just fine. So I'm still leaning towards a hardware issue.

/Henrik.

pmafer
- 8th November 2013, 19:17
Hello,

Thanks all for your comments.

i recheck hardware and all seems ok.

i'm going crazy with this one. defective ic? its uncommon...

Henrik: can post hex to see if any diference? do you use default settings file?

thanks again,
Paul

HenrikOlsson
- 8th November 2013, 19:42
Hi,
Have you verified that MCLR is at Vcc?
LED connected with correct polarity and verified to be working?
Verified that the programmer and its application is working correctly, can you program other chips?

Yes, I've compiled your code with the PBP default CONFIG, which I quote here for reference:

#CONFIG
__config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_ON & _CP_OFF
#ENDCONFIG

This is the code I compiled, using PBP 3.0.7.4

Define OSCCAL_1K 1
DEFINE OSC 4

CMCON = 7
OPTION_REG.7= 0
GPIO = %00000000
TRISIO = %00000001

Start:

HIGH GPIO.0
PAUSE 1000
LOW GPIO.0
PAUSE 1000

GOTO Start
END

And here's the resulting hex

:020000040000FA
:100000002828A301A200FF30A207031CA307031C9A
:1000100023280330A100DF300F200328A101E83E90
:10002000A000A109FC30031C1828A00703181528FC
:10003000A0076400A10F152820181E28A01C222844
:1000400000002228080083130313831264000800B1
:10005000FF238316900083120730990083168113C3
:1000600083128501831601308500831205148316DF
:100070000510FA3083120120051083160510FA309E
:0A0080008312012036286300432894
:02400E00FC3F75
:00000001FF

Again, it works fine here. 10k pullup on MCLR, 1k5 in series with LED on GPIO.0

AvionicsMaster1
- 8th November 2013, 21:19
I guess you actually have to read the hyperscript numbers. Sorry for the inconenience.

Archangel
- 9th November 2013, 07:13
Hello,

Thanks all for your comments.

i recheck hardware and all seems ok.

i'm going crazy with this one. defective ic? its uncommon...


Paul
How OLD is your breadboard ? Those breadboards into which you just push the wires in corrode BIG TIME in just a couple of years especially if kept in a basement or garage. So verify your connections with an ohm meter, if it is not relatively new.