色婷婷AⅤ一区二区三区|亚洲精品第一国产综合亚AV|久久精品官方网视频|日本28视频香蕉

          新聞中心

          EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > DIY 1602時(shí)鐘可調(diào)節(jié)顯示

          DIY 1602時(shí)鐘可調(diào)節(jié)顯示

          作者: 時(shí)間:2012-08-31 來(lái)源:網(wǎng)絡(luò) 收藏
          #includereg52.h>#define uint unsigned int#define uchar unsigned charsbit key0 = P3^0;//時(shí)間調(diào)節(jié)分秒時(shí)切換sbit key1 = P3^1; //時(shí)間加sbit key2 = P3^2; //時(shí)間減sbit lcdrw = P2^5;//讀寫(xiě)操作選擇,1讀 0寫(xiě)sbit rs = P2^6;//寄存器選擇,1數(shù)據(jù) 0指令sbit lcden = P2^7;//使能信號(hào)uchar code table[] = {" 2010-10-22 FRI"};uchar code table1[] = {"    00:00:00"};uchar count,shi,fen,miao,s1num;void delay(uint z){uint x,y;for(x = z;x > 0;x --)for(y = 110;y > 0;y --);}void write_com(uchar com)//寫(xiě)指令{rs = 0;lcden = 0;P0 = com;delay(5);lcden = 1;delay(5);lcden = 0; }void write_date(uchar date)//寫(xiě)數(shù)據(jù){rs = 1;lcden = 0;P0 = date;delay(5);lcden = 1;delay(5);lcden = 0; }void init(){uchar num;lcdrw = 0;lcden = 0;write_com(0x38);write_com(0x0c);write_com(0x06);write_com(0x01);//清零write_com(0x80); //液晶第一行地址for(num = 0;num  15;num ++){write_date(table[num]);delay(5); }write_com(0x80+0x40);//液晶第二行地址for(num = 0;num  12;num ++){write_date(table1[num]);delay(5);}TMOD = 0x01;TH0 = (65536-50000)/256;TL0 = (65536-50000)%256;EA = 1; // 開(kāi)中斷ET0 = 1; //定時(shí)器0中斷TR0 = 1; //啟動(dòng)定時(shí)器}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 keyscan(){if(key0 == 0){delay(5);if(key0 == 0){s1num ++;while(!key0);if(s1num == 1){TR0 = 0;write_com(0x80+0x40+10);write_com(0x0f);}if(s1num == 2){write_com(0x80+0x40+7);}if(s1num == 3){write_com(0x80+0x40+4);}if(s1num == 4){s1num = 0;write_com(0x0c);//不閃光標(biāo)TR0 = 1;}}}if(s1num != 0){if(key1 == 0){delay(5);if(key1 == 0){while(!key1);if(s1num == 1){miao ++;if(miao == 60)miao = 0;write_sfm(10,miao);write_com(0x80+0x40+10);}if(s1num == 2){fen ++;if(fen == 60)fen = 0;write_sfm(7,fen);write_com(0x80+0x40+7); }if(s1num == 3){shi ++;if(shi == 24)shi = 0;write_sfm(4,shi);write_com(0x80+0x40+4); }}}if(key2 == 0){delay(5);if(key2 == 0){while(!key2);if(s1num == 1){if(miao == 0){miao = 60;write_sfm(10,miao);write_com(0x80+0x40+10);}miao --;write_sfm(10,miao);write_com(0x80+0x40+10);}if(s1num == 2){if(fen == 0){fen = 60;write_sfm(7,fen);write_com(0x80+0x40+7);}fen --;write_sfm(7,fen);write_com(0x80+0x40+7); }if(s1num == 3){if(shi == 0){shi = 24;write_sfm(4,shi);write_com(0x80+0x40+4);}shi --;write_sfm(4,shi);write_com(0x80+0x40+4);}}}} }void main(){init();while(1){keyscan();// while(1);}}void timer0() interrupt 1{TH0 = (65536-50000)/256;TL0 = (65536-50000)%256;count ++;if(count == 20){count = 0;miao ++;if(miao == 60){miao = 0;fen ++;if(fen == 60){fen = 0;shi ++;if(shi ==24){shi = 0;}write_sfm(4,shi);}write_sfm(7,fen);}write_sfm(10,miao);} }


          評(píng)論


          相關(guān)推薦

          技術(shù)專(zhuān)區(qū)

          關(guān)閉