第七届蓝桥杯大赛模拟题

上传人:第*** 文档编号:33333938 上传时间:2018-02-14 格式:DOCX 页数:8 大小:26.48KB
返回 下载 相关 举报
第七届蓝桥杯大赛模拟题_第1页
第1页 / 共8页
第七届蓝桥杯大赛模拟题_第2页
第2页 / 共8页
第七届蓝桥杯大赛模拟题_第3页
第3页 / 共8页
第七届蓝桥杯大赛模拟题_第4页
第4页 / 共8页
第七届蓝桥杯大赛模拟题_第5页
第5页 / 共8页
点击查看更多>>
资源描述

《第七届蓝桥杯大赛模拟题》由会员分享,可在线阅读,更多相关《第七届蓝桥杯大赛模拟题(8页珍藏版)》请在金锄头文库上搜索。

1、1main.c#include#include#includehead.h#define uchar unsigned char#define uint unsigned int#define ulong unsigned longsbit LSA=P10;sbit LSB=P11;sbit LSC=P12;sbit L1=P13;uint i,j,k,t,s,cs;uchar KeyValue;uchar code DATA17=0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71;ui

2、nt code ts=1,5,30,60;uchar code jump=0x40,0x00;uchar displaydata8;uint Tempdata10=0,0,0,0,0,0,0,0,0,0;void KeyDown();void main()float tp;TMOD=0x10;TH1=(65536-50000)/256;TL1=(65536-50000)%256;EA=1;ET1=1;TR1=0;L1=0;Ds18b20ReadTemp();one:i=0;j=0;t=1;T1:displaydata0=0x00;displaydata1=0x00;displaydata2=0

3、x00;displaydata3=0x00;displaydata4=0x00;displaydata5=0x40;displaydata6=DATAtsj/10;displaydata7=DATAtsj%10;t=tsj;while(1)TR1=1;for(i=0;i= 1;SCLK = 1;/数据在上升沿时,DS1302 读取数据_nop_();SCLK = 0;_nop_();5for (n=0; n= 1;SCLK = 1;/数据在上升沿时,DS1302 读取数据_nop_();SCLK = 0;_nop_();RST = 0;/传送数据结束_nop_();/* 函 数 名 : Ds1

4、302Read* 函数功能 : 读取一个地址的数据* 输 入 : addr* 输 出 : dat*/uchar Ds1302Read(uchar addr)uchar n,dat,dat1;RST = 0;_nop_();SCLK = 0;/先将 SCLK 置低电平。_nop_();RST = 1;/然后将 RST(CE)置高电平。_nop_();for(n=0; n= 1;SCLK = 1;/数据在上升沿时,DS1302 读取数据_nop_();SCLK = 0;/DS1302 下降沿时,放置数据_nop_();_nop_();for(n=0; n1) | (dat10; y-)for(x=

5、110; x0; x-);/* 函 数 名 : Ds18b20Init* 函数功能 : 初始化* 输 入 : 无* 输 出 : 初始化成功返回 1,失败返回 0*/uchar Ds18b20Init()uchar i;DSPORT = 0; /将总线拉低 480us960usi = 70;while(i-);/延时 642usDSPORT = 1; /然后拉高总线,如果 DS18B20 做出反应会将在15us60us 后总线拉低i = 0;Delay1ms(1); /等待 DS18B20 拉低总线while(DSPORT)return 0;/初始化失败return 1;/初始化成功/* 函 数

6、 名 : Ds18b20WriteByte* 函数功能 : 向 18B20 写入一个字节* 输 入 : com* 输 出 : 无*/void Ds18b20WriteByte(uchar dat)uint i, j;for(j=0; j= 1;/* 函 数 名 : Ds18b20ReadByte* 函数功能 : 读取一个字节* 输 入 : com* 输 出 : 无*/uchar Ds18b20ReadByte()uchar byte, bi;uint i, j;for(j=8; j0; j-)DSPORT = 0;/先将总线拉低 1usi+;DSPORT = 1;/然后释放总线i+;i+;/延

7、时 6us 等待数据稳定bi = DSPORT; /读取数据,从最低位开始读取/*将 byte 左移一位,然后与上右移 7 位后的 bi,注意移动之后移掉那位补 0。*/byte = (byte 1) | (bi #include/-重定义关键字-/#ifndef uchar#define uchar unsigned char#endif#ifndef uint #define uint unsigned int#endif/-定义 ds1302 使用的 IO 口-/sbit DSIO=P34;sbit RST=P35;sbit SCLK=P36;/-定义 ds1302 使用的 IO 口-/

8、sbit DSPORT=P37;/-定义全局函数-/void Ds1302Write(uchar addr, uchar dat);uchar Ds1302Read(uchar addr);void Ds1302Init();void Ds1302ReadTime();void Delay1ms(uint );uchar Ds18b20Init();void Ds18b20WriteByte(uchar com);uchar Ds18b20ReadByte();void Ds18b20ChangTemp();void Ds18b20ReadTempCom();int Ds18b20ReadTemp();/-加入全局变量-/extern uchar Time7;#endif

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

当前位置:首页 > 办公文档 > 解决方案

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