📄 carq.c
字号:
/*********************************************************
* PULSE SOURCE BY 12F675 *
*********************************************************/
#include <pic.h>
#define UCHAR unsigned char
#define UINT unsigned int
#define ULONG unsigned long
#define PUL5 GPIO5 //脉冲输出
#define PUL4 GPIO4 //脉冲输出
#define MCLR GPIO3 //复位
#define LED GPIO2 //备用2
#define KR1 GPIO1 //并用
#define KR GPIO0 //键
#define INIT_GPIO 0b00001011
#define PULSE TRIS5 //脉冲输出
#define INIT_TRIS 0b00111011
#define INIT_WPU 0b00110111
#define NOP asm("nop")
#define CLRWDT asm("clrwdt")
__CONFIG(PWRTEN & INTIO & PROTECT & CPD);
/*************************************************************************/
static UCHAR MFlage @ 0x5f;
static bit INVALID @ (unsigned)&MFlage*8+7; //
static bit PDIS @ (unsigned)&MFlage*8+6; //
static bit LEDEN @ (unsigned)&MFlage*8+5; //
static bit SCALER @ (unsigned)&MFlage*8+3; //
static UCHAR Key @ 0x5e;
static bit KEYVFY @ (unsigned)&Key*8+3; //
static bit KEYTMP @ (unsigned)&Key*8+2; //
static bit KINIT @ (unsigned)&Key*8+1; //
static bit KEY @ (unsigned)&Key*8+0; //
/*************************************************************************/
void delay(UCHAR us)
{
us-=2;
do{NOP;}
while(--us);
}
/*************************************************************************/
void main(void)
{
UINT Valid;
UCHAR i;
CLRWDT;
#asm
bsf status,5
call 0x3ff
movwf 0x10
bcf status,5
#endasm
GPIO=INIT_GPIO;
TRISIO=INIT_TRIS;
WPU=INIT_WPU;
ANSEL=0b00010000;
CMCON=0b00000111;
OPTION=0b00000001;
T0IE=1;
MFlage=0;
Key=0;
GIE=1;
i=200;
do{
CLRWDT;
delay(250);
}while(--i);
Valid=EEPROM_READ(1);
Valid<<=8;
Valid+=EEPROM_READ(0);
if(Valid==0xffff)
Valid=0;
else if(Valid)
{
if(Valid==1)
INVALID=PDIS=1;
else
Valid--;
}
if(KEY)
{
KEY=0;
Valid=2000;
INVALID=PDIS=1;
}
KINIT=0;
EEPROM_WRITE(0,(UCHAR)Valid);
EEPROM_WRITE(1,(UCHAR)(Valid>>8));
LEDEN=1;
while(1)
{
CLRWDT;
if(KEY)
{
KEY=0;
PDIS=!PDIS || INVALID;
}
else if(KINIT)
{
KINIT=0;
PDIS=INVALID=0;
Valid=0;
EEPROM_WRITE(0,0);
EEPROM_WRITE(1,0);
}
}
}
/******************************************************************************/
void interrupt isr(void)
{
static UCHAR PulseCnt,AlarmCnt,scaler;
static UCHAR KeyCnt,KeyCnt1;
if(T0IF)
{
T0IF=0;TMR0+=6;
KEYTMP=!KR;
if(KEYTMP && KEYVFY)
KeyCnt++;
else
{
KEYVFY=KEYTMP;
KeyCnt=KeyCnt1=0;
}
if(KeyCnt==60)
KEY=1;
else if(KeyCnt>=250)
{
KeyCnt-=100;
if(++KeyCnt1==100)
KINIT=1;
else if(KeyCnt1==250)
KeyCnt1--;
}
if(++PulseCnt==250)
PulseCnt=0;
PULSE = PulseCnt<25 && !PDIS;
if(++scaler>=12)
{
scaler=0;
if(PDIS)
AlarmCnt++;
else
AlarmCnt=0;
}
if(LEDEN)
LED = !PDIS || AlarmCnt>=160;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -