《单片机课程设计报告可编程作息时间控制器.doc》由会员分享,可在线阅读,更多相关《单片机课程设计报告可编程作息时间控制器.doc(20页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、单片机原理及应用课程设计报告 设计课题: 可编程作息时间控制器 专业班级: 工学院信工091 学生姓名: 肖冬冬 熊俊飞 指导教师: 何秀文 2012 年 5 月目 录目 录11 设计任务书21.1 基本设计要求22 设计阐明212.1设计内容21.2设计要求21.3设备及工作环境33 系统方案整体设计33.1 设计思路43.2 系统整体框图44 硬件设计44.1 系统硬件设计44.1.1 键盘扫描54.1.2 LCD显示器54.2 系统工作原理论述55 软件设计55.1 分析论证55.1.1 显示模块65.1.2 运算模块65.1.3 校时模块63.1.4 启动/暂停,复位模块65.1.5
2、整体功效65.2程序清单76 调试过程及分析247 设计总结25参 考 文 献261 设计任务书1.1 基本设计要求(1)在综合单片机实验箱的硬件结构上编写软件完成设计。(2)程序的首地址应使目标机可以直接运行,即从0000H开端。在主程序的开端部分必须设置一个合适的栈底。程序放置的地址须持续且靠前,不要在中间留下大批的空间地址,以使目标机可以应用较少的硬件资源。(3)2*16位LCD显示器从左到右分辨显示闹钟时间和现在时间,采用24小时标准计时制。(4)在4个键控开关上选定2个键分辨作为小时. 分的调校键。每按一次键,对应的显示值便加1。分. 秒加到59后变为00;小时加到23后再按键即变为
3、00.再调校时均不向上一单位进位(例如分加到59后变为00;但小时不产生转变)。(5)软件设计应用片内定时器,采用定时中断结构,应用软件延时法。2 设计阐明12.1设计内容用ZY15MCU12BD型综合单片机实验箱及串口电路设计实现显示现在时间和闹钟时间并能够调校现在时间和闹钟时间的时钟,还能够实现闹钟的复位功能以及广播和蜂鸣器的响应。说明设计中包含的内容1.2设计要求(1) 在ZY15MCU12BD型综合单片机实验箱的硬件结构上编写软件完成设计。(2) 程序的首地址应使目标机可以直接运行,即从0000H开端。在主程序的开端部分必须设置一个合适的栈底。程序放置的地址须持续且靠前,不要在中间留下
4、大批的空间地址,以使目标机可以应用较少的硬件资源。 (3) 2*16位LCD显示器从左到右分别显示时.分,采用24小时标准计时制。 (4) 在4个键控开关上选定2个键分别作为小时. 分的调校键。每按一次键,对应的显示值便加1或减1。分加到59后变为00;小时加到23后再按键即变为00.再调校时均不向上一单位进位(例如分加到59后变为00;但小时不产生转变).(5) 软件设计应用AT89S52片内定时器,采用定时中断结构,应用软件延时法。(6) 上机调试程序。(7) 写出设计报告。1.3设备及工作环境 (1) 硬件:计算机一台 (2) 软件:Windows操纵系统、Keil C51软件,prot
5、eus软件。3 系统方案整体设计3.1 设计思路或设计方案论证现在时间程序和闹钟程序由显示模块、校时模块和时钟运算模块三大部分组成。其中校时模块和时钟运算模块要对时、分、秒的数值进行操作,并且秒算到60时,要自己清零并向分进1;分算到60时,要自己清零并向时进1;时算到24时,要清零。这样,才能循环记时。秒表程序也由显示模块,秒时算到60时,要自己清零并向分进1,秒时算到60时,要自己清零。用按键决定是进入时钟程序还是秒表程序。3.2 系统整体框图图1 系统整体框图4 硬件设计4.1 系统硬件设计4.1.1 键盘扫描采用定时器结构,每过0.5s对键盘扫描一次。键盘采用复用结构,前三个键控开关均
6、有两个功能,第四个键控开关只有闹钟复位的功能。每当按一个健后均进入其相应的程序。4.1.3 LCD显示器LCD液晶显示器采用2*16位的结构。在使用LCD液晶显示器之前必须先对显示器初始化。确定显示器的工作方式等。4.2 系统工作原理论述硬件由AT89S51芯片、2*16LCD液晶显示器、晶振电路、5个键控开关、1个蜂鸣器和两个LED发光二极管组成.。软件采用片内定时器结构,每过50ms中断一次,一个发光二极管每闪一次表示时间过一秒。LCD液晶显示器显示现在的时间和闹钟的时间以及相应的字符。在4个键控开关上选定2个键分辨作为小时. 分的调校键。每按一次键,对应的显示值便加1。分. 秒加到59后
7、变为00;小时加到23后再按键即变为00.再调校时均不向上一单位进位(例如分加到59后变为00;但小时不产生转变)。设置四个闹钟,任何一路闹钟到时均广播和响蜂鸣器一分钟。同时还有闹钟显示以及复位功能。5 软件设计5.1 分析论证此可编程作息时间控制的设计与实现,主要采用了2*16液晶显示器,AT89S51片内16位定时器/计数器等,包含显示模块,运算模块和校时模块三大功效模块。5.1.1 显示模块用2*16液晶显示器功效来显示现在的时间以及闹钟的时间。与AT89S51连接,用程序来控制时间的走动。5.1.2 运算模块该模块的重要功效是对时、分、秒运算,并把运算出的终极成果存到事先已经开辟的内存
8、单元里,以便显示模块即时地显示出来。该模块可以细分为定时模块和运算模块。定时模块负责供给中断信号,由于CPU运算模块中的指令耗费必定的时间,所以中断信号最好通过硬件来实现,因此必须通过软件的方法在运算模块中设置一个统计中断次数的变量,并且这一变量必须事先在内存里开辟存储单元。中断信号是定时器工作方法为方法1,产生一个50ms的脉冲信号。运算模块负责时、分、秒的计算,在中断服务程序里,必须对秒、分和时的单元内的数值进行判断,当秒加到60时,分必须加1 、秒清零;当分加到60时,时加1、分清零。当时加到24时,直接清零,然后转到调用处。秒表也是如此。5.1.3 校时模块该模块重要功效是修正时、分、
9、秒内存单元的数值。每按一次键,对应的显示值便加1。分、 秒加到59后变为00;小时加到23后再按键即变为00.再调校时均不向上一单位进位(例如分加到59后变为00;但小时不产生转变)。要注意在主程序中对时间进行调校前应封闭中断,以防在调校过程中定时中断服务程序也对时间进行修正而造成混杂。3.1.4 复位模块该模块的功能是实现四个闹钟的复位。5.1.5 整体功效在LCD液晶显示器上能实现现在时间的时、分显示和表示秒的法功二极管的闪烁,并能对时、分进行加1校订、减1校订。本实验中01键(设置现在的时间/时的调整)、02健(显示闹钟设置的时间/分的调整)、03健(设置闹钟的时间.设置完成)、闹钟复位
10、。5.2程序清单 #include #define uint unsigned int #define uchar unsigned char sbit key1=P10; sbit key2=P11; sbit key3=P12; sbit key4=P13; sbit lcdcn=P22; sbit lcdrs=P20; sbit lcdrw=P21; sbit lcd=P24; sbit sound=P25; sbit lighter=P23; uint a,b,i,min,hour,minge,minshi,hourge,hourshi,sec; uint a0min,a0hour,a
11、0minge,a0minshi,a0hourge,a0hourshi,a1min,a1hour,a1minge,a1minshi,a1hourge,a1hourshi; uint a2min,a2hour,a2minge,a2minshi,a2hourge,a2hourshi,a3min,a3hour,a3minge,a3minshi,a3hourge,a3hourshi; uchar code table1=0,1,2,3,4,5,6,7,8,9; uchar code table2=Time:00:00; uchar code Alarm_0=Alar0:00:00; uchar code
12、 Alarm_1=Alar1:00:00; uchar code Alarm_2=Alar2:00:00; uchar code Alarm_3=Alar3:00:00; uchar code table0=A,0,A,1,A,2,A,3;uchar code null= ; uint num1,num2; void delay(unsigned int xms) uint i,j; for(i=xms;i0;i-) for(j=124;j0;j-); void write_com(uchar com) delay(5); lcdrs=0; P0=com; delay(5); lcdcn=1;
13、 delay(5); lcdcn=0;void write_data(uchar date) delay(5); lcdrs=1; P0=date; delay(5); lcdcn=1; delay(5); lcdcn=0; void time() while(1) if(key1=0)delay(10);if(key1=0) if(hour=23) hour=0; else hour+; hourge=hour%10; hourshi=hour/10; write_com(0x0f); delay(2); write_com(0x80+6); write_data(table1hourge)
14、; delay(5); write_com(0x80+5); delay(2); write_data(table1hourshi); while (!key1); /delay(1);if(key2=0) delay(10); if(key2=0) if(min=59)/分钟设置 min=0; else min+; minge=min%10; minshi=min/10; write_com(0x0f); write_com(0x80+9); write_data(table1minge); delay(1); write_com(0x80+8); write_data(table1mins
15、hi); delay(1); while (!key2); if(key3=0) delay(10); if(key3=0) write_com(0x0c); while(!key3); break; void alarm0() while(1) if(key1=0) delay(10);if(key1=0) if(a0hour=23) a0hour=0; else a0hour+; a0hourge=a0hour%10; a0hourshi=a0hour/10; write_com(0x0f); /delay(2); write_com(0x0c); write_com(0x80+0x40)
16、; for(i=0;i5;i+) write_data(Alarm_0i); delay(5); write_com(0x80+0x40+8); write_data(:); write_com(0x80+0x40+7); write_data(table1a0hourge); delay(1); write_com(0x80+0x40+6); /delay(2); write_data(table1a0hourshi); delay(1); while(!key1); if(key2=0) delay(10); if(key2=0) if(a0min=59) a0min=0;elsea0mi
17、n+;a0minge=a0min%10;a0minshi=a0min/10;write_com(0x0f);/delay(2);write_com(0x80+0x40+10);write_data(table1a0minge);delay(1);write_com(0x80+0x40+9);/delay(2); write_data(table1a0minshi); delay(1); while(!key2); if(key3=0) delay(10); if(key3=0) write_com(0x0c); write_com(0x80+0x40); for(i=0;i11;i+) wri
18、te_data(nulli);while(!key3);break; void alarm1() while(1) if(key1=0) delay(10);if(key1=0) if(a1hour=23) a1hour=0; else a1hour+; a1hourge=a1hour%10; a1hourshi=a1hour/10; write_com(0x0f); /delay(2); write_com(0x80+0x40); for(i=0;i5;i+) write_data(Alarm_1i); delay(5); write_com(0x80+0x40+8); write_data
19、(:); write_com(0x80+0x40+7); write_data(table1a1hourge); delay(1); write_com(0x80+0x40+6); /delay(2); write_data(table1a1hourshi); delay(1); while(!key1); if(key2=0) delay(10); if(key2=0) if(a1min=59) a1min=0;elsea1min+;a1minge=a1min%10;a1minshi=a1min/10;write_com(0x0f);/delay(2);write_com(0x80+0x40
20、+10);write_data(table1a1minge);delay(1);write_com(0x80+0x40+9);/delay(2); write_data(table1a1minshi); delay(1); while(!key2); if(key3=0) delay(10); if(key3=0) write_com(0x0c); write_com(0x80+0x40); for(i=0;i11;i+) write_data(nulli);while(!key3);break; void alarm2() while(1) if(key1=0) delay(10);if(k
21、ey1=0) if(a2hour=23) a2hour=0; else a2hour+; a2hourge=a2hour%10; a2hourshi=a2hour/10; write_com(0x0f); /delay(2); write_com(0x0c); write_com(0x80+0x40); for(i=0;i5;i+) write_data(Alarm_2i); delay(5); write_com(0x80+0x40+8); write_data(:); write_com(0x80+0x40+7); write_data(table1a2hourge); delay(1);
22、 write_com(0x80+0x40+6); /delay(2); write_data(table1a2hourshi); delay(1); while(!key1); if(key2=0) delay(10); if(key2=0) if(a2min=59) a2min=0;elsea2min+;a2minge=a2min%10;a2minshi=a2min/10;write_com(0x0f);/delay(2);write_com(0x80+0x40+10);write_data(table1a2minge);delay(1);write_com(0x80+0x40+9);/de
23、lay(2); write_data(table1a2minshi); delay(1); while(!key2); if(key3=0) delay(10); if(key3=0) write_com(0x0c); write_com(0x80+0x40); for(i=0;i11;i+) write_data(nulli);while(!key3);break; void alarm3() while(1) if(key1=0) delay(10);if(key1=0) if(a3hour=23) a3hour=0; else a3hour+; a3hourge=a3hour%10; a
24、3hourshi=a3hour/10; write_com(0x0f); /delay(2); write_com(0x0c); write_com(0x80+0x40); for(i=0;i5;i+) write_data(Alarm_3i); delay(5); write_com(0x80+0x40+8); write_data(:); write_com(0x80+0x40+7); write_data(table1a3hourge); delay(1); write_com(0x80+0x40+6); /delay(2); write_data(table1a3hourshi); d
25、elay(1); while(!key1); if(key2=0) delay(10); if(key2=0) if(a3min=59) a3min=0;elsea3min+;a3minge=a3min%10;a3minshi=a3min/10;write_com(0x0f);/delay(2);write_com(0x80+0x40+10);write_data(table1a3minge);delay(1);write_com(0x80+0x40+9);/delay(2); write_data(table1a3minshi); delay(1); while(!key2); if(key
26、3=0) delay(10); if(key3=0) write_com(0x0c); write_com(0x80+0x40); for(i=0;i11;i+) write_data(nulli);while(!key3);break; void keyscan() if(key1=0) delay(10); if(key1=0) while(!key1); time();/时间调用 else if(key2=0) delay(10); if(key2=0) while(!key2); a0hourge=a0hour%10; a0hourshi=a0hour/10; write_com(0x
27、80+0x40+0); write_data(table00); delay(5); write_com(0x80+0x40+1); write_data(table01); delay(5); write_com(0x80+0x40+7); write_data(table1a0hourge); delay(5); write_com(0x80+0x40+6); delay(2); write_data(table1a0hourshi); a0minge=a0min%10; a0minshi=a0min/10; write_com(0x80+0x40+10); write_data(tabl
28、e1a0minge); delay(5); write_com(0x80+0x40+9); delay(2); write_data(table1a0minshi); delay(500);a1hourge=a1hour%10; a1hourshi=a1hour/10; write_com(0x80+0x40+0); write_data(table02); delay(5); write_com(0x80+0x40+1); write_data(table03); delay(5); write_com(0x80+0x40+7); write_data(table1a1hourge); de
29、lay(5); write_com(0x80+0x40+6); delay(2); write_data(table1a1hourshi); a1minge=a1min%10; a1minshi=a1min/10; write_com(0x80+0x40+10); write_data(table1a1minge); delay(5); write_com(0x80+0x40+9); delay(2); write_data(table1a1minshi); delay(500); a2hourge=a2hour%10; a2hourshi=a2hour/10; write_com(0x80+
30、0x40+0); write_data(table04); delay(5); write_com(0x80+0x40+1); write_data(table05); delay(5); write_com(0x80+0x40+7); write_data(table1a2hourge); delay(5); write_com(0x80+0x40+6); delay(2); write_data(table1a2hourshi); a2minge=a2min%10; a2minshi=a2min/10; write_com(0x80+0x40+10); write_data(table1a
31、2minge); delay(5); write_com(0x80+0x40+9); delay(2); write_data(table1a2minshi); delay(500); a3hourge=a3hour%10; a3hourshi=a3hour/10; write_com(0x80+0x40+0); write_data(table06); delay(5); write_com(0x80+0x40+1); write_data(table07); delay(5); write_com(0x80+0x40+7); write_data(table1a3hourge); dela
32、y(5); write_com(0x80+0x40+6); delay(2); write_data(table1a3hourshi); a3minge=a3min%10; a3minshi=a3min/10; write_com(0x80+0x40+10); write_data(table1a3minge); delay(5); write_com(0x80+0x40+9); delay(2); write_data(table1a3minshi); delay(500); write_com(0x80+0x40); for(i=0;i11;i+) write_data(nulli);el
33、se if(key3=0) delay(10); if(key3=0)while(!key3);a0hourge=a0hour%10; a0hourshi=a0hour/10; write_com(0x80+0x40+7); write_data(table1a0hourge); delay(5); write_com(0x80+0x40+6); delay(2); write_data(table1a0hourshi); a0minge=a0min%10;a0minshi=a0min/10;write_com(0x80+0x40+10);write_data(table1a0minge);d
34、elay(5);write_com(0x80+0x40+9);delay(2); write_data(table1a0minshi); write_com(0x80+0x40); for(i=0;i11;i+) write_data(Alarm_0i); alarm0(); a1hourge=a1hour%10; a1hourshi=a1hour/10; write_com(0x80+0x40+7); write_data(table1a1hourge); delay(5); write_com(0x80+0x40+6); delay(2); write_data(table1a1hours
35、hi); a1minge=a1min%10;a1minshi=a1min/10;write_com(0x80+0x40+10);write_data(table1a1minge);delay(5);write_com(0x80+0x40+9);delay(2); write_data(table1a1minshi); write_com(0x80+0x40); for(i=0;i11;i+) write_data(Alarm_1i); alarm1(); a2hourge=a2hour%10; a2hourshi=a2hour/10; write_com(0x80+0x40+7); write
36、_data(table1a2hourge); delay(5); write_com(0x80+0x40+6); delay(2); write_data(table1a2hourshi); a2minge=a2min%10;a2minshi=a2min/10;write_com(0x80+0x40+10);write_data(table1a2minge);delay(5);write_com(0x80+0x40+9);delay(2); write_data(table1a2minshi); write_com(0x80+0x40); for(i=0;i11;i+) write_data(
37、Alarm_2i); alarm2(); a3hourge=a3hour%10; a3hourshi=a3hour/10; write_com(0x80+0x40+7); write_data(table1a3hourge); delay(5); write_com(0x80+0x40+6); delay(2); write_data(table1a3hourshi); a3minge=a3min%10;a3minshi=a2min/10;write_com(0x80+0x40+10);write_data(table1a3minge);delay(5);write_com(0x80+0x40+9);delay(2); write_data(table1a3minshi); write_com(0x80+0x40); for(i=0;i11;i+) write_data(Alarm_3i); alarm3(); /闹钟调用else if(key4=0)delay(5);if(key4=0) while(!key4); a0min=a0hour=a0minge=a0minshi=a0hourge=a0hourshi=a1min=a1hour=a1minge=a1minshi=a1hourge=a1
限制150内