Setting GPIO and TRISIO


Closed Thread
Results 1 to 6 of 6

Hybrid View

  1. #1
    Join Date
    Sep 2010
    Location
    Las Vegas, NV
    Posts
    305


    Did you find this post helpful? Yes | No

    Default Re: Setting GPIO and TRISIO

    Hey, thanks for the reply and for showing the progression from functional to elegant. But would you mind verifying my logic?

    Since I'm an unsophisticated person, I want to make sure I understand what's going on in the following snippet. Variables get declared, TRIS set and then LED1= !LED1 sets a 1, because its prior value was 0, turning on LED1. LED2= ! LED1 turns off LED2 because it's value is set to 1 in the previouse line. Then it loops and the !LED1 keeps toggling the state of LED1 and LED2.

    Is that close? Is it necessary to set the gpio.0 or gpio.6 to 0 to make sure they turn off at start up?


    .. again in a more sophisticated way:

    Code:
    LED1 VAR GPIO.0
    LED2 VAR GPIO.6
    
    TRISIO = %00011110
    
    main:
    LED1 = !LED1
    LED2 = !LED1
    PAUSE 500
    GOTO MAIN
    
    END
    Cheers

    Al.[/QUOTE]

  2. #2
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default Re: Setting GPIO and TRISIO

    Is that close?
    You have got it!

    Is it necessary to set the gpio.0 or gpio.6 to 0 to make sure they turn off at start up?
    No, since Led1 and Led2 has been declared as alias of gpio.0 and gpio.6. So if you want set them to zero just state Led1=0 : Led2=0.

    Cheers

    Al.
    Last edited by aratti; - 10th March 2011 at 22:43.
    All progress began with an idea

  3. #3
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default Re: Setting GPIO and TRISIO

    Also... don't overlook the fact that GPIO.3 can only be an INPUT. It defaults to MCLR or "Master Clear with internal pull-up". This means it will reset the chip whenever it goes low.

    In order to make it a normal input pin you MUST change the "Configuration Word Register" bit 5. This register can ONLY be defined once at the time of programming. I think some refer to it as the "FUSE bits" or "configuration fuses" This special register can only be changed each time you program the chip and is not change-able during runtime of your program.

    I think I lost a few hairs and much sleep trying to understand the details of configuring PIC's and the registers. I now keep the .pdf of what ever chip I am working with open and refer to it often as I am defining the functionality of my chip and the various I/O pins, analog, comparators, pulse width modulation, etc, etc.

    I hope this helps and is not too basic for your level.

    In the beginning I tried to use GPIO.3 as a normal input and could not for the life of me figure out why it kept resetting my program...

    regards
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

Members who have read this thread : 0

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