PIC12F629 beginner needs help

Hi,

I ordered some 12f629 & 12f675 from microchip direct and wanted to play with them.

I have a simple circuit that have a LED that flash every second, a piezo that will buzz at 800Hz. Plus 4 switches for Start, Stop, 2/5 beeps select, 3 min/5 min select. That used up all the gpio pins and nothing was left for the osc and reset.

I dont know how to configure it to internal oscillation and do a power on rest without a reset button. And how do I calibrate the internal osc freq using OSCCAL bits? Can someone here help?

Thanks.

Allen

Reply to
Allen Bong
Loading thread data ...

For a reset, one way around this could be to reset when both Start AND Stop are pressed together. Think of it as the PIC version of Ctrl-Alt-Del.

You could also have one switch alternate

3min/5min/3min/5min, rather than 1 switch for each.

Try to find some project code for that micro online. You should be able to find some with the configuration codes for INTOSC mode.

As to OSCCAL, I can't help you there.

Reply to
Randy Day

_config (_INTRC_OSC_NOCLKOUT & ...)

Reply to
Nobody

Thanks, That would solve half my problem.

Allen

Reply to
Allen Bong

Hi Randy,

My circuit looks like below:

+----+----+------+ | | | | .-. .-. .-. | | | | | | | | |R| |R| |R| | VCC '-' '-' '-' +----+---------------------+ | | | | | | | | | 12f629 | | | | .----o-----. 330 LED | | +-----------ogp5 gp0o--|___|---| |=3D|> | | =3D=3D=3D | | STOP| o | |START GND | | | | o | ___ | .-. | | |=3D| VCC -|_R_|---+ | | =3D=3D=3D | o | | | |100 GND | | | o '-' | o | |=3D|> 2/5 B | __ /| |=3D|> =3D=3D=3D | o +-| | | 3/5 M| o GND | +-|__| | | | | \| | =3D=3D=3D =3D=3D=3D =3D=3D=3D GND GND GND

