//实例64:用数码管显示动态检测结果
#include<reg51.h> // 包含51单片机寄存器定义的头文件
#include<stdlib.h> //包含随机函数rand()的定义文件
unsigned char i; //记录中断次数
unsigned int x; //随机检测的数据
unsigned char code Tab[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; //数码管显示0~9的段码表
/***********************************************************************
函数功能:快速动态扫描延时,延时约0.9毫秒
************************************************************************/
void delay(void)
{
unsigned int i;
for(i=0;i<300;i++)
;
}
/***********************************************************************
函数功能:4位数的数码显示器显示
入口参数:k
出口参数:无
************************************************************************/
void display(unsigned int k)
{
P2=0xfe; //即P2=1111 1110B,P2.0引脚输出低电平,数码显示器DS0接通电源
P0=Tab[k/1000]; //显示千位
delay();
P2=0xfd ; //即P2=1111 1101B,P2.1引脚输出低电平,数码显示器DS1接通电源
P0=Tab[(k%1000)/100]; //显示百位
delay();
P2=0xfb; //即P2=1111 1011B,P2.2引脚输出低电平,数码显示器DS2接通电源
P0=Tab[(k%100)/10]; //显示十位
delay();
P2=0xf7; //即P2=1111 0111B ,P2.3引脚输出低电平,数码显示器DS3接通电源
P0=Tab[k%10];//显示个位
delay();
P2=0xff; //关闭所有显示器
}
void main(void) //主函数
{
TMOD=0x01; //使用定时器T0
TH0=(65536-46083)/256; //将定时器计时时间设定为46083×1.085微秒=50000微秒=50毫秒
TL0=(65536-46083)%256;
EA=1; //开启总中断
ET0=1; //定时器T0中断允许
TR0=1; //启动定时器T0开始运行
while(1)
{
display(x); //调用检测结果的显示程序
}
}
/********************************************************
函数功能:定时器T0的中断服务程序
*******************************************************/
void Time0(void) interrupt 1 using 1
{
TR0=0; //关闭定时器T0
i++; //每来一次中断,i自加1
if(i==20) //够20次中断,即1秒钟进行一次检测结果采样
{
x=rand()/10; //随机产生一个从0到32767的整数,再将其除以10,获得一个随机4位数,模拟检测结果
i=0; //将i清0,重新统计中断次数
}
TH0=(65536-46083)/256; //重新给计数器T0赋初值
TL0=(65536-46083)%256;
TR0=1; //启动定时器T0
}
没有合适的资源?快使用搜索试试~ 我知道了~
064、用数码管显示动态检测结果 (AT89S52单片机).rar
![preview](https://csdnimg.cn/release/downloadcmsfe/public/img/white-bg.ca8570fa.png)
共4个文件
dsn:1个
dbk:1个
hex:1个
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 104 浏览量
2023-02-06
12:01:35
上传
评论
收藏 29KB RAR 举报
温馨提示
免责声明:资料部分来源于合法的互联网渠道收集和整理,部分自己学习积累成果,供大家学习参考与交流。收取的费用仅用于收集和整理资料耗费时间的酬劳。 本人尊重原创作者或出版方,资料版权归原作者或出版方所有,本人不对所涉及的版权问题或内容负法律责任。如有侵权,请举报或通知本人删除。
资源推荐
资源详情
资源评论
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
共 4 条
- 1
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/default.jpg!1)
大富大贵7
- 粉丝: 325
- 资源: 8864
![benefits](https://csdnimg.cn/release/downloadcmsfe/public/img/vip-rights-1.c8e153b4.png)
下载权益
![privilege](https://csdnimg.cn/release/downloadcmsfe/public/img/vip-rights-2.ec46750a.png)
C知道特权
![article](https://csdnimg.cn/release/downloadcmsfe/public/img/vip-rights-3.fc5e5fb6.png)
VIP文章
![course-privilege](https://csdnimg.cn/release/downloadcmsfe/public/img/vip-rights-4.320a6894.png)
课程特权
![rights](https://csdnimg.cn/release/downloadcmsfe/public/img/vip-rights-icon.fe0226a8.png)
开通VIP
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)