#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; //数码管位选数据
sbit duan=P2^6;//段选信号,写数码管数据
sbit wei=P2^7;//位选信号,选择数码管
uint miao=0; //秒
uint fen=0; //分
uint n=0; //计数
uint date[6]={0,0,0,0};
void delay(uint xms) //延时函数
{
uint i,j;
for(i=xms;i>0;i--)
for(j=112;j>0;j--);
}
void write_address(uchar address) //写地址函数,选择数码管
{
wei=1;
P0=address;
wei=0;
}
void write_date(uint n) //写数据函数,送入段选信号
{
duan=1;
P0=table[n];
duan=0;
} //显示函数
void display()
{
write_date(date[0]);
P0=0xff;
write_address(0x7f);
delay(1);
write_date(date[1]);
P0=0xff;
write_address(0xbf);
delay(1);
write_date(date[2]);
P0=0xff;
write_address(0xef);
delay(1);
write_date(date[3]);
中断函数编写计时器
最新推荐文章于 2024-05-26 20:44:35 发布