目的是完成数码管动态显示,但是数码管刷不出来程序和电路图如下:
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar code tab[] = {0xc0,0xf9,0xa4,0xb0,0x99,
0x92,0x82,0xf8,0x80,
0x90,0x08,0x00,0x46,
0x21,0x06,0x0e,0x10,0xbf};
uchar data disp[] = {2,3,17,5,9,17,5,5};
uchar data smgcom[] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
void Timer0Init(void);
void main(void)
{
Timer0Init();
while(1);
}
void Timer0Ser(void) interrupt 1
{
static uint counter;
static uchar second = 55,min = 59,hour = 23;
static uchar dispcom = 0;
P0 = tab[disp[dispcom]];
P1 = smgcom[dispcom];
if(++dispcom == 8)
{
dispcom = 0;
}
if(++counter == 500)
{
counter = 0;
if(++second == 60)
{
second =0;
if(++min == 60)
{
min = 0;
if(++hour == 24)
{
hour = 0;
}
}
}
disp[7] = second % 10;
disp[6] = second / 10;
disp[4] = min % 10;
disp[3] = min / 10;
disp[1] = hour % 10;
disp[0] = hour / 10;
}
Timer0Init();
}
void Timer0Init(void)//2ms@12.000MHz
{
TMOD &= 0xF0;
TL0 = 0x40;
TH0 = 0xA2;
TF0 = 0;
TR0 = 1;
EA = 1;
ET0 = 1;
}
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar code tab[] = {0xc0,0xf9,0xa4,0xb0,0x99,
0x92,0x82,0xf8,0x80,
0x90,0x08,0x00,0x46,
0x21,0x06,0x0e,0x10,0xbf};
uchar data disp[] = {2,3,17,5,9,17,5,5};
uchar data smgcom[] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
void Timer0Init(void);
void main(void)
{
Timer0Init();
while(1);
}
void Timer0Ser(void) interrupt 1
{
static uint counter;
static uchar second = 55,min = 59,hour = 23;
static uchar dispcom = 0;
P0 = tab[disp[dispcom]];
P1 = smgcom[dispcom];
if(++dispcom == 8)
{
dispcom = 0;
}
if(++counter == 500)
{
counter = 0;
if(++second == 60)
{
second =0;
if(++min == 60)
{
min = 0;
if(++hour == 24)
{
hour = 0;
}
}
}
disp[7] = second % 10;
disp[6] = second / 10;
disp[4] = min % 10;
disp[3] = min / 10;
disp[1] = hour % 10;
disp[0] = hour / 10;
}
Timer0Init();
}
void Timer0Init(void)//2ms@12.000MHz
{
TMOD &= 0xF0;
TL0 = 0x40;
TH0 = 0xA2;
TF0 = 0;
TR0 = 1;
EA = 1;
ET0 = 1;
}