PDA

View Full Version : 12F683 GPIO.3 problem



ozarkshermit
- 17th October 2009, 17:29
Hi all:

I am pulling out what little hair I have left on this.
Such a simple program segment, that I cannot get to work using GPIO.3 as an input.

I simply want to turn on a test LED connected to GPIO.4 for a short time (PAUSE 2000), after GPIO.3 is momentarily pulled low, and then turn it off, and loop till GPIO.3 is momentarily pulled low again. This is only to confirm whether this module is working or not.

It works fine with other GPIO's set up as inputs / outputs, but when I try to use GPIO.3 as the input, it does the following:

The test LED instantly comes on, and stays on, until GPIO.3 is pulled low, it will then turn off and stay off out as long as GPIO.3 is pulled low. (I have a 10K pull-up on GPIO.3 , probably do not need it but it's there.)

I have searched the forum, read Melanies thread on fuse configs, etc , but must be missing something very basic.

The simple program segment is below:

ANSEL = %00000000
CMCON0 = 7
CMCON1 = 7
ADCON0 = %00000000
INTCON = 0
define OSC 8
@DeviceMCLR_OFF
TRISIO = %101000

Main:

GPIO.4 = 0
IF GPIO.3 = 1 THEN Main
GPIO.4 = 1 'TEST LED IS TURNED ON HERE
PAUSE 2000
GPIO.4 = 0 'TEST LED IS TURNED OFF HERE
GOTO Main

For test purposes I have nothing else connected to the PIC.

As you can see, I have the TRIS register configured to also use GPIO.5 as an output rather than .3 , which does indeed work fine.
Can someone please enlighten me?

Thanks

Ken

mackrackit
- 17th October 2009, 17:58
1 = INPUT
0 = OUTPUT

take another look at you TRIS.

ozarkshermit
- 17th October 2009, 18:09
Thanks for pointing that out - however - that did not solve the problem. If I read the data sheet correctly, it does not matter anyway how the TRIS is configured for GPIO.3 , 'cause it always defaults to input only.

Ken

LinkMTech
- 17th October 2009, 18:13
Try putting:
@ DEVICE PIC12F683, MCLR_OFF

at the very top of you program

ozarkshermit
- 17th October 2009, 18:20
Louie:

THANK YOU THANK YOU

I knew the answer would be found from one of the great contributors to this group.

I thought that the MCLR business might have had something to do with it, but your simple answer fixed it.

Thanks again

Ken

LinkMTech
- 17th October 2009, 18:38
Cool!!
Happy to contribute

Heckler
- 30th October 2009, 04:35
What programmer are you using...

I use the PICKIT2... and this exact thing drove me NUTS!! about a week ago... finally while reading the docs for the 12f683 (something you MUST get used to doing) I came across the "configuration" register and realized this is what people call setting the "fuses"... this configuration register can only be set on initial programming. I found it right on the main screen of the pickit2 program, look for the "configuration" link just under the "Help" dropdown. It is an 12 bit register and bit 5 controls that mclr/gpio.3 pin.

I have not figured out exactly how to set each of these bits in my program... yet. So I do it manually each time I burn the chip.

This is one of the (in my opinion) very frustrating aspects of learning to work with these amazing PIC's.

I did not realize this register was VERY DIFFERENT than the other registers like ANSEL, CMCON0... etc. Different in that it can only be setup on initial programming and can not be changed by the program.

Hope this helps... Keep studying those .pdf docs.

Dwight

PS. This is my first post on this forum :)

mackrackit
- 30th October 2009, 08:43
What programmer are you using...

I use the PICKIT2... and this exact thing drove me NUTS!! about a week ago... finally while reading the docs for the 12f683 (something you MUST get used to doing) I came across the "configuration" register and realized this is what people call setting the "fuses"... this configuration register can only be set on initial programming. I found it right on the main screen of the pickit2 program, look for the "configuration" link just under the "Help" dropdown. It is an 12 bit register and bit 5 controls that mclr/gpio.3 pin.

I have not figured out exactly how to set each of these bits in my program... yet. So I do it manually each time I burn the chip.

This is one of the (in my opinion) very frustrating aspects of learning to work with these amazing PIC's.

I did not realize this register was VERY DIFFERENT than the other registers like ANSEL, CMCON0... etc. Different in that it can only be setup on initial programming and can not be changed by the program.

Hope this helps... Keep studying those .pdf docs.

Dwight

PS. This is my first post on this forum :)

http://www.picbasic.co.uk/forum/showthread.php?t=11116