基于单片机的电子时钟和显示屏的设计_第1页
基于单片机的电子时钟和显示屏的设计_第2页
基于单片机的电子时钟和显示屏的设计_第3页
基于单片机的电子时钟和显示屏的设计_第4页
基于单片机的电子时钟和显示屏的设计_第5页
已阅读5页,还剩34页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、目录1 方案设计1.1单片机电子时钟的背景11.2电子时钟的意义11.3 电子时钟的工作原理及其具体实现11.4 设计任务22 电路方案设计32.1 模块一电路图32.2 模块二电路图32.3 模块三电路图42.4 总电路图43程序设计53.1 主程序流程图53.2模块一ds1302流程图63.3模块二12864lcd流程图83.4 模块三ds18b20流程图73.5 源程序74 仿真与调试7总结语7参考文献7 1 方案设计1.1单片机电子时钟的背景随着电子技术和计算机技术的迅速发展,单片机已经在工业过程控制、智能仪表、计算机集成控制、人工智能、通信设备的智能化以及家电的智能化等方面得到广泛的

2、应用。以单片机和微控制器为核心仍然是当今实现智能化技术的主流。随着单片机技术广泛地应用与人们生活的各个方面,一些人们经常使用的产品大多数是基于单片机研发的,如电子时钟。钟表从原来的沙漏计时和机械打点塔钟等演变到如今的电池驱动钟、交流钟、指针式石英电子钟表和数字式石英电子钟表,并且钟表的准确度越来越高了。随着人们的时间观念逐渐地增强,时钟在我们人类的世界里扮演着一个非常重要的角色,几乎出现在我们生活的各个角落里,并且人们几乎离不开它了。如今的时钟的功能更加全面,与机械时钟相比具有更高的正确性和直观性,且无机械装置,具有更长的寿命,因此广泛地应用于人类正常生活中,得到人们的关注和研发。1.2电子时

3、钟的意义电子时钟采用数字电路实现对时、分、秒和数字显示的计时装置,广泛使用于个人家庭、车站、机场等公共场所,成为人们日常生活中不可缺少的必需品,给人们的生活、学习、工作、娱乐带来了极大的方便。由于数字集成电路的发展和石英晶体振荡器的广泛应用,使得电子时钟的精度、稳定性大幅度提高。现在的钟表的功能越来越强,具有定时自动报警、按时自动打铃、时间程序自动控制、定时广播、自动启闭路灯、定时开关烘箱、通断动力设备、甚至各种定时电气的自动启用等,因此,研究数字时钟及其扩展,有着重大意义。1.3 电子时钟的工作原理及其具体实现电子时钟的工作原理是采用单片机最小系统,用ds1302时钟芯片和12864lcd液

4、晶显示屏芯片以及ds18b20温度传感器分别进行寄存相关信息、显示年月日时分秒和采取温度,用四个键分别实现选择调整对象为、增加调节对象的数值、减少调节对象的数值和调整确定,采用24小时制、定时器0中断和外部中断0,从而实现可调式中文电子日历、温度及整点报时功能。采用定时器0中断,定时50ms,其中断服务程序的功能是将时间和日期显示到lcd上。每1s时间,刷新液晶显示屏上的秒钟数值;每60s时间,刷新显示屏的分钟数值;每60min时间,刷新显示屏的小时数值;每24h时间,刷新显示屏的日期;星期是通过年月日进行调整;温度是通过温度传感器芯片ds18b20进行调整;时钟每次到整点时,通过蜂鸣器进行整

5、点报时。采用外部中断0实现时钟的调整,将四个键通过“与门”连接单片机p32端口,从而通过键产生外部中断信号。当要调整日期时间的时候,首先要按k1键来选择调整对象,否则按其他键不会进行时间调整,然后可以按k2和k3键对日期时间进行加减调整,最后按k4键可以将改动的日期时间重新显示到lcd上。并且每次按下键后,都会通过蜂鸣器发出按键声音。1.4 设计任务(1)可调式中文电子日历的硬件和软件设计;(2)画出程序流程图;(3)编写代码;(4)程序分析与调试;2 电路方案设计2.1 模块一电路图该模块主要通过ds1302时钟芯片实现计算秒、分、时、星期、日、月、年的信息,且具有闰年补偿的功能,其在pro

