PDA

View Full Version : PIC12F629 w/ Internal Oscillator



RossW
- 21st June 2004, 21:37
This chip has an internal oscillator (20 Mhz). Here's my question: how do I program this chip with (a) PIC Basic and (b) PIC Basic Pro, and do I need to do anything special in order to drop it into a breadboard with an LED (i.e. the simple blink.bas program). Will the EPIC programmer save the configuration bits each time I erase/program it?

Melanie
- 21st June 2004, 21:46
Actually the internal Oscillator is 4MHz...

Dwayne
- 22nd June 2004, 05:19
Hello Rossw,

Rossw>>This chip has an internal oscillator (20 Mhz). Here's my question: how do I program this chip with (a) PIC Basic and (b) PIC Basic Pro, and do I need to do anything special in order to drop it into a breadboard with an LED (i.e. the simple blink.bas program). Will the EPIC programmer save the configuration bits each time I erase/program it?<<

I believe it has up to 20 MHZ capability, and only a 4 mhz internal Osc. Make sure your MCLR pin is set as a input, not reset. <g>. I have ran into this a few times when I forget to reset my programmer.

Set one of your I/O pins as a output through your TRIS commmand, Turn off all digital, put your diode in, and a small resister in series... program it as you like. It will look something like the follolwing..
(The following program was done on a 12F675.) Should be somewhat close to what you are looking for...



ANSEL=0
CMCON=%00000111
TRISIO=%00001000

Loop:
GPIO.0=1
Pause 500
GPIO.0=0
PAUSE 500
goto Loop
end.

RossW
- 22nd June 2004, 14:52
Thanks for the info, Dwanye.

Dwanye>>Make sure your MCLR pin is set as a input, not reset. .

Not sure what that means, being a newbie to microcontrollers and all. Does this mean I hook up this pin to +5V through a resistor?

Also, I'd eventually like to use 4 other pins for output to LEDs - do I need additional TRISIO commands for that?

Dwayne
- 22nd June 2004, 15:27
Hello Rossw,


Dwanye>>Make sure your MCLR pin is set as a input, not reset. .

Rossw>>Not sure what that means, being a newbie to microcontrollers and all. Does this mean I hook up this pin to +5V through a resistor?<<

When you use your HEX programmer, you must do a couple of things... Make sure you choose the "INTOSC" (so the chip will use its internal oscillator, and Make sure your HEX programmer is set us as such...

OSC INTOSC
WTD Enabled
PUT Disabled
BOR Enabled
MCLR input pin
Code Not protected
EEPROM Not protected



Also, I'd eventually like to use 4 other pins for output to LEDs - do I need additional TRISIO commands for that?

Yes, teh TRISIO tells the chip to make the pins Input or Output. You need to have output to light up a LED. You must also make sure that the pins *are* output, by checking the Chips documentation. (It will say I/O pin)

Dwayne

Melanie
- 24th June 2004, 01:36
See the code I posted in answer to the "HPWM Question" Thread. Change the defines to match 16F629 instead of 16F628 and you're in business.

RossW
- 24th June 2004, 18:13
Thanks, Melanie, for the cross-reference.

If I set MCLR as input do I still need to connect to +5V through a 4.7k resistor, for example?

Melanie
- 24th June 2004, 19:12
I'm now going to reveal the secret of Life, the Universe and Everything here (as far as the PIC's setup Defines are concerned)... just you and me... so follow me to the end on this one...

There are two possible MCLR defines...

MCLR_ON
MCLR_OFF

MCLR_OFF has the PIC handling the MCLR function internally, allowing you to use pin RA5 as an Input (Big NOTE here... on the PIC16F628/629 it's the only pin in the whole PIC that's INPUT ONLY - so don't design anything expecting to use this pin as an Output - it won't happen - again read the Datasheet).

MCLR_ON has the PIC expecting you to provide external MCLR circuitry and RA5 is otherwise unavailable to you. Generally, if you are an electronics God (or Godess), you can strap MCLR (if you actually need to use one) directly to Vcc (+5v). If you are a lesser mortal, you can take it through a 4K7 Resistor. If you're totally inept, then you might need a 100nF Capacitor (actual value depending on ones level of incompetence) between MCLR and Vss (0v) as well.

Now... here's the secret stuff... How do we know what PIC defines I can use?

Well, open up the PBP directory, and in it you will find an INC subdirectory. Open that up and you'll see a heap of files. Find the Mxxxx.INC file for the PIC you're interested in... in your case you have a PIC16F629 so find the file M16F62X.INC and open it up with something like Notepad. Don't make any changes now, but just have a look at it. It reveals the internal sex life of the PIC. All the Configuration Fuse Defines that you can use from within PBP are listed here at the top, and lower down all the Registers are Listed. If it's not in the list, you can't use it - but trust me, it's usually all there. This list is for use with the PM (default assembler). If you're going to use MPASM, look for the appropriate file (eg P16F628.INC) located in something like the MCHIP_Tools subdirectory - there are some minor differences, like MCLR_ON for PM, is _MCLRE_ON for MPASM.

Cross-reference the Configuration Fuses with the PIC's Datasheet Section entitled "Special features of the CPU" (section 14 I think for your PIC). If you look down the eleven OSC selections listed in the INC file for example, you'll find them all in the Datasheet (Section 14.1 & 14.2) named appropriately (although some may be known under multiple names like ER_OSC is the same as ER_OSC_NOCLKOUT the little extra being provided by MeLabs for your convenience).

Finally... writing those defines into your program... it's easiest and cleanest using the default PM Assembler...

@ DEVICE MCLR_OFF

or

@ DEVICE pic16F629, MCLR_OFF

Both are identical, except if you use the one specifying the PIC, the Compiler will error with a message if you attempt to compile your program for any PIC other than a 16F629. It's actually handly to be reminded by the compiler that you potentially might be compiling for the wrong PIC... for my part it means that I don't spend nights pulling my hair out over silly mistakes and my golden locks are all intact.

If you need (or prefer) to use the MPASM assembler, you have to string multiple defines on one line, using line extenders when you run off the right-hand margin of your page.

Example

@ __config _XT_OSC & _WDT_ON & _LVP_OFF & _MCLRE_ON

is for MPASM as what's listed below is for PM...

@ DEVICE XT_OSC
@ DEVICE WDT_ON
@ DEVICE LVP_OFF
@ DEVICE MCLR_ON

Note the difference between _MCLRE_ON and MCLR_ON (as previously mentioned a couple of paragraphs ago).

btw... the @ just indicates that you are entering an Assembler instruction or directive.

Melanie