Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

12F675 Input problems

Status
Not open for further replies.

Jerran

New Member
Im trying to make a variable timer using 4 input pins of my 12f675 pic but Im unable to read a voltage off Pins 0,1 and 4 for some reason. Pin 5 input functions as it should but cant read a logical 1 off the others. Programs written and programmed in Basic Pro using MPLabs.

Small program goes as follows, I added check for 0 on Pin0 to see if it was even configed as a input correctly. As I assumed I can get a longer delay if I check for 0 <so I am reading inputs I assume just not a logical 1>.

GPIO = %00111101
W0 VAR Word
W1 VAR Word
W2 VAR Word
W3 VAR Word
W4 VAR Word
B0 VAR Byte
loop:
W0 = 0
W1 = 0
W2 = 0
W3 = 0
Peek GPIO, B0
if B0.0 = 1 Then
W0 = W0 + 3000
Endif
if B0.0 = 0 Then
W0 = W0 + 24000
Endif
if B0.2 = 1 Then
W1 = W1 + 6000
Endif
if B0.4 = 1 Then
W2 = W2 + 12000
Endif
if B0.5 = 1 Then
W3 = W3 + 24000
Endif
W0 = W0 + 15000
High 1
Pause 200
Low 1
Pause W0
Pause W1
Pause W2
Pause W3
Goto loop

Originally all the inputs would add to W0 and the end result was added once more to 15K to ensure atleast a 15 second delay. I added the extra words and pauses to make sure I wasnt overwritting the pause<65K limit I believe>.

As for hardware Im using 4 10K resistors each in series with a SPST switch connected to ground. All inputs connected between the switch and resistor, 1 resistor and switch per input.
<aka HIGH on open LOW on closed>.

Any help will be greatly appreciated.
 
Jerran said:
Im trying to make a variable timer using 4 input pins of my 12f675 pic but Im unable to read a voltage off Pins 0,1 and 4 for some reason. Pin 5 input functions as it should but cant read a logical 1 off the others. Programs written and programmed in Basic Pro using MPLabs.

The 12F675 (like most PIC's with A2D) have their defaults set to use the A2D convertors, so GP0, GP1, GP2 and GP4 are probably still set as analogue inputs. You need to set them to be digital inputs, details are in the data sheet - it's done in the ANSEL register.
 
The 12F675 has A/D converter inputs on those pins, wich are activated on power on, you must turn of the A/D to make the pins act as digital IO
Look at the datasheet to see how to do it.

I think it was:
-clearing bit 0 of register ADCON0 to turn off ADC
-clearing bits 0-3 of register ANSEL to turn the pins into digital IO
 
Cool that got it :)
I read threw that section on that data sheets already but seeing that my special registers on my Pic Pro Plus showed them all as cleared I didnt mess with it. After manually adding these commands it works like a charm.

ADCON0.0 = 0
ANSEL.0 = 0
ANSEL.1 = 0
ANSEL.2 = 0
ANSEL.3 = 0

Thanks Exo and Nigel for the quick replies.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top