#include<pic.h>
#include<pic10f200.h>
#define uchar unsigned char
#define uint unsigned int
#define Led GP0
#define Switch GP1
//#define Beep GP2
#define Sensor GP3
#pragma config WDTE = OFF // Watchdog Timer (WDT disabled)
#pragma config CP = ON // Code Protect (Code protection on)
#pragma config MCLRE = OFF // Master Clear Enable (GP3/MCLR pin fuction is digital I/O, MCLR internally tied to VDD)
uchar disturb,count,count02;
int count01;
void LED(uchar i)
{
if(i==0)
{
Led=0;//GP0 ON
}
else
{
Led=1;//GPO OFF
}
}
void init()
{
//WDTE=0;
TRIS=0X08;//??GP0/1/2???;GP3 ???
FOSC4=0;//??GP2??Fosc/4????
OPTION=0X02;//choose the 16 bits
// GPIO=0X0F;
GP2=0;
disturb=1;//bit for the time control
count=0;
TMR0=0;
count01=0;
}
void main()
{
init();
while(1)
{
if((Sensor==0)&&(disturb==1))
{
if(TMR0==255)//3.5mS
{
count++;
TMR0=0;
if(count==48)//100ms delete the false trigger
{
count=0;
GP2=~GP2;
if(Sensor==0)
{
Switch=~Switch;
disturb=0;
//LED(Switch);//GP0 on/off by Switch
//PWM* 100ms*3 10%
uchar i;
for(i=3;i>0;i--)
{
while(1)
{
if(TMR0==255)
{
TMR0=0;
count++;
}
if(count>3&&count<48)//BEEP OFF
{
GP2=1;
}
else//BEEP ON
{
GP2=0;
}
if(count==48)
{
count=0;
GP2=0;
break;
}
}
}
//PWM
}
}
}
}
else
{
// SLEEP();
count=0;
// GP2=0;
}
if(disturb==0)
{
/* if(TMR0=255)
{
TMR0=0;
count01++;
if(count01==1)//
{
TMR0=0;
count02++;
if(TMR0=255)
{
if(count02==2)
{
TMR0=0;
count02=0;
count01=0;
disturb=1;
Led=~Led;
}
}
}
}
*///delay 1.5s
if(TMR0=255)
{
TMR0=0;
count01++;
if(count01==25470)//0.7S delay to disable the sensor(32730)
{
count01=0;
disturb=1;
Led=~Led;
}
}
}
//SLEEP();
}
}
|