|
发表于 2012-9-28 08:46:25
|
显示全部楼层
本帖最后由 yao1 于 2012-9-28 09:10 编辑
void t0() interrupt 1 using 1 /*中断程序负责显示b的值 */
{
unsigned char a1=0,a2=0,a3=0,a4=0; //临时变量
static int k=0;
TH0=(65536-1000)/256; //1ms
TL0=(65536-1000)%256;;//扫描速度
a1=b/1000;/*取b的千位*/
a2=b%1000/100;/*取b的百位*/
a3=b%100/10;/*取b的十位*/
a4=b%10;/*取b的个位*/
if (k==0){shu1=1;shu2=0;shu3=0;shu4=0;P0=yima[a1];}
else if(k==1){shu1=0;shu2=1;shu3=0;shu4=0;P0=yima[a2];}
else if(k==2){shu1=0;shu2=0;shu3=1;shu4=0;P0=yima[a3];}
else if(k==3){shu1=0;shu2=0;shu3=0;shu4=1;P0=yima[a4];}
k++;
if(k>3) k=0;
}
延迟可以这么写
void display()
{
unsigned char a1=0,a2=0,a3=0,a4=0; //临时变量
static int k=0;
a1=b/1000;/*取b的千位*/
a2=b%1000/100;/*取b的百位*/
a3=b%100/10;/*取b的十位*/
a4=b%10;/*取b的个位*/
if (k==0){shu1=1;shu2=0;shu3=0;shu4=0;P0=yima[a1];}
else if(k==1){shu1=0;shu2=1;shu3=0;shu4=0;P0=yima[a2];}
else if(k==2){shu1=0;shu2=0;shu3=1;shu4=0;P0=yima[a3];}
else if(k==3){shu1=0;shu2=0;shu3=0;shu4=1;P0=yima[a4];}
k++;
if(k>3) k=0;
delayms(1); //扫描速度1ms
}
带闪烁:
void tiTimer0() interrupt 1
{
unsigned char a1=0,a2=0,a3=0,a4=0; //临时变量
static int k=0;
static unsigned int Time0count=0;
TH0=(65536-1000)/256; //1ms
TL0=(65536-1000)%256;
time_1ms_ok=1; //1ms标志
Time0count++; //1ms
if(Time0count>flashTime)Time0count=0; //主函数宏定义#define flashTime 600 闪烁速度
a1=b1;
a2=b2/100;
a3=b2%100/10;
a4=b2%10;
k++;
if(k>3)k=0;
if(flash==1) //进入设定标志 闪烁 速度300ms
{
if(Time0count<flashTime/2) //显示
{
if (k==0){shu4=1;shu1=0;shu2=0;shu3=0;P0=yima[a1];}
else if(k==1){shu4=0;shu1=1;shu2=0;shu3=0;P0=yima[a4];}
else if(k==2){shu4=0;shu1=0;shu2=1;shu3=0;P0=yima[a3];}
else if(k==3){shu4=0;shu1=0;shu2=0;shu3=1;P0=yima[a2];}
}
else //熄灭
{
shu1=shu2=shu3=shu4=0; // P0=yima[10];
}
}
else //正常显示
{
if (k==0){shu4=1;shu1=0;shu2=0;shu3=0;P0=yima[a1];}
else if(k==1){shu4=0;shu1=1;shu2=0;shu3=0;P0=yima[a4];}
else if(k==2){shu4=0;shu1=0;shu2=1;shu3=0;P0=yima[a3];}
else if(k==3){shu4=0;shu1=0;shu2=0;shu3=1;P0=yima[a2];}
}
}
if((k_see==0)&&(k_seeflag==0))
{
if(k_see_time_1ms_ok) //1ms
{
k_see_time_1ms_ok=0;
k_see_press_i++;
if(k_see_press_i>3000) //按下3s进入设定
{
k_see_press_i=0;
k_seeflag=1;
k_see_count=1;
}
}
}
else if(k_see==1) { k_seeflag=0;}
if((k_jia==0)&&(k_jia_flag==0)) //+
{
if(key_time_1ms_ok) //1ms
{
key_time_1ms_ok=0;
k_jia_press_i++;
if(k_jia_press_i>50) //50ms 消抖
{
if(k_jia==0) //确认+按键 按下
{
k_jia_flag=1;
see_cnt++;
if(see_cnt>N-1) see_cnt=1;
}
}
}
}
else if(k_jia==1) { k_jia_flag=0;k_jia_press_i=0; } |
|