单片机数码管显示温度程序(共6页).doc

上传人:飞****2 文档编号:13350581 上传时间:2022-04-29 格式:DOC 页数:6 大小:22.50KB
返回 下载 相关 举报
单片机数码管显示温度程序(共6页).doc_第1页
第1页 / 共6页
单片机数码管显示温度程序(共6页).doc_第2页
第2页 / 共6页
点击查看更多>>
资源描述

《单片机数码管显示温度程序(共6页).doc》由会员分享,可在线阅读,更多相关《单片机数码管显示温度程序(共6页).doc(6页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。

1、精选优质文档-倾情为你奉上/项目:数码管温度显示器/编写:LGY/功能:数码管显示温度#includereg52.h#includeintrins.h#define uchar unsigned char#define uint unsigned int/*位定义*/sbit RX =P30;sbit TX =P31;sbit RX_TX_con =P32;/sbit Fre_check =P35;sbit DQ =P35;sbit SDA =P36;sbit SCL =P37;sbit LED_1 =P02;sbit LED_2 =P00;sbit LED_3 =P01;sbit LED_4

2、 =P03;unsigned char a1,a2,a3,a4;unsigned int temper;unsigned char code displaycode= / 0 1 2 3 4 5 6 7 8 9 0x28, 0xee, 0x32, 0xa2, 0xe4, 0xa1, 0x21, 0xea, 0x20, 0xa0, ;unsigned char code displaycode1= / 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 0x08, 0xce, 0x12, 0x82, 0xc4, 0x81, 0x01, 0xca, 0x00, 0x80, ;void IN

3、T() P0=0xff; P1=0xff; P2=0; P3=0; DQ=1; / Fre_check=1; void Delay(uint x) uint a,b; for(a=x;a0;a-) for(b=110;b0;b-);/*void Delay1(uint x,uchar y)uint i;uchar j;for(i=x;i0;i-);for(j=y;j0;j-);void reset()unsigned char st=1;Fre_check=1;/_nop_();/_nop_();while(st)Fre_check=0;Delay1(70,30);Fre_check=1;De

4、lay1(4,4);if(Fre_check=1) st=1;else st=0;Delay1(50,10);void write_byte(unsigned char date)unsigned char temp,i;Fre_check=1;/_nop_();/_nop_();for(i=8;i0;i-) temp=date&0x01;Fre_check=0; /Delay1(1);_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_

5、nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();if(temp=1) Fre_check=1;Delay1(2,2);Fre_check=1;date=date1;unsigned char read_byte()unsigned char i,date;static bit j;for(i=8;i0;i-)date=date1;Fre_check=1;_nop_();_nop_();Fre_check=0;_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();Fre_check=1;_no

6、p_();_nop_();_nop_();_nop_();j=Fre_check;if(j=1) date=date|0x08;Delay1(1,1);return (date);*/void delay1(int b)int s;for (s = 0; s b; s+);unsigned char ow_reset(void)unsigned char presence;DQ = 0; /pull DQ line lowdelay1(29); / leave it low for 480sDQ = 1; / allow line to return highdelay1(3); / wait

7、 for presencepresence = DQ; / get presence signaldelay1(25); / wait for end of timeslotreturn(presence); / presence signal returned / presence = 0, no part = 1unsigned char read_bit(void)unsigned char i;DQ = 0; / pull DQ low to start timeslotDQ = 1; / then return highfor (i = 0; i 3; i+); / delay 15

8、s fromstart of timeslotreturn(DQ); / return value of DQ linevoid write_bit(char bitval)DQ = 0; / pull DQ low to start timeslotif(bitval=1) DQ =1; / return DQ high if write 1delay1(5);/ hold value for remainder of timeslotDQ = 1;/ Delay provides 16s per loop, plus 24s/Therefore, delay(5) = 104sunsign

9、ed char read_byte(void)unsigned char i;unsigned char value = 0;for (i = 0; i 8; i+)if(read_bit() value=value|0x01i;/ reads byte in, one byte at a time and then/ shifts it leftdelay1(6); / wait for rest of timeslot return(value);void write_byte(char val)unsigned char i;unsigned char temp;for (i = 0;

10、i i; / shifts val right i spacestemp &= 0x01; / copy that bit to tempwrite_bit(temp); / write bit in temp intodelay1(5);void DisplayLed(uchar num1,uchar num2,uchar num3,uchar num4) LED_1=0;LED_2=1;LED_3=1;LED_4=1;P1=displaycodenum1;Delay(3); LED_1=1;LED_2=0;LED_3=1;LED_4=1;P1=displaycode1num2;Delay(

11、3); LED_1=1;LED_2=1;LED_3=0;LED_4=1;P1=displaycodenum3;Delay(3); LED_1=1;LED_2=1;LED_3=1;LED_4=0;P1=displaycodenum4;Delay(3);void Get_tem()unsigned char tem1,tem2,num;float aaa;int temper;ow_reset(); /复位write_byte(0xCC);/跳过ROMwrite_byte(0x44);/温度转换for(num=1000;num0;num-) DisplayLed(a1,a2,a3,a4);ow_reset();write_byte(0xCC);write_byte(0xBE);tem1=read_byte();tem2=read_byte();aaa=(tem2*256+tem1)*6.25;temper=(int)aaa;a1=temper/1000;a2=temper%1000/100;a3=temper%100/10;a4=temper%10;void main()unsigned char num=0; INT(); while(1) Get_tem(); 专心-专注-专业

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

当前位置:首页 > 教育专区 > 教案示例

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知得利文库网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号-8 |  经营许可证:黑B2-20190332号 |   黑公网安备:91230400333293403D

© 2020-2023 www.deliwenku.com 得利文库. All Rights Reserved 黑龙江转换宝科技有限公司 

黑龙江省互联网违法和不良信息举报
举报电话:0468-3380021 邮箱:hgswwxb@163.com