基于51单片机的英文论文

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

the Real-Time Clock Based on AT89S51
Author: Class: ; Name:
Abstract: Digital clock has become indispensable in people's daily life, it is widely used in public places such as the family and the office, and it gives people great convenience in study, work and entertainment. Due to the development of digital integrated circuit technology and the advanced quartz technology, the digital clock has advantages of accurate, stable performance and easy to carry. It is also used in automatic control, automatic signal and etc. Although the digital clocks are already sold on the market, but the single chip microcomputer timer function also can complete the design of the digital clock circuit. So it is necessary to the design of the digital clock. By single chip microcomputer internal timer timing precision, the four digital tube display year, month, day, time, minutes and seconds. With the keyboard, users can be preset time, display the time, set the content, set time operation mode, etc.
Keywords: AT89S51; clock; digital tube; keyboard switch; function Introduction: AT89S51 is a very suitable for the beginners of the single chip microcomputer, it is fully compatible with the traditional instruction system of 8051,8031.
Can realize the following functions:
1. Use the keyboard switch, show respectively the seconds, minutes, hour, day, month, year;
2. Use the keyboard preset year, month, day, time, minutes and seconds;
3. Can the countdown, the countdown units for minutes;
4. Every second , the four decimal point shine once;
5. Timing alarm clock function, a buzzer call reminder.
6. The clock error daily is not more than 1 second.
Methods:
1.The minimum single chip microcomputer system
AT89S51 has the following standard functions: 8 k bytes Flash, 256 bytes RAM, and 32-bit I/O lines, a watchdog timer, two data pointer, three 16 timer/counter, a level 6 vector 2 interrupt structure, full duplex serial port, piece of crystals and the clock circuit . In idle mode, the CPU stops working, allows RAM, timer/counter, serial port and interrupt continue to work. In fall protection mode, RAM content are stored, has been frozen, single chip microcomputer stops all work, until the next interruption or hardware reset.
2.The display
Display uses the method of dynamic LED digital tube to display, P0 port output characters code to display, position codes are controlled by P2.4 ~ P2.7. The cost of the dynamic display is very low, but the dynamic display occupies more resources of the CPU interface. The design uses 12 lines. In addition by the dynamic display refreshing, which takes part of the work time of the CPU. So for some higher demand control system, we should consider the time taken by the display.
3.The keyboard
Keyboard uses 4 * 4 matrix keyboard, by P2.0 ~ P2.3 for row line, P1.4 ~ P1.7 for column line, phalanxes of 4 * 4 are made, and using the method of scanning software can determine the key value of each key. In the design, each key can be used to input data and commands.
4.The power supply
Control power supply can be provided by DC 12V voltage, the power supply can be used by stepping motor driver, at the same time through the three linear stabilizer 7805 to provide other circuit power supply; If you don't need to use stepper motor, the control system of the DC5V power supply can be collected from ordinary USB interface of the computer, as long as the USB connects a computer USB port, the other connects two core power interface of controller.
5.Programming interface
Microprocessor uses AT89S51. AT89S51 has ISP online programming function, and P1.5 ~ P1.7 are for the programming interface and software compilation and debugging includes two processes:
1. By using keil software programming, input source program, and then compile until no grammar mistakes, using compilation command hex into system files(suffix:hex).
2. After connecting the power cord and programming line, start USBASP programming software. Select the chip microprocessors model in the selection of AT89S51. Open and load in the flash. Load in the hex into system files. Use erase commands to erase chip in the original program, with programming command to write new programs in AT89S51. After finished, reset the program running, observing the consequence. If there is any error, it is needed to re-open the Medwin and modify the source program, to create the hex file, and then repeat the above operation, to meet the design requirements.
Results:
Key:
| 1 | 2 | 3 | 分秒|
| 4 | 5 | 6 | 时分|
| 7 | 8 | 9 | 月日|
| 确定| 0 | 倒计时| 年|
#include <reg51.h>
#include<stdio.h>
#define uchar unsigned char
sbit P1_3=P1^3;
sbit P3_2=P3^2;
unsigned char t=0;
unsigned char t1=50;
unsigned char t2=59;
unsigned char t3=23;
unsigned char t4=7;
unsigned char t5=60;
unsigned char t6=60;
unsigned char k1=4;
uchar i;
uchar c;
uchar a[10]={0x81,0xED,0x43,0x49,0x2D,0x19,0x11,0xCD,0x01,0x09};
uchar p[5];
void delay(int MS)
{
int i,j;
for( i=0;i<MS;i++)
for(j=0;j<1141;j++);
}
uchar encoder(uchar num) {
uchar i;
switch(num)
{
case 0x11:
i=0x11;break;
case 0x12:
i=0x12;break;
case 0x14:
i=0x13;break;
case 0x18:
i=0x14;break;
case 0x21:
i=0x15;break;
case 0x22:
i=0x09;break;
case 0x24:
i=0x06;break;
case 0x28:
i=0x03;break;
case 0x41:
i=0x00;break;
case 0x42:
i=0x08;break;
case 0x44:
i=0x05;break;
case 0x48:
i=0x02;break;
case 0x81:
i=0x16;break;
case 0x82:
i=0x07;break;
case 0x84:
i=0x04;break;
case 0x88:
i=0x01;break;
}
return(i);
}
uchar key_value()
{
uchar tem,s,t,n;
P1&=0x0f;
P2|=0x0f;
;
tem=P2;
tem|=0xf0;
s=~tem;
P2&=0xf0;
P1|=0xf0;
;
tem=P1;
tem|=0x0f;
t=~tem;
s=s+t;
n=encoder(s);
return(n);
}
uchar key(void)
{
uchar i;
P2|=0x0f;
P1&=0x0f;
;
i=P2;
i|=0xf0;
i=~i;
return(i);
}
void show1(uchar i,uchar j)
{
P0=a[j];
P2=P2&0x0f;
P2|=1<<(i+3);
}
void show(uchar i,uchar j,uchar k,uchar l)
{
uchar a[10]={0x81,0xED,0x43,0x49,0x2D,0x19,0x11,0xCD,0x01,0x09};
uchar b,c,d,e;
b=a[i];
c=a[j];
d=a[k];
e=a[l];
P2&=0x0f;
P2=0x1f;
P0=b;
delay(1);
P2&=0x0f;
P2=0x2f;
P0=c;
delay(1);
P2=0x4f;
P0=d;
delay(1);
P2=0x8f;
P0=e;
delay(1);
}
void year(void)
{
while(key()==0)
{
show1(4,2);
delay(1);
show1(3,0);
delay(1);
show1(2,1);
delay(1);
show1(1,3);
delay(1);
}
}
void monthday(void) {
TMOD=0X01;
TH0=0x4c;
TR0=1;
IE=0X82;
TMOD=0x01;
while(key()==0)
{
show1(4,0);
delay(1);
show1(3,1);
delay(1);
show1(2,0);
delay(1);
show1(1,t4%10);
delay(1);
}
}
void hourminute(void) {
TMOD=0X01;
TH0=0x4c;
TL0=0x00;
TR0=1;
IE=0X82;
TMOD=0x01;
while(key()==0)
{
show1(4,t3/10);
delay(1);
show1(3,t3%10);
delay(1);
show1(2,t2/10);
delay(1);
show1(1,t2%10);
delay(1);
}
}
void minutesecond() {
TMOD=0X01;
TH0=0x4c;
TL0=0x00;
TR0=1;
IE=0X82;
while(key()==0)
{
show1(4,t2/10);
delay(1);
show1(3,t2%10);
delay(1);
show1(2,t1/10);
delay(1);
show1(1,t1%10);
delay(1);
}
}
void jishi(void)
{
TMOD=0X01;
TH0=0x4c;
TL0=0x00;
TR0=1;
IE=0X82;
TMOD=0x01;
while(key()==0)
{
show1(2,t5/10);
delay(1);
show1(1,t5%10);
delay(1);
}
}
void shuru(void) {
--k1;
if(k1==0)k1=4; while(key()==0)
{
p[k1]=c;
show1(4,c);
delay(1);
}
}
void sure(void)
{
while(key()==0)
{
show(p[1],p[2],p[3],p[4]);
delay(1);
}
}
void timer0(void) interrupt 1 {
t++;
if(t==20)
{
t=0;
t1++;
t5--;
if(t5==0)
{
while(key()==0)
{
show1(2,0);
delay(1);
show1(1,0);
delay(1);
P3_2=~P3_2;
delay(1);
P1_3=~P1_3;
delay(1);
}
}
t6--;
if(t6==0)
{
}
if(t1==60)
{
t1=0;
t2++;
if(t2==60)
{
t2=0;
t3++;
if(t3==24)
{
t3=1;
t4++;
if(t4==30)t4==1;
}
}
}
}
TH0=0x4c;
TL0=0x00;
}
void main()
{
while(1)
{
i=key();
while(i!=0)
{
if(i==key())
{
uchar k;
k=key_value();
c=k;
if(c==0x11)year();
else
if(c==0x12)monthday();
else
if(c==0x13)hourminute();
else
if(c==0x14)minutesecond();
else
if(c==0x15)jishi();
else
if(c==0x16)sure();
else
if(c==0x00||0x01||0x02||0x03||0x04||0x05||0x06||0x07||0x08||0x09) shuru();
else;
}
else
break;
}
}
}
Conclusion: Through the single chip microcomputer can accurately realize the accurate per time, can realize the countdown, display determined year, month, day, hour, minutes, seconds, and some other functions.
Reference:
[1]郭晓林.基于单片机的电子时钟设计[J].中国科技博览,2010,(9).
[2]何立民.单片机应用技术选编(11)[M].北京航天航空大学出版社,2006.
[3]刘守义.单片机应用技术[M].西安电子科技大学出版社,2009.
[4]时钟芯片DS1302中文资料,/info/commonIC/0083003.html。

相关文档
最新文档