(created by AACircuit v1.28.6 beta 04/19/05

formatting link

I am not sure what you meant by pressing 2 keys together to cause a Reset. Do you mean when both keys are detected together would cause a jump to address 0x0000? Then that's a good idea. I would give it a try to see if it works.

Allen

Reply to
Allen Bong
[snip]

That's the idea I wanted to get across...

Hope it works for you.

Reply to
Randy Day

Why would it need a reset if it's running well enough to even read the keypresses?

Thanks, Rich

Reply to
Rich Grise

t a

Hi Rich,

I think I get caught here..... First I said I used up all the port pins and there is no pin left for a reset button on the MCLR. Then Randy suggested a software reset by pressing 2 buttons, so it seems that didn't totally solve my problems. My question should be "How do I do an auto Power on Reset leaving the MCLR pin alone so I can use it as a PORT pin?"

I guess the question is clearer now.

Allen

Reply to
Allen Bong

e

it a

I usually use this configuration. The power-up timer delays startup by

72 milliseconds to allow the supply to reach operating level. No reset needed, just turn off the power and back on.

__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT & _MCLRE_OFF & _CPD_OFF

CP_OFF ------- (Code protection off) WDT_OFF ---- (Watch Dog Timer off) BODEN_OFF -- (Brownout detection off) PWRTE_ON -- (Power up timer enable) INTRC_OSC -- (Internal 4 MHz oscillator, no clock out) MCLRE_OFF -- (Master clear/ reset off) CPD_OFF --- (Data Code Protection off)

-Bill

Reply to
Bill Bowden
[snip]

I was trying (poorly) to get across the idea that you can use switches in combination to call different functions, not just reset.

Insisting on having the mclr line available as a port pin automatically presumes your code must work, since mclr isn't available for resets. Your only real option is power-off.

---------

Picking nits here, but you can use a 2-button combo to cause a reset; the mclr line button just has to be one of them:

detect press of Button2 ; not the mclr button set bit 5 of CONFIG register ; mclr is now a reset line set your flags for Button2

loop until Button2 is released clear bit 5 of CONFIG ;set mclr back to port pin

Setting bit 5 makes the MCLR line active while Button2 is pressed. If the MCLR button doesn't get pressed, Button2 behaves as usual. Yes, your code has to be running normally, but it can issue a hard reset if you really want it to.

---------

Other options to free up the mclr line:

- alternating two states with one button (stop/start or 3min/5min, for example)

- using 2-button combinations to call other functions.

- use a short button press to signal one state, hold the button longer to signal another state.

If you can't make your switches multi-function in some fashion, your options are pretty much a) reset by cutting the power, or b) get a micro with more pins.

Reply to
Randy Day

You really don't need all those pins for those functions. Why not use one pin for start and stop -they are exclusive after all. You could get away with 2 pins if you just use one switch for start and stop functions and the analog in for the other functions. The key is to realize that the switches can each add a different current to the input so that by measuring the input voltage you can decide what combinations of switches are set. You could even use just one pin with this method ...

Hope this helps.

MC

Reply to
Varactor

e

OK, I get the general concept of how to use 2 buttons 'making' together to get the function of a 3rd button. I will apply it in my future project when I get the codes working.

The other method of alternating 2 functions with one button has to be indicated visually (eg an LED), or else I would know which function I am in.

The long and short duration technique is nice and I wonder if you have some codes for me to try out?

At the moment, my task is very simple and I dont plan to use a bigger chip. My program assembled to 138 words only so I will apply all the techniques above to reduce the hardware.

Thank you very much for your time and I have learnt a great deal from you today.

Regards,

Allen

Reply to
Allen Bong

Do you mean like the circuit below? My 12f675 does have 4 analog inputs.

So AN0 will normally be 2.5V when A nor B is pressed. If Button A is pressed then AN0=3D5V. If button B is pressed then AN0=3D0V, right? Good idea !!!!

Allen

VCC VCC | | 12F675 .-. o | .------. | | |=3D| "A" | | 4.7K | | o | | | '-' | | | | | | | 2.5V | | | AN0|--------+----+ | | | | | | | | | | .-. o | | | | | |=3D| "B" '------' 4.7K | | o | '-' | | | | =3D=3D=3D =3D=3D=3D GND GND

(created by AACircuit v1.28.6 beta 04/19/05

formatting link

Reply to
Allen Bong

5

nd

r
l

od

Yes, that would be OK for 2 buttons. To get more you need to think about binary coding and about each button being a part of a digital to analog converter. The press of each button adds in a current which is then measured. So, if each button is connected to the pin via a resistor to Vcc and each resistor value goes as a power of 2 then the voltage on that pin, measured by a resistor to ground will be binary coded. The limit is the precision of the resistors and the A/D converter. With a 10 bit converter you could easily code > 4 buttons (the theoretical maximum is the bit resolution of the converter, but with only 5% resistors the maximum is 4) ... Just make sure you use the whole range of the converter.

With an A/D converter pin you can do a lot of tricks.

Cheers MC

Reply to
Varactor

2/5

and

wer

nal

d
h

Good

The circuit below would detect 4 switches at 5v, 3.75, 2.5, 1.25v idealling at 0V. Would this setup work? How many switches can I connect to my 12F675 running at 4 MHz, 4.5V Vcc with 1% resistors if the setup works?

Regards,

Allen

VCC +----+ T | | --- | .-. 12F675 +---o o----+ | | .-----. | | |1k | | | T '-' | | | --- | | | +------+-o o----+ | | | | | | | .-. | | | | | | | | | |1k | | | T '-' | | | --- | | AN1|----+---+--+-o o----+ | | | | | | '-----' .-. | | .-. | | - | | | 10k| | ^ | | |1k '-' | | T '-' | | | --- | +---+ +-o o----+ | | | .-. GND | | | |1k '-' | GND

(created by AACircuit v1.28.6 beta 04/19/05

formatting link

Reply to
Allen Bong

o
a

, 2/5

ns and

power

ernal

se

uld

ith

is

=A0Good

s

Close, but not quite. Look at it, the top switch connects the pin to Vcc regardless of the other switches so the pic will only see that switch. There are a couple of ways of doing it. Try putting the switches with their coding resistors in parallel to Vcc and all connected to the input pin. Now, the resistor to ground from the pin forms a voltage divider (you can also use the input resistance of the pic alone) with the resistor to Vcc formed by variable numbers of //'d resistors. The number of those resistors and their values determines the voltage. So, provided each resistor value is unique, the overall resistance from the pin to Vcc is uniquely coded by the switches. The second way is to use each switch to short out a single resistor from the chain (which may be simpler to think about). Again the value of each resistor in the chain must be unique and ideally very different (say powers of 2 (i.e. 1k, 2k, 4k, 8k). A few (fun :-)) minutes with a soldering iron and a multimeter will let you see how it works -by whatever method. Finally, if the switches are double pole you can use a R2R ladder (you can google that). The R2R ladder is a method used to make many D/A converters. You may also want to look up 'Gray coding' to further your knowledge of how to reliably encode physical parameters for a computer.

Good luck!

MC

Reply to
Varactor

to

, a

op, 2/5

pins and

a power

nternal

use

could

p
o

with

A is

=A0Good

=3D

o

is

g

Thanks very much MC,

I would need more time to digest what you have said. Google is my best friend anyway not forgetting wikidepia as well. I will post back here if there's anything I dont understand.

I would like to thanks those answering my post including Bill Bowden whose web site I frequently visit to get circuit ideas. I have another 2 more projects I am going to do: poor man's o'scope using

12F675 and a bike computer using 16F628 for my newly bought bicycle.

Cheers,

Allen.

Reply to
Allen Bong
[snip]

Just air code. I'm using timer SFR names from micros I use, so they may not apply to the '675:

Button_Loop btfsc GPIO, 0 goto Button_Loop

; enable 1 second timer here

Short_Loop btfsc GPIO, 0 goto Short_Press

; loop until timer expires btfss PIR1, TMR1IF goto Short_Loop

; if timer manages to expire, the ; button is still pressed, ; and is considered a 'long' (>1sec) ; press.

; turn off timer here

Long_Press ; keep looping until button is released btfss GPIO, 0 goto Long_Press

; run your 'long press' code goto Main_Program

Short_Press ; if gpio went high before 1sec, ; the button was released as a 'short' ; (

Reply to
Randy Day

that's one way to wire a 'push A and B ro reset the MCU'.

doesn't work to well with a low impedance supply. :)

--
?? 100% natural
Reply to
Jasen Betts

Let me see if I understand it right.

For a short press: It enters Botton_Loop, pass the first btfsc test. Then enable 1 sec timer, past second btfsc test. Timer 1 not yet expired, Loop back into the Short_Loop. Release button before timer 1 expires and exit into Short_Press.

For a long press: Enters at Button_Loop, pass the first btfsc test, set up timer 1 for 1 sec, Goes through second btfsc test and on 3rd btfss test, also dropped into the Short_Loop until > 1 second, timer1 expires, will drop onto Long_Press loop and exit btfss when the button is released.

Very nice, but at first glance, a bit tough to understand how it works.

Thank you Randy for teaching me this new trick!! I'll put it into my macro library file and include it on my next program.

Cheers,

Allen

Reply to
Allen Bong

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.