找回密码
 注册会员
img_loading
智能检测中
更新自动建库工具PCB Footprint Expert 2024.04 Pro / Library Expert 破解版

疑问 求大侠帮助 为啥断电后再上电只有秒在按原来的走啊

[复制链接]
admin 发表于 2012-9-2 04:55:52 | 显示全部楼层 |阅读模式

本文包含原理图、PCB、源代码、封装库、中英文PDF等资源

您需要 登录 才可以下载或查看,没有账号?注册会员

×
#include <reg52.h>
#define uint unsigned int
#define uchar unsigned char
uchar num,num1,slnum;
char miao,shi,fen;
sbit lcden=P3^4;
sbit rd=P3^7;
sbit lcdrs=P3^5;
sbit dula=P2^6;
sbit wela=P2^7;
bit write=0;
sbit sda=P2^0;
sbit scl=P2^1;
sbit beep=P2^3;
sbit s1=P3^0;//功能键
sbit s2=P3^1;//增大键
sbit s3=P3^2;//减小键
uchar code dipup[]="2012-8-10 FRIDAY";
uchar code dipdn[]=" 00:00:00" ;
void delay(uchar z)
{
uchar x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void delay1()
{
;;
}

void start()
{
sda=1;
delay1();
scl=1;
delay1();
sda=0;
delay1();
}
void stop()
{
sda=0;
delay1();
scl=1;
delay1();
sda=1;
delay1();
}
void respons()
{
uchar i;
scl=1;
delay1();
while((sda==1)&&(i<250))i++;
scl=0;
delay1();
}
void write_byte(uchar date)
{
uchar i,temp;
temp=date;
for(i=0;i<8;i++)
{
temp=temp<<1;
scl=0;
delay1();
sda=CY;
delay1();
scl=1;
delay1();
}
scl=0;
delay1();
sda=1;
delay1();
}
uchar read_byte()
{
uchar i,k;
scl=0;
delay1();
sda=1;
delay1();
for(i=0;i<8;i++)
{
scl=1;
delay1();
k=(k<<1)|sda;
scl=0;
}
return k;
}
void write_add(uchar address,uchar date)
{
start();
write_byte(0xa0);
respons();
write_byte(address);
respons();
write_byte(date);
respons();
stop();

}
uchar read_add(uchar address)
{
uchar date;
start();
write_byte(0xa0);
respons();
write_byte(address);
respons();
start();
write_byte(0xa1);
respons();
date=read_byte();
stop();
return date;


}

void di()
{
beep=0;
delay(100);
beep=1;
}

void write_com(uchar com)
{
lcdrs=0;
P0=com;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void write_date(uchar date)
{
lcdrs=1;
P0=date;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
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);
}

void init()
{
sda=1;
delay1();
scl=1;
delay1();
TMOD=0x01;
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
EA=1;
dula=0;
wela=0;
ET0=1;
TR0=1;
dula=0;
wela=0;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
miao=read_add(3);
fen=read_add(2);
shi=read_add(1);

}
void keyscan()
{
rd=0;
if(s1==0)
{
delay(10);
if(s1==0)
{
slnum++;
di();
while(!s1);
if(slnum==1)
{
TR0=0;
write_com(0x80+0x40+10);
write_com(0x0f);
}
if(slnum==2)
{
write_com(0x80+0x40+7);
}
if(slnum==3)
{
write_com(0x80+0x40+4);
}
if(slnum==4)
{
slnum=0;
TR0=1;
write_com(0x0c);
}
}
}
if(slnum!=0)
{
if(slnum==1)
{
if(s2==0)
{
delay(5);
if(s2==0)
{
while(!s2);
miao++;
if(miao==60)
miao=0;
write_sfm(10,miao);write_add(1,miao);
write_com(0x80+0x40+10);
}
}
}
if(slnum==2)
{
if(s2==0)
{
delay(5);
if(s2==0)
{
while(!s2);
fen++;
if(fen==60)
fen=0;
write_sfm(7,fen);write_add(2,fen);
write_com(0x80+0x40+7);
}
}
}
if(slnum==3)
{
if(s2==0)
{
delay(5);
if(s2==0)
{
while(!s2);
shi++;
if(shi==24)
shi=0;
write_sfm(4,shi);write_add(3,shi);
write_com(0x80+0x40+4);
}
}
}
if(slnum!=0)
{
if(slnum==1)
{
if(s3==0)
{
delay(5);
if(s3==0)
{
while(!s3);
miao--;
if(miao==-1)
miao=59;
write_sfm(10,miao);write_add(1,miao);
write_com(0x80+0x40+10);
}

}
}
if(slnum==2)
{
if(s3==0)
{
delay(5);
if(s3==0)
{
while(!s3);
fen--;
if(fen==-1)
fen=59;
write_sfm(7,fen);write_add(2,fen);
write_com(0x80+0x40+7);
}

}
}
if(slnum==3)
{
if(s3==0)
{
delay(5);
if(s3==0)
{
while(!s3);
shi--;
if(shi==-1)
shi=23;
write_sfm(4,shi);write_add(3,shi);
write_com(0x80+0x40+4);
}

}
}
}


}
}
void main()
{
init();
write_com(0x80);
for(num=0;num<16;num++)
{
write_date(dipup[num]);
delay(5);
}
write_com(0x80+0x40);
for(num=0;num<12;num++)
{
write_date(dipdn[num]);
delay(5);
}

while(1)
{
keyscan();
}

}
void time() interrupt 1
{
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
num1++;

if(num1==20)
{
num1=0;
miao++;

if(miao==60)
{
miao=0;
fen++;

if(fen==60)
{
fen=0;
shi++;

if(shi==24)
{
shi=0;
}write_sfm(4,shi);write_add(3,shi);
}write_sfm(7,fen);write_add(2,fen);
}write_sfm(10,miao);write_add(1,miao);

}
}
您需要登录后才可以回帖 登录 | 注册会员

*滑块验证:
img_loading
智能检测中
本版积分规则

QQ|手机版|MCU资讯论坛 ( 京ICP备18035221号-2 )|网站地图

GMT+8, 2025-7-26 10:32 , Processed in 0.053695 second(s), 9 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表