weixin_45920312 2019-11-23 18:53 采纳率: 0%
浏览 263

使用定时中断来设计时钟数码管除了第一位不闪 其他位都在闪?

使用定时中断来设计时钟,数码管除了第一位不闪 其他位都在闪
#include
#include

#define uchar unsigned char
#define uint unsigned int
uchar ms,s,m,h;
int a,b,x,y,q,p;
unsigned char code t_display[]={ //??????
// 0 1 2 3 4 5 6 7 8 9 A B C D E F
0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71,
//black - H J K L N o P U t G Q r M y
0x00,0x40,0x76,0x1E,0x70,0x38,0x37,0x5C,0x73,0x3E,0x78,0x3d,0x67,0x50,0x37,0x6e,
0xBF,0x86,0xDB,0xCF,0xE6,0xED,0xFD,0x87,0xFF,0xEF,0x46}; //0. 1. 2. 3. 4. 5. 6. 7. 8. 9. -1

uchar code T_COM[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}; //λ??

void Delay10us() //@11.0592MHz
{
unsigned char i;

i = 2;
while (--i);

}

void Delay1ms() //@11.0592MHz
{
unsigned char i, j;

_nop_();
i = 2;
j = 199;
do
{
    while (--j);
} while (--i);

}
void Delay2ms() //@11.0592MHz
{
unsigned char i, j;

_nop_();
_nop_();
i = 22;
j = 128;
do
{
    while (--j);
} while (--i);

}

void Delay5ms() //@11.0592MHz
{
unsigned char i, j;

i = 9;
j = 244;
do
{
    while (--j);
} while (--i);

}

void display (uint s,uint m,uint h ) //???????????
{
a=s%10;
b=s/10;
P2=0XE0;
P0=~t_display[a];
P2=0X00;

   P2=0XC0;
   P0=T_COM[7];
   P2=0X00;


   P2=0XE0;
   P0=~t_display[b];
   P2=0x00;

   P2=0XC0;
   P0=T_COM[6];
   P2=0X00;


   x=m%10;
   y=m/10;
   P2=0XE0;
   P0=~t_display[x];
   P2=0X00;

   P2=0XC0;
   P0=T_COM[4];
   P2=0X00;


   P2=0XE0;
   P0=~t_display[y];
   P2=0x00;

   P2=0XC0;
   P0=T_COM[3];
   P2=0X00;

   P2=0XE0;           
   P0=~t_display[p];
   P2=0x00;

   P2=0XC0;
   P0=T_COM[1];
   P2=0X00;

   p=h%10;
   q=h/10;
   P2=0XE0;
   P0=~t_display[q];
   P2=0X00;

   P2=0XC0;
   P0=T_COM[0];
   P2=0X00;

}

void timer0 () interrupt 1 using 1 //????????ж??

{
static ms,s,m,h;
TH0=0X4B;
TL0=0XFD;
ms++;
display (s,m,h);
if (ms==20)
{
ms=0;
s++;
if(s==60)
{
s=0;
m++;
{
if(m==60)
{
m=0;
h++;
if(h==24)
{
h=0;
}
}
}
}
}

}

void timer0Init () //????????????
{
EA=1;
ET0=1;
TR0=1;
TMOD|=0X01;
TH0=0X4B;
TL0=0XFD;
}

void main ()
{
P2=0XA0;
P0=0XAA;
P2=0X00;
P0=0XFF;

timer0Init ();
while(1);

}

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 R语言Rstudio突然无法启动
    • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
    • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
    • ¥15 用windows做服务的同志有吗
    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值