各位大佬,想要在这个程序的基础上增加一个延时函数,作用是想要在上电前三秒系统不工作,所以想延时3s才开始工作,按键生效。
#include <sc.h>//芯片头文件,会根据工程选项自动寻找对应型号头文件
#define uint8_t unsigned char
#define uint16_t unsigned int
#define uint32_t unsigned long int
#define FinshDingShi_8H 959 //定时8小时
#define FinshDingShi_12H 1439 //定时12小时
#define DLU_FinshDingShi 2879
//#define FinshDingShi_4MIN 7 //3MIN
//#define DLU_FinshDingShi 11 //6MIN
#define LED1 RB1
#define LED2 RB0
#define LED3 RB4
#define PTC_EN RB2
#define KEY RB3
#define FST RB5
volatile bit Start_flat;
volatile bit Get_AC220_flat;
volatile bit biaozhi1;
volatile bit PTC_GPIO_flat;
volatile uint16_t tt=0;
volatile uint16_t aa=0;
volatile uint16_t Timer=0;
volatile uint8_t count=0;
volatile uint8_t Ptc_DingShi_flat=0;
volatile uint8_t count1=0;
void Init_System();
void KEY_Ptc_DingShi_Scan(void)
{
if(KEY)
{
if(count1>5)
{
Ptc_DingShi_flat++;
if(Ptc_DingShi_flat>3)Ptc_DingShi_flat=0;
aa=0;Timer=0;
count1=0;
}
biaozhi1=0;count1=0;
}
else if(biaozhi1==0)
{
if(KEY==0)
{
count1++;
if(count1==65500)
{
count1=0;biaozhi1=1;
}
}
}
}
void main()
{
Start_flat=0;
Get_AC220_flat=0;
biaozhi1=0;
PTC_GPIO_flat=0;
Init_System();
Get_AC220_flat=1;
while(1)
{
asm("clrwdt");
KEY_Ptc_DingShi_Scan();
if(!FST)
{
if(!FST)
{
if(Start_flat==1)
{
aa++;
if(aa>=1500)
{
aa=0;
Timer++;
}
}
count++;
if(count>2)
{
Get_AC220_flat=1;
count=0;
}
while(!FST);
}
}
if(Get_AC220_flat==1)
{
if(Ptc_DingShi_flat==0)
{
LED1=0;LED2=0;LED3=0;
PTC_EN=0;PTC_GPIO_flat=0;
Start_flat=0;
}
else if(Ptc_DingShi_flat==1)
{
Start_flat=1;
LED1=0;
LED3=0;
if(Timer<=FinshDingShi_8H )
{
LED2=1;
PTC_EN=1;
PTC_GPIO_flat=1;
}
else if((Timer>FinshDingShi_8H )&&(Timer<=DLU_FinshDingShi))
{
LED2=0;
PTC_EN=0;
PTC_GPIO_flat=0;
}
else if(Timer>DLU_FinshDingShi)
{
Timer=0;aa=0;
}
}
else if(Ptc_DingShi_flat==2)
{
Start_flat=1;
LED2=0;
LED3=0;
if(Timer<=FinshDingShi_12H )
{
LED1=1;
PTC_EN=1;
PTC_GPIO_flat=1;
}
else if((Timer>FinshDingShi_12H )&&(Timer<=DLU_FinshDingShi))
{
LED1=0;
PTC_EN=0;
PTC_GPIO_flat=0;
}
else if(Timer>DLU_FinshDingShi)
{
Timer=0;aa=0;
}
}
else if(Ptc_DingShi_flat==3)//定时24小时=浅黄
{
Start_flat=1;
LED2=0;
LED1=0;
LED3=1;
PTC_EN=1;
PTC_GPIO_flat=1;
}
}
}
}
谢谢大佬们
|
@xch :就是为了防止误判,通电后前三秒执行任何操作无效
“上电前系统不工作3秒” 好古怪的需求。也许烧柴油的内燃机可以工作。