单片机程序12-18b20和pld与eda讲义

上传人:tian****1990 文档编号:71760702 上传时间:2019-01-21 格式:DOCX 页数:14 大小:583.89KB
返回 下载 相关 举报
单片机程序12-18b20和pld与eda讲义_第1页
第1页 / 共14页
单片机程序12-18b20和pld与eda讲义_第2页
第2页 / 共14页
单片机程序12-18b20和pld与eda讲义_第3页
第3页 / 共14页
单片机程序12-18b20和pld与eda讲义_第4页
第4页 / 共14页
单片机程序12-18b20和pld与eda讲义_第5页
第5页 / 共14页
点击查看更多>>
资源描述

《单片机程序12-18b20和pld与eda讲义》由会员分享,可在线阅读,更多相关《单片机程序12-18b20和pld与eda讲义(14页珍藏版)》请在金锄头文库上搜索。

1、/*数字中C程序设计*/#include#include#define uint unsigned int #define uchar unsigned char/*时间位变量定义*/sbit mode=P37;sbit inc=P36;sbit dec=P35;sbit enter=P34;sbit point=P07;bit flag=1;sbit DQ=P11; /设定温度采集端sbit led=P27;/三色指示时钟sbit speaker=P26;/声音报警端口sbit d2=P25;sbit d3=P24;sbit d4=P23;sbit d5=P22;sbit d6=P21;sb

2、it d7=P20;/*变量定义*/uchar t,hhour,lhour,hmin,lmin,hsec,lsec;uchar hour,min,sec,vmode; uchar ahour,amin;uchar m,n,deta;uchar day,week,mon;/定义日期uint year;uchar temp;/存放温度值uchar str3;/存放温度分离值uchar code table=0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x00,0x00;/共阴型七段数码管09的断码uchar code choosebit=0x

3、01,0x02,0x04,0x08,0x10,0x20;/P20P25是6个数码管从地位到高位的位选uchar table1=31,31,29,31,30,31,30,31,31,30,31,30,31; /闰年uchar table2=31,31,28,31,30,31,30,31,31,30,31,30,31; /非闰年/*声明时钟调用子函数*/void delay(uint z);void delay_spk(uint cnt);void mode0();void mode1();void mode2();void mode3();void mode4();void mode5();/显

4、示日期void mode6();/显示温度void display(uchar t_hour,uchar t_min,uchar t_sec);/*声明ds18b20调用的子函数*/ uchar ReadTemperature(void); /读取温度void Init_DS18B20(void); /18b20初始化函数uchar ReadOneChar(void);/读一个字节void WriteOneChar(uchar dat); /写一个字节void delay_temperature(uint y);/延时函数void display_temperature();/*主函数*/vo

5、id main() vmode=0;speaker=0; hour=0;min=1;sec=0;ahour=0;amin=3;led=0;year=2009;mon=05;day=25;week=01;/日期赋初值TMOD=0x11;/设置定时器0,1为工作方式1TH0=0xd8;/定时器定时10msTL0=0xf0; TH1=(65536-5000)/256;TL1=(65536-5000)%256;IE=0X8a;/开定时器0,1中断 TR0=1;/启动定时器0TR1=1;/启动定时器1 t=0;/赋显示初值while(1) switch(vmode)case 0:mode0();brea

6、k;/正常走时case 1:mode1();break;/调整当前时间分钟case 2:mode2();break;/调整当前时间小时case 3:mode3();break;/调整闹钟时间分钟case 4:mode4();break;/调整闹钟时间分钟 case 5:/正常日期case 6:/调整月值case 7:/调整日值case 8:mode5();break;/调整周值 case 9:mode6();break;/显示温度default:break;/*10mS定时中断服务子函数*/void timer1_ISR(void) interrupt 3 TH1=(65536-5000)/2

7、56;TL1=(65536-5000)%256;if(m=1)n+;if(n=50)n=0;m=0;P3=0xff;if(P3!=0xff) if(n=0)m=1; if(n=1) if(mode=0) vmode+; if(enter=0) vmode=0;TR0=1; if(vmode=1&inc=0) TR0=0;min+;if(min=60) min=0; if(vmode=1&dec=0) TR0=0;min-;if(min=24) hour=0; if(vmode=2&dec=0) TR0=0;hour-;if(hour=60) amin=0; if(vmode=3&dec=0)

8、TR0=0;amin-;if(amin=24) ahour=0; if(vmode=4&dec=0) TR0=0;ahour-;if(ahour=13) mon=1; if(vmode=6&dec=0) TR0=0;mon-;if(mon=0) mon=12; if(vmode=7&inc=0) TR0=0;day+;if(year%4=0&year%100!=0|year%400=0) if(day=table1mon+1) day=1; else /非闰年if(day=table2mon+1) day=1; if(vmode=7&dec=0) TR0=0;day-;if(year%4=0&year%100!=0|year%400=0) if(day=0) day=table1mon-1; else if(day=8) week=1; if(vmode=8&dec=0) TR0=0;week-;if(week=10)vmode=0;switch(vmode) case 0:mode0();break;/正常走时case 1:mode1();break;/调整正常走时的分钟case 2:mode2();break;/调整正常走时的小时case 3:mode3();break;/调整定时的分钟c

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

当前位置:首页 > 大杂烩/其它

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