PDA

View Full Version : How to set GPIO.5 as output ?



Sam
- 9th September 2009, 02:37
I have been trying everything I can think of to set GPIO.5 of a 12F675 to work properly as an output and no matter what I do it remains HIGH all the time.

Can you tell me what I must set to have it work correctly ? I have scoured the data sheets and I'm obviously missing it.

Thx.

Meriachee
- 9th September 2009, 03:13
Sam,

Using a set of instructions like:
output GPIO.5
Led1 var GPIO.5
low Led1

as a setup, will allow you to set the output high or low at your liesure.

Cheers
Gary

Melanie
- 9th September 2009, 10:46
You need to do a little more than that...

Datasheet is your friend... use it...

First... TRISIO will set INPUT (1) or OUTPUT (0)... so...

TRISIO=%01111 ' example will set GPIO.5 as OUTPUT and all the others as INPUT...

then always check for COMPARATORS... now GPIO.5 doesn't have any, but if you are not going to use them, switch them OFF, because by the time you start playing with GPIO.0, GPIO.1 and GPIO.2, you'll be back on this forum asking us why they don't work... so add...

CMCON=%00000111 ' see Datasheet Section 6

Next check that you have your A/D's switched off... again, they don't affect GPIO.5, but if you are not going to use them, they can impact on the other GPIO's so disable the A/D with the instruction...

ANSEL=%00000000 ' see Datasheet section 7

