专家
公告
财富商城
电子网
旗下网站
首页
问题库
专栏
标签库
话题
专家
NEW
门户
发布
提问题
发文章
有关用DS12C887制作时钟的问题,自学的孩子伤不起啊~
2019-03-24 19:34
发布
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
站内问答
/
51单片机
11638
3
1133
时钟编完之后,送显示屏时间走的过程中会出现和0跳变,但不影响时间,比如:1 2 3 0 5 6 7 8 0 10 11 0 13.········这是为什么啊??? 此帖出自
小平头技术问答
友情提示:
此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
3条回答
孤獨の快樂
1楼-- · 2019-03-24 21:27
这跳变是随机的吗?
加载中...
yangyangshuai10
2楼-- · 2019-03-24 22:58
貌似是随机的 看不出什么规律。。。。
加载中...
yangyangshuai10
3楼-- · 2019-03-25 00:54
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit RS=P2^1;
sbit RW=P1^5;
sbit E=P1^6;
sbit dula=P2^6;
sbit wela=P2^7;
sbit key=P3^1;
sbit s6=P3^6;
sbit s7=P3^7;
sbit s5=P3^5;
sbit CSDS=P1^4;
sbit ASDS=P1^3;
sbit RWDS=P1^1;
sbit DSDS=P1^7;
sbit SPK=P1^2;
sbit IRQ=P3^2;
uchar num,num1,num2,keynum,flag,n,m,k;
char shi,fen,miao,nian,yue,ri,week;
uchar code table[]={"20 / / "};
uchar code table1[]={" : : "};
uchar code table2[]={"MONTUEWENTHUFRISATSUN"};
uchar code table3[]={"SUNSATFRITHUWENTUEMON"};
void set_time();
void write_ds(uchar,uchar);
void naozhongsfm(uchar,uchar,uchar);
uchar read_ds(uchar);
void delay(uchar z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void write_com(uchar com)
{ delay(5);
E=0;
RS=0;
RW=0;
delay(5);
E=1;
P0=com;
delay(5);
E=0;
}
void write_date(uchar date)
{ delay(5);
E=0;
RS=1;
RW=0;
delay(5);
E=1;
P0=date;
E=0;
}
void write_sfm(uchar add,uchar date)
{
uchar si,ge;
si=date/10;
ge=date%10;
write_com(0x80+0x40+add);
write_date(0x30+si);
write_date(0x30+ge);
}
void keys()
{ key=0;
if(s6==0)
{
delay(1);
if(s6==0)
{ keynum++;
flag=1;
SPK=0;
while(!s6);
if(keynum==1)
{
write_com(0x80+0x40+6);
write_com(0x0f);
}
}
if(keynum==2)
{
write_com(0x80+0x40+3);
}
if(keynum==3)
{
write_com(0x80+0x40);
}
if(keynum==4)
{
write_com(0x80+2);
}
if(keynum==5)
{
write_com(0x80+5);
}
if(keynum==6)
{
write_com(0x80+8);
}
if(keynum==7)
{
write_com(0x80+11);
}
if(keynum==8)
{
keynum=0;
flag=0;
write_com(0x0c);
write_ds(0,miao);
write_ds(2,fen);
write_ds(4,shi);
m=week+3;
k=m/3-1;
write_ds(6,k);
write_ds(8,yue);
write_ds(9,nian);
write_ds(7,ri);
}
}
if(keynum!=0)
{
if(s7==0)
{
delay(5);
if(s7==0)
{
while(!s7);
if(keynum==1)
{
miao++;
if(miao==60)
{
miao=0;
}
write_com(0x80+0x40+6);
write_sfm(6,miao);
write_com(0x80+0x40+6);
}
if(keynum==2)
{
fen++;
if(fen==60)
{
fen=0;
}
write_com(0x80+0x40+3);
write_sfm(3,fen);
write_com(0x80+0x40+3);
}
if(keynum==3)
{
shi++;
if(shi==24)
{
shi=0;
}
write_com(0x80+0x40);
write_sfm(0,shi);
write_com(0x80+0x40);
}
if(keynum==4)
{
nian++;
if(nian==100)
{
nian=0;
}
write_com(0x80+2);
write_sfm(-0x40+2,nian);
write_com(0x80+2);
}
if(keynum==5)
{
yue++;
if(yue==13)
{
yue=1;
}
write_com(0x80+5);
write_sfm(-0x40+5,yue);
write_com(0x80+5);
}
if(keynum==6)
{
ri++;
if(ri==32)
{
ri=1;
}
write_com(0x80+8);
write_sfm(-0x40+8,ri);
write_com(0x80+8);
}
if(keynum==7)
{
if(week==21)
{
week=0;
}
write_com(0x80+11);
for(num2=0;num2<3;num2++)
{
write_date(table2[week]);
week++;
delay(5);
}
write_com(0x80+11);
}
if(keynum==8)
{
write_com(0x0c);
keynum=0;
}
}
}
if(s5==0)
{
delay(5);
if(s5==0)
{
while(!s5);
if(keynum==1)
{
miao--;
if(miao==-1)
{
miao=59;
}
write_sfm(6,miao);
write_com(0x80+0x40+6);
}
if(keynum==2)
{
fen--;
if(fen==-1)
{
fen=59;
}
write_sfm(3,fen);
write_com(0x80+0x40+3);
}
if(keynum==3)
{
shi--;
if(shi==-1)
{
shi=23;
}
write_sfm(0,shi);
write_com(0x80+0x40);
}
if(keynum==4)
{
nian--;
if(nian==-1)
{
nian=99;
}
write_sfm(-0x40+2,nian);
write_com(0x80+2);
}
if(keynum==5)
{
yue--;
if(yue==-1)
{
yue=12;
}
write_sfm(-0x40+5,yue);
write_com(0x80+5);
}
if(keynum==6)
{
ri--;
if(ri==-1)
{
ri=30;
}
write_sfm(-0x40+8,ri);
write_com(0x80+8);
}
if(keynum==7)
{
if(week==21)
{
week=0;
}
write_com(0x80+11);
for(num2=0;num2<3;num2++)
{
write_date(table3[week]);
week++;
delay(5);
}
write_com(0x80+11);
}
}
}
}
}
void init()
{
SPK=0;
EA=1;
EX0=1;
IT0=1;
week=0;
keynum=0;
dula=0;
wela=0;
E=0;
write_ds(11,0x26); //寄存器B设置返回值BCD形式并开启闹钟
// write_ds(12,0x00); //寄存器C设置中断 2
// write_ds(10,0xa0); //寄存器A设置
naozhongsfm(16,41,15);
read_ds(12);
// miao=45;
// shi=23;
// fen=59;
write_com(0x38);
write_com(0x06);
write_com(0x0c);
write_com(0x80);
for(num=0;num<14;num++)
{
write_date(table[num]);
delay(5);
}
write_com(0x80+0x40);
for(num=0;num<8;num++)
{
write_date(table1[num]);
delay(5);
}
}
void write_ds(uchar add,uchar date)
{
ASDS=1;
DSDS=1;
RWDS=1;
CSDS=0;
P0=add;
ASDS=0;
RWDS=0;
P0=date;
RWDS=1;
ASDS=1;
CSDS=1;
}
uchar read_ds(uchar add)
{
uchar ds_date;
ASDS=1;
DSDS=1;
RWDS=1;
CSDS=0;
P0=add;
ASDS=0;
DSDS=0;
P0=0xff; //P0清1
ds_date=P0;
DSDS=1;
ASDS=1;
CSDS=1;
return ds_date;
}
void naozhongsfm(uchar ashi,uchar afen,uchar amiao)
{ write_ds(5,ashi);
write_ds(3,afen);
write_ds(1,amiao); //闹钟时间设置
}
void main()
{ init();
while(1)
{ keys();
if(flag==0)
{
//write_ds(9,11); //初始化
//write_ds(8,11);
//write_ds(7,18);
//write_ds(6,5);
//write_ds(4,21);
//write_ds(2,9);
//write_ds(0,0);
miao=read_ds(0); //读时间
fen=read_ds(2);
shi=read_ds(4);
nian=read_ds(9);
yue=read_ds(8);
n=read_ds(6);
week=n*3-3; //读星期
ri=read_ds(7);
write_sfm(6,miao); //送显示屏
write_sfm(3,fen);
write_sfm(0,shi);
write_com(0x80+11);
for(num2=0;num2<3;num2++)
{
write_date(table2[week]);
week++;
delay(1);
}
write_sfm(-0x40+5,yue);
write_sfm(-0x40+2,nian);
write_sfm(-0x40+8,ri);
}
}
}
void exter() interrupt 0
{ uchar c;
SPK=1;
c=read_ds(12);
}
加载中...
一周热门
更多
>
相关问题
相关文章
基于51单片机的计算器设计
0个评论
51单片机300个proteus仿真实例下载
0个评论
51单片机 蜂鸣器
0个评论
51单片机驱动RC522模块
0个评论
基于51单片机的指纹密码锁
0个评论
AT89C51单片机制作简易密码锁
0个评论
51单片机汇编语言计数器
0个评论
51单片机精确延时设计
0个评论
×
关闭
采纳回答
向帮助了您的网友说句感谢的话吧!
非常感谢!
确 认
×
关闭
编辑标签
最多设置5个标签!
保存
关闭
×
关闭
举报内容
检举类型
检举内容
检举用户
检举原因
广告推广
恶意灌水
回答内容与提问无关
抄袭答案
其他
检举说明(必填)
提交
关闭
×
关闭
您已邀请
15
人回答
查看邀请
擅长该话题的人
回答过该话题的人
我关注的人
这跳变是随机的吗?
#define uchar unsigned char
#define uint unsigned int
sbit RS=P2^1;
sbit RW=P1^5;
sbit E=P1^6;
sbit dula=P2^6;
sbit wela=P2^7;
sbit key=P3^1;
sbit s6=P3^6;
sbit s7=P3^7;
sbit s5=P3^5;
sbit CSDS=P1^4;
sbit ASDS=P1^3;
sbit RWDS=P1^1;
sbit DSDS=P1^7;
sbit SPK=P1^2;
sbit IRQ=P3^2;
uchar num,num1,num2,keynum,flag,n,m,k;
char shi,fen,miao,nian,yue,ri,week;
uchar code table[]={"20 / / "};
uchar code table1[]={" : : "};
uchar code table2[]={"MONTUEWENTHUFRISATSUN"};
uchar code table3[]={"SUNSATFRITHUWENTUEMON"};
void set_time();
void write_ds(uchar,uchar);
void naozhongsfm(uchar,uchar,uchar);
uchar read_ds(uchar);
void delay(uchar z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void write_com(uchar com)
{ delay(5);
E=0;
RS=0;
RW=0;
delay(5);
E=1;
P0=com;
delay(5);
E=0;
}
void write_date(uchar date)
{ delay(5);
E=0;
RS=1;
RW=0;
delay(5);
E=1;
P0=date;
E=0;
}
void write_sfm(uchar add,uchar date)
{
uchar si,ge;
si=date/10;
ge=date%10;
write_com(0x80+0x40+add);
write_date(0x30+si);
write_date(0x30+ge);
}
void keys()
{ key=0;
if(s6==0)
{
delay(1);
if(s6==0)
{ keynum++;
flag=1;
SPK=0;
while(!s6);
if(keynum==1)
{
write_com(0x80+0x40+6);
write_com(0x0f);
}
}
if(keynum==2)
{
write_com(0x80+0x40+3);
}
if(keynum==3)
{
write_com(0x80+0x40);
}
if(keynum==4)
{
write_com(0x80+2);
}
if(keynum==5)
{
write_com(0x80+5);
}
if(keynum==6)
{
write_com(0x80+8);
}
if(keynum==7)
{
write_com(0x80+11);
}
if(keynum==8)
{
keynum=0;
flag=0;
write_com(0x0c);
write_ds(0,miao);
write_ds(2,fen);
write_ds(4,shi);
m=week+3;
k=m/3-1;
write_ds(6,k);
write_ds(8,yue);
write_ds(9,nian);
write_ds(7,ri);
}
}
if(keynum!=0)
{
if(s7==0)
{
delay(5);
if(s7==0)
{
while(!s7);
if(keynum==1)
{
miao++;
if(miao==60)
{
miao=0;
}
write_com(0x80+0x40+6);
write_sfm(6,miao);
write_com(0x80+0x40+6);
}
if(keynum==2)
{
fen++;
if(fen==60)
{
fen=0;
}
write_com(0x80+0x40+3);
write_sfm(3,fen);
write_com(0x80+0x40+3);
}
if(keynum==3)
{
shi++;
if(shi==24)
{
shi=0;
}
write_com(0x80+0x40);
write_sfm(0,shi);
write_com(0x80+0x40);
}
if(keynum==4)
{
nian++;
if(nian==100)
{
nian=0;
}
write_com(0x80+2);
write_sfm(-0x40+2,nian);
write_com(0x80+2);
}
if(keynum==5)
{
yue++;
if(yue==13)
{
yue=1;
}
write_com(0x80+5);
write_sfm(-0x40+5,yue);
write_com(0x80+5);
}
if(keynum==6)
{
ri++;
if(ri==32)
{
ri=1;
}
write_com(0x80+8);
write_sfm(-0x40+8,ri);
write_com(0x80+8);
}
if(keynum==7)
{
if(week==21)
{
week=0;
}
write_com(0x80+11);
for(num2=0;num2<3;num2++)
{
write_date(table2[week]);
week++;
delay(5);
}
write_com(0x80+11);
}
if(keynum==8)
{
write_com(0x0c);
keynum=0;
}
}
}
if(s5==0)
{
delay(5);
if(s5==0)
{
while(!s5);
if(keynum==1)
{
miao--;
if(miao==-1)
{
miao=59;
}
write_sfm(6,miao);
write_com(0x80+0x40+6);
}
if(keynum==2)
{
fen--;
if(fen==-1)
{
fen=59;
}
write_sfm(3,fen);
write_com(0x80+0x40+3);
}
if(keynum==3)
{
shi--;
if(shi==-1)
{
shi=23;
}
write_sfm(0,shi);
write_com(0x80+0x40);
}
if(keynum==4)
{
nian--;
if(nian==-1)
{
nian=99;
}
write_sfm(-0x40+2,nian);
write_com(0x80+2);
}
if(keynum==5)
{
yue--;
if(yue==-1)
{
yue=12;
}
write_sfm(-0x40+5,yue);
write_com(0x80+5);
}
if(keynum==6)
{
ri--;
if(ri==-1)
{
ri=30;
}
write_sfm(-0x40+8,ri);
write_com(0x80+8);
}
if(keynum==7)
{
if(week==21)
{
week=0;
}
write_com(0x80+11);
for(num2=0;num2<3;num2++)
{
write_date(table3[week]);
week++;
delay(5);
}
write_com(0x80+11);
}
}
}
}
}
void init()
{
SPK=0;
EA=1;
EX0=1;
IT0=1;
week=0;
keynum=0;
dula=0;
wela=0;
E=0;
write_ds(11,0x26); //寄存器B设置返回值BCD形式并开启闹钟
// write_ds(12,0x00); //寄存器C设置中断 2
// write_ds(10,0xa0); //寄存器A设置
naozhongsfm(16,41,15);
read_ds(12);
// miao=45;
// shi=23;
// fen=59;
write_com(0x38);
write_com(0x06);
write_com(0x0c);
write_com(0x80);
for(num=0;num<14;num++)
{
write_date(table[num]);
delay(5);
}
write_com(0x80+0x40);
for(num=0;num<8;num++)
{
write_date(table1[num]);
delay(5);
}
}
void write_ds(uchar add,uchar date)
{
ASDS=1;
DSDS=1;
RWDS=1;
CSDS=0;
P0=add;
ASDS=0;
RWDS=0;
P0=date;
RWDS=1;
ASDS=1;
CSDS=1;
}
uchar read_ds(uchar add)
{
uchar ds_date;
ASDS=1;
DSDS=1;
RWDS=1;
CSDS=0;
P0=add;
ASDS=0;
DSDS=0;
P0=0xff; //P0清1
ds_date=P0;
DSDS=1;
ASDS=1;
CSDS=1;
return ds_date;
}
void naozhongsfm(uchar ashi,uchar afen,uchar amiao)
{ write_ds(5,ashi);
write_ds(3,afen);
write_ds(1,amiao); //闹钟时间设置
}
void main()
{ init();
while(1)
{ keys();
if(flag==0)
{
//write_ds(9,11); //初始化
//write_ds(8,11);
//write_ds(7,18);
//write_ds(6,5);
//write_ds(4,21);
//write_ds(2,9);
//write_ds(0,0);
miao=read_ds(0); //读时间
fen=read_ds(2);
shi=read_ds(4);
nian=read_ds(9);
yue=read_ds(8);
n=read_ds(6);
week=n*3-3; //读星期
ri=read_ds(7);
write_sfm(6,miao); //送显示屏
write_sfm(3,fen);
write_sfm(0,shi);
write_com(0x80+11);
for(num2=0;num2<3;num2++)
{
write_date(table2[week]);
week++;
delay(1);
}
write_sfm(-0x40+5,yue);
write_sfm(-0x40+2,nian);
write_sfm(-0x40+8,ri);
}
}
}
void exter() interrupt 0
{ uchar c;
SPK=1;
c=read_ds(12);
}
一周热门 更多>