PDA

View Full Version : Pic 12f629



runrite
- 18th January 2008, 19:01
Hi I am very new to the 8pin pics
I need some help using a 12f629 and all I want is for it to sense
a hi or low on GP0 pin 7 and output on GP4 pin 3
I am using an ICD2 programmer
Configuration bits are:
internal RC no clock
Watchdog timer on
power up timer off
mclr enable external
brown out detect on
I have a 8k resistor connected from vdd to pin 4 MCLR
I do not seem to get the pic to read an input condition
my code is as follows

DEFINE OSCCAL_1K 1
DEFINE OSC 4

RELAY VAR GPIO.4

Pswitch VAR GPIO.0

INITIALISE:
CLEAR
TRISIO = %00000001 '0 in rest output
INTCON = %00000000
PIR1 = %00000000
PIE1 = %00000000
WPU = %00000000
CMCON = %11111111 'disable comparators
PAUSE 10

MAIN:
While(pswitch = 1)
relay = 0



wend
relay = 1

GOTO MAIN
end
I would be grateful if anyone could help

skimask
- 18th January 2008, 19:39
Hi I am very new to the 8pin pics
I need some help using a 12f629 and all I want is for it to sense
a hi or low on GP0 pin 7 and output on GP4 pin 3

Program looks ok, even used CMCON. Have you tried the old blinky LED program yet?
Put an LED an GP4 and make it blink. When that works, put the switch on GP0, and turn the LED on and off with that switch under program control.
After that, it should be easy to change it over to do what you want.

runrite
- 18th January 2008, 20:57
Hi There thanks
I have done just that on the input I have
100k to ground permanently on GP0
the switch is wired in this order +5V 10K switch then GP0
still no luck
It just does nt want to check the input condition I have a relay conected via a transistor to the output
This is quite a puzzling problem

skimask
- 18th January 2008, 21:08
Hi There thanks
I have done just that on the input I have
100k to ground permanently on GP0
the switch is wired in this order +5V 10K switch then GP0
still no luck
It just does nt want to check the input condition I have a relay conected via a transistor to the output
This is quite a puzzling problem

Your answer is just a little bit cryptic...
Have you gotten the blinky LED thing to work?
You have a relay connected to the output?
Does it have a 'flyback diode' connected across the coil?
Is the same power supply driving the PIC that's driving the relay coil?

runrite
- 18th January 2008, 21:17
Hi there
Yes 12V to relay and 5V to pic
flyback diode
If I change the code I can get the relay to go on and off
I have used the 16f876's never had a problem like this
am i not doing something wrong with the configuration in MP Lab
I am using microcode studio with PBP

skimask
- 18th January 2008, 21:32
Yes 12V to relay and 5V to pic
flyback diode
If I change the code I can get the relay to go on and off
am i not doing something wrong with the configuration in MP Lab
I am using microcode studio with PBP

Maybe try turning off the WDT?
Try different code, just for grins...
main:
if pswitch = 1 then relay = 0
if pswitch = 0 then relay = 1
goto main
end

runrite
- 18th January 2008, 21:44
Hi There thanks will try
to morrow let you know the outcome

Darrel Taylor
- 18th January 2008, 21:44
I have done just that on the input I have
100k to ground permanently on GP0
the switch is wired in this order +5V 10K switch then GP0
still no luck

Not sure if it's 10k or 100k. 100k would be too high.
But, either way ...

Turn off the Pull-up's, by commenting the WPU statement.
It's not letting the voltage go far enough towards Vss.
<br>

runrite
- 18th January 2008, 21:57
Many thanks it works..
It is sensing now..
the relay chatters when I get it on
Is it to do with the external MCLR
There is an error message that comes on it says that ICD can not program internal clock and internal MCLR at same time any way to sort it out I have to use the on board clock

Bruce
- 18th January 2008, 22:05
I'm a sucker for simplicity.

Try this;


GPIO.4 ----/\/\/\---|<|----+5V.
LED

10K
GPIO.0 --|--/\/\/\---+5V
|--switch---GND.

When you press the switch it grounds GPIO.0.


@ device pic12F629, intrc_osc_noclkout, wdt_on, mclr_off, protect_off

DEFINE OSCCAL_1K 1
DEFINE OSC 4

RELAY VAR GPIO.4 ' relay output
Pswitch VAR GPIO.0 ' switch input

TRISIO = %00000001 ' GPIO.0 input, rest outputs
WPU = 0 ' input pull-ups disabled
CMCON = 7 ' disable comparators
PAUSE 10 ' POR delay

MAIN:
RELAY = ! Pswitch ' Relay pin = the opposite of Psiwtch pin
GOTO MAIN
END
Does this work?

Darrel Taylor
- 18th January 2008, 23:49
Switch to ground. Definately the better way to go.

I might suggest a different Main loop though.
MAIN:
IF RELAY = Pswitch THEN
RELAY = ! Pswitch ' Relay pin = the opposite of Pswitch pin
ENDIF
PAUSE 20
GOTO MAIN

END

Those pesky R-M-W's
<br>

runrite
- 24th January 2008, 05:26
Hi all out there
The last time I did a 8 pin pic was 10 years ago
The problem was to do with the weak pull up
I really want to thank all out there
Bye for now

sayzer
- 24th January 2008, 08:48
Switch to ground. Definately the better way to go.

I might suggest a different Main loop though.
MAIN:
IF RELAY = Pswitch THEN
RELAY = ! Pswitch ' Relay pin = the opposite of Pswitch pin
ENDIF
PAUSE 20
GOTO MAIN

END

Those pesky R-M-W's
<br>



Darrel,

I just want to learn;

Is it really a safe way to read the status of an output pin?

Thanks

mister_e
- 24th January 2008, 21:19
Yes, in fact, from my understanding, it reads the content of the output-latch.

Darrel Taylor
- 24th January 2008, 21:26
Is it really a safe way to read the status of an output pin?
Is it safe?

Well, as far as doing damage, it's perfectly "Safe".
In fact the chip "reads" the state of the OUTPUT pin, everytime you you change the state of any pin on the same port.

The only un-safe part, is if you don't take the R-M-W problems into account.
Can really mess with the program.
<br>