I have a little project with a strange problem.
Here is my plan:
When GPIO4=1, GPIO0 goes high, while GPIO1 & GPIO2 alternate.
After 30 seconds (or if GPIO4 goes low), they ALL shut off until GPIO4 is triggered again.
I've tried doing this a few different ways, but am having a heck of a time nailing it down.
Any help would be greatly appreciated!
Here is my code:
- Code: Select all
#include<pic12f629.h>
#include<htc.h>
#include <stdio.h>
#include <stdlib.h>
#include"xc.h"
#pragma config MCLRE=OFF , CP=OFF & CPD=OFF , BOREN=OFF , WDTE=OFF , PWRTE=OFF , FOSC=INTRCIO
#ifndef _XTAL_FREQ
// Unless already defined assume 4MHz system frequency
// This definition is required to calibrate __delay_us() and __delay_ms()
#define __delay_ms(x) _delay((unsigned long)((x)*(_XTAL_FREQ/4000.0)))
#define _XTAL_FREQ 4000000
#endif
//#define BUTTON GPIO3
#define PERIOD 1000000
#define XTAL 4000000
#define IPERIOD (4 * 1000000 / XTAL) // Period of instruction clock in uSeconds
volatile int i;
void sys_init(void);
void sys_init(void)
{
GPIE=0;
CMCON =0b00000111;
TRISIO =0; TRISIO0=0; TRISIO1=0; TRISIO2=0; TRISIO4=1; TRISIO5=0; TRISIO3=1; GPIO =0;
T0IE = 0; // Disable timer interrupt
GIE = 0;
OPTION_REG=0x00;
WPU=0x30;
STATUS=(1<<RP0);
}
int main(int argc, char** argv) {
sys_init();
while(1)
{
if (GPIO4==0)
{
for (int i=0;i<30;i++)
{
GPIO0=1;
GPIO1=1;GPIO2=0; __delay_ms(110);
GPIO1=0;GPIO2=1; __delay_ms(110);
}
}
if (GPIO4==1)
{
GPIO0=0; GPIO1=0; GPIO2=0;
}
}
}