//****************************************************************************************************************************
课程设计 : 功能齐全的简易时钟
班级:光电学院104—3班
姓名:陶英健
学号:37
指导老师:王欣欣
设计思想及目的:用C语言编写时钟代码,然后下载到51单片机上,用1602液晶屏实现年、月、日、星期、时、分、秒的可调简易时钟。
//***********************************************************************************************************************************
#include
#define uchar unsigned char
#define uint unsigned int
uchar code table[]=" 2000-01-01 MON";
uchar code table1[]=" 00:00:00";
uchar code table2[]={"MONTUEWEDTHUFRISATSUN"};
sbit en=P2^7;
sbit rs=P2^5;
sbit rw=P2^6;
sbit s1=P3^2;
sbit s2=P3^3;
sbit s3=P3^4;
uchar count,num,keynum;
char shi,fen,miao,nian,yue,ri,week;
//延时程序
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
//1602写指令
void write1(uchar com)
{
rs=0;
rw=0;
P0=com;
delay(5);
en=1;
delay(5);
en=0;
}
//1602写程序
void write2(uchar dat)
{
rs=1;
rw=0;
P0=dat;
delay(5);
en=1;
delay(5);
en=0;
}
void sfm(uchar add,uchar dat)
{
uchar s,g;
s=dat/10;
g=dat%10;
write1(0x80+0x40+add);
write2(0x30+s);
write2(0x30+g);
}
void nyr(uchar add,uchar dat)
{
uchar s,g;
s=dat/10;
g=dat%10;
write1(0x80+add);
write2(0x30+s);
write2(0x30+g);
}
//按键控制程序
void contorl()
{
if(s1==0)
{
delay(10);
if(s1==0)
{
keynum++;
while(!s1);
delay(5);
while(!s1);
if(keynum==1)
{
TR0=0;
write1(0x80+0x40+9);
write1(0x0f);
}
if(keynum==2)
write1(0x80+0x40+6);
if(keynum==3)
write1(0x80+0x40+3);
if(keynum==4)
write1(0x80+9);
if(keynum==5)
write1(0x80+6);
if(keynum==6)
write1(0x80+3);
if(keynum==7)
write1(0x80+12);
if(keynum==8)
{
keynum=0;
write1(0x0c);
TR0=1;
}
}
}
if(keynum!=0)
{
if(s2==0)
{delay(5);
if(s2==0)
{
while(!s2);
if(keynum==1)
{
miao++;
if(miao==60)
miao=0;
sfm(9,miao);
write1(0x80+0x40+9);
}
if(keynum==2)
{
fen++;
if(fen==60)
fen=0;
write1(0x80+0x40+6);
sfm(6,fen);
}
if(keynum==3)
{
shi++;
if(shi==24)
shi=0;
write1(0x80+0x40+3);
sfm(3,shi);
}
if(keynum==4)
{
ri++;
if(ri==31)
ri=0;
write1(0x80+9);
nyr(9,ri);
}
if(keynum==5)
{
yue++;
if(yue==
13)
yue=1;
write1(0x80+6);
nyr(6,yue);
}
if(keynum==6)
{
nian++;
if(nian==100)
nian=0;
write1(0x80+3);
nyr(3,nian);
}
if(keynum==7)