利用中断实现十进制

作者在 2017-04-11 09:13:51 发布以下内容
 #include <reg52.h>
typedef  unsigned int  U16;
typedef  unsigned char  U8;
U8 num[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x7f,0xFF};
sbit LED3=P1^3;
sbit LED2=P1^2;
sbit LED1=P1^1;
sbit LED0=P1^0;
U8 shuma[4]={0};
void T0_Init()
{
TMOD=0x10;
TH1=0xFC;
TL1=0x18;
TR1=1;
}
void refresh()
{
 U8 j,flag =0;
 static  U8 t=0;


for (j=3;j>1;j--)
{
 
flag=flag|shuma[j];
if(0==flag)
shuma[j]=11;
 
}
switch(t)
  {
  case 0:LED0=0;LED1=1;LED2=1;LED3=1;P0=num[shuma[3]];t++;break;
  case 1:LED0=1;LED1=0;LED2=1;LED3=1;P0=num[shuma[2]];t++;break;
  case 2:LED0=1;LED1=1;LED2=0;LED3=1;P0=num[10];t++;break;
  case 3:LED0=1;LED1=1;LED2=0;LED3=1;P0=num[shuma[1]];t++;break;
  case 4:LED0=1;LED1=1;LED2=1;LED3=0;P0=num[shuma[0]];t=0;break;
  default:break;
  }
}
void Inter_init()
{
ET1=1;
EA=1;
}
void main()
 {
   
T0_Init();
Inter_init();
 while(1);
  }
 void guo_t0_inter()  interrupt 3
{  
  static   U16 n=0, x=0;


TH1=0xFC;
TL1=0x18;
n++;
refresh();
 
 if(100==n)
 {   x++;
  n=0;
shuma[0] =x%10;
shuma[1] = x/10%10;
shuma[2] =x/100%10;
shuma[3] =x/1000%10;
  }
 
  } 
默认分类 | 阅读 630 次
文章评论,共0条
游客请输入验证码
文章分类
文章归档
最新评论