6、teus中的电路图如图2.1.1所示。图2.1.1 记录年月日秒分时星期的电路图2.2 模块二电路图该模块主要通过12864lcd实现中文电子日历功能,其在proteus中的电路图如图2.2.1所示图2.2.1 显示时间电路图2.3 模块三电路图该模块主要通过ds18b20温度传感芯片、四个键以及蜂鸣器实现温度采集,时间调节和闹钟等功能。图2.3.1 时间调整电路图2.4 总电路图如图2.4.1所示。图2.4.1 总体硬件电路图3程序设计3.1 主程序流程图图3.1.1 主函数流程图3.2模块一ds1302流程图图3.2.1获取当前时间的流程图图3.2.2 年月日时分秒+/-流程图图3.2.3

7、定时器0的中断服务程序图3.2.4外部中断0服务程序3.3模块二12864lcd流程图图3.3.1 lcd初始化流程图图3.3.2 通用显示函数流程图3.4 模块三ds18b20流程图图3.4 1 读取温度值3.5 源程序#include<reg51.h>#include<intrins.h>#include<string.h>#define uchar unsigned char#define uint unsigned intsbit sda=p10;/*ds1302数据线*/sbit clk=p11;/*ds1302时钟线*/sbit rst=p12;

8、/*ds1302复位线*/sbit k1=p34; /*选择键*/sbit k2=p35; /*加键*/sbit k3=p36; /*减键*/sbit k4=p37; /*确定键*/sbit spk=p26;/*子函数定义*/*显示年函数*/extern void lcd_initialize();/*液晶初始化函数*/*读取温度值*/extern void read_temperature();extern void display_temperature(); /*显示时间函数*/extern void display_a_char_8x16(uchar p,uchar l,ucha*m

9、)reentrant;/*显示年月日,星期,时分秒的固定汉字函数*/extern void display_a_word(uchar p,uchar l,uchar *m)reentrant;void beep();/*启动蜂鸣器函数*/*在调整日期时间时,用该位决定是否反白显示*/extern bit reverse_display;extern uchar display_digit=0,0,0,0;/*待显示的各温度数位*/extern bit ds18b20_is_ok=1;/*传感器正常标志*/*全局变量和数组定义*/uchar tcount=0;/*一年中每个月的天数,2月的天数由

10、年份决定*/uchar monthsdays=0,31,0,31,30,31,30,31,31,30,31,30,31;/*所读取的日期时间*/uchar datetime7;/*当前调整的时间对象:秒,分,时,日,月,星期,年(0,1,2,3,4,5,6)变量*/*其中星期由年月日调整自动完成*/char adjust_index=-1;uchar h_offset=10,v_page_offset=0;/*水平与垂直偏移变量*/*年月日,星期,时分秒汉字点阵16乘16*/uchar code date_time_words= 0x40,0x20,0x10,0x0c,0xe3,0x22,0x

11、22,0x22,0xfe,0x22,0x22,0x22,0x22,0x02,0x00,0x00, 0x04,0x04,0x04,0x04,0x07,0x04,0x04,0x04,0xff,0x04,0x04,0x04,0x04,0x04,0x04,0x00, /*年*/ 0x00,0x00,0x00,0x00,0x00,0xff,0x11,0x11,0x11,0x11,0x11,0xff,0x00,0x00,0x00,0x00, 0x00,0x40,0x20,0x10,0x0c,0x03,0x01,0x01,0x01,0x21,0x41,0x3f,0x00,0x00,0x00,0x00, /*

12、月*/ 0x00,0x00,0x00,0xfe,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0xfe,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x3f,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x3f,0x00,0x00,0x00,0x00, /*日*/ 0x00,0x00,0x00,0xbe,0x2a,0x2a,0x2a,0xea,0x2a,0x2a,0x2a,0x2a,0x3e,0x00,0x00,0x00, 0x00,0x48,0x46,0x41,0x49,0x49,0x49,0x7f,0x49,0x

13、49,0x49,0x49,0x49,0x41,0x40,0x00, /*星*/ 0x00,0x04,0xff,0x54,0x54,0x54,0xff,0x04,0x00,0xfe,0x22,0x22,0x22,0xfe,0x00,0x00, 0x42,0x22,0x1b,0x02,0x02,0x0a,0x33,0x62,0x18,0x07,0x02,0x22,0x42,0x3f,0x00,0x00, /*期*/ 0x00,0xfc,0x44,0x44,0x44,0xfc,0x10,0x90,0x10,0x10,0x10,0xff,0x10,0x10,0x10,0x00, 0x00,0x07,0

