PIC12F629 Code help

Discussion in 'Embedded Systems and Microcontrollers' started by mayilsamy, Mar 26, 2013.

  1. mayilsamy

    Thread Starter New Member

    Mar 26, 2013
    5
    0
    I'm using PIC12F629 for On/Off function in my project.

    I'm using Internal oscillator 4 MHz.

    I'm using GPIO0 for led;
    GPIO2 for switch input;

    If I press switch led turn on;
    I hold a same switch 3 sec led off.

    how to code this?
     
  2. absf

    Senior Member

    Dec 29, 2010
    1,493
    372
    This is a sample code by Randy Day for long and short button press using 12F675..

    Code ( (Unknown Language)):
    1. Button_Loop
    2.         btfsc GPIO, 0
    3.         goto Button_Loop
    4.  
    5.         ; enable 1 second timer here
    6.  
    7. Short_Loop
    8.         btfsc GPIO, 0
    9.         goto  Short_Press
    10.  
    11.         ; loop until timer expires
    12.         btfss        PIR1, TMR1IF
    13.         goto Short_Loop
    14.  
    15.         ; if timer manages to expire, the
    16.         ; button is still pressed,
    17.         ; and is considered a 'long' (>1sec)
    18.         ; press.
    19.  
    20.         ; turn off timer here
    21.  
    22. Long_Press        ; keep looping until button is released
    23.         btfss GPIO, 0
    24.         goto Long_Press
    25.  
    26.         ; run your 'long press' code
    27.         goto Main_Program
    28.  
    29. Short_Press
    30.         ; if gpio<0> went high before 1sec,
    31.         ; the button was released as a 'short'
    32.         ; (<1sec) press.
    33.  
    34.         ; turn off timer here
    35.         ; run your 'short press' code
    36.         goto        Main_Program
    HTH

    Allen
     
    Last edited: Mar 26, 2013
  3. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    If it's battery powered you can use sleep mode and a wake on pin change interrupt. It can execute code like the above when it wakes up.
    Sleep mode ~ 1μA
    Normal running at 4MHz ~ 1mA
     
Loading...