基于51单片机的简易电子表
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
基于51单片机的简易电子表
/***************************************************************** 阿斌独家制作:
电子表1602液晶显示带有闹钟功能
每天到指定时间后闹钟提醒闹钟响后按s4键关闭闹钟
如果闹钟响后大约20秒未检测到s4键按下,则闹钟自动关闭
******************************************************************/ 主程序:
#include
#define uchar unsigned char
#define uint unsigned int
sbit lcden=P2^2;
sbit lcdrw=P2^1;
sbit lcdrs=P2^0;
sbit s1=P3^0;
sbit s2=P3^1;
sbit s3=P3^2;
sbit s4=P3^3;
sbit rd=P3^7;
sbit beep=P1^2;
uint nian,a;
uchar count,s1num,i,xq,ri,yue,flag;
char shi,fen,miao,shia,fena,miaoa;
uchar code table[]=" 2012-11-19 MON"; uchar code table1[]=" 00:00:00"; uchar code xq1[]="MON";
uchar code xq2[]="TUE";
uchar code xq3[]="WED";
uchar code xq4[]="THU";
uchar code xq5[]="FRI";
uchar code xq6[]="SA T";
uchar code xq7[]="SUN";
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void didi()
{
beep=1;
delay(5);
beep=0;
delay(5);
beep=1;
delay(5);
beep=0;
delay(5);
}
void write_com(uchar com) {
lcdrs=0;
lcden=0;
lcdrw=0;
P0=com;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void write_date(uchar date) {
lcdrs=1;
lcden=0;
lcdrw=0;
P0=date;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void init()
{
uchar num;
lcden=0;
xq=1;ri=19;yue=11;nian=2012;
a=1000;flag=0;
shia=00;fena=00;miaoa=05;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
write_com(0x80);
for(num=0;num<16;num++)
{
write_date(table[num]);
delay(5);
}
write_com(0x80+0x40);
for(num=0;num<12;num++)
{
write_date(table1[num]);
delay(5);
}
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
}
void write_sfm2(uchar add,uint date) {
uchar qian,bai,shi,ge;
qian=date/1000;
bai=date%1000/100;
shi=date%100/10;
ge=date%10;
write_com(0x80+add);
write_date(0x30+qian);
write_date(0x30+bai);
write_date(0x30+shi);
write_date(0x30+ge);
}
void write_sfm1(uchar add,uchar date) {
uchar shi,ge;
shi=date/10;
ge=date%10;
write_com(0x80+add);
write_date(0x30+shi);
write_date(0x30+ge);
}
void write_sfm(uchar add,uchar date) {
uchar shi,ge;
shi=date/10;
ge=date%10;
write_com(0x80+0x40+add);
write_date(0x30+shi);
write_date(0x30+ge);