Menu

Pin state to default

Help
Kaka
2015-05-06
2015-05-07
  • Kaka

    Kaka - 2015-05-06

    Hi Guys,
    I am a new member of GCB Community. I am writing a code for AVR but i am stuck into a situation. My requierment is to set a pin to its default state (not 1 or not Zero). Please tell me how can i do this. I Could not find any command of GCB for this purpose.

    Thanks

     

    Last edit: Kaka 2015-05-06
  • Peter Stone

    Peter Stone - 2015-05-06

    I am not sure that there is such a command.
    I would look at the data sheet for the device to see what the pin defaults to on reset and then just set the output accordingly. You might wish to define a constant for this state. eg

    define Pin1Default 0.

    Then you just use

    set PortA.1 Pin1Default

    or whatever is appropriate for the port/pin in question.

    Most pins on micros default to inputs also (check the data sheet again).

    Peter.

     
  • Anobium

    Anobium - 2015-05-06

    Welcome.

    Have a look at the demonstration folder within your installation. Then, the LED example folder. This folder has many examples on how to turn a port (with an LED attached).

    The summary is:

    ~~~~

    chip, (chip type)

    'set direction of the port. I have used porta.1 in this example
    dir porta.1

    do forever

    set porta.1 on
    wait 1 s
    set port1.off
    wait 1 s
    

    Loop

     

    Last edit: Anobium 2015-05-06
  • David Stephenson

    As you said you want it "not 1 and not zero" you need to set the pin as an input.
    DIR porta.0 in
    will do this (for porta pin 0) puts the pin effectively into open circuit state.
    Pins are generally tristate either 0,1 or floating.

    DIR porta.0 out
    set porta.0 on 'puts pin zero
    set porta.0 off ' puts pin at one
    dir porta.0 in ' puts pin open circuit

     
  • William Roth

    William Roth - 2015-05-06

    I believe that David has it correct.
    A tri-state Pin by definition has three states:

    ON (High)
    OFF (Low)
    Floating (Indeterminate/High Impedance) or Input

    If we assume that the default power up state is floating and the Pin has been made an output, then to return to the default state the code would be:

    Dir PORTx.x IN
    
     
  • Kaka

    Kaka - 2015-05-07

    Good, You guys are great. following script works fine for me.


    DIR portC.3 out

    Do Forever
    set PortC.3 off
    Wait 500 ms
    set PortC.3 on
    Wait 500 ms
    dir portc.3 in
    Wait 500 ms
    dir portc.3 out
    Wait 500 ms
    loop

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.