1602与1302做的闹钟
时间:10-02
整理:3721RD
点击:
我在网上找了个程序,功能一切正常, 现在闹钟能闹但天天都要调,我想让下面的程序每天在同一时间闹不用去调它,要怎么改,望高手指点,
//端口自己修改一下 用的1602液晶显示
#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit wela=P1^6;
sbit nz=P1^7;//闹钟
//液晶使能
sbit lcdrs=P1^5;
sbit lcdwr=P1^4;
sbit lcden=P1^3;
//按键
sbit k1=P3^0;
sbit k2=P3^1;
sbit k3=P3^2;
sbit k4=P3^3;
sbit ajjd=P0^4;
//1302位
sbit clk=P1^2;
sbit io=P1^0;
sbit rst=P1^1;
void naozhongscan();//闹钟
uchar num0,num1,num2,num3,num4;
void init();
void delay(uchar);
void keyscan();
void didi();
uchar lcd_date_add[7]={0x40+9,0x40+6,0x40+3,0xa,7,0xd,4};
uchar date_write_add[7]={0x80,0x82,0x84,0x86,0x88,0x8a,0x8c};//miao fen shi ri yue zhou nian
uchar date_read_add[7]={0x81,0x83,0x85,0x87,0x89,0x8b,0x8d};
uchar date[7]={30,32,16,27,2,7,11};
uchar date1[7];
uchar naozhong[7]={35,32,16,27,2,7,11};
uchar flag,flag1,flag2;
uchar code table0[]=" - - ";
uchar code table1[]=" : : ";
void lcd_com(uchar);
void lcd_date(uchar);
void lcd_time(uchar,uchar);
void write_ds1302(uchar add,uchar date);
uchar read_ds1302(uchar add);
void read_rtc();
void set_ds1302(uchar add,uchar time);
void display();
void init_ds1302();
void main()
{
nz=1;
wela=1;
P3=0x0f;
// nz=0;
wela=0;
init();
init_ds1302();
while(1)
{
if(flag1==1)
naozhongscan();//判断闹钟开起没有
read_rtc();
if(flag==0)
display();
keyscan();
}
}
void init()
{
flag=0;
flag1=0;
flag2=0;
lcden=0;
lcdwr=0;
num2=0;
num3=0;
num4=0;
lcd_com(0x38);//显示模式设置,16*2显示,5*7点阵,8位数据接口
lcd_com(0x01);//清屏,显示、指针清零
lcd_com(0x0c);//显示开关及光标设置,开显示,显示光标,光标闪烁
lcd_com(0x06);//读写后指针加一光标加一
lcd_com(0x80);//从第一个显示地址开始显示
for(num0=0;num0<16;num0++)//写上一行的位置
lcd_date(table0[num0]);
lcd_com(0x80+0x40);
for(num0=0;num0<11;num0++)//下一行要写的位置二个数组
lcd_date(table1[num0]);
}
void init_ds1302()
{
uchar i,j;
uchar flag3;
flag3=read_ds1302(0x81);//读1302是否初始发了
if(flag3&0x80)//如果ch=1则进行初始化
{
write_ds1302(0x8e,0x00);
for(i=0;i<7;i++)
{
j=date[i]/10;
date[i]=date[i]%10;
date[i]=date[i]+j*16;
write_ds1302(date_write_add[i],date[i]);//在1602相应的地址写上相应的字
}
write_ds1302(0x8e,0x80);
}
}
void delay(uchar z)
{
uchar x,y;
for(x=110;x>0;x--)
for(y=z;y>0;y--);
}
void didi()
{
nz=0;
delay(50);
nz=1;
delay(100);
nz=0;
delay(50);
nz=1;
}
//1602
void lcd_com(uchar com)//写地址
{
lcdrs=0;
P2=com;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void lcd_date(uchar date)//写数据
{
lcdrs=1;
P2=date;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void lcd_time(uchar add,uchar Date)//十位个位
{
uchar shi,ge;
shi=Date/10;
ge=Date%10;
lcd_com(0x80+add);
lcd_date(0x30+shi);
lcd_date(0x30+ge);
}
void keyscan()
{
ajjd=0;
if(num3!=2)
{
if(k1==0)//选择光标所在的位置开始
{
delay(5);
if(k1==0)
{
while(!k1);
num2++;
if(num2==1)
{
flag=1;
lcd_com(0x80+lcd_date_add[0]);
lcd_com(0x0f);//显示开关及光标设置,开显示,显示光标,光标闪烁
}
if(num2==2)
{
lcd_com(0x80+lcd_date_add[1]);
}
if(num2==3)
{
lcd_com(0x80+lcd_date_add[2]);
}
if(num2==4)
{
lcd_com(0x80+lcd_date_add[3]);
}
if(num2==5)
{
lcd_com(0x80+lcd_date_add[4]);
}
if(num2==6)
{
lcd_com(0x80+lcd_date_add[5]);
}
if(num2==7)
{
lcd_com(0x80+lcd_date_add[6]);
}
if(num2==8)
{
lcd_com(0x0c);//关光标
num2=0;
flag=0;//选择光标所在的位置结束
}
}
}
if(num2!=0)
{
if(k2==0)
{
delay(5);
if(k2==0)
{
while(!k2);
if(num2==1)//秒
{
date[0]++;
if(date[0]==60)
date[0]=0;
_nop_();
lcd_time(lcd_date_add[0],date[0]);//先转换
lcd_com(0x80+lcd_date_add[0]);//地扯秒
set_ds1302(date_write_add[0],date[0]);//数据
}
if(num2==2)//分
{
date[1]++;
if(date[1]==60)
date[1]=0;
_nop_();
lcd_time(lcd_date_add[1],date[1]);
lcd_com(0x80+lcd_date_add[1]);
set_ds1302(date_write_add[1],date[1]);
}
if(num2==3)//时
{
date[2]++;
if(date[2]==24)
date[2]=0;
_nop_();
lcd_time(lcd_date_add[2],date[2]);
lcd_com(0x80+lcd_date_add[2]);
set_ds1302(date_write_add[2],date[2]);
}
if(num2==4)//天
{
date[3]++;
if(date[3]==32)
date[3]=1;
_nop_();
lcd_time(lcd_date_add[3],date[3]);
lcd_com(0x80+lcd_date_add[3]);
set_ds1302(date_write_add[3],date[3]);
}
if(num2==5)//月
{
date[4]++;
if(date[4]==13)
date[4]=1;
_nop_();
lcd_time(lcd_date_add[4],date[4]);
lcd_com(0x80+lcd_date_add[4]);
set_ds1302(date_write_add[4],date[4]);
}
if(num2==6)//星期
{
date[5]++;
if(date[5]==8)
date[5]=1;
_nop_();
lcd_time(lcd_date_add[5],date[5]);
lcd_com(0x80+lcd_date_add[5]);
set_ds1302(date_write_add[5],date[5]);
}
if(num2==7)//年
{
date[6]++;
if(date[6]==99)
date[6]=1;
_nop_();
lcd_time(lcd_date_add[6],date[6]);
lcd_com(0x80+lcd_date_add[6]);
set_ds1302(date_write_add[6],date[6]);
}
}
}
if(k3==0)
{
delay(5);
if(k3==0)
{
while(!k3);
if(num2==1)
{
date[0]--;
if(date[0]==-1)
date[0]=59;
_nop_();
lcd_time(lcd_date_add[2],date[0]);
lcd_com(0x80+lcd_date_add[0]);
set_ds1302(date_write_add[0],date[0]);
}
if(num2==2)
{
date[1]--;
if(date[1]==-1)
date[1]=59;
_nop_();
lcd_time(lcd_date_add[1],date[1]);
lcd_com(0x80+lcd_date_add[1]);
set_ds1302(date_write_add[1],date[1]);
}
if(num2==3)
{
date[2]--;
if(date[2]==-1)
date[2]=23;
_nop_();
lcd_time(lcd_date_add[2],date[2]);
lcd_com(0x80+lcd_date_add[2]);
set_ds1302(date_write_add[2],date[2]);
}
if(num2==4)
{
date[3]--;
if(date[3]==0)
date[3]=31;
_nop_();
lcd_time(lcd_date_add[3],date[3]);
lcd_com(0x80+lcd_date_add[3]);
set_ds1302(date_write_add[3],date[3]);
}
if(num2==5)
{
date[4]--;
if(date[4]==0)
date[4]=12;
_nop_();
lcd_time(lcd_date_add[4],date[4]);
lcd_com(0x80+lcd_date_add[4]);
set_ds1302(date_write_add[4],date[4]);
}
if(num2==6)
{
date[5]--;
if(date[5]==0)
date[5]=7;
_nop_();
lcd_time(lcd_date_add[5],date[5]);
lcd_com(0x80+lcd_date_add[5]);
set_ds1302(date_write_add[5],date[5]);
}
if(num2==7)
{
date[6]--;
if(date[6]==0)
date[6]=99;
_nop_();
lcd_time(lcd_date_add[6],date[6]);
lcd_com(0x80+lcd_date_add[6]);
set_ds1302(date_write_add[6],date[6]);
}
}
}
}
}
if(k4==0)
{
delay(5);
if(k4==0)
{
while(!k4);
num3++;
}
}
if(num3==1)
{
flag1=1;
lcd_com(0x80+1);
lcd_date(0x41);
}
if(num3==2)
{
ajjd=0;
flag1=0;
if(num4==0)
{
for(num0=0;num0<7;num0++)
lcd_time(lcd_date_add[num0],naozhong[num0]);
lcd_com(0x80+1);
lcd_com(0x0c);//关光标
lcd_date(0x42);
}
//lcd_com(0x0f);
flag=1;
if(k1==0)
{
delay(5);
if(k1==0)
{
while(!k1);
num4++;
if(num4==1)
{
lcd_com(0x80+lcd_date_add[0]);
lcd_com(0x0f);//显示开关及光标设置,开显示,显示光标,光标闪烁
}
if(num4==2)
{
lcd_com(0x80+lcd_date_add[1]);
}
if(num4==3)
{
lcd_com(0x80+lcd_date_add[2]);
}
if(num4==4)
{
lcd_com(0x80+lcd_date_add[3]);
}
if(num4==5)
{
lcd_com(0x80+lcd_date_add[4]);
}
if(num4==6)
{
lcd_com(0x80+lcd_date_add[5]);
}
if(num4==7)
{
lcd_com(0x80+lcd_date_add[6]);
}
if(num4==8)
{
lcd_com(0x0c);//关光标
num4=0;
flag=1;
}
}
}
if(num4!=0)
{
if(k2==0)
{
delay(5);
if(k2==0)
{
while(!k2);
if(num4==1)
{
naozhong[0]++;
if(naozhong[0]==60)
naozhong[0]=0;
_nop_();
lcd_time(lcd_date_add[0],naozhong[0]);
lcd_com(0x80+lcd_date_add[0]);
}
if(num4==2)
{
naozhong[1]++;
if(naozhong[1]==60)
naozhong[1]=0;
_nop_();
lcd_time(lcd_date_add[1],naozhong[1]);
lcd_com(0x80+lcd_date_add[1]);
}
if(num4==3)
{
naozhong[2]++;
if(naozhong[2]==24)
naozhong[2]=0;
_nop_();
lcd_time(lcd_date_add[2],naozhong[2]);
lcd_com(0x80+lcd_date_add[2]);
}
if(num4==4)
{
naozhong[3]++;
if(naozhong[3]==32)
naozhong[3]=1;
_nop_();
lcd_time(lcd_date_add[3],naozhong[3]);
lcd_com(0x80+lcd_date_add[3]);
}
if(num4==5)
{
naozhong[4]++;
if(naozhong[4]==13)
naozhong[4]=1;
_nop_();
lcd_time(lcd_date_add[4],naozhong[4]);
lcd_com(0x80+lcd_date_add[4]);
}
if(num4==6)
{
naozhong[5]++;
if(naozhong[5]==8)
naozhong[5]=1;
_nop_();
lcd_time(lcd_date_add[5],naozhong[5]);
lcd_com(0x80+lcd_date_add[5]);
}
if(num4==7)
{
naozhong[6]++;
if(naozhong[6]==99)
naozhong[6]=1;
_nop_();
lcd_time(lcd_date_add[6],naozhong[6]);
lcd_com(0x80+lcd_date_add[6]);
}
}
}
if(k3==0)
{
delay(5);
if(k3==0)
{
while(!k3);
if(num4==1)
{
naozhong[0]--;
if(naozhong[0]==-1)
naozhong[0]=59;
_nop_();
lcd_time(lcd_date_add[2],naozhong[0]);
lcd_com(0x80+lcd_date_add[0]);
}
if(num4==2)
{
naozhong[1]--;
if(naozhong[1]==-1)
naozhong[1]=59;
_nop_();
lcd_time(lcd_date_add[1],naozhong[1]);
lcd_com(0x80+lcd_date_add[1]);
}
if(num4==3)
{
naozhong[2]--;
if(naozhong[2]==-1)
naozhong[2]=23;
_nop_();
lcd_time(lcd_date_add[2],naozhong[2]);
lcd_com(0x80+lcd_date_add[2]);
}
if(num4==4)
{
naozhong[3]--;
if(naozhong[3]==0)
naozhong[3]=31;
_nop_();
lcd_time(lcd_date_add[3],naozhong[3]);
lcd_com(0x80+lcd_date_add[3]);
}
if(num4==5)
{
naozhong[4]--;
if(naozhong[4]==0)
naozhong[4]=12;
_nop_();
lcd_time(lcd_date_add[4],naozhong[4]);
lcd_com(0x80+lcd_date_add[4]);
}
if(num4==6)
{
naozhong[5]--;
if(naozhong[5]==0)
naozhong[5]=7;
_nop_();
lcd_time(lcd_date_add[5],naozhong[5]);
lcd_com(0x80+lcd_date_add[5]);
}
if(num4==7)
{
naozhong[6]--;
if(naozhong[6]==0)
naozhong[6]=99;
_nop_();
lcd_time(lcd_date_add[6],naozhong[6]);
lcd_com(0x80+lcd_date_add[6]);
}
}
}
}
}
if(num3==3)
{
flag=0;
flag1=0;
lcd_com(0x80+1);
lcd_date(20);//让lcd什么都不显示
num3=0;
num4=0;
}
}
void write_ds1302(uchar add,uchar date)
{
uchar i,temp;
rst=0;
clk=0;
_nop_();
rst=1;
for(i=0;i<8;i++)
{
clk=0;
temp=add;
io=temp&0x01;
add>>=1;
clk=1;
_nop_();
}
for(i=0;i<8;i++)
{
clk=0;
temp=date;
io=temp&0x01;
date>>=1;
clk=1;
_nop_();
}
rst=0;
}
uchar read_ds1302(uchar add)
{
uchar i,temp,data1,j;
rst=0;
clk=0;
_nop_();;
rst=1;
for(i=0;i<8;i++)
{
clk=0;
temp=add;
io=temp&0x01;
add>>=1;
clk=1;
_nop_();
}
for(i=0;i<8;i++)
{
data1>>=1;
clk=0;
if(io)
data1=data1|0x80;
clk=1;
}
rst=0;
_nop_();
j=data1%16;
data1=data1/16;
data1=data1*10+j;
return(data1);
}
void set_ds1302(uchar add,uchar time)
{
uchar j;
write_ds1302(0x8e,0x00);
j=time/10;
time=time%10;
time=time+j*16;
write_ds1302(add,time);
write_ds1302(0x8e,0x80);
}
void read_rtc()
{
uchar i;
for(i=0;i<7;i++)
{
date[i]=read_ds1302(date_read_add[i]);
}
}
void display()
{
uchar i;
for(i=0;i<7;i++)
{
lcd_time(lcd_date_add[i],date[i]);
}
}
void naozhongscan()
{
uchar i=0;
uchar j=0;
while((j==0)&&(i<7))
{
j=naozhong[i]^date[i];
i++;
}
if(i==7)
didi();
}
这个函数里的
void naozhongscan()
{
uchar i=0;
uchar j=0;
while((j==0)&&(i<7))
{
j=naozhong[i]^date[i];
i++;
}
if(i==7)
didi();
}
是怎么判闹钟开起的我看不懂
//端口自己修改一下 用的1602液晶显示
#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit wela=P1^6;
sbit nz=P1^7;//闹钟
//液晶使能
sbit lcdrs=P1^5;
sbit lcdwr=P1^4;
sbit lcden=P1^3;
//按键
sbit k1=P3^0;
sbit k2=P3^1;
sbit k3=P3^2;
sbit k4=P3^3;
sbit ajjd=P0^4;
//1302位
sbit clk=P1^2;
sbit io=P1^0;
sbit rst=P1^1;
void naozhongscan();//闹钟
uchar num0,num1,num2,num3,num4;
void init();
void delay(uchar);
void keyscan();
void didi();
uchar lcd_date_add[7]={0x40+9,0x40+6,0x40+3,0xa,7,0xd,4};
uchar date_write_add[7]={0x80,0x82,0x84,0x86,0x88,0x8a,0x8c};//miao fen shi ri yue zhou nian
uchar date_read_add[7]={0x81,0x83,0x85,0x87,0x89,0x8b,0x8d};
uchar date[7]={30,32,16,27,2,7,11};
uchar date1[7];
uchar naozhong[7]={35,32,16,27,2,7,11};
uchar flag,flag1,flag2;
uchar code table0[]=" - - ";
uchar code table1[]=" : : ";
void lcd_com(uchar);
void lcd_date(uchar);
void lcd_time(uchar,uchar);
void write_ds1302(uchar add,uchar date);
uchar read_ds1302(uchar add);
void read_rtc();
void set_ds1302(uchar add,uchar time);
void display();
void init_ds1302();
void main()
{
nz=1;
wela=1;
P3=0x0f;
// nz=0;
wela=0;
init();
init_ds1302();
while(1)
{
if(flag1==1)
naozhongscan();//判断闹钟开起没有
read_rtc();
if(flag==0)
display();
keyscan();
}
}
void init()
{
flag=0;
flag1=0;
flag2=0;
lcden=0;
lcdwr=0;
num2=0;
num3=0;
num4=0;
lcd_com(0x38);//显示模式设置,16*2显示,5*7点阵,8位数据接口
lcd_com(0x01);//清屏,显示、指针清零
lcd_com(0x0c);//显示开关及光标设置,开显示,显示光标,光标闪烁
lcd_com(0x06);//读写后指针加一光标加一
lcd_com(0x80);//从第一个显示地址开始显示
for(num0=0;num0<16;num0++)//写上一行的位置
lcd_date(table0[num0]);
lcd_com(0x80+0x40);
for(num0=0;num0<11;num0++)//下一行要写的位置二个数组
lcd_date(table1[num0]);
}
void init_ds1302()
{
uchar i,j;
uchar flag3;
flag3=read_ds1302(0x81);//读1302是否初始发了
if(flag3&0x80)//如果ch=1则进行初始化
{
write_ds1302(0x8e,0x00);
for(i=0;i<7;i++)
{
j=date[i]/10;
date[i]=date[i]%10;
date[i]=date[i]+j*16;
write_ds1302(date_write_add[i],date[i]);//在1602相应的地址写上相应的字
}
write_ds1302(0x8e,0x80);
}
}
void delay(uchar z)
{
uchar x,y;
for(x=110;x>0;x--)
for(y=z;y>0;y--);
}
void didi()
{
nz=0;
delay(50);
nz=1;
delay(100);
nz=0;
delay(50);
nz=1;
}
//1602
void lcd_com(uchar com)//写地址
{
lcdrs=0;
P2=com;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void lcd_date(uchar date)//写数据
{
lcdrs=1;
P2=date;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void lcd_time(uchar add,uchar Date)//十位个位
{
uchar shi,ge;
shi=Date/10;
ge=Date%10;
lcd_com(0x80+add);
lcd_date(0x30+shi);
lcd_date(0x30+ge);
}
void keyscan()
{
ajjd=0;
if(num3!=2)
{
if(k1==0)//选择光标所在的位置开始
{
delay(5);
if(k1==0)
{
while(!k1);
num2++;
if(num2==1)
{
flag=1;
lcd_com(0x80+lcd_date_add[0]);
lcd_com(0x0f);//显示开关及光标设置,开显示,显示光标,光标闪烁
}
if(num2==2)
{
lcd_com(0x80+lcd_date_add[1]);
}
if(num2==3)
{
lcd_com(0x80+lcd_date_add[2]);
}
if(num2==4)
{
lcd_com(0x80+lcd_date_add[3]);
}
if(num2==5)
{
lcd_com(0x80+lcd_date_add[4]);
}
if(num2==6)
{
lcd_com(0x80+lcd_date_add[5]);
}
if(num2==7)
{
lcd_com(0x80+lcd_date_add[6]);
}
if(num2==8)
{
lcd_com(0x0c);//关光标
num2=0;
flag=0;//选择光标所在的位置结束
}
}
}
if(num2!=0)
{
if(k2==0)
{
delay(5);
if(k2==0)
{
while(!k2);
if(num2==1)//秒
{
date[0]++;
if(date[0]==60)
date[0]=0;
_nop_();
lcd_time(lcd_date_add[0],date[0]);//先转换
lcd_com(0x80+lcd_date_add[0]);//地扯秒
set_ds1302(date_write_add[0],date[0]);//数据
}
if(num2==2)//分
{
date[1]++;
if(date[1]==60)
date[1]=0;
_nop_();
lcd_time(lcd_date_add[1],date[1]);
lcd_com(0x80+lcd_date_add[1]);
set_ds1302(date_write_add[1],date[1]);
}
if(num2==3)//时
{
date[2]++;
if(date[2]==24)
date[2]=0;
_nop_();
lcd_time(lcd_date_add[2],date[2]);
lcd_com(0x80+lcd_date_add[2]);
set_ds1302(date_write_add[2],date[2]);
}
if(num2==4)//天
{
date[3]++;
if(date[3]==32)
date[3]=1;
_nop_();
lcd_time(lcd_date_add[3],date[3]);
lcd_com(0x80+lcd_date_add[3]);
set_ds1302(date_write_add[3],date[3]);
}
if(num2==5)//月
{
date[4]++;
if(date[4]==13)
date[4]=1;
_nop_();
lcd_time(lcd_date_add[4],date[4]);
lcd_com(0x80+lcd_date_add[4]);
set_ds1302(date_write_add[4],date[4]);
}
if(num2==6)//星期
{
date[5]++;
if(date[5]==8)
date[5]=1;
_nop_();
lcd_time(lcd_date_add[5],date[5]);
lcd_com(0x80+lcd_date_add[5]);
set_ds1302(date_write_add[5],date[5]);
}
if(num2==7)//年
{
date[6]++;
if(date[6]==99)
date[6]=1;
_nop_();
lcd_time(lcd_date_add[6],date[6]);
lcd_com(0x80+lcd_date_add[6]);
set_ds1302(date_write_add[6],date[6]);
}
}
}
if(k3==0)
{
delay(5);
if(k3==0)
{
while(!k3);
if(num2==1)
{
date[0]--;
if(date[0]==-1)
date[0]=59;
_nop_();
lcd_time(lcd_date_add[2],date[0]);
lcd_com(0x80+lcd_date_add[0]);
set_ds1302(date_write_add[0],date[0]);
}
if(num2==2)
{
date[1]--;
if(date[1]==-1)
date[1]=59;
_nop_();
lcd_time(lcd_date_add[1],date[1]);
lcd_com(0x80+lcd_date_add[1]);
set_ds1302(date_write_add[1],date[1]);
}
if(num2==3)
{
date[2]--;
if(date[2]==-1)
date[2]=23;
_nop_();
lcd_time(lcd_date_add[2],date[2]);
lcd_com(0x80+lcd_date_add[2]);
set_ds1302(date_write_add[2],date[2]);
}
if(num2==4)
{
date[3]--;
if(date[3]==0)
date[3]=31;
_nop_();
lcd_time(lcd_date_add[3],date[3]);
lcd_com(0x80+lcd_date_add[3]);
set_ds1302(date_write_add[3],date[3]);
}
if(num2==5)
{
date[4]--;
if(date[4]==0)
date[4]=12;
_nop_();
lcd_time(lcd_date_add[4],date[4]);
lcd_com(0x80+lcd_date_add[4]);
set_ds1302(date_write_add[4],date[4]);
}
if(num2==6)
{
date[5]--;
if(date[5]==0)
date[5]=7;
_nop_();
lcd_time(lcd_date_add[5],date[5]);
lcd_com(0x80+lcd_date_add[5]);
set_ds1302(date_write_add[5],date[5]);
}
if(num2==7)
{
date[6]--;
if(date[6]==0)
date[6]=99;
_nop_();
lcd_time(lcd_date_add[6],date[6]);
lcd_com(0x80+lcd_date_add[6]);
set_ds1302(date_write_add[6],date[6]);
}
}
}
}
}
if(k4==0)
{
delay(5);
if(k4==0)
{
while(!k4);
num3++;
}
}
if(num3==1)
{
flag1=1;
lcd_com(0x80+1);
lcd_date(0x41);
}
if(num3==2)
{
ajjd=0;
flag1=0;
if(num4==0)
{
for(num0=0;num0<7;num0++)
lcd_time(lcd_date_add[num0],naozhong[num0]);
lcd_com(0x80+1);
lcd_com(0x0c);//关光标
lcd_date(0x42);
}
//lcd_com(0x0f);
flag=1;
if(k1==0)
{
delay(5);
if(k1==0)
{
while(!k1);
num4++;
if(num4==1)
{
lcd_com(0x80+lcd_date_add[0]);
lcd_com(0x0f);//显示开关及光标设置,开显示,显示光标,光标闪烁
}
if(num4==2)
{
lcd_com(0x80+lcd_date_add[1]);
}
if(num4==3)
{
lcd_com(0x80+lcd_date_add[2]);
}
if(num4==4)
{
lcd_com(0x80+lcd_date_add[3]);
}
if(num4==5)
{
lcd_com(0x80+lcd_date_add[4]);
}
if(num4==6)
{
lcd_com(0x80+lcd_date_add[5]);
}
if(num4==7)
{
lcd_com(0x80+lcd_date_add[6]);
}
if(num4==8)
{
lcd_com(0x0c);//关光标
num4=0;
flag=1;
}
}
}
if(num4!=0)
{
if(k2==0)
{
delay(5);
if(k2==0)
{
while(!k2);
if(num4==1)
{
naozhong[0]++;
if(naozhong[0]==60)
naozhong[0]=0;
_nop_();
lcd_time(lcd_date_add[0],naozhong[0]);
lcd_com(0x80+lcd_date_add[0]);
}
if(num4==2)
{
naozhong[1]++;
if(naozhong[1]==60)
naozhong[1]=0;
_nop_();
lcd_time(lcd_date_add[1],naozhong[1]);
lcd_com(0x80+lcd_date_add[1]);
}
if(num4==3)
{
naozhong[2]++;
if(naozhong[2]==24)
naozhong[2]=0;
_nop_();
lcd_time(lcd_date_add[2],naozhong[2]);
lcd_com(0x80+lcd_date_add[2]);
}
if(num4==4)
{
naozhong[3]++;
if(naozhong[3]==32)
naozhong[3]=1;
_nop_();
lcd_time(lcd_date_add[3],naozhong[3]);
lcd_com(0x80+lcd_date_add[3]);
}
if(num4==5)
{
naozhong[4]++;
if(naozhong[4]==13)
naozhong[4]=1;
_nop_();
lcd_time(lcd_date_add[4],naozhong[4]);
lcd_com(0x80+lcd_date_add[4]);
}
if(num4==6)
{
naozhong[5]++;
if(naozhong[5]==8)
naozhong[5]=1;
_nop_();
lcd_time(lcd_date_add[5],naozhong[5]);
lcd_com(0x80+lcd_date_add[5]);
}
if(num4==7)
{
naozhong[6]++;
if(naozhong[6]==99)
naozhong[6]=1;
_nop_();
lcd_time(lcd_date_add[6],naozhong[6]);
lcd_com(0x80+lcd_date_add[6]);
}
}
}
if(k3==0)
{
delay(5);
if(k3==0)
{
while(!k3);
if(num4==1)
{
naozhong[0]--;
if(naozhong[0]==-1)
naozhong[0]=59;
_nop_();
lcd_time(lcd_date_add[2],naozhong[0]);
lcd_com(0x80+lcd_date_add[0]);
}
if(num4==2)
{
naozhong[1]--;
if(naozhong[1]==-1)
naozhong[1]=59;
_nop_();
lcd_time(lcd_date_add[1],naozhong[1]);
lcd_com(0x80+lcd_date_add[1]);
}
if(num4==3)
{
naozhong[2]--;
if(naozhong[2]==-1)
naozhong[2]=23;
_nop_();
lcd_time(lcd_date_add[2],naozhong[2]);
lcd_com(0x80+lcd_date_add[2]);
}
if(num4==4)
{
naozhong[3]--;
if(naozhong[3]==0)
naozhong[3]=31;
_nop_();
lcd_time(lcd_date_add[3],naozhong[3]);
lcd_com(0x80+lcd_date_add[3]);
}
if(num4==5)
{
naozhong[4]--;
if(naozhong[4]==0)
naozhong[4]=12;
_nop_();
lcd_time(lcd_date_add[4],naozhong[4]);
lcd_com(0x80+lcd_date_add[4]);
}
if(num4==6)
{
naozhong[5]--;
if(naozhong[5]==0)
naozhong[5]=7;
_nop_();
lcd_time(lcd_date_add[5],naozhong[5]);
lcd_com(0x80+lcd_date_add[5]);
}
if(num4==7)
{
naozhong[6]--;
if(naozhong[6]==0)
naozhong[6]=99;
_nop_();
lcd_time(lcd_date_add[6],naozhong[6]);
lcd_com(0x80+lcd_date_add[6]);
}
}
}
}
}
if(num3==3)
{
flag=0;
flag1=0;
lcd_com(0x80+1);
lcd_date(20);//让lcd什么都不显示
num3=0;
num4=0;
}
}
void write_ds1302(uchar add,uchar date)
{
uchar i,temp;
rst=0;
clk=0;
_nop_();
rst=1;
for(i=0;i<8;i++)
{
clk=0;
temp=add;
io=temp&0x01;
add>>=1;
clk=1;
_nop_();
}
for(i=0;i<8;i++)
{
clk=0;
temp=date;
io=temp&0x01;
date>>=1;
clk=1;
_nop_();
}
rst=0;
}
uchar read_ds1302(uchar add)
{
uchar i,temp,data1,j;
rst=0;
clk=0;
_nop_();;
rst=1;
for(i=0;i<8;i++)
{
clk=0;
temp=add;
io=temp&0x01;
add>>=1;
clk=1;
_nop_();
}
for(i=0;i<8;i++)
{
data1>>=1;
clk=0;
if(io)
data1=data1|0x80;
clk=1;
}
rst=0;
_nop_();
j=data1%16;
data1=data1/16;
data1=data1*10+j;
return(data1);
}
void set_ds1302(uchar add,uchar time)
{
uchar j;
write_ds1302(0x8e,0x00);
j=time/10;
time=time%10;
time=time+j*16;
write_ds1302(add,time);
write_ds1302(0x8e,0x80);
}
void read_rtc()
{
uchar i;
for(i=0;i<7;i++)
{
date[i]=read_ds1302(date_read_add[i]);
}
}
void display()
{
uchar i;
for(i=0;i<7;i++)
{
lcd_time(lcd_date_add[i],date[i]);
}
}
void naozhongscan()
{
uchar i=0;
uchar j=0;
while((j==0)&&(i<7))
{
j=naozhong[i]^date[i];
i++;
}
if(i==7)
didi();
}
这个函数里的
void naozhongscan()
{
uchar i=0;
uchar j=0;
while((j==0)&&(i<7))
{
j=naozhong[i]^date[i];
i++;
}
if(i==7)
didi();
}
是怎么判闹钟开起的我看不懂
1302不带闹钟功能,最简单的是把闹钟时间记在单片机里,由单片机对比时间,到了闹钟时间就响,缺点就是如果单片机没有eeprom的话,掉电后就要重新设置闹钟时间了。
这个程序能闹啊,我想问闹钟能使能这段程序的含意望指点
j=naozhong[i]^date[i];是做异或运算,相同内容的两个字节做异或运算,结果是为0的,所以闹钟设定时间和读取出来的时间一致,就是可以闹响了,不过这个做法就是每天必须更改闹钟的设定时间。
&&这外符号是什么意思,谢谢指点
代表&&两边的条件必须同时成立
谢谢指点
很多代码啊,,眼晕
不喜欢那么乱的东西