#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
sbit DULA = P2^6;
sbit WELA = P2^7;
unsigned char code WETable[8] =
{
~0x80,~0x40,~0x20,~0x10,
~0x08,~0x04,~0x02,~0x01
};
unsigned char code DUTable[16] =
{
0x3F,0x06,0x5B,0x4F,
0x66,0x6D,0x7D,0x07,
0x7F,0x6F,0x77,0x7C,
0x39,0x5E,0x79,0x71
};
unsigned char LedBuff[8] =
{
0x3F,0x3F,0x3F,0x3F,
0x3F,0x3F,0x3F,0x3F
};
bit flag = 0;
void Timer0Init(void); //1毫秒@11.0592MHz
void main(void)
{
unsigned long sec = 0;
Timer0Init();
while(1)
{
if(1==flag)
{
flag = 0;
sec++;
LedBuff[0] = DUTable[sec/1%10];
LedBuff[1] = DUTable[sec/10%10];
LedBuff[2] = DUTable[sec/100%10];
LedBuff[3] = DUTable[sec/1000%10];
LedBuff[4] = DUTable[sec/10000%10];
LedBuff[5] = DUTable[sec/100000%10];
LedBuff[6] = DUTable[sec/1000000%10];
LedBuff[7] = DUTable[sec/10000000%10];
}
}
}
void Timer0Init(void) //1毫秒@11.0592MHz
{
EA = 1;
ET0 = 1;
//AUXR &= 0x7F; //定时器时钟12T模式
TMOD &= 0xF0; //设置定时器模式
TMOD |= 0x01; //设置定时器模式
TL0 = 0x66; //设置定时初值
TH0 = 0xFC; //设置定时初值
TF0 = 0; //清除TF0标志
TR0 = 1; //定时器0开始计时
}
void LedScan(void)
{
static unsigned char i = 0;
P0 = 0x00;
DULA = 1;
DULA = 0;
P0 = WETable[i];
WELA = 1;
WELA = 0;
P0 = LedBuff[i];
DULA = 1;
DULA = 0;
if(i<7)
{
i++;
}
else
{
i = 0;
}
}
void InterruptTimer0(void) interrupt 1
{
static unsigned int cnt = 0;
TL0 = 0x66; //设置定时初值
TH0 = 0xFC; //设置定时初值
LedScan();
cnt++;
if(cnt>=1000)
{
cnt = 0;
flag = 1;
}
}
计数器.........zip
需积分: 8 156 浏览量
2020-02-17
04:16:42
上传
评论 2
收藏 22KB ZIP 举报
「已注销」
- 粉丝: 75
- 资源: 17
最新资源
- Image_1713714819368.png
- 数据可视化 matplotlib 实例.docx
- Python 使用 Matplotlib 绘制甘特图的实践.docx
- matplotlib 中的 cmap 参数介绍.docx
- 基于matlab的毕业设计基于Matlab使用LQR实现车辆轨迹跟踪源码.zip
- 基于Matplotlib 的高互动性可视化系统设计与实现
- matplotlib 数据可视化报告.docx
- 传统网页UI设计在移动应用开发中的应用研究.pdf
- 基于pytorch实现BERT+BiLSTM+CRF实现中文命名实体识别源码.zip
- 校园帮项目,毕业设计/课程设计/javaWeb/SSM
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