PDA

View Full Version : 12F683 Startup



GregK
- 18th March 2005, 00:23
Hi

When powering up the Pic the outputs are high, when I set them as outputs and low. When I ground an input pin, the loop works fine. Please tell me what I am doing wrong.

Set registers for all digital I/O:
ANSEL = 0
CMCONO =7
ADCON0 = 7
VRON = 0.

TRISIO = %00111000 'Set all pins as outputs except 3.4.5

'Inputs:
ExtendIn var gpio.4
RetractIn var gpio.5

'Outputs:
ExtendOut var gpio.0
Low ExtendOut
RetractOut var gpio.1
Low RetractOut

Loop:

If ExtendIn = 0 then
High ExtendOut
Pause 2000
Low ExtendOut
Endif

If RetractIn = 0 then
High RetractOut
Pause 2000
Low RetractOut
Endif

Goto Loop


My output's are just LED's with 1K ohm series resistors. The LED's are connected so a high pin lites the Led. I have read the data sheets and I'm still not sure about the register settings. I am using Pic Basic Pro 2.45.

Any help or suggestions would be greatly appreciated.

Thanks

Greg

NavMicroSystems
- 18th March 2005, 01:17
Greg,

looks like your program works as designed.

If you leave the inputs floating they will be read HIGH, so your loop doesn't do anything else than looping.

GregK
- 18th March 2005, 03:54
Hi Ralph,

Thanks for your reply.

Let me explain a little more about the problem. The "Loop" is just to debug a problem I am having when I first power up the pic. The two input pins used in the program are pulled up through 10K resis. The third input pin (gpio.3) is always an input, and internally pulled up.

The problem I don't understand is why both LED's are ON when I first power up the pic, with no input pins grounded. I set the outputs Low before the "Loop" and yet they are High when I power the Pic up. I have tried other 12F683's with the same results.

Greg

Bruce
- 18th March 2005, 20:36
See if this configuration works for you. Note - you won't need the external pull-ups.


@ device pic12f683, fcmen_off, ieso_off, intrc_osc, wdt_off
@ device pic12f683, pwrt_on, mclr_off, protect_off

GPIO = %00000000 ' All outputs low
CMCON0=7 ' Comparators off
ANSEL=0 ' All digital
TRISIO=%00111000 ' Setup ins & outs
WPU=%00110000 ' Pull-ups on for GPIO.4 & 5 inputs
OPTION_REG.7=0 ' Enable internal pull-ups

The default PBP header file for this device doesn't call-out the power-up timer (PWRT), so it defaults to off. This can cause some odd things to happen if your power supply is slow rising.

You don't need to configure ADCON0 or VRCON unless you're using A/D & comparators.

GregK
- 19th March 2005, 00:25
Hi Bruce,

I tried your changes and it works like a charm!
Now if I can get the rest of the program to work.

Thanks for your help.

Greg