程序說明:這是一個用51單片機驅(qū)動DS1302時間模塊+DS18B20溫度傳感器模塊+12864液晶顯示完整程序設計實例,有四個鍵盤KEY0 到KEY3,key0是修改時間的 首先是秒到分到時到年到月到日到星期 key1是加1 key2是減一 在修改時間狀態(tài)再按一下key3的時候就出去并修改時間日期,在平時狀態(tài)按著key3再按著key2 就會打開lcd 的燈 單單是只按key3那就是把燈關(guān)了。
文件一:DS1302驅(qū)動.c
#include
//ds1302 sbit sclk=P0^3; sbit io=P0^4; sbit rst=P0^5; sbit acc0=ACC^0; sbit acc1=ACC^1; sbit acc2=ACC^2; sbit acc3=ACC^3; sbit acc4=ACC^4; sbit acc5=ACC^5; sbit acc6=ACC^6; sbit acc7=ACC^7;
delay() { unsigned char i; i=10; i=10; i=10; i=10; i=10; i=10; i=10;} w_1302(unsigned char dat,unsigned char shu){//寫一個八位的數(shù)去DS1302 //上升效 ;;;選寫地址再寫數(shù)據(jù)
ACC=dat;//地址 sclk=0; rst=1;// io=acc0;/// sclk=0; delay(); sclk=1; io=acc1; sclk=0; delay(); sclk=1; io=acc2; sclk=0; delay(); sclk=1; io=acc3; sclk=0; delay(); sclk=1; io=acc4; sclk=0; delay(); sclk=1; io=acc5; sclk=0; delay(); sclk=1; io=acc6; sclk=0; delay(); sclk=1; io=acc7; sclk=0; delay(); sclk=1;///
//sclk=0; ACC=shu; //數(shù)據(jù) io=acc0;/// sclk=0; delay(); sclk=1; io=acc1; sclk=0; delay(); sclk=1; io=acc2; sclk=0; delay(); sclk=1; io=acc3; sclk=0; delay(); sclk=1; io=acc4; sclk=0; delay(); sclk=1; io=acc5; sclk=0; delay(); sclk=1; io=acc6; sclk=0; delay(); sclk=1; io=acc7; sclk=0; delay(); sclk=1;///
rst=0; sclk=0; } ///寫完畢 unsigned char r_1302(unsigned char ADD){
sclk=0; rst=1; ACC=ADD; //地址 io=acc0;/// sclk=0; delay(); sclk=1; io=acc1; sclk=0; delay(); sclk=1; io=acc2; sclk=0; delay(); sclk=1; io=acc3; sclk=0; delay(); sclk=1; io=acc4; sclk=0; delay(); sclk=1; io=acc5; sclk=0; delay(); sclk=1; io=acc6; sclk=0; delay(); sclk=1; io=acc7; sclk=0;///// delay(); sclk=1; delay(); sclk=0; acc0=io; delay(); sclk=1; delay(); sclk=0; acc1=io; delay(); sclk=1; delay(); sclk=0; acc2=io; delay(); sclk=1; delay(); sclk=0; acc3=io; delay(); sclk=1; delay(); sclk=0; acc4=io; delay(); sclk=1; delay(); sclk=0; acc5=io; delay(); sclk=1; delay(); sclk=0; acc6=io; delay(); sclk=1; delay(); sclk=0; acc7=io; delay();
rst=0; sclk=0; return(ACC); } ds1302_c() { w_1302(0x80,0x80); w_1302(0x8e,0x00);
w_1302(0x80,0x50); //;秒 w_1302(0x82,0x06); // 分=0 w_1302(0x84,0x01); //時 =0 w_1302(0x86,0x22); // w_1302(0x88,0x11);// w_1302(0x8a,0x04);// w_1302(0x8b,0x07);//
w_1302(0x8e,0x80); w_1302(0x90,0xa6); w_1302(0x80,0x00); } main(){ rst=0; ds1302_c();
for(;;){ P2=r_1302(0x81); } }
--------------------------------------------------------------------------------------------------------------- 文件2:完全版 有關(guān)燈鍵.c
#include sbit di = P2^7; ////////定義引腳 sbit rw = P2^6; sbit e = P2^5; sbit cs1 = P2^4; sbit cs2 = P2^1; sbit lcd_d = P2^0; sbit key0 = P2^3; sbit key1 = P2^2; sbit key2 = P1^0; sbit key3 = P1^1; sbit P07 = P0^7; sbit P06 = P0^6; sbit P05 = P0^5; sbit P04 = P0^4; sbit P03 = P0^3; //ds1302 sbit sclk=P1^4; sbit io=P1^3; sbit rst=P1^2; sbit acc0=ACC^0; sbit acc1=ACC^1; sbit acc2=ACC^2; sbit acc3=ACC^3; sbit acc4=ACC^4; sbit acc5=ACC^5; sbit acc6=ACC^6; sbit acc7=ACC^7; typedef unsigned char byte; typedef unsigned int word; sbit KEY=P3^7;//根據(jù)實際情況定義端口ds1820 unsigned char key_time=0; //全局變量
//////////////////////////////////溫度 //ds18b20數(shù)字溫度傳感器模塊程序
void delay1(word useconds) { for(;useconds>0;useconds--); }
//復位 byte ow_reset(void) { byte presence; KEY = 0; //pull DQ line low delay1(29); // leave it low for 480us KEY = 1; // allow line to return high delay1(3); // wait for presence presence = KEY; // get presence signal delay1(25); // wait for end of timeslot return(presence); // presence signal returned } // 0=presence, 1 = no part
//從 1-wire 總線上讀取一個字節(jié) byte read_byte(void) { byte i; byte value = 0; for (i=8;i>0;i--) { value>>=1; KEY = 0; // pull DQ low to start timeslot KEY = 1; // then return high delay1(1); //for (i=0; i<3; i++); if(KEY)value|=0x80; delay1(6); // wait for rest of timeslot } return(value); }
//向 1-WIRE 總線上寫一個字節(jié) void write_byte(char val) { byte i; for (i=8; i>0; i--) // writes byte, one bit at a time { KEY = 0; // pull DQ low to start timeslot KEY = val&0x01; delay1(5); // hold value for remainder of timeslot KEY = 1; val=val/2; } delay1(5); }
//讀取溫度 float wendu(void) { float tem; union{ byte c[2]; int x; }temp;
ow_reset(); write_byte(0xCC); // Skip ROM write_byte(0xBE); // Read Scratch Pad temp.c[1]=read_byte(); //lsd temp.c[0]=read_byte(); //msd ow_reset(); write_byte(0xCC); //Skip ROM write_byte(0x44); // Start Conversion
tem=0.0; if(temp.x & 0x01) tem+=0.0625;temp.x>>=1; if(temp.x & 0x01) tem+=0.125;temp.x>>=1; if(temp.x & 0x01) tem+=0.25;temp.x>>=1; if(temp.x & 0x01) tem+=0.5;temp.x>>=1; tem+=temp.x;
return tem; }
void cs1_lcd(){ ////////選擇左邊 bit a=1; cs1=a; cs2=!a; } void cs2_lcd(){ ////////選擇右邊 bit a=1; cs1=!a; cs2=a; } void busy_lcd(){//////判斷忙 bit a=1; di=!a; rw=a; e=a; while(P07==a); } w_lcd(unsigned b){ ///寫a到12864 bit a=1; busy_lcd(); rw =!a; di =a; P0=b; e=a; e=!a; } void dis_lcd(){//打開顯示選擇第一行顯示 bit a=1; busy_lcd(); rw=!a; di=!a; P0=0x3f; e=a; e=!a; P0=0xc0; e=a; e=!a; } y_lcd(unsigned a){///由A確定y軸 bit b=1; busy_lcd(); rw=!b; di=!b; P0=a; P07=b; P06=!b; P05=b; P04=b; P03=b; e=b; e=!b; } x_lcd(unsigned a){//由a確定X軸 bit b=1; busy_lcd(); rw=!b; di=!b; P0=a; P07=!b; P06=b; e=b; e=!b; }
void clr_lcd(){///清屏 bit a=0; unsigned x,y,date,i; cs1_lcd(); date=0x00; for(i=0;i<2;i++){ for(y=0;y<8;y++) for(x=0;x<64;x++){ x_lcd(x); y_lcd(y); w_lcd(date); } cs2_lcd();} }
unsigned char code shu[18][16]={///0到9數(shù)字 {0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00},//0 {0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00},//1 {0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00},//2 {0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00},//3 {0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00},///4 {0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00},//5 {0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00},//6 {0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00},//7 {0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00},//8 {0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00},//9 {0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00},// : {0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00},// / }; unsigned char code shu1[9][32]={/// {0x02,0x42,0x42,0xFE,0x42,0x42,0xFE,0x02,0x02,0xFA,0x02,0x02,0xFE,0x00,0x00,0x00,0x08,0x08,0x08,0x07,0x84,0x44,0x23,0x18,0x06,0x01,0x3E,0x40,0x43,0x40,0x78,0x00},//現(xiàn)12 {0x00,0x04,0x04,0xC4,0x64,0x9C,0x87,0x84,0x84,0xE4,0x84,0x84,0x84,0x84,0x04,0x00,0x04,0x02,0x01,0x7F,0x00,0x20,0x20,0x20,0x20,0x3F,0x20,0x20,0x20,0x20,0x20,0x00},//在 13 {0x00,0xFC,0x44,0x44,0x44,0xFC,0x10,0x90,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x00,0x00,0x07,0x04,0x04,0x04,0x07,0x00,0x00,0x03,0x40,0x80,0x7F,0x00,0x00,0x00,0x00},//時 14 {0x00,0xF8,0x01,0x06,0x00,0xF0,0x92,0x92,0x92,0x92,0xF2,0x02,0x02,0xFE,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x07,0x04,0x04,0x04,0x04,0x07,0x40,0x80,0x7F,0x00,0x00},//間 15 {0x00,0x00,0x00,0xBE,0x2A,0x2A,0x2A,0xEA,0x2A,0x2A,0x2A,0x2A,0x3E,0x00,0x00,0x00,0x00,0x48,0x46,0x41,0x49,0x49,0x49,0x7F,0x49,0x49,0x49,0x49,0x49,0x41,0x40,0x00},//星 16 {0x00,0x04,0xFF,0x54,0x54,0x54,0xFF,0x04,0x00,0xFE,0x22,0x22,0x22,0xFE,0x00,0x00,0x42,0x22,0x1B,0x02,0x02,0x0A,0x33,0x62,0x18,0x07,0x02,0x22,0x42,0x3F,0x00,0x00},//期 17 {0x10,0x21,0x86,0x70,0x00,0x7E,0x4A,0x4A,0x4A,0x4A,0x4A,0x7E,0x00,0x00,0x00,0x00,0x02,0xFE,0x01,0x40,0x7F,0x41,0x41,0x7F,0x41,0x41,0x7F,0x41,0x41,0x7F,0x40,0x00},//溫18 {0x00,0x00,0xFC,0x04,0x24,0x24,0xFC,0xA5,0xA6,0xA4,0xFC,0x24,0x24,0x24,0x04,0x00,0x80,0x60,0x1F,0x80,0x80,0x42,0x46,0x2A,0x12,0x12,0x2A,0x26,0x42,0xC0,0x40,0x00},//度19 };
unsigned char time1[7]={0x30,0x00,0x16,8,7,2,8};//分別是秒,分,時,日,月,星期,年 次子程序出自http://www.51hei.com hkcd斑竹,已通過測試無誤。 delay() { unsigned char i; i=10; i=10; i=10; i=10; i=10; i=10; i=10;} w_1302(unsigned char dat,unsigned char shu){//寫一個八位的數(shù)去DS1302 //上升效 ;;;選寫地址再寫數(shù)據(jù)
ACC=dat;//地址 sclk=0; rst=1;// io=acc0;/// sclk=0; delay(); sclk=1; io=acc1; sclk=0; delay(); sclk=1; io=acc2; sclk=0; delay(); sclk=1; io=acc3; sclk=0; delay(); sclk=1; io=acc4; sclk=0; delay(); sclk=1; io=acc5; sclk=0; delay(); sclk=1; io=acc6; sclk=0; delay(); sclk=1; io=acc7; sclk=0; delay(); sclk=1;///
//sclk=0; ACC=shu; //數(shù)據(jù) io=acc0;/// sclk=0; delay(); sclk=1; io=acc1; sclk=0; delay(); sclk=1; io=acc2; sclk=0; delay(); sclk=1; io=acc3; sclk=0; delay(); sclk=1; io=acc4; sclk=0; delay(); sclk=1; io=acc5; sclk=0; delay(); sclk=1; io=acc6; sclk=0; delay(); sclk=1; io=acc7; sclk=0; delay(); sclk=1;///
rst=0; sclk=0; } ///寫完畢 unsigned char r_1302(unsigned char ADD){
sclk=0; rst=1; ACC=ADD; //地址 io=acc0;/// sclk=0; delay(); sclk=1; io=acc1; sclk=0; delay(); sclk=1; io=acc2; sclk=0; delay(); sclk=1; io=acc3; sclk=0; delay(); sclk=1; io=acc4; sclk=0; delay(); sclk=1; io=acc5; sclk=0; delay(); sclk=1; io=acc6; sclk=0; delay(); sclk=1; io=acc7; sclk=0;///// delay(); sclk=1;
delay(); sclk=0; acc0=io; delay(); sclk=1; delay(); sclk=0; acc1=io; delay(); sclk=1; delay(); sclk=0; acc2=io; delay(); sclk=1; delay(); sclk=0; acc3=io; delay(); sclk=1; delay(); sclk=0; acc4=io; delay(); sclk=1; delay(); sclk=0; acc5=io; delay(); sclk=1; delay(); sclk=0; acc6=io; delay(); sclk=1; delay(); sclk=0; acc7=io; delay();
rst=0; sclk=0; return(ACC); } ds1302_c() { w_1302(0x80,0x80); w_1302(0x8e,0x00); w_1302(0x80,time1[0]); //;秒 w_1302(0x82,time1[1]); // 分=0 w_1302(0x84,time1[2]); //時 =0 w_1302(0x86,time1[3]); // 日 w_1302(0x88,time1[4]);// 月 w_1302(0x8a,time1[5]);//星期 w_1302(0x8c,time1[6]);//年 w_1302(0x8e,0x80); w_1302(0x90,0xb8); w_1302(0x80,0x00); }
//x_lcd(unsigned a){//由a確定X軸 //y_lcd(unsigned a){///由A確定y軸 //void dis_lcd(){//打開顯示選擇第一行顯示 //w_lcd(unsigned b){ ///寫a到12864 //void busy_lcd(){//////判斷忙 //void cs1_lcd(){ ////////選擇左邊 //void cs2_lcd(){ ////////選擇右邊 d12864_lcd(unsigned char x,y,k){ unsigned char ix,iy,i; dis_lcd();//打開顯示 if(x>63){ x=x-64; cs2_lcd(); } else cs1_lcd(); i=0; if(k<12){ for(iy=0;iy<2;iy++) for(ix=0;ix<8;ix++){ y_lcd(iy+y); x_lcd(ix+x); w_lcd(shu[k][i]); i++; } } else{k-=12; for(iy=0;iy<2;iy++) for(ix=0;ix<16;ix++){ y_lcd(iy+y); x_lcd(ix+x); w_lcd(shu1[k][i]); i++; } } }
time_lcd(){ unsigned char y,k,time,add,i,we1,we2; add=128;///////必須是小于64-8大于64 d12864_lcd(0,0,12);//: 北 d12864_lcd(16,0,13);//: 京 d12864_lcd(31,0,14);//: 時 d12864_lcd(47,0,15);//: 間 k=0x81; y=0; //在第幾行顯示 for(i=0;i<3;i++){ time=r_1302(k); time1[i]=time; add=add-8;; time=time&0x0f; d12864_lcd(add,y,time);///秒個位 add=add-8; time=r_1302(k); time&=0xf0; time>>=4; d12864_lcd(add,y,time);//秒十位 add=add-8;; k+=2; } d12864_lcd(40+64,y,10);//: d12864_lcd(16+64,y,10);//: 顯示兩點 // time1[5]=r_1302(0x8b); d12864_lcd(64,4,16);//: 星 d12864_lcd(64+16,4,17);//: 期 r_1302(0x8b);//讀星期 d12864_lcd(64+32,4,r_1302(0x8b));//: 讀星期幾`并顯示 //// y=2;//在第四行顯示 add=56+16; time=r_1302(0x87); time1[3]=time; d12864_lcd(add,y,time&0x0f);//: 顯示日 time=r_1302(0x87); time&=0xf0; time>>=4; add-=8; d12864_lcd(add,y,time); //顯示日的十位 add-=8; add-=8; time1[4]=time=r_1302(0x89); d12864_lcd(add,y,time&0x0f);//: 顯示月 time=r_1302(0x89); time&=0xf0; time>>=4; add-=8; d12864_lcd(add,y,time); //顯示月的十位 add-=8; add-=8; time1[6]=time=r_1302(0x8d); d12864_lcd(add,y,time&0x0f);//: 顯示年 time=r_1302(0x8d); time&=0xf0; time>>=4; add-=8; d12864_lcd(add,y,time); //顯示年的十位 //////讀完
d12864_lcd(40+16,y,11);//: d12864_lcd(16+16,y,11);//: 顯示兩/ add-=8; d12864_lcd(add,y,0);//: 0 add-=8; d12864_lcd(add,y,2);//: 2
d12864_lcd(0,4,18);//: 溫 d12864_lcd(16,4,19);//: 度 we1=wendu(); we2=we1/10; d12864_lcd(32,4,we2);//: 2 we2=we1-we2*10; d12864_lcd(40,4,we2);//: 顯示溫度值 cs1_lcd(); y_lcd(4); x_lcd(50); w_lcd(0x18); x_lcd(51); w_lcd(0x18); } /////////////////////////顯示時間完畢
hei_lcd(unsigned char x,y){ //全黑用來做閃標用 char iy,ix,di,i; di=0x00; if(x>63){ x=x-64; cs2_lcd(); } else cs1_lcd(); i=0; for(iy=0;iy<2;iy++){ for(ix=0;ix<16;ix++){ y_lcd(iy+y); x_lcd(ix+x); w_lcd(di); } } } key_t(){ //鍵盤key1 加1 key2 減1
if(!key1){ key_time++; delay1(20000); while(!key1); } if(!key2){ key_time--; delay1(20000); while(!key2); } }
void delay11(word useconds) { for(;useconds>0;useconds--) key_t(); }
time_key(){ unsigned char keyd,ktime; unsigned int year; word kk; keyd=0; kk=10000;///閃動快慢 if(!key0){ for(;;){ if(!key0){ keyd=keyd+1; delay1(500); if(keyd>8)keyd=1; key_time=0;//////每設牟換一個就把存設時間清0 key0=1; while(!key0); key0=1; } ////////////////////////閃程序 if(keyd==1){//=1進入秒閃 同時設置秒時間 key_time=(time1[0]&0x0f)+((time1[0]&0xf0)>>4)*10; //將數(shù)姐里的數(shù)度到key_time里 10進制 hei_lcd(112,0);//x y delay11(kk);//////閃動快慢 if(key_time>=60)key_time=0; d12864_lcd(112,0,key_time/10); d12864_lcd(120,0,key_time-(key_time/10)*10); time1[0]=(((key_time/10)<<4)&0xf0)+(key_time-(key_time/10)*10); //換成BCD碼存到數(shù)組里 delay1(10000); } if(keyd==2){//=1進入分閃 同時設置秒時間 key_time=(time1[1]&0x0f)+((time1[1]&0xf0)>>4)*10; //將數(shù)姐里的數(shù)度到key_time里 10進制 hei_lcd(88,0);//x y delay11(kk);//////閃動快慢 if(key_time>=60)key_time=0; d12864_lcd(88,0,key_time/10); d12864_lcd(96,0,key_time-(key_time/10)*10); delay1(10000); time1[1]=(((key_time/10)<<4)&0xf0)+(key_time-(key_time/10)*10); //換成BCD碼存到數(shù)組里 } if(keyd==3){//=1進入時閃 同時設置秒時間 key_time=(time1[2]&0x0f)+((time1[2]&0xf0)>>4)*10; //將數(shù)姐里的數(shù)度到key_time里 10進制 hei_lcd(64,0);//x y delay11(kk);//////閃動快慢 if(key_time>=24)key_time=0; d12864_lcd(64,0,key_time/10); d12864_lcd(72,0,key_time-(key_time/10)*10); time1[2]=(key_time/10)<<4+(key_time-key_time/10); delay1(10000); time1[2]=(((key_time/10)<<4)&0xf0)+(key_time-(key_time/10)*10); //換成BCD碼存到數(shù)組里 } if(keyd==4){//=1進入年閃 同時設置秒時間 key_time=(time1[6]&0x0f)+((time1[6]&0xf0)>>4)*10; //將數(shù)姐里的數(shù)度到key_time里 10進制 hei_lcd(16,2);//x y delay11(kk);//////閃動快慢 if(key_time>99)key_time=0; d12864_lcd(16,2,key_time/10); d12864_lcd(24,2,key_time-(key_time/10)*10); time1[6]=(key_time/10)<<4+(key_time-key_time/10); delay1(10000); time1[6]=(((key_time/10)<<4)&0xf0)+(key_time-(key_time/10)*10); //換成BCD碼存到數(shù)組里 }
if(keyd==5){//=1進入月閃 同時設置秒時間 key_time=(time1[4]&0x0f)+((time1[4]&0xf0)>>4)*10; //將數(shù)姐里的數(shù)度到key_time里 10進制 hei_lcd(40,2);//x y delay11(kk);//////閃動快慢 if(key_time>=13)key_time=0; d12864_lcd(40,2,key_time/10); d12864_lcd(48,2,key_time-(key_time/10)*10); time1[4]=(key_time/10)<<4+(key_time-key_time/10); delay1(10000); time1[4]=(((key_time/10)<<4)&0xf0)+(key_time-(key_time/10)*10); //換成BCD碼存到數(shù)組里 }
if(keyd==6){//=1進入日閃 同時設置秒時間 key_time=(time1[3]&0x0f)+((time1[3]&0xf0)>>4)*10; //將數(shù)姐里的數(shù)度到key_time里 10進制 year=(time1[4]&0x0f)+(((time1[4]&0xf0)>>4)*10)+2000; switch(time1[4]){ //計算閏月 case 1: ktime=31;break; case 3: ktime=31;break; case 5: ktime=31;break; case 7: ktime=31;break; case 8: ktime=31;break; case 10: ktime=31;break; case 12: ktime=31;break; case 4: ktime=30;break; case 6: ktime=30;break; case 9: ktime=30;break; case 11: ktime=30;break; case 2: if(year%4==0&&year%100!=0||year%400==0) ktime=29; else ktime=29;break; } hei_lcd(64,2);//x y delay11(kk);//////閃動快慢 if(key_time>ktime)key_time=0; d12864_lcd(64,2,key_time/10); d12864_lcd(72,2,key_time-(key_time/10)*10); time1[3]=(key_time/10)<<4+(key_time-key_time/10); delay1(10000); time1[3]=(((key_time/10)<<4)&0xf0)+(key_time-(key_time/10)*10); //換成BCD碼存到數(shù)組里 }
if(keyd==7){//=1進入星期閃 同時設置秒時 char iy,ix,di,i; key_time=time1[5]; di=0x00; cs2_lcd(); i=0; for(iy=0;iy<2;iy++){ for(ix=0;ix<8;ix++){ y_lcd(iy+4); x_lcd(ix+96); w_lcd(di); } di=00; } delay11(kk);//////閃動快慢 if(key_time>7)key_time=0; d12864_lcd(96,4,key_time); time1[5]=key_time; delay1(10000); time1[5]=key_time; //換成BCD碼存到數(shù)組里 } //////////////////// if(!key3)break; } ds1302_c(); ///更改時間 } }
/////////////// lcd_key(){ if(!key3){ if(!key2)lcd_d=1; else lcd_d=0; } } main(){ ds1302_c(); clr_lcd(); for(;;){ time_lcd(); time_key(); lcd_key(); } }
|
|