14、x04,0x04,0x04,0x07,0x00,0x00,0x03,0x40,0x80,0x7f,0x00,0x00,0x00,0x00, /*时*/ 0x80,0x40,0x20,0x98,0x87,0x82,0x80,0x80,0x83,0x84,0x98,0x30,0x60,0xc0,0x40,0x00, 0x00,0x80,0x40,0x20,0x10,0x0f,0x00,0x00,0x20,0x40,0x3f,0x00,0x00,0x00,0x00,0x00, /*分*/ 0x12,0x12,0xd2,0xfe,0x91,0x11,0xc0,0x38,0x10,0x00,0xff,0

15、x00,0x08,0x10,0x60,0x00, 0x04,0x03,0x00,0xff,0x00,0x83,0x80,0x40,0x40,0x20,0x23,0x10,0x08,0x04,0x03,0x00, /*秒*/ 0x10,0x21,0x86,0x70,0x00,0x7e,0x4a,0x4a,0x4a,0x4a,0x4a,0x7e,0x00,0x00,0x00,0x00, 0x02,0xfe,0x01,0x40,0x7f,0x41,0x41,0x7f,0x41,0x41,0x7f,0x41,0x41,0x7f,0x40,0x00, /*温*/ 0x00,0x00,0xfc,0x04,

16、0x24,0x24,0xfc,0xa5,0xa6,0xa4,0xfc,0x24,0x24,0x24,0x04,0x00, 0x80,0x60,0x1f,0x80,0x80,0x42,0x46,0x2a,0x12,0x12,0x2a,0x26,0x42,0xc0,0x40,0x00, /*度*/;/*星期几的汉字点阵16乘16*/uchar code weekday_words= 0x00,0x00,0x00,0xfe,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0xfe,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x3f,0x10,0x1

17、0,0x10,0x10,0x10,0x10,0x10,0x3f,0x00,0x00,0x00,0x00, /*日*/ 0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0xc0,0x80,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /*一*/ 0x00,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x06,0x04,0x00,0x0

18、0,0x00, 0x00,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x18,0x10,0x00, /*二*/ 0x00,0x04,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x04,0x00,0x00, 0x00,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x00, /*三*/ 0x00,0xfe,0x02,0x02,0x02,0xfe,0x02,0x

19、02,0xfe,0x02,0x02,0x02,0x02,0xfe,0x00,0x00, 0x00,0x7f,0x28,0x24,0x23,0x20,0x20,0x20,0x21,0x22,0x22,0x22,0x22,0x7f,0x00,0x00, /*四*/ 0x00,0x02,0x82,0x82,0x82,0x82,0xfe,0x82,0x82,0x82,0xc2,0x82,0x02,0x00,0x00,0x00, 0x20,0x20,0x20,0x20,0x20,0x3f,0x20,0x20,0x20,0x20,0x3f,0x20,0x20,0x30,0x20,0x00, /*五*/ 0

20、x10,0x10,0x10,0x10,0x10,0x91,0x12,0x1e,0x94,0x10,0x10,0x10,0x10,0x10,0x10,0x00, 0x00,0x40,0x20,0x10,0x0c,0x03,0x01,0x00,0x00,0x01,0x02,0x0c,0x78,0x30,0x00,0x00, /*六*/;/*半角数字点阵8乘16*/uchar code digits= 0x00,0xe0,0x10,0x08,0x08,0x10,0xe0,0x00,0x00,0x0f,0x10,0x20,0x20,0x10,0x0f,0x00,/*0*/ 0x00,0x10,0x10

21、,0xf8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3f,0x20,0x20,0x00,0x00,/*1*/ 0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,/*2*/ 0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0e,0x00,/*3*/ 0x00,0x00,0xc0,0x20,0x10,0xf8,0x00,0x00,0x00,0x07,0x04,0

22、x24,0x24,0x3f,0x24,0x00,/*4*/ 0x00,0xf8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0e,0x00,/*5*/ 0x00,0xe0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0f,0x11,0x20,0x20,0x11,0x0e,0x00,/*6*/ 0x00,0x38,0x08,0x08,0xc8,0x38,0x08,0x00,0x00,0x00,0x00,0x3f,0x00,0x00,0x00,0x00,/*7*/ 0x00,0x70,0x

23、88,0x08,0x08,0x88,0x70,0x00,0x00,0x1c,0x22,0x21,0x21,0x22,0x1c,0x00,/*8*/ 0x00,0xe0,0x10,0x08,0x08,0x10,0xe0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0f,0x00,/*9*/;/*生日快乐歌的音符频率表,不同的频率由不同的延时值来决定*/uchar code song_tone=212,212,190,212,159,169,212,212,190,212,142,159, 212,212,106,126,159,169,190,119,119,126

24、,159,142,159,0;/*生日快乐歌节拍表,节拍表决定了每个音符的演奏长短*/uchar code song_long=9,3,12,12,12,24,9,3,12,12,12,24,9,3,12,12,12,12,12,9,3,12,12,12,24,0;void delayms(uint x) /*调用延时子函数*/uchar i;while(x-) for(i=0;i<120;i+);void playmusic()/*音乐播放函数*/uint i=0,j,k;while(song_longi!=0|song_tonei!=0)/*播放各个音符,song_long为拍*/f

25、or(j=0;j<song_longi*20;j+)spk=spk;/*song_tone延时表决定了每个音符的频率*/for(k=0;k<song_tonei/3;k+);delayms(100);/*下一个音符的索引*/i+;void alarm(uchar t) /*温度报警函数*/uchar i,j;for(i=0;i<200;i+)spk=spk;/*由参数t形成不同的频率*/for(j=0;j<t;j+);/*向ds1302写入一字节*/void write_a_byte_to_ds1302(uchar x)uchar i;for(i=0;i<8;i+

26、)sda=x&1; clk=1; clk=0; x>>=1;/*从ds1302读取一字节*/uchar get_a_byte_from_ds1302()uchar i,b,t;for(i=0;i<8;i+)b>>=1;t=sda;b|=t<<7;clk=1;clk=0;/*bcd码转换*/return(b/16*10+b%16);/*从ds1302指定位置读数据*/uchar read_data(uchar addr)uchar dat;rst=0;clk=0;rst=1;write_a_byte_to_ds1302(addr);dat=get

