本帖最后由 坏小孩~ 于 2015-8-2 19:50 编辑
如图,我一般是在main.c中位域出时间标志位,struct //位域出时间平台标志位 {
unsigned char flag_1mS :1;
unsigned char flag_2mS :1;
unsigned char flag_4mS :1;
unsigned char flag_50mS :1;
unsigned char flag_100mS :1;
unsigned char flag_500mS :1;
unsigned char flag_1S :1;
unsigned char flag_2S :1;
}Time = {0,0,0,0,0,0,0,0};
然后把中断函数写在main.c中,在里面构造时间平台
INTERRUPT_HANDLER(TIM1_UPD_OVF_TRG_BRK_IRQHandler, 11)
{
TIM1_ClearITPendingBit(TIM1_IT_UPDATE); //清除TIM1溢出标志
static unsigned char Cnt_1mS = 0;
static unsigned char Cnt_2mS = 0;
static unsigned char Cnt_100mS = 0;
static unsigned char Cnt_500mS = 0;
static unsigned char Cnt_1S = 0;
Cnt_1mS++;
if(Cnt_1mS == 10)
{
Cnt_1mS = 0;
Time.flag_1mS = 1;
Cnt_2mS++;
if(Cnt_2mS == 2)
{
Cnt_2mS = 0;
Time.flag_2mS = 1;
Cnt_100mS++;
if(Cnt_100mS == 50)
{
Cnt_100mS = 0;
Time.flag_100mS = 1;
Cnt_500mS++;
if(Cnt_500mS == 5)
{
Cnt_500mS = 0;
Time.flag_500mS = 1;
Cnt_1S++;
if(Cnt_1S == 2)
{
Cnt_1S = 0;
Time.flag_1S = 1;
}
}
}
}
}
}
再在主循环里面判断标志位来确定时间,执行任务
for(;;)
{
if(Time.flag_500mS == 1)
{
Time.flag_500mS = 0;
LED_Running();
}
}
/***********************************分隔线***********************************************/
以前一直是用寄存器的,没有问题,现在改库函数了,报错重复编译。可是stm8s_it.h里面不是声明了中断函数了吗,main.c中我也引用了stm8s_it.h,为什么会这样呢?
|