/***************************************************************************
实验名称: 数码管动态扫描实验
实验模块: 51单片机核心板、动态扫描数码管区
实验接线: 51单片机核心板------动态扫描数码管区
P0----------------J6
P2----------------J5
现象描述: 8位数码管从左向右依次显示“0~7”
更新时间:2019.8.19
***************************************************************************/
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
#define DIGI P0//宏定义 将P0口定义为数码管段选择口
#define SELECT P2//宏定义 将P2定义为数码管选择口
uint a=0;
uint miao=0,m_shi=0,m_ge=0;
uint fen=0,f_shi=0,f_ge=0;
uint shi=0,s_shi=0,s_ge;
uint digivalue[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7f,0x6f};
//显示的数字数组,依次为0,1,...?
uint select[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};//选择数码管数组,依次选择1,2,...
uint save[8]={0};
void delay()
{
uchar ii=200;
while(ii--);
}
void main()
{
uint i;
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
IE=0x82;
TR0=1;
while(1)
{
if(a>=20)
{
a=0;
miao++;
m_shi=miao/10;
save[4]=digivalue[m_shi];
m_ge=miao%10;
save[5]=digivalue[m_ge];
if(miao>=60)
{
miao=1;
fen++;
f_shi=fen/10;
save[2]=digivalue[f_shi];
f_ge=fen%10;
save[3]=digivalue[f_ge];
if(fen>=60)
{
fen=0;
shi++;
s_shi=shi/10;
save[0]=digivalue[s_shi];
s_ge=shi%10;
save[1]=digivalue[s_ge];
}
}
}
for(i=0;i<6;i++)
{
SELECT=select[i];
DIGI=save[i];
delay();
}
}
}