PIC12F629 Code help

Thread Starter

mayilsamy

Joined Mar 26, 2013
5
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?
 

absf

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

Just air code. I'm using timer SFR names
from micros I use, so they may not apply
to the '675:
Rich (BB code):
Button_Loop
        btfsc GPIO, 0
        goto Button_Loop

        ; enable 1 second timer here

Short_Loop
        btfsc GPIO, 0
        goto  Short_Press

        ; loop until timer expires
        btfss        PIR1, TMR1IF
        goto Short_Loop

        ; if timer manages to expire, the 
        ; button is still pressed, 
        ; and is considered a 'long' (>1sec) 
        ; press.

        ; turn off timer here

Long_Press        ; keep looping until button is released
        btfss GPIO, 0
        goto Long_Press

        ; run your 'long press' code
        goto Main_Program

Short_Press
        ; if gpio<0> went high before 1sec,
        ; the button was released as a 'short' 
        ; (<1sec) press.

        ; turn off timer here
        ; run your 'short press' code
        goto        Main_Program
HTH

Allen
 
Last edited:

Markd77

Joined Sep 7, 2009
2,806
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
 
Top