?? 按鍵溫度.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 + -