专家
公告
财富商城
电子网
旗下网站
首页
问题库
专栏
标签库
话题
专家
NEW
门户
发布
提问题
发文章
51单片机
急求!!关于DS12C887的数字钟设计不能修改时间的问题
2019-07-15 17:21
发布
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
站内问答
/
51单片机
11879
3
1482
附件是程序和问题截图,求大神指教!
程序2.rar
下载积分: 积分 -1 分
9.76 KB, 下载次数: 12, 下载积分: 积分 -1 分
友情提示:
此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
3条回答
203110922
2019-07-15 23:59
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit rs=P1^3;//液晶数据命令选择断
sbit lcden=P3^4;//液晶使能端
sbit s1=P2^4;//功能键
sbit s2=P2^5;//增大键
sbit s3=P2^6;//减小键
sbit beep=P1^2;//蜂鸣器
sbit dscs=P1^4;//芯片片选端
sbit dsas=P1^5;//地址选通输入端
sbit dsrw=P1^6;//写允许输入
sbit dsds=P1^7;//读允许输入
sbit dsirq=P3^3;//终端请求输出
uchar count,s1num,flag;
bit flag1;
char miao,shi,fen,nian,yue,ri,week;
uchar code table[]=" 20 - - ";//液晶固定显示
uchar code table1[]=" : : ";
uchar code table2[]=" Hello everyone!";
uchar code table3[]="Nice to meet you!";
void write_ds(uchar,uchar);
void set_alarm(uchar,uchar,uchar);
uchar read_ds(uchar);void set_time();
uchar amiao,ashi,afen;
void delay(uint z)//延时函数
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void di()//按键时蜂鸣器发音
{
beep=0;
delay(100);
beep=1;
}
void didi() //闹钟时蜂鸣器发音
{
beep=0;
delay(50);
beep=1;
delay(100);
beep=0;
delay(50);
beep=1;
}
void write_com(uchar com)//写液晶命令函数
{
rs=0;
lcden=0;
P0=com;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void write_date(uchar date)//写液晶具体数据函数
{
rs=1;
lcden=0;
P0=date;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void init()//程序初始化
{
uchar num;
EA=1;//打开总中断
EX1=1;//开外部中断1
IT1=1;//设置负跳变沿触发方式
lcden=0;
week=1;
// set_time();//给DS12C887设置时间函数
set_alarm(2,2,10);//设置闹铃函数
write_ds(0x0B,0x26);//设置DS12C887 24小时模式
write_com(0x38);//1602液晶初始化
write_com(0x0c);
write_com(0x06);
write_com(0x01);
write_com(0x80);//定位数据指针第一行第一列
for(num=0;num<16;num++)//写入液晶平移内容
{
write_date(table2[num]);
delay(5);
}
write_com(0x80+0x40);
for(num=0;num<16;num++)
{
write_date(table3[num]);
delay(5);
}
write_com(0x80+0x10);//写入液晶固定内容
for(num=0;num<16;num++)
{
write_date(table[num]);
delay(5);
}
write_com(0x80+0x50);
for(num=0;num<16;num++)
{
write_date(table1[num]);
delay(5);
}
}
void write_sfm(uchar add,uchar date)//在液晶上写入时分秒
{
uchar shi,ge;
shi=date/10;
ge=date%10;
write_com(0x80+0x50+add);
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+0x10+add);
write_date(0x30+shi);
write_date(0x30+ge);
}
void write_week(uchar we)//星期函数
{
write_com(0x80+0x10+13);
switch(we)
{
case 1:
write_date('M');delay(5);
write_date('O');delay(5);
write_date('N');
break;
case 2:
write_date('T');delay(5);
write_date('U');delay(5);
write_date('E');
break;
case 3:
write_date('W');delay(5);
write_date('E');delay(5);
write_date('D');
break;
case 4:
write_date('T');delay(5);
write_date('H');delay(5);
write_date('U');
break;
case 5:
write_date('F');delay(5);
write_date('R');delay(5);
write_date('I');
break;
case 6:
write_date('S');delay(5);
write_date('A');delay(5);
write_date('T');
break;
case 7:
write_date('S');delay(5);
write_date('U');delay(5);
write_date('N');
break;
}
}
void keyscan()
{
if(flag1==1)//闹铃响
{
if(s2==0)
{
delay(5);
if(s2==0)
{
while(!s2);
di();
flag1=0;//中断闹铃
}
}
if(s3==0)
{
delay(5);
if(s3==0)
{
while(!s3);
di();
flag1=0;//中断闹铃
}
}
}
if(s1==0)
{
delay(5);
if(s1==0)
{ s1num++;
flag=1;
flag1=0;
while(!s1);
di();
if(s1num==1)
{
write_com(0x80+0x50+10);
write_com(0x0f);//光标停止位置不断闪烁
}
if(s1num==2)
{
write_com(0x80+0x50+7);
}
if(s1num==3)
{
write_com(0x80+0x50+4);
}
if(s1num==4)
{
write_com(0x80+0x10+13);
}
if(s1num==5)
{
write_com(0x80+0x10+10);
}
if(s1num==6)
{
write_com(0x80+0x10+7);
}
if(s1num==7)
{
write_com(0x80+0x10+4);
}
if(s1num==8)
{
s1num=0;
write_com(0x0c);//光标停止闪烁
write_ds(0,miao);//将此时时间信息写入DS12C887
write_ds(2,fen);
write_ds(4,shi);
write_ds(6,week);
write_ds(7,ri);
write_ds(8,yue);
write_ds(9,nian);
miao=read_ds(0);//平移时从时钟芯片中读取时间
fen=read_ds(2);
shi=read_ds(4);
week=read_ds(6);
ri=read_ds(7);
yue=read_ds(8);
nian=read_ds(9);
write_sfm(10,miao);//平移时将读取的时间写到液晶
write_sfm(7,fen);
write_sfm(4,shi);
write_week(week);
write_sfm1(10,ri);
write_sfm1(7,yue);
write_sfm1(4,nian);
flag=0;
}
}
}
if(s1num!=0)
{
if(s2==0)
{
delay(1);
if(s2==0)
{
while(!s2);
di();
if(s1num==1)
{
miao++;
if(miao==60)
miao=0;
write_sfm(10,miao);//将变化后的时间写入液晶
write_com(0x80+0x50+10);
}
if(s1num==2)
{
fen++;
if(fen==60)
fen=0;
write_sfm(7,fen);
write_com(0x80+0x50+7);
}
if(s1num==3)
{
shi++;
if(shi==24)
shi=0;
write_sfm(4,shi);
write_com(0x80+0x50+4);
}
if(s1num==4)
{
week++;
if(week==8)
week=1;
write_week(week);
write_com(0x80+0x10+13);
}
if(s1num==5)
{
ri++;
if(ri==32)
ri=1;
write_sfm1(10,ri);
write_com(0x80+0x10+10);
}
if(s1num==6)
{
yue++;
if(yue==13)
yue=1;
write_sfm1(7,yue);
write_com(0x80+0x10+7);
}
if(s1num==7)
{
nian++;
if(nian==100)
nian=0;
write_sfm1(4,nian);
write_com(0x80+0x10+4);
}
}
}
if(s3==0)
{
delay(1);
if(s3==0)
{
while(!s3);
di();
if(s1num==1)
{
miao--;
if(miao==-1)
miao=59;
write_sfm(10,miao);
write_com(0x80+0x50+10);
}
if(s1num==2)
{
fen--;
if(fen==-1)
fen=59;
write_sfm(7,fen);
write_com(0x80+0x50+7);
}
if(s1num==3)
{
shi--;
if(shi==-1)
shi=23;
write_sfm(4,shi);
write_com(0x80+0x50+4);
}
if(s1num==4)
{
week--;
if(week==0)
week=7;
write_week(week);
write_com(0x80+0x10+13);
}
if(s1num==5)
{
ri--;
if(ri==0)
ri=31;
write_sfm1(10,ri);
write_com(0x80+0x10+10);
}
if(s1num==6)
{
yue--;
if(yue==0)
yue=12;
write_sfm1(7,yue);
write_com(0x80+0x10+7);
}
if(s1num==7)
{
nian--;
if(nian==-1)
yue=99;
write_sfm1(4,nian);
write_com(0x80+0x10+4);
}
}
}
}
}
void write_ds(uchar add,uchar date)// DS12C887写入程序函数
{
dscs=0;
dsas=1;
dsds=1;
dsrw=1;
P0=add;
dsas=0;
dsrw=0;
P0=date;
dsrw=1;
dsas=1;
dscs=1;
}
uchar read_ds(uchar add)//从DS12C887中读取数据
{
uchar ds_date;
dsas=1;
dsds=1;
dsrw=1;
dscs=0;
P0=add;
dsas=0;
dsds=0;
P0=0xff;
ds_date=P0;
dsds=1;
dsas=1;
dscs=1;
return ds_date;
}
void set_time()//设置时间
{
write_ds(4,1);//小时
write_ds(2,2);//分钟
write_ds(6,3);//星期
write_ds(7,4);//日
write_ds(8,5);//月
write_ds(9,6);//年
}
void set_alarm(uchar ashi,uchar afen,uchar amiao)//设置闹铃
{
write_ds(1,amiao);
write_ds(3,afen);
write_ds(5,ashi);
}
void main()
{
uchar num,bo=0;
init();
delay(4000);
for(num=0;num<16;num++)
{
{
write_com(0x18);//1602平移函数
delay(600);
}
keyscan();//按键检测
if(flag1==1)
didi();
if(flag==0)
{
miao=read_ds(0);//平移时从时钟芯片中读取时间
fen=read_ds(2);
shi=read_ds(4);
week=read_ds(6);
ri=read_ds(7);
yue=read_ds(8);
nian=read_ds(9);
write_sfm(10,miao);//平移时将读取的时间写到液晶
write_sfm(7,fen);
write_sfm(4,shi);
write_week(week);
write_sfm1(10,ri);
write_sfm1(7,yue);
write_sfm1(4,nian);
}
}
while(1)
{
keyscan();
if(flag1==1)
didi();
if(flag==0)
{
miao=read_ds(0);//读取数据
fen=read_ds(2);
shi=read_ds(4);
week=read_ds(6);
ri=read_ds(7);
yue=read_ds(8);
nian=read_ds(9);
write_sfm(10,miao);//写入数据
write_sfm(7,fen);
write_sfm(4,shi);
write_week(week);
write_sfm1(10,ri);
write_sfm1(7,yue);
write_sfm1(4,nian);
}
}
}
void exter() interrupt 2
{ uchar c;
flag1=1;
c=read_ds(0x0c);
}
附件是这个程序
加载中...
查看其它3个回答
一周热门
更多
>
相关问题
【东软载波ESF0654 PDS开发板活动】开箱
1 个回答
东软载波ESF0654 PDS开发板外部中断
1 个回答
东软载波ESF0654 PDS开发板高级控制定时器AD16C4T
1 个回答
用串口调试助手为什么只能在hex模式接收发送而在文本模式不行
9 个回答
触摸芯片SC02B/SC04B在地砖灯的设计方案
1 个回答
相关文章
51单片机与蓝牙模块连接
0个评论
51单片机的硬件结构
0个评论
基于51单片机的无线遥控器制作
0个评论
51单片机 AD转换
0个评论
51单片机数码管递增显示
0个评论
如何实现对单片机寄存器的访问
0个评论
基于51单片机的指纹密码锁
0个评论
×
关闭
采纳回答
向帮助了您的知道网友说句感谢的话吧!
非常感谢!
确 认
×
关闭
编辑标签
最多设置5个标签!
51单片机
保存
关闭
×
关闭
举报内容
检举类型
检举内容
检举用户
检举原因
广告推广
恶意灌水
回答内容与提问无关
抄袭答案
其他
检举说明(必填)
提交
关闭
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
×
付费偷看金额在0.1-10元之间
确定
×
关闭
您已邀请
0
人回答
查看邀请
擅长该话题的人
回答过该话题的人
我关注的人
#define uchar unsigned char
#define uint unsigned int
sbit rs=P1^3;//液晶数据命令选择断
sbit lcden=P3^4;//液晶使能端
sbit s1=P2^4;//功能键
sbit s2=P2^5;//增大键
sbit s3=P2^6;//减小键
sbit beep=P1^2;//蜂鸣器
sbit dscs=P1^4;//芯片片选端
sbit dsas=P1^5;//地址选通输入端
sbit dsrw=P1^6;//写允许输入
sbit dsds=P1^7;//读允许输入
sbit dsirq=P3^3;//终端请求输出
uchar count,s1num,flag;
bit flag1;
char miao,shi,fen,nian,yue,ri,week;
uchar code table[]=" 20 - - ";//液晶固定显示
uchar code table1[]=" : : ";
uchar code table2[]=" Hello everyone!";
uchar code table3[]="Nice to meet you!";
void write_ds(uchar,uchar);
void set_alarm(uchar,uchar,uchar);
uchar read_ds(uchar);void set_time();
uchar amiao,ashi,afen;
void delay(uint z)//延时函数
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void di()//按键时蜂鸣器发音
{
beep=0;
delay(100);
beep=1;
}
void didi() //闹钟时蜂鸣器发音
{
beep=0;
delay(50);
beep=1;
delay(100);
beep=0;
delay(50);
beep=1;
}
void write_com(uchar com)//写液晶命令函数
{
rs=0;
lcden=0;
P0=com;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void write_date(uchar date)//写液晶具体数据函数
{
rs=1;
lcden=0;
P0=date;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void init()//程序初始化
{
uchar num;
EA=1;//打开总中断
EX1=1;//开外部中断1
IT1=1;//设置负跳变沿触发方式
lcden=0;
week=1;
// set_time();//给DS12C887设置时间函数
set_alarm(2,2,10);//设置闹铃函数
write_ds(0x0B,0x26);//设置DS12C887 24小时模式
write_com(0x38);//1602液晶初始化
write_com(0x0c);
write_com(0x06);
write_com(0x01);
write_com(0x80);//定位数据指针第一行第一列
for(num=0;num<16;num++)//写入液晶平移内容
{
write_date(table2[num]);
delay(5);
}
write_com(0x80+0x40);
for(num=0;num<16;num++)
{
write_date(table3[num]);
delay(5);
}
write_com(0x80+0x10);//写入液晶固定内容
for(num=0;num<16;num++)
{
write_date(table[num]);
delay(5);
}
write_com(0x80+0x50);
for(num=0;num<16;num++)
{
write_date(table1[num]);
delay(5);
}
}
void write_sfm(uchar add,uchar date)//在液晶上写入时分秒
{
uchar shi,ge;
shi=date/10;
ge=date%10;
write_com(0x80+0x50+add);
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+0x10+add);
write_date(0x30+shi);
write_date(0x30+ge);
}
void write_week(uchar we)//星期函数
{
write_com(0x80+0x10+13);
switch(we)
{
case 1:
write_date('M');delay(5);
write_date('O');delay(5);
write_date('N');
break;
case 2:
write_date('T');delay(5);
write_date('U');delay(5);
write_date('E');
break;
case 3:
write_date('W');delay(5);
write_date('E');delay(5);
write_date('D');
break;
case 4:
write_date('T');delay(5);
write_date('H');delay(5);
write_date('U');
break;
case 5:
write_date('F');delay(5);
write_date('R');delay(5);
write_date('I');
break;
case 6:
write_date('S');delay(5);
write_date('A');delay(5);
write_date('T');
break;
case 7:
write_date('S');delay(5);
write_date('U');delay(5);
write_date('N');
break;
}
}
void keyscan()
{
if(flag1==1)//闹铃响
{
if(s2==0)
{
delay(5);
if(s2==0)
{
while(!s2);
di();
flag1=0;//中断闹铃
}
}
if(s3==0)
{
delay(5);
if(s3==0)
{
while(!s3);
di();
flag1=0;//中断闹铃
}
}
}
if(s1==0)
{
delay(5);
if(s1==0)
{ s1num++;
flag=1;
flag1=0;
while(!s1);
di();
if(s1num==1)
{
write_com(0x80+0x50+10);
write_com(0x0f);//光标停止位置不断闪烁
}
if(s1num==2)
{
write_com(0x80+0x50+7);
}
if(s1num==3)
{
write_com(0x80+0x50+4);
}
if(s1num==4)
{
write_com(0x80+0x10+13);
}
if(s1num==5)
{
write_com(0x80+0x10+10);
}
if(s1num==6)
{
write_com(0x80+0x10+7);
}
if(s1num==7)
{
write_com(0x80+0x10+4);
}
if(s1num==8)
{
s1num=0;
write_com(0x0c);//光标停止闪烁
write_ds(0,miao);//将此时时间信息写入DS12C887
write_ds(2,fen);
write_ds(4,shi);
write_ds(6,week);
write_ds(7,ri);
write_ds(8,yue);
write_ds(9,nian);
miao=read_ds(0);//平移时从时钟芯片中读取时间
fen=read_ds(2);
shi=read_ds(4);
week=read_ds(6);
ri=read_ds(7);
yue=read_ds(8);
nian=read_ds(9);
write_sfm(10,miao);//平移时将读取的时间写到液晶
write_sfm(7,fen);
write_sfm(4,shi);
write_week(week);
write_sfm1(10,ri);
write_sfm1(7,yue);
write_sfm1(4,nian);
flag=0;
}
}
}
if(s1num!=0)
{
if(s2==0)
{
delay(1);
if(s2==0)
{
while(!s2);
di();
if(s1num==1)
{
miao++;
if(miao==60)
miao=0;
write_sfm(10,miao);//将变化后的时间写入液晶
write_com(0x80+0x50+10);
}
if(s1num==2)
{
fen++;
if(fen==60)
fen=0;
write_sfm(7,fen);
write_com(0x80+0x50+7);
}
if(s1num==3)
{
shi++;
if(shi==24)
shi=0;
write_sfm(4,shi);
write_com(0x80+0x50+4);
}
if(s1num==4)
{
week++;
if(week==8)
week=1;
write_week(week);
write_com(0x80+0x10+13);
}
if(s1num==5)
{
ri++;
if(ri==32)
ri=1;
write_sfm1(10,ri);
write_com(0x80+0x10+10);
}
if(s1num==6)
{
yue++;
if(yue==13)
yue=1;
write_sfm1(7,yue);
write_com(0x80+0x10+7);
}
if(s1num==7)
{
nian++;
if(nian==100)
nian=0;
write_sfm1(4,nian);
write_com(0x80+0x10+4);
}
}
}
if(s3==0)
{
delay(1);
if(s3==0)
{
while(!s3);
di();
if(s1num==1)
{
miao--;
if(miao==-1)
miao=59;
write_sfm(10,miao);
write_com(0x80+0x50+10);
}
if(s1num==2)
{
fen--;
if(fen==-1)
fen=59;
write_sfm(7,fen);
write_com(0x80+0x50+7);
}
if(s1num==3)
{
shi--;
if(shi==-1)
shi=23;
write_sfm(4,shi);
write_com(0x80+0x50+4);
}
if(s1num==4)
{
week--;
if(week==0)
week=7;
write_week(week);
write_com(0x80+0x10+13);
}
if(s1num==5)
{
ri--;
if(ri==0)
ri=31;
write_sfm1(10,ri);
write_com(0x80+0x10+10);
}
if(s1num==6)
{
yue--;
if(yue==0)
yue=12;
write_sfm1(7,yue);
write_com(0x80+0x10+7);
}
if(s1num==7)
{
nian--;
if(nian==-1)
yue=99;
write_sfm1(4,nian);
write_com(0x80+0x10+4);
}
}
}
}
}
void write_ds(uchar add,uchar date)// DS12C887写入程序函数
{
dscs=0;
dsas=1;
dsds=1;
dsrw=1;
P0=add;
dsas=0;
dsrw=0;
P0=date;
dsrw=1;
dsas=1;
dscs=1;
}
uchar read_ds(uchar add)//从DS12C887中读取数据
{
uchar ds_date;
dsas=1;
dsds=1;
dsrw=1;
dscs=0;
P0=add;
dsas=0;
dsds=0;
P0=0xff;
ds_date=P0;
dsds=1;
dsas=1;
dscs=1;
return ds_date;
}
void set_time()//设置时间
{
write_ds(4,1);//小时
write_ds(2,2);//分钟
write_ds(6,3);//星期
write_ds(7,4);//日
write_ds(8,5);//月
write_ds(9,6);//年
}
void set_alarm(uchar ashi,uchar afen,uchar amiao)//设置闹铃
{
write_ds(1,amiao);
write_ds(3,afen);
write_ds(5,ashi);
}
void main()
{
uchar num,bo=0;
init();
delay(4000);
for(num=0;num<16;num++)
{
{
write_com(0x18);//1602平移函数
delay(600);
}
keyscan();//按键检测
if(flag1==1)
didi();
if(flag==0)
{
miao=read_ds(0);//平移时从时钟芯片中读取时间
fen=read_ds(2);
shi=read_ds(4);
week=read_ds(6);
ri=read_ds(7);
yue=read_ds(8);
nian=read_ds(9);
write_sfm(10,miao);//平移时将读取的时间写到液晶
write_sfm(7,fen);
write_sfm(4,shi);
write_week(week);
write_sfm1(10,ri);
write_sfm1(7,yue);
write_sfm1(4,nian);
}
}
while(1)
{
keyscan();
if(flag1==1)
didi();
if(flag==0)
{
miao=read_ds(0);//读取数据
fen=read_ds(2);
shi=read_ds(4);
week=read_ds(6);
ri=read_ds(7);
yue=read_ds(8);
nian=read_ds(9);
write_sfm(10,miao);//写入数据
write_sfm(7,fen);
write_sfm(4,shi);
write_week(week);
write_sfm1(10,ri);
write_sfm1(7,yue);
write_sfm1(4,nian);
}
}
}
void exter() interrupt 2
{ uchar c;
flag1=1;
c=read_ds(0x0c);
}
附件是这个程序
一周热门 更多>