Next GPIO.5 and GPIO.4 is where you normally connect your Xtal or Resonator... if you are going to use those pins for I/O then you probably want to enable the INTERNAL OSCILLATOR... so use the command (if you are using PBP's default PM Assembler)...

@ DEVICE pic12F675, INTRC_OSC_NOCLKOUT ' System Clock Options (Internal)

Finally, if you want to use GPIO.3 as INPUT (rather than have to connect MCLR externally), then have the PIC handle MCLR internally for you with the setup...

@ DEVICE pic12F675, MCLR_OFF ' Master Clear Options (Internal)

A good set of CONFIGURATION SETUP's for playing with the 12F675 are...



'
' PIC Defines
' -----------
@ DEVICE pic12F675, INTRC_OSC_NOCLKOUT
' System Clock Options (Internal - GPIO.4 and GPIO.5 available for I/O)
@ DEVICE pic12F675, WDT_ON
' Watchdog Timer
@ DEVICE pic12F675, PWRT_ON
' Power-On Timer
@ DEVICE pic12F675, MCLR_OFF
' Master Clear Options (Internal - GPIO.3 available for INPUT)
@ DEVICE pic12F675, BOD_ON
' Brown-Out Detect


Your PIC's GPIO.5 should now be working with Gary's code... if it isn't, check you've not shorted GPIO.5 against the adjacent Vdd pin which could cause it to hold HIGH.

Sam
- 9th September 2009, 15:44
I knew I should have posted my code but I was on a different computer at the time. The first is the program I have tried, with it, GPIO.4 works properly but GPIO.5 remains HIGH always. There's no short btwn any pins, I'm using a clean breadboard.



POR
ADCON0=0
VRCON=0
OPTION_REG.5=0
OPTION_REG.7=1
CMCON=7
TRISIO=%00001000



LED1 var GPIO.0
LED2 VAR GPIO.1
LED3 VAR GPIO.2
LED4 VAR GPIO.4
LED5 VAR GPIO.5

PAUSE 50

loop: 'scroll test pattern

high led1
pause 75
LOW LED1
PAUSE 50

high led2
PAUSE 75
LOW LED2
PAUSE 50

HIGH LED3
PAUSE 75
LOW LED3
PAUSE 50

high led4
PAUSE 75
LOW LED2
PAUSE 50

HIGH LED5
PAUSE 75
LOW LED3
PAUSE 50


goto loop









The code below is based on your reply (which I appreciate) and it makes GPIO.4 and GPIO.5 remain HIGH at all times. I have tried compiling in both PM and mpasm. Also, I have the MCLR disabled in EPIC'c configuration. I'm not using an ext. osc.



TRISIO=%00000
CMCON=%00000111
ANSEL=%00000000


@ DEVICE pic12F675, INTRC_OSC_NOCLKOUT
@ DEVICE pic12F675, WDT_ON
@ DEVICE pic12F675, PWRT_ON
@ DEVICE pic12F675, MCLR_OFF
@ DEVICE pic12F675, BOD_ON

LED1 var GPIO.0
LED2 VAR GPIO.1
LED3 VAR GPIO.2
LED4 VAR GPIO.4
LED5 VAR GPIO.5

PAUSE 50


loop: 'scroll test pattern

high led1
pause 75
LOW LED1
PAUSE 50

high led2
PAUSE 75
LOW LED2
PAUSE 50

HIGH LED3
PAUSE 75
LOW LED3
PAUSE 50

high led4
PAUSE 75
LOW LED2
PAUSE 50

HIGH LED5
PAUSE 75
LOW LED3
PAUSE 50


goto loop




So I must be doing something wrong or missing something ? If I remove ANSEL GPIO.4 works ???

This is just a way for me to learn to use GPIO.4 and 5 and plan to use them in another program later.

Thanks for the help !

mackrackit
- 9th September 2009, 19:32
I see
HIGH LED5
but I do not see
LOW LED5

Maybe I am missing something???

Sam
- 9th September 2009, 21:00
I see
HIGH LED5
but I do not see
LOW LED5

Maybe I am missing something???

No, you're not missing anything, that was it ! Good job on catching that, I can't believe how many times I looked at that and never saw it. I still had to remove ANSEL to get GPIO.4 to work but it's all good now.

Thank you for pointing that simple (read STUPID) mistake out, and thanks Melanie and Gary,

Sam

Andy Wood
- 9th September 2009, 21:34
I see
HIGH LED5
but I do not see
LOW LED5

Maybe I am missing something???

There is no LOW LED4 either.....................

Andy

Sam
- 9th September 2009, 22:11
There is no LOW LED4 either.....................

Andy

Yeah, I fixed that too. I copied and pasted those last two sections then changed them and that's where I really started screwing up. I'll read my own stuff a LOT closer after this ordeal.

I did learn how to properly initiate this PIC now though, thanks to Melanie's post.

Dwayne
- 10th September 2009, 15:40
You need to do a little more than that...

Datasheet is your friend... use it...

First... TRISIO will set INPUT (1) or OUTPUT (0)... so...

TRISIO=%01111 ' example will set GPIO.5 as OUTPUT and all the others as INPUT...

then always check for COMPARATORS... now GPIO.5 doesn't have any, but if you are not going to use them, switch them OFF, because by the time you start playing with GPIO.0, GPIO.1 and GPIO.2, you'll be back on this forum asking us why they don't work... so add...

CMCON=%00000111 ' see Datasheet Section 6

Next check that you have your A/D's switched off... again, they don't affect GPIO.5, but if you are not going to use them, they can impact on the other GPIO's so disable the A/D with the instruction...

ANSEL=%00000000 ' see Datasheet section 7

Next GPIO.5 and GPIO.4 is where you normally connect your Xtal or Resonator... if you are going to use those pins for I/O then you probably want to enable the INTERNAL OSCILLATOR... so use the command (if you are using PBP's default PM Assembler)...

@ DEVICE pic12F675, INTRC_OSC_NOCLKOUT ' System Clock Options (Internal)

Finally, if you want to use GPIO.3 as INPUT (rather than have to connect MCLR externally), then have the PIC handle MCLR internally for you with the setup...

@ DEVICE pic12F675, MCLR_OFF ' Master Clear Options (Internal)

A good set of CONFIGURATION SETUP's for playing with the 12F675 are...



'
' PIC Defines
' -----------
@ DEVICE pic12F675, INTRC_OSC_NOCLKOUT
' System Clock Options (Internal - GPIO.4 and GPIO.5 available for I/O)
@ DEVICE pic12F675, WDT_ON
' Watchdog Timer
@ DEVICE pic12F675, PWRT_ON
' Power-On Timer
@ DEVICE pic12F675, MCLR_OFF
' Master Clear Options (Internal - GPIO.3 available for INPUT)
@ DEVICE pic12F675, BOD_ON
' Brown-Out Detect


Your PIC's GPIO.5 should now be working with Gary's code... if it isn't, check you've not shorted GPIO.5 against the adjacent Vdd pin which could cause it to hold HIGH.


Hello Melanie!

Long time no see. . .

It has been a while since I have been on, but I saw this response... I don't remember if there was a "sticky" or a such a good definition in the FAQ side of this forum of chip headers / switches and why.

I ran into a situation of two chips about 1 month ago. Had them working together, then suddenly one stopped. Could not for the life of me figure out what happened. It just seemed to work for about 15 seconds, get "soft", then die. Soon it stopped working all together. AFter running in circles,I found I guess I blew one of the pins somehow. I only switched my code to another pin and it has been working since. :smile:

Dwayne

zibatare
- 24th July 2015, 17:52
write this code:
T1CON.3 = 0





@__config _INTRC_OSC_NOCLKOUT & _MCLRE_OFF


CMCON = 7
'VRCON = 0
'WPU = 0 'no wake pullup
'IOCB = 0 'no int. on change
ANSEL = %00000000 '16tosc gpio0 input analogico
ADCON0 = 0 'right just , Vref=Vdd , ch.0 , A/D on
T1CON = %11110101
T1CON.3 = 0
'OPTION_REG.7 = 0


TRISIO=%001000

LEDT1 var GPIO.1
LEDT2 var GPIO.2




B0 var byte
B1 var byte
B2 var byte
I var byte
N var byte
O var byte
S1 var byte
S2 var byte
S3 var byte


start:
high GPIO.4
high GPIO.5
pause 500
low GPIO.4
low GPIO.5
pause 500
goto start

zibatare
- 24th July 2015, 17:53
write this code: T1CON.3 = 0




@__config _INTRC_OSC_NOCLKOUT & _MCLRE_OFF

CMCON = 7
'VRCON = 0
'WPU = 0 'no wake pullup
'IOCB = 0 'no int. on change
ANSEL = %00000000 '16tosc gpio0 input analogico
ADCON0 = 0 'right just , Vref=Vdd , ch.0 , A/D on
T1CON = %11110101
T1CON.3 = 0
'OPTION_REG.7 = 0

TRISIO=%001000

LEDT1 var GPIO.1
LEDT2 var GPIO.2
Power var GPIO.5



B0 var byte
B1 var byte
B2 var byte
I var byte
N var byte
O var byte
S1 var byte
S2 var byte
S3 var byte

high power
start:
' gosub light
high GPIO.4
high GPIO.5
pause 500
low GPIO.4
low GPIO.5
pause 500
goto start

Acetronics2
- 24th July 2015, 20:26
nice digging out !!!


- 10th September 2009, 16:40

hope he has found a solution ... +/- 6 years later ....
:D:D:D

Alain

zibatare
- 25th July 2015, 04:36
nice digging out !!!



hope he has found a solution ... +/- 6 years later ....

Alain

Yes, I realized.:cool:
But my goal was to show the correct solution
Because of the low price and economy,
12f675 in many applications:)

Archangel
- 25th July 2015, 09:51
You realize the T1CON.3 BOD /POR is 0 by default . . .
7941