标签:解析 其他 最小 led clu 手动 stat 小系统 nbsp
#include<reg52.h> //头文件
sbit LS1 = P2^2; //74LS138控制端
sbit LS2 = P2^3;
sbit LS3 = P2^4;
unsigned char shu_ma_guan[16] = {
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07, //0~F的对应值
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
unsigned char LedBuff[8]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; //定义8个数码管初始状态均为00000000,即都不显示
void SecondCount(); //函数的申明
void LedRefresh();
void main() /主函数
{
TMOD = 0x01; //定时器定义,晶振12Mhz,每次1ms
TH0 = 0xFC;
TL0 = 0x18;
TR0 = 1; //打开定时器
while(1)
{
if(TF0 == 1) //溢出标志
{
TF0 = 0; //溢出标志复位
TH0 = 0xFC; //定时器定义复位
TL0 = 0x18;
SecondCount();
LedRefresh();
}
}
}
void SecondCount()
{
static unsigned int cnt = 0; //定义为静态变量,使得每次调用时cnt的值可以保持住
static unsigned long sec = 0;
cnt++; //定时器溢出计次
if(cnt == 1000) //溢出1000次,时长1000ms,为1秒
{
cnt = 0; //计次清零
sec++; //时长加1.即过了一秒钟
LedBuff[0] = shu_ma_guan[sec%10]; //确定数码管在某个时间时各个位的显示数字
LedBuff[1] = shu_ma_guan[sec/10%10];
LedBuff[2] = shu_ma_guan[sec/100%10];
LedBuff[3] = shu_ma_guan[sec/1000%10];
LedBuff[4] = shu_ma_guan[sec/10000%10];
LedBuff[5] = shu_ma_guan[sec/100000%10];
LedBuff[6] = shu_ma_guan[sec/1000000%10];
LedBuff[7] = shu_ma_guan[sec/10000000%10];
}
}
void LedRefresh()
{
static unsigned char i = 0;
if(i == 0) //定义数码管刷新
{LS1=0; LS2=0; LS3=0;i++;P0=LedBuff[0];} //片选使得第一个数码管显示
else if(i == 1)
{LS1=1; LS2=0; LS3=0;i++;P0=LedBuff[1];} //片选使得第二个数码管显示
else if(i == 2)
{LS1=0; LS2=1; LS3=0;i++;P0=LedBuff[2];}
else if(i == 3)
{LS1=1; LS2=1; LS3=0;i++;P0=LedBuff[3];}
else if(i == 4)
{LS1=0; LS2=0; LS3=1;i++;P0=LedBuff[4];}
else if(i == 5)
{LS1=1; LS2=0; LS3=1;i++;P0=LedBuff[5];}
else if(i == 6)
{LS1=0; LS2=1; LS3=1;i++;P0=LedBuff[6];}
else if(i == 7)
{LS1=1; LS2=1; LS3=1;i=0;P0=LedBuff[7];}
}
标签:解析 其他 最小 led clu 手动 stat 小系统 nbsp
原文地址:https://www.cnblogs.com/shihaoyang/p/14379841.html