27、_a_byte_from_ds1302();clk=1;rst=0;return dat;/*向ds1302某地址写入数据*/void write_ds1302(uchar addr,uchar dat)clk=0; rst=1;write_a_byte_to_ds1302(addr);write_a_byte_to_ds1302(dat);clk=1;rst=0;/*设置时间*/void set_ds1302()uchar i;write_ds1302(0x8e,0x00);/*秒分时日月年依次写入*/for(i=0;i<7;i+)/*秒,分,时,日,月,星期,年的起始地址分别为0x8

28、0,0x82,0x84,0x86,0x88,0x8a,0x8c*/ write_ds1302(0x80+2*i,(datetimei/10<<4)|(datetimei%10);write_ds1302(0x8e,0x80);/*读取当前时间*/void gettime()uchar i;for(i=0;i<7;i+)datetimei=read_data(0x81+2*i); uchar isleapyear(uint y)/*判断是否为闰年*/return (y%4=0&&y%100!=0)|(y%400=0);/*刷新星期*/void refreshwe

29、ekday()uint i,d,w=5;/*已知1999.12.31是周五*/for(i=2000;i<2000+datetime6;i+)d=isleapyear(i)?366:365;w=(w+d)%7;d=0;for(i=1;i<datetime4;i+) d+=monthsdaysi;d+=datetime3;/*保存星期,06表示星期日,星期一,二,三,四,五,六,为了与ds1302的星期格式匹配,返回值需要加1*/datetime5=(w+d)%7+1;/*蜂鸣器函数*/void beep(uchar t)uchar i;for(i=0;i<100;i+)spk=

30、spk;delayms(t);spk=0;void datetime_adjust(char x)/*年月日时分+或-*/switch(adjust_index)case 6: /*年00-99*/if(x=1&&datetime6<99) datetime6+;if(x=-1&&datetime6>0) datetime6-;/*获取2月天数*/ monthsdays2=isleapyear(2000+datetime6)?29:28;/*如果年份变化后当前月份的天数大于上限则设为上限*/if(datetime3>monthsdaysdate

31、time4)datetime3=monthsdaysdatetime4;refreshweekday();/*刷新星期*/break;case 4: /*月01至12*/if(x=1&&datetime4<12) datetime4+;if(x=-1&&datetime4>1) datetime4-;/*获取2月天数*/ monthsdays2=isleapyear(2000+datetime6)?29:28;/*如果年份变化后当前月份的天数大于上限则设为上限*/if(datetime3>monthsdaysdatetime4) datetim

32、e3=monthsdaysdatetime4;refreshweekday();/*刷新星期*/break;case 3:/*日00至28/29/30/31;调节之前首先根据年份得出该年中2月的天数*/ monthsdays2=isleapyear(2000+datetime6)?29:28;/*再根据当前月份决定调节日期的上限*/if(x=1&&datetime3<monthsdaysdatetime4) datetime3+;if(x=-1&&datetime3>0) datetime3-;refreshweekday();/*刷新星期*/bre

33、ak;case 2: /*小时*/if(x=1&&datetime2<23) datetime2+;datetime2-;break;case 1: /*分钟*/if(x=1&&datetime1<59) datetime1+;if(x=-1&&datetime1>0) datetime1-;break;case 0: /*秒*/if(x=1&&datetime0<59) datetime0+;break;/*定时器0每秒刷新lcd显示*/void t0_int() interrupt 1th0=(6553

34、6-50000)/256;tl0=(65536-50000)%256;if(+tcount!=2) return;tcount=0;/*年(后两位)*/reverse_display=adjust_index=6; display_a_char_8x16(v_page_offset,70+h_offset,digits+datetime6/10*16); display_a_char_8x16(v_page_offset,78+h_offset,digits+datetime6%10*16);/*星期*/reverse_display=adjust_index=5; display_a_wor

35、d(v_page_offset+3,32+h_offset,weekday_words+(datetime5%10-1)*32);/*月*/reverse_display=adjust_index=4; display_a_char_8x16(v_page_offset,102+h_offset,digits+datetime4/10*16); display_a_char_8x16(v_page_offset,110+h_offset,digits+datetime4%10*16);/*日*/reverse_display=adjust_index=3; display_a_char_8x1

36、6(v_page_offset,5+h_offset,digits+datetime3/10*16); display_a_char_8x16(v_page_offset,13+h_offset,digits+datetime3%10*16);/*时*/reverse_display=adjust_index=2; display_a_char_8x16(v_page_offset+6,56+h_offset,digits+datetime2/10*16); display_a_char_8x16(v_page_offset+6,64+h_offset,digits+datetime2%10*

37、16);/*分钟*/reverse_display=adjust_index=1; display_a_char_8x16(v_page_offset+6,88+h_offset,digits+datetime1/10*16); display_a_char_8x16(v_page_offset+6,96+h_offset,digits+datetime1%10*16);/*秒*/reverse_display=adjust_index=0; display_a_char_8x16(v_page_offset+6,-10+h_offset,digits+datetime0/10*16); di

38、splay_a_char_8x16(v_page_offset+6,-2+h_offset,digits+datetime0%10*16);/*键盘中断(int0)*/void ex_int0() interrupt 0if(k1=0) /*选择调整对象*/ beep(1);if(adjust_index=-1|adjust_index=0) adjust_index=7;adjust_index-;if(adjust_index=5) adjust_index=4; /*跳过对星期的调整*/elseif(k2=0) /*加*/ beep(1);datetime_adjust(1);elsei

39、f(k3=0) /*减*/ beep(1); datetime_adjust(-1);elseif(k4=0) /*确定*/beep(1);set_ds1302(); /*将调整后的时间写入ds1302*/adjust_index=-1; /*操作索引重设为-1,时间继续正常显示*/*主函数*/void main()lcd_initialize();/*液晶初始化*/read_temperature();delayms(50);delayms(50);/*显示年的固定前两位*/ display_a_char_8x16(v_page_offset,55+h_offset,digits+2*16)

40、; display_a_char_8x16(v_page_offset,62+h_offset,digits);/*显示固定汉字:年月日,星期,时分秒,温度:*/ display_a_word(v_page_offset,86+h_offset,date_time_words+0*32); display_a_word(v_page_offset,-10+h_offset,date_time_words+1*32); display_a_word(v_page_offset,21+h_offset,date_time_words+2*32); display_a_word(v_page_off

41、set+3,0+h_offset,date_time_words+3*32); display_a_word(v_page_offset+3,16+h_offset,date_time_words+4*32); display_a_word(v_page_offset+3,56+h_offset,date_time_words+8*32); display_a_word(v_page_offset+3,72+h_offset,date_time_words+9*32); display_a_word(v_page_offset+6,72+h_offset,date_time_words+5*3

42、2); display_a_word(v_page_offset+6,104+h_offset,date_time_words+6*32); display_a_word(v_page_offset+6,6+h_offset,date_time_words+7*32);/*允许外部中断,定时器0中断*/ie=0x83;ip=0x01;it0=0x01;tmod=0x01;th0=0x3c;tl0=0xb0;tr0=1;while(1)/*如果未执行调整时间操作,则就继续显示当前时间*/if(adjust_index=-1) gettime();read_temperature();if(ds1

43、8b20_is_ok) display_temperature();delayms(100);/*温度*/if(display_digit3!=0) display_a_char_8x16(v_page_offset+3,80+h_offset,digits+display_digit3*16);if(display_digit3=0&&display_digit2!=0) display_a_char_8x16(v_page_offset+3,88+h_offset,digits+display_digit2*16); display_a_char_8x16(v_page_o

44、ffset+3,96+h_offset,digits+display_digit1*16); if(display_digit3!=0)|(display_digit2=6)&&(display_digit1=5)alarm(90); alarm(120);if(datetime0=0&&datetime1=0)playmusic(); delayms(5001);/*lcd_12864.c*/*名称:12864lcd显示驱动程序(不带字库)*/#include<reg51.h>#include<intrins.h>#define uch

45、ar unsigned char#define uint unsigned int#define lcd_db_port p0 /*液晶db0db7*/#define lcd_start_row 0xc0 /*起始行*/#define lcd_page 0xb8 /*页指令*/#define lcd_col 0x40 /*列指令*/*液晶引脚定义*/sbit di=p20;sbit rw=p21;sbit e=p22;sbit cs1=p23;sbit cs2=p24;sbit rs=p25;/*是否反相显示(白底黑字/黑底白字)*/bit reverse_display=0;/*检查lcd是

46、否忙*/bit lcd_check_busy()rw=1;_nop_();di=0;e=1;_nop_();e=0;return (bit)(p0&0x80);/*向lcd发送命令*/void lcd_write_command(uchar c)while(lcd_check_busy();lcd_db_port=0x00;rw=0;_nop_();di=0;lcd_db_port=c;e=1;_nop_();e=0;/*向lcd发送数据*/void lcd_write_data(uchar d)while(lcd_check_busy();lcd_db_port=0x00;rw=0;

47、_nop_();di=1;/*根据reverse_display决定是否反相显示*/if(!reverse_display)lcd_db_port=d;else lcd_db_port=d;e=1;_nop_();e=0;/*初始化lcd*/void lcd_initialize()cs1=1; cs2=1;lcd_write_command(0x38); /*8位形式,2行字符*/lcd_write_command(0x0f); /*开显示*/lcd_write_command(0x01); /*清屏*/lcd_write_command(0x06); /*画面不动光标右移*/lcd_wri

48、te_command(lcd_start_row); /*设置起始行*/*通用显示函数*/*从第p页第l列开始显示w字节,数据在r所指向的缓冲*/*每字节8位是垂直显示的,高位在下,低位在上*/*每个8*128的矩形区域为一页(每页分左半页与右半页)*/*整个lcd又由64*64的左半屏和64*64的右半屏构成*/void common_show(uchar p,uchar l,uchar w,uchar *r) reentrantuchar i;if(l<64)/*显示在左半屏或右半屏*/cs1=1; cs2=0;lcd_write_command(lcd_page+p);lcd_wr

49、ite_command(lcd_col+l);if(l+w<64)/*全部显示在左半屏*/for(i=0;i<w;i+) lcd_write_data(ri);else /*如果越界则跨越左右半屏显示*/for(i=0;i<64-l;i+) lcd_write_data(ri); /*左半屏显示*/cs1=0; cs2=1; /*右半屏显示*/lcd_write_command(lcd_page+p);lcd_write_command(lcd_col);for(i=64-l;i<w;i+) lcd_write_data(ri);else /*全部显示在左右半屏*/cs

50、1=0;cs2=1;lcd_write_command(lcd_page+p);lcd_write_command(lcd_col+l-64);for(i=0;i<w;i+) lcd_write_data(ri);/*显示一个8*16点阵字符*/void display_a_char_8x16(uchar p,uchar l,uchar *m) reentrantcommon_show(p,l,8,m); /*显示汉字上半部分*/ common_show(p+1,l,8,m+8);/*显示一个16*16点阵汉字*/void display_a_word(uchar p,uchar l,uchar *m)reentrantcommon_show(p,l,16,m);/*显示汉字上部分*/common_show(p+1,l,16,m+16);/*显示汉字下部分*/*名称:ds18b20温度传感器*/#include<reg51.h>#include<intrins.h>#define uchar unsigned char#define uint unsigned int#define delaynop() _nop_();_nop_();_nop_();_nop_();sbit dq=p33;uchar currentt=0;/*当前温度

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论