📄 按键温度.c
字号:
}while(count==2);break;
case 2:do //count=2,调整分
{
hide_sec=0;
outkey();
Upkey();
Downkey();
if(temp>0x60)
temp=0;
if(up_flag==1||down_flag==1)
{
Write1302(0x8e,0x00); //写入允许
Write1302(0x82,temp); //写入新的分数
Write1302(0x8e,0x80); //禁止写入
up_flag=0;
down_flag=0;
}
hide_min++;
if(hide_min>3)
hide_min=0;
show_time();
}while(count==3);break;
case 3:do //count=3,调整小时
{
hide_min=0;
outkey();
Upkey();
Downkey();
if(up_flag==1||down_flag==1)
{
Write1302(0x8e,0x00); //写入允许
Write1302(0x84,temp); //写入新的小时数
Write1302(0x8e,0x80); //禁止写入
up_flag=0;
down_flag=0;
}
hide_hour++;
if(hide_hour>3)
hide_hour=0;
show_time();
}while(count==4);break;
case 4:do //count=4,调整星期
{
hide_hour=0;
outkey();
Upkey();
Downkey();
if(up_flag==1||down_flag==1)
{
Write1302(0x8e,0x00); //写入允许
Write1302(0x8a,temp); //写入新的星期数
Write1302(0x8e,0x80); //禁止写入
up_flag=0;
down_flag=0;
}
hide_week++;
if(hide_week>3)
hide_week=0;
show_time();
}while(count==5);break;
case 5:do //count=5,调整日
{
hide_week=0;
outkey();
Upkey();
Downkey();
if(up_flag==1||down_flag==1)
{
Write1302(0x8e,0x00); //写入允许
Write1302(0x86,temp); //写入新的日数
Write1302(0x8e,0x80); //禁止写入
up_flag=0;
down_flag=0;
}
hide_day++;
if(hide_day>3)
hide_day=0;
show_time();
}while(count==6);break;
case 6:do //count=6,调整月
{
hide_day=0;
outkey();
Upkey();
Downkey();
if(up_flag==1||down_flag==1)
{
Write1302(0x8e,0x00); //写入允许
Write1302(0x88,temp); //写入新的月数
Write1302(0x8e,0x80); //禁止写入
up_flag=0;
down_flag=0;
}
hide_month++;
if(hide_month>3)
hide_month=0;
show_time();
}while(count==7);break;
case 7:do //count=7,调整年
{
hide_month=0;
outkey();
Upkey();
Downkey();
if(up_flag==1||down_flag==1)
{
Write1302(0x8e,0x00); //写入允许
Write1302(0x8c,temp); //写入新的年数
Write1302(0x8e,0x80); //禁止写入
up_flag=0;
down_flag=0;
}
hide_year++;
if(hide_year>3)
hide_year=0;
show_time();
}while(count==8);break;
case 8: count=0;hide_year=0; //count8, 跳出调整模式,返回默认显示状态
Second=Read1302(DS1302_SECOND);
Write1302(0x8e,0x00); //写入允许
Write1302(0x80,Second&0x7f);
Write1302(0x8E,0x80); //禁止写入
done=0;
break; //count=7,开启中断,标志位置0并退出
default:break;
}
}
//向ds1302写入一字节子程序
void ds1302_write(unsigned char ds1302_temp)
{
unsigned char i,temp;
long_delay();
temp=ds1302_temp;
for(i=0;i<8;i++)
{
DS1302_IO=temp&0x01;
short_delay();
DS1302_CLK=1;
short_delay();
DS1302_CLK=0;
temp=temp>>1;
}
}
//从ds1302读取一字节子程序
unsigned char ds1302_read(void)
{
unsigned char i,temp;
long_delay();
temp=0;
for(i=0;i<8;i++)
{
temp=temp>>1;
if(DS1302_IO)
{
temp=temp|0x80;
}
DS1302_CLK=1;
short_delay();
DS1302_CLK=0;
short_delay();
}
return(temp);
}
void show_time()
{
uchar i;
DS1302_CLK=0;
short_delay();
DS1302_RST=1;
ds1302_write(0x81);
i=ds1302_read();
DS1302_RST=0;
short_delay();
DS1302_CLK=1;
dispbuf[12]=(i>>4)&0x07;//秒
dispbuf[13]=i&0x0f;
DS1302_CLK=0;
short_delay();
DS1302_RST=1;
ds1302_write(0x83);
i=ds1302_read();
DS1302_RST=0;
short_delay();
DS1302_CLK=1;
dispbuf[10]=(i>>4)&0x07;//分
dispbuf[11]=i&0x0f;
DS1302_CLK=0;
short_delay();
DS1302_RST=1;
ds1302_write(0x85);
i=ds1302_read();
DS1302_RST=0;
short_delay();
DS1302_CLK=1;
dispbuf[8]=(i>>4)&0x03;//小时
dispbuf[9]=i&0x0f;
DS1302_CLK=0;
short_delay();
DS1302_RST=1;
ds1302_write(0x87);
i=ds1302_read();
DS1302_RST=0;
short_delay();
DS1302_CLK=1;
dispbuf[6]=(i>>4)&0x03;//日
dispbuf[7]=i&0x0f;
DS1302_CLK=0;
short_delay();
DS1302_RST=1;
ds1302_write(0x89);
i=ds1302_read();
DS1302_RST=0;
short_delay();
DS1302_CLK=1;
dispbuf[4]=(i>>4)&0x01;//月
dispbuf[5]=i&0x0f;
DS1302_CLK=0;
short_delay();
DS1302_RST=1;
ds1302_write(0x8d);
i=ds1302_read();
DS1302_RST=0;
short_delay();
DS1302_CLK=1;
dispbuf[2]=(i>>4)&0x0f;//年
dispbuf[3]=i&0x0f;
DS1302_CLK=0;
short_delay();
DS1302_RST=1;
ds1302_write(0x8b);
i=ds1302_read();
DS1302_RST=0;
short_delay();
DS1302_CLK=1;
dispbuf[14]=((i&0x07)-1);//周
}
//主程序
void main(void)
{
flag=1;
up_flag=0;
down_flag=0;
done=0; //进入默认液晶显示
wireless_1=0;
wireless_2=0;
wireless_3=0;
wireless_4=0;
TMOD=0x02;
TL0=0x06;
TH0=0x06;
TR0=1;
ET0=1;
EA=1;
DS1302_RST=0;
while(1)
{
while(done==1)
keydone(); //进入调整模式
while(done==0)
{
show_time(); //液晶显示数据
flag=0;
Setkey(); //扫描各功能键
}
}
}
void t0(void)interrupt 1 using 0
{
mscnt++;
if(mscnt==8)//2ms数码管扫描显示
{
mscnt=0;
P2=dispbitcnt;
P1=dispcode[dispbuf[dispbitcnt]];
dispbitcnt++;
if(dispbitcnt==15)
dispbitcnt=0;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -