数码管显示时间
7段八位共阴数码管
89C51
P0口接上拉电阻接到段选位,
P2口控制位选
/*7seg_pex8_CC_smg_Clock01*/
/*2020.4.7*/
#include<reg52.h>
#define uchar unsigned char;
#define uint unsigned int;
uchar tcount;
uchar hr;
uchar minite;
uchar sec;
uchar code seg1=[0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
void delay_ms(unsigned int n)
{
unsigned int i;
unsigned int j;
for(i=0;i<n;i++)
for(j=0;j<123;j++);
}
void SMG_Clock_display()
{
P0=seg1[sec % 10];
P2=0x01;
delay_ms(2);
P2=0x00;
P0=seg1[sec / 10];
P2=0x02;
delay_ms(2);
P2=0x00;
P0=0x40;
P2=0x04;
delay_ms(2);
P2=0x00;
P0=seg1[minite % 10];
P2=0x08;
delay_ms(2);
P2=0x00;
P0=seg1[minite / 10];
P2=0x10;
delay_ms(2);
P2=0x00;
P0=0x20;
P2=0x20;
delay_ms(2);
P2=0x00;
P0=seg1[hr % 10];
P2=0x40;
delay_ms(2);
P2=0x00;
P0=seg1[hr / 10];
P2=0x80;
delay_ms(2);
P2=0x00;
}
/* 定时器初始化 */
void Timer0Init()
{
TMOD=0x01;
TH0=(65536-5000)/ 256;
TL0=(65536-5000)%256;
EA=1;
ET0=1;
TR0=1;
}
void timer0() interrupt 1
{
TH0=(65536-5000)/ 256;
TL0=(65536-5000)% 256;
tcount++;
if(tcount== 200)
{
tcount=0;
sec++;
if(sec == 60)
{
sec=0;
minite++;
if(minite == 60)
{
minite=0;
hr++;
if(hr == 24)
hr=0;
}
}
}
}
void main()
{
Timer0Init();
SMG_Clock_display();
while(1);
}
没有用的!不知道问题在哪里,