超声波测距用数码管显示

上传人:mg****85 文档编号:34445859 上传时间:2018-02-24 格式:DOC 页数:4 大小:34.50KB
返回 下载 相关 举报
超声波测距用数码管显示_第1页
第1页 / 共4页
超声波测距用数码管显示_第2页
第2页 / 共4页
超声波测距用数码管显示_第3页
第3页 / 共4页
超声波测距用数码管显示_第4页
第4页 / 共4页
亲,该文档总共4页,全部预览完了,如果喜欢就下载吧!
资源描述

《超声波测距用数码管显示》由会员分享,可在线阅读,更多相关《超声波测距用数码管显示(4页珍藏版)》请在金锄头文库上搜索。

1、#include /库文件#include #define uchar unsigned char#define uint unsigned intsbit dula=P26; /申明 U1 锁存器的锁存端sbit wela=P27; /申明 U2 锁存器的锁存端sbit RX=P10;sbit TX=P11;uchar bai,shi,ge;unsigned int time=0;unsigned int timer=0;unsigned char posit=0;unsigned long S=0;bit flag =0;uchar code table=0x3f,0x06,0x5b,0x

2、4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71;void delayms(uint xms)uint i,j;for(i=xms;i0;i-) /i=xms 即延时约 xms 毫秒for(j=110;j0;j-);/*/void display()dula=1;P0=tablebai; /送段选数据dula=0;P0=0xff; /送位选数据前关闭所有显示,防止打开位选锁存时wela=1; /原来段选数据通过位选锁存器造成混乱P0=0x7e; /送位选数据wela=0;delayms(1); /延时dula=1;P0

3、=tableshi;dula=0;P0=0xff;wela=1;P0=0x7d;wela=0;delayms(1);dula=1;P0=tablege;dula=0;P0=0xff;wela=1;P0=0x7b;wela=0;delayms(1); /*/void Conut()time=TH0;time=(time=700)|flag=1) /超出测量范围显示“-” flag=0;bai=0;shi=0;ge=0;elsebai=S%1000/100; /分出百,十,和个位shi=S%1000%100/10;ge=S%1000%10 %10;/*/ void zd0() interrupt

4、1 /T0 中断用来计数器溢出,超过测距范围flag=1; /中断溢出标志/*/void zd3() interrupt 3 /T1 中断用来扫描数码管和计 800MS 启动模块TH1=0xf8;/TL1=0x30;/display();timer+;if(timer=10)timer=0;TX=1; /800MS 启动一次模块/_nop_(); /_nop_(); /_nop_(); /_nop_(); /_nop_(); /_nop_(); /_nop_(); /_nop_(); /_nop_(); /_nop_(); / _nop_(); /_nop_(); / _nop_(); / _

5、nop_(); /_nop_(); /_nop_(); /_nop_();_nop_(); _nop_(); _nop_(); _nop_();TX=0; /*/void main( void ) TMOD=0x11; /设 T0 为方式 1,GATE=1;TH0=0;TL0=0; TH1=0xf8; /2MS 定时TL1=0x30;ET0=1; /允许 T0 中断ET1=1; /允许 T1 中断TR1=1; /开启定时器EA=1; /开启总中断while(1)while(!RX); /当 RX 为零时等待TR0=1; /开启计数while(RX); /当 RX 为 1 计数并等待TR0=0; /关闭计数Conut();/计算/*结束*/

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 行业资料 > 教育/培训

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号