#include "reg51.h"
#define uint unsigned int
#define uchar unsigned char
uchar code table[] = { //共阴段码
0x3f, 0x06, 0x5b, 0x4f, 0x66,
0x6d, 0x7d, 0x07, 0x7f, 0x6f}; //0 ~ 9
uchar wei[4] = {0, 0, 0, 0};
uint sec;
void delay()
{
uint miss=0;
TR1=1;
TH1=0x3c;
TL1=0xb0;
while(!TF1);
TF1=0;
miss++;
if(miss==20)
{
miss=0;
sec++;
if(sec==9999)
{
sec=0;
}
}
}
void main()
{
uchar k;
TMOD=0x10;
TH1=0x3c;
TL1=0xb0;
delay();
while(1)
{
wei[3]=sec/1000; //千位
wei[2]=sec/100%10 ;//百位
wei[1]=sec/10%10; //十位
wei[0]=sec%10; //个位
for(k=0;k<4;k++)
{
P3=(0xfe<<k|0xfe>>(8-k)); //循环左移
P2=table[wei[3-k]];
}
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
#define uint unsigned int
#define uchar unsigned char
uchar code table[] = { //共阴段码
0x3f, 0x06, 0x5b, 0x4f, 0x66,
0x6d, 0x7d, 0x07, 0x7f, 0x6f}; //0 ~ 9
uchar wei[4] = {0, 0, 0, 0};
uint sec,miss;
void delay()
{
if(miss==20)
{
miss=0;
if(++sec==9999)
{
sec=0;
}
}
}
void main()
{
uchar k;
miss=0;
TMOD=0x10;
TH1=0x3c;
TL1=0xb0;
ET1=1;
TR1=1;
EA=1;
while(1)
{
delay();
wei[3]=sec/1000; //千位
wei[2]=sec/100%10 ;//百位
wei[1]=sec/10%10; //十位
wei[0]=sec%10; //个位
for(k=0;k<4;k++)
{
P3=(0xfe<<k|0xfe>>(8-k)); //循环左移
P2=table[wei[3-k]];
}
}
}
void timer1() interrupt 3
{
TH1=0x3c;
TL1=0xb0;
miss++;
}
一周热门 更多>