How to set GPIO.5 as output ?


Closed Thread
Results 1 to 14 of 14
  1. #1
    Join Date
    Mar 2004
    Posts
    92

    Default How to set GPIO.5 as output ?

    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.

  2. #2
    Join Date
    Oct 2006
    Location
    Edmonton AB Canada
    Posts
    52


    Did you find this post helpful? Yes | No

    Default

    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

  3. #3
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    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...

    Code:
    	'
    	'	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.

  4. #4
    Join Date
    Mar 2004
    Posts
    92


    Did you find this post helpful? Yes | No

    Default

    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.

    Code:
    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.

    Code:
    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 !

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    I see
    HIGH LED5
    but I do not see
    LOW LED5

    Maybe I am missing something???
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Mar 2004
    Posts
    92


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    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

  7. #7
    Join Date
    Apr 2007
    Posts
    53


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    I see
    HIGH LED5
    but I do not see
    LOW LED5

    Maybe I am missing something???
    There is no LOW LED4 either.....................

    Andy

  8. #8
    Join Date
    Mar 2004
    Posts
    92


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Andy Wood View Post
    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.

  9. #9
    Join Date
    Dec 2003
    Location
    Wichita KS
    Posts
    511


    Did you find this post helpful? Yes | No

    Default You should sticky this. . ..

    Quote Originally Posted by Melanie View Post
    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...

    Code:
    	'
    	'	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.

    Dwayne
    Ability to Fly:
    Hurling yourself towards the ground, and missing.

    Engineers that Contribute to flying:
    Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute

    Pilots that are Flying:
    Those who know their limitations, and respect the green side of the grass...

  10. #10
    Join Date
    Jul 2015
    Posts
    3


    Did you find this post helpful? Yes | No

    Default Re: How to set GPIO.5 as output ?

    write this code:
    T1CON.3 = 0



    Code:
              
    @__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

  11. #11
    Join Date
    Jul 2015
    Posts
    3


    Did you find this post helpful? Yes | No

    Default Re: How to set GPIO.5 as output ?

    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

  12. #12
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Default Re: How to set GPIO.5 as output ?

    nice digging out !!!

    - 10th September 2009, 16:40
    hope he has found a solution ... +/- 6 years later ....


    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  13. #13
    Join Date
    Jul 2015
    Posts
    3


    Did you find this post helpful? Yes | No

    Default Re: How to set GPIO.5 as output ?

    Quote Originally Posted by Acetronics2 View Post
    nice digging out !!!



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

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

  14. #14
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: How to set GPIO.5 as output ?

    You realize the T1CON.3 BOD /POR is 0 by default . . .
    Name:  12F675 T1CON.jpg
Views: 1264
Size:  154.6 KB
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

Similar Threads

  1. Interruptus Frustratus
    By Byte_Butcher in forum General
    Replies: 16
    Last Post: - 17th April 2009, 20:36
  2. 16F628A - Stops if release power switch.
    By dene12 in forum General
    Replies: 16
    Last Post: - 14th February 2009, 07:57
  3. Help with sound command in 2 programs
    By hyperboarder in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th July 2007, 20:36
  4. Serious Serial Situation Setbacks...
    By Dansdog in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 7th February 2007, 03:46
  5. error on compiling
    By parker in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 16th June 2005, 14:31

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts