发布网友 发布时间:2022-04-23 04:40
共1个回答
热心网友 时间:2023-07-12 11:50
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
uint time=0;
uchar display_data[8]={0,0,0,0,0,0,0,0};
uchar display_code[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E};
void delay(void)
{
uchar i;
for(i=250;i>0;i--);
}
void calc()
{
time++;
if(time==10000)
time=0;
}
void convert()
{
display_data[0]=time/1000;
display_data[1]=time%1000/100;
display_data[2]=time%1000%100/10;
display_data[3]=time%1000%100%10;
}
void display()
{
P2=0xFE;
P0=display_code[display_data[3]];
delay();
P2=0xFF;
P2=0xFD;
P0=display_code[display_data[2]];
delay();
P2=0xFF;
P2=0xFB;
P0=display_code[display_data[1]];
delay();
P2=0xFF;
P2=0xF7;
P0=display_code[display_data[0]];
delay();
P2=0xFF;
}
void main(void)
{
uint i;
while(1)
{
for(i=0;i<500;i++)
{
display();
}
calc();
convert();
}
}