基于单片机的电子钟毕业设计安徽工程大学(5)

2018-12-23 00:26

安徽工程大学机电学院毕业设计(论文)

附录B 源程序清单 主程序

#include sbit ksec=P3^0; sbit kmin=P3^1; sbit khour=P3^2;

unsigned char secshi=0,secge=0,minshi=0,minge=0,hourshi=0,hourge=0; unsigned int num=0,sec=0,min=0,hour=0;

unsigned char code table[10]={0x3f,0xxx,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; void delay(unsigned int); void keyscan(); void display(); main()

{TMOD=0x01;

TH0=(65536-50000)/256; TL0=(65536-50000)%6; EA=1;ET0=1;TR0=1; while(1) {display(); keyscan(); } }

void delay(unsigned int z) {unsigned int x,y; for(x=z;x>0;x--)

for(y=110;y>0;y--);} 时钟设置子程序

void time0() interrupt 1 {num++;

TH0=(65536-50000)/256; TL0=(65536-50000)%6; }

定时器中断子程序 void time0() interrupt 1 {num++;

TH0=(65536-50000)/256; TL0=(65536-50000)%6; }

LED显示程序 void display() {if(num==20) {num=0; sec++;

if(sec==60)

- 17 -

xxx:基于单片机的电子钟设计

{sec=0; min++;

if(min==60) {min=0; hour++; if(hour==24) {hour=0; min=0; sec=0; } } } }

secge=sec; secshi=sec/10; minge=min; minshi=min/10; hourge=hour; hourshi=hour/10; P2=0xfe;

P0=table[secge]; delay(5); P2=0xfd;

P0=table[secshi]; delay(5); P2=0xfb; P0=0x40; delay(5); P2=0xf7;

P0=table[minge]; delay(5); P2=0xef;

P0=table[minshi]; delay(5); P2=0xdf; P0=0x40; delay(5); P2=0xbf;

P0=table[hourge]; delay(5); P2=0x7f;

P0=table[hourshi]; delay(5); }

- 18 -

安徽工程大学机电学院毕业设计(论文)

按键控制子程序 void keyscan() {if(ksec==0) {delay(10); if(ksec==0) {sec++;

if(sec>=60) sec=0; }

while(ksec==0) display();} if(kmin==0) {delay(10); if(kmin==0) {min++;

if(min>=60) min=0; }

while(kmin==0) display(); }

if(khour==0) {delay(10); if(khour==0) {hour++;

if(hour>=60) hour=0; }

while(khour==0) display(); } }

- 19 -

xxx:基于单片机的电子钟设计

附录C 一篇外文文献及译文

Design and Simulation of LED Clock Circuit Based on Proteus

Abstract:Based on the Proteus simulation software, the circuits of MCV controlling LED clock have been designed. The circuits include four parts: Hardware design, software programming, software simulation and physical display. Eventually, through the Proteus software simulation and physical display prove that the method of the circuit design is correct. This paper systematically introduces the design method of MCV controlling circuits and provides a complete design idea for the design of display circuit. Keywords:Proteus; LED; clock circuit

I. INTRODUCTION

Proteus is EDA software developed by the UK Labcenter Company, which can not only realize fundamental circuit simulation, but also simulate, debug MCU and peripheral circuits. With the Proteus powerful simulation capabilities and extensive resource libraries,the design process of hardware circuit can be effectively simplified. The Proteus simulation software can be firstly used in the design, simulation and debugging of the hardware circuit. When the results reach the demand, the physical circuits would been finally set up and debugged.This makes sure not only a high effective, low invested circuit design but also reduces the loss caused by burning of debugging in practice . In addition, it has also provided an effective design approach for hardware circuit design under scarce resource conditions in laboratory.

II. HARDWARE DESIGN

80C52 is the control center of the whole hardware circuit. PO pins connect with six LED nixie tubes through two latches 74HC573 respectively. P2.6 and P2.7 in P2 pins of 80C52 respectively control the nixie tube segments elected and bit-selected signals. The \connects with the P3.7 pin, which can clear the display . Six nixie tubes are divided into three groups from left to right,which presents respectively: hour (Hour_H, Hour_L),minute(Min_H, Min_L), second (Sec_H, Sec_L) ; PO pins connect with 74HC373 through external pull-up resistors;Using two latches is mainly to save 80C52 port resources, in order to facilitate follow-up development of circuit design. Peripheral circuits include input power circuit, power supply filter circuit, reset circuit and the LED indicating circuit and so on. The whole hardware circuits have been displayed in figure .

- 20 -

安徽工程大学机电学院毕业设计(论文)

Figure 1. LED clock circuits

III. SOFTWARE DESIGN

Through using C language to control each pin of the 80C52 MCU, the designed circuits are required to achieve the electronic clock function. The display contents of LED nixie tubes \and bit selection through the pins P2.6 and p 2.7. When P2.6 = I,the segment selection is selected, then the output data through PO connect to \the corresponding display, finally commanding P2.6 = 0 to close the latch; when P2.7 = 1, the bit selection is selected, then the output data through PO connect to six nixie tubes in order to control which one to display, finally commanding P2.7 = 0 to close the latch.That means, segment selection P2.6 achieves the control for the display; while, bit selection P2.7 controls the bit of nixie tubes.

The designed electronic clock program includes two key points: (1) timer settings. The display time of nixie tube is controlled according to the delay time of second hand; (2) counter settings. When the second hand, minute hand counts to 60, respectively, it starts to carry and clear;it starts to clear when the hour hand counts to 24.

The clock control programming can be designed trough two ways: (1) Using delay function controls second hand to count. In the Keil 11 Vision2 software virtual environment, it debugs the delay function and sets the delay parameter just for a second, and then setting the count methods of second hand, minute hand and hour hand. Advantages of this method are simple and easy to understand, easy to implement, a little knowledge points involved; drawback is that some delay error exits during counting time. (2) The internal microcontroller timer counter tImmg. Advantages of this method are time accurate, error small; drawback is difficult to achieve,hard to understand, much knowledge involved. By contrast, the two methods of time-setting having been used demonstrate their advantages and disadvantages in order to provide a theoretical reference for the software design in future. Keil llVision2 software compiler interface is compiled successfully and displayed in Figure 2 (\

- 21 -


基于单片机的电子钟毕业设计安徽工程大学(5).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:农村义务教育社会实践报告

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: