Page 2 of 2

Re: PIC12F629 help

PostPosted: Mon Nov 30, 2015 2:42 am
by ric
scuba_ wrote:That's what it's doing .. but i want it to stop after ten times. Then go to sleep, only to be woken up by GPIO4 going LOW then HIGH again.
...

You didn't have any code actually doing what you describe.
Try this:

Code: Select all
#include"xc.h"

#pragma config MCLRE=OFF , CP=OFF, CPD=OFF, BOREN=OFF, WDTE=OFF, PWRTE=OFF, FOSC=INTRCIO

#define _XTAL_FREQ 4000000

void sys_init(void) {
    TRISIO = 0b011000;    //GP0, 1, 2 output, GP3 & 4 input
    GPIO = 0;
    GIE = 0;
    OPTION_REG = 0x00;  //global enable WPU
    WPU = 0b00110000;    //enable WPU on GP4 (N/A on GP3)
}

void main(void) {
    sys_init();
    while (1) {
        int i = 0;

        for (i = 0; i < 10; i++) {
            GPIO = 0b010011; //drop GP2,GP0, raise GP1
            __delay_ms(150);
            GPIO = 0b010101; //drop GP1, raise GP2
            __delay_ms(150);
        }

        while (GPIObits.GP4 == 1)    //wait until GP4 goes low
            ;
        while (GPIObits.GP4 == 0)    //wait until GP4 goes high
            ;
    }
}