ET2 永恒時(shí)鐘2
【本次功能更新】: 多方法鬧鐘(鬧鐘可設(shè)置 周一至周五 、周六周日、周六、周日、只響一次、天天響、關(guān)閉) 整點(diǎn)報(bào)時(shí)設(shè)置 (可設(shè)置整點(diǎn)報(bào)時(shí)和半點(diǎn)報(bào)時(shí)的時(shí)間范圍。)

這是整點(diǎn)報(bào)時(shí)設(shè)置:↓









這個(gè)作品里面飽含著歡笑與酸辛,甚至還有危險(xiǎn)…… 我原本打算用的是一塊手機(jī)鋰電池(撿的),不帶保護(hù)板,我把電池芯給拆了出來(lái)。接著我用這個(gè)做電源,還給ET2背上安了2塊太陽(yáng)能板。當(dāng)這個(gè)作品裝成,我興高采烈地拿到客廳。誰(shuí)知,危險(xiǎn)的事發(fā)生了,ET2開(kāi)始冒“清”煙,這下了我一跳,渾身出冷汗,條件反射似的把電池直接拔了下來(lái)……后來(lái)檢查電路時(shí),發(fā)現(xiàn)電源沒(méi)有問(wèn)題,鋰電池沒(méi)燒壞,但是連接鋰電池的導(dǎo)線居然燒糊了,導(dǎo)線的塑料殼都是又黑又“脆”的,一碰就“碎”,仔細(xì)檢查,終于發(fā)現(xiàn)了問(wèn)題:太陽(yáng)能板上面的濾波電容的引腳掉了,造成短路……于是我換了一塊電池,選用了18650電池(還是鋰電池),裝在1602后面,單片機(jī)下面,從正面看不到,保證了美觀。 (在此提醒大家:玩鋰電池的時(shí)候注意點(diǎn),鋰電池的輸出能力特別強(qiáng)……這一點(diǎn)我是親身體驗(yàn)過(guò)的……經(jīng)常搞豆腐渣工程的人士們一定要 (像我一樣……)注意啦!你可以選用鎳氫電池或是帶保護(hù)板的鋰電池,短路是不會(huì)爆炸,不會(huì)冒煙的。)
【功能】: 溫度顯示, 16級(jí)背光設(shè)置, 自動(dòng)調(diào)光, 9路鬧鐘, 4鍵調(diào)時(shí)設(shè)置, 整點(diǎn)報(bào)時(shí), 半點(diǎn)報(bào)時(shí), 39個(gè)公歷節(jié)日提醒, 生日提醒, 日期及星期顯示。 多方法鬧鐘(鬧鐘可設(shè)置 周一至周五 、周六周日、周六、周日、只響一次、天天響、關(guān)閉) 整點(diǎn)報(bào)時(shí)設(shè)置 (可設(shè)置整點(diǎn)報(bào)時(shí)和半點(diǎn)報(bào)時(shí)的時(shí)間范圍。)
唉,廢話少說(shuō),上圖! 所需元器件很簡(jiǎn)單!液晶屏直接與單片機(jī)連接,無(wú)需電路板,無(wú)需走線。單片機(jī)產(chǎn)生時(shí)間,無(wú)需時(shí)鐘芯片。四鍵調(diào)時(shí)并設(shè)置,按鈕直接焊在單片機(jī)背部。并具有自動(dòng)調(diào)光功能。
十分簡(jiǎn)單的設(shè)計(jì),大家都可以做的。對(duì)了,我用的一節(jié)18650電池,無(wú)保護(hù)板。可以連接一片5V太陽(yáng)能電池,這樣就無(wú)需維護(hù),充電。
做工不是很美觀,獻(xiàn)丑了。
所需元件列表: 鋰電池*1 標(biāo)準(zhǔn)型1602液晶屏*1 (最好是藍(lán)底白字的,藍(lán)色有永恒的含義。) STC12c5a56s2單片機(jī)*1 (可用stc12c5a08s2或stc12c5a16s2或stc12c5a32s2或stc12c5a56s2或stc12c5a60s2替換) 12M晶振*1 30P電容*2 5V太陽(yáng)能板*2 (一片也可) 排針(圓孔)排孔(圓孔) *2 (16PIN) 微動(dòng)開(kāi)關(guān) 直徑3mmLED*1 5v有源蜂鳴器*1
這么點(diǎn)東西可以做出時(shí)鐘?是不是不信?愛(ài)動(dòng)手的人士們快開(kāi)電烙鐵去吧~

提供電路原理圖:(整整畫(huà)了2個(gè)多小時(shí)啊……) DIY牛人照著這個(gè)圖可以拼出來(lái)。
以上圖片均為第一硬件版本,給大家看看第二硬件版本吧(全新的):(做工相比之前好看多了):
圖片看著不爽?沒(méi)關(guān)系,有視頻:(效果不好,請(qǐng)見(jiàn)諒。。。。)(此為硬件第一版本)
熱烈熱烈熱烈歡迎提出批評(píng)表?yè)P(yáng)或任何建議!
純屬個(gè)人原創(chuàng),希望大家支持! 版權(quán)“龜”我所有,轉(zhuǎn)載請(qǐng)注明出處,謝謝!
源程序公開(kāi): - /********************************************************************
- 編寫人:譚澤睿
- ET2主程序
- 最后修改于2017年8月
- ********************************************************************/
- #include <stc12c5a60s2.h>
- #include <intrins.h>
- //#include <float.h>
- /********************************************************************************************/
- unsigned char code nums[12]={0xfc,0x60,0xda,0xf2,0x66,0xb6,0xbe,0xe0,0xfe,0xf7,0x00,0x02};
- typedef unsigned char uint8; // 無(wú)符號(hào)8位整型變量 //
- unsigned int code fs[39]={32,76,101,105,107,108,114,115,125,129,131,146,156,159,163,178,
- 187,191,209,218,228,249,/*260*/289,311,314,315,319,334,338,339,341,349,355,373,375,396,397,
- 403
- };
- unsigned int code tab[]={ //音階表
- 63628,63835,64021,64103,64260,64400,64524, //低音1-7
- 64580,64684,64777,64820,64898,64968,65030,//中音1-7
- 65058,65110,65157,65178,65217,65252,65283//高音1-7
- };
- unsigned int code br[3]={213,222,216};
- unsigned char alm[9][3]={{6,30,0},{7,30,0},{8,30,0},
- {0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}
- };//Hour Min Way
- //#defineLCM2402_DB0_DB7P0
- sbit LCM2402_RS = P2 ^ 3;
- sbit LCM2402_RW = P2 ^ 4;
- sbit LCM2402_E = P2 ^ 5;
- sbit LCM2402_Busy = P0 ^ 5;
- data unsigned char year,month,day,week,hour,min,sec;
- data bit db = 0;
- bit kj;
- bit rbit;
- unsigned char autolum;
- data unsigned char cou = 0;
- unsigned char i,hh,ll;
- //unsigned char mh;
- //unsigned char ml;
- unsigned char set,aln,reps,repe;
- unsigned char mo;
- unsigned char p;
- unsigned char v;
- unsigned char ke;
- unsigned char mt;
- unsigned char menu;
- unsigned char RP;
- unsigned char dbs;
- unsigned char light;
- unsigned int beepc,C,D;
- #defineCMD_clear0x01 // 清除屏幕
- #defineCMD_back0x02 // DDRAM回零位
- #defineCMD_dec10x04 // 讀入后AC(指針)減1,向左寫
- #defineCMD_add10x06 // 讀入后AC(指針)加1,向右寫
- #defineCMD_dis_gb10x0f // 開(kāi)顯示_開(kāi)光標(biāo)_開(kāi)光標(biāo)閃爍
- #defineCMD_dis_gb20x0e // 開(kāi)顯示_開(kāi)光標(biāo)_關(guān)光標(biāo)閃爍
- #defineCMD_dis_gb30x0c // 開(kāi)顯示_關(guān)光標(biāo)_關(guān)光標(biāo)閃爍
- #defineCMD_OFF_dis0x08 // 關(guān)顯示_關(guān)光標(biāo)_關(guān)光標(biāo)閃爍
- #defineCMD_set820x38 // 8位總線_2行顯示
- #defineCMD_set810x30 // 8位總線_1行顯示(上邊行)
- #defineCMD_set420x28 // 4位總線_2行顯示
- #defineCMD_set410x20 // 4位總線_1行顯示(上邊行)
- #definelin_10x80 // 4位總線_1行顯示(上邊行)
- #definelin_20xc0 // 4位總線_1行顯示(上邊行)
- #define bee beep=0;beepc=1
- #define lbee beep=0;beepc=10
- sbit vss = P2^0;
- sbit vdd = P2^1;
- sbit vo = P2^2;
- //sbit RS = P2^3;
- sbit db0 = P2^6;
- sbit db1 = P2^7;
- sbit db2 = P4^4;
- sbit db3 = P4^5;
- sbit db4 = P4^6;
- sbit db5 = P0^7;
- sbit db6 = P0^6;
- sbit db7 = P0^5;
- sbit blv=P0^4;
- sbit blg=P0^3;
- sbit KEYAG=P3^7;
- sbit KEYA=P3^5;
- sbit KEYBG=P3^4;
- sbit KEYB=P3^2;
- sbit KEYCG=P3^1;
- sbit KEYC=P4^7;
- sbit KEYDG=P1^7;
- sbit KEYD=P1^5;
- sbit ka=P1^4;
- sbit RC=P1^1;
- sbit beep=P1^0;
- sbit ltv=P4^6;
- sbit lm35vcc=P1^1;
- sbit lm35gnd=P1^3;
- sbit rlv=P0^1;
- sbit rl=P0^0;
- void delay (unsigned int a){
- unsigned int i;
- while(a > 0){
- a--;
- for(i=0;i<600;i++);
- }
- }
- void db07(unsigned char dbs){
- db0=dbs%2;
- db1=dbs/2%2;
- db2=dbs/4%2;
- db3=dbs/8%2;
- db4=dbs/16%2;
- db5=dbs/32%2;
- db6=dbs/64%2;
- db7=dbs/128%2;
- }
- /*********************************************************************************************
- 函數(shù)名:10位A/D轉(zhuǎn)換初始化函數(shù)
- 調(diào) 用:Read_init (?);
- 參 數(shù):輸入的端口(0000 0XXX 其中XXX是設(shè)置輸入端口號(hào),可用十進(jìn)制0~7表示,0表示P1.0,7表示P1.7)
- 返回值:無(wú)
- 結(jié) 果:開(kāi)啟ADC功能并設(shè)置ADC的輸入端口
- 備 注:使用ADC功能時(shí)需要將對(duì)應(yīng)的IO接口設(shè)置為高阻輸入方式(例如:P1M1 = 0x01;)
- /**********************************************************************************************/
- void Read_init (unsigned char CHA){
- unsigned char AD_FIN=0; //存儲(chǔ)A/D轉(zhuǎn)換標(biāo)志
- CHA &= 0x07; //選擇ADC的8個(gè)接口中的一個(gè)(0000 0111 清0高5位)
- ADC_CONTR = 0x40;//ADC轉(zhuǎn)換的速度(0XX0 0000 其中XX控制速度,請(qǐng)根據(jù)數(shù)據(jù)手冊(cè)設(shè)置)
- _nop_();
- ADC_CONTR |= CHA; //選擇A/D當(dāng)前通道
- _nop_();
- ADC_CONTR |= 0x80; //啟動(dòng)A/D電源
- delay(1); //使輸入電壓達(dá)到穩(wěn)定(1ms即可)
- }
- /**********************************************************************************************/
- /*********************************************************************************************
- 函數(shù)名:10位A/D轉(zhuǎn)換函數(shù)
- 調(diào) 用:? = ADC_Read();
- 參 數(shù):無(wú)
- 返回值:10位ADC數(shù)據(jù)高(從0到1023(十進(jìn)制))
- 結(jié) 果:讀出指定ADC接口的A/D轉(zhuǎn)換值,并返回?cái)?shù)值
- 備 注:適用于STC12C5A60S2系列單片機(jī)(必須使用STC12C5A60S2.h頭文件)
- /**********************************************************************************************/
- unsigned int ADC_Read (void){
- unsigned char AD_FIN=0; //存儲(chǔ)A/D轉(zhuǎn)換標(biāo)志
- ADC_CONTR |= 0x08; //啟動(dòng)A/D轉(zhuǎn)換(0000 1000 令A(yù)DCS = 1)
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- while (AD_FIN ==0){ //等待A/D轉(zhuǎn)換結(jié)束
- AD_FIN = (ADC_CONTR & 0x10); //0001 0000測(cè)試A/D轉(zhuǎn)換結(jié)束否
- }
- ADC_CONTR &= 0xE7; //1111 0111 清ADC_FLAG位, 關(guān)閉A/D轉(zhuǎn)換,
- return (ADC_RES*4+ADC_RESL);//返回A/D轉(zhuǎn)換結(jié)果(10位ADC數(shù)據(jù)高8位在ADC_RES中,低2位在ADC_RESL中)
- }
- void LCM2402_TestBusy(void){
- db07(0xff);//設(shè)備讀狀態(tài)
- LCM2402_RS = 0;
- LCM2402_RW = 1;
- LCM2402_E = 1;
- while(LCM2402_Busy);//等待LCM不忙
- LCM2402_E = 0;//
- }
- /********************************************************************************************
- // 寫指令程序 //
- // 向LCM2402寫命令 本函數(shù)需要1個(gè)指令集的入口參數(shù) //
- /********************************************************************************************/
- void LCM2402_WriteCMD(uint8 LCM2402_command) {
- LCM2402_TestBusy();
- db07(LCM2402_command);
- LCM2402_RS = 0;
- LCM2402_RW = 0;
- LCM2402_E = 1;
- LCM2402_E = 0;
- }
- void PWM_init (void){
- CMOD=0x00; //設(shè)置PCA定時(shí)器
- CL=0x00;
- CH=0x00;
- CCAPM0=0x42; //PWM0設(shè)置PCA工作方式為PWM方式(0100 0010)
- CCAP0L=0x00; //設(shè)置PWM0初始值與CCAP0H相同
- CCAP0H=0x00; // PWM0初始時(shí)為0
- CR=1; //啟動(dòng)PCA定時(shí)器
- }
- /**********************************************************************************************/
- /*********************************************************************************************
- 函數(shù)名:PWM0占空比設(shè)置函數(shù)
- 調(diào) 用:PWM0_set();
- 參 數(shù):0x00~0xFF(亦可用0~255)
- 返回值:無(wú)
- 結(jié) 果:設(shè)置PWM模式占空比,為0時(shí)全部高電平,為1時(shí)全部低電平
- 備 注:如果需要PWM1的設(shè)置函數(shù),只要把CCAP0L和CCAP0H中的0改為1即可
- /**********************************************************************************************/
- void PWM0_set (unsigned char a){
- hh=a;
- ll=0xff-a;
- TR1=1;
- }
- /********************************************************************************************
- // 寫數(shù)據(jù)程序 //
- // 向LCM2402寫數(shù)據(jù) //
- /********************************************************************************************/
- void LCM2402_WriteData(uint8 LCM2402_data){
- LCM2402_TestBusy();
- db07(LCM2402_data);
- LCM2402_RS = 1;
- LCM2402_RW = 0;
- LCM2402_E = 1;
- LCM2402_E = 0;
- }
- /********************************************************************************************
- // 打印字符串程序 // (本函數(shù)調(diào)用指針函數(shù))
- // 向LCM發(fā)送一個(gè)字符串,長(zhǎng)度48字符之內(nèi)
- // 第一行位置 0x00~0x17 第二行位置 0x40~0x57
- // 應(yīng)用舉例:print(0x80,"doyoung.net"); //在第一行第一位處從左向右打印doyoung.net字符串
- /********************************************************************************************/
- void print(uint8 a,uint8 *str){
- LCM2402_WriteCMD(a | 0x80);
- while(*str != '\0'){
- LCM2402_WriteData(*str++);
- }
- *str = 0;
- }
- /********************************************************************************************
- // 打印單字符程序 //
- // 第一行位置 0x00~0x17 第二行位置 0x40~0x57
- // 向LCM發(fā)送一個(gè)字符,以十六進(jìn)制(0x00)表示
- // 應(yīng)用舉例:print(0xc0,0x30); //在第二行第一位處打印字符“0”
- /********************************************************************************************/
- void print2(uint8 a,uint8 t){
- LCM2402_WriteCMD(a | 0x80);
- LCM2402_WriteData(t+0x30);
- }
- void print3(uint8 a,uint8 t){
- LCM2402_WriteCMD(a | 0x80);
- LCM2402_WriteData(t);
- }
- /********************************************************************************************
- // 定義小漢字 //
- // 可寫入8個(gè)自字義字符,寫入后可用其CGRAM代碼直接提取顯示。
- // 字符定義方法請(qǐng)參考技術(shù)手冊(cè)
- /********************************************************************************************/
- uint8 code Xword[]={
- 0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00, //上,代碼 0x00
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F, //下,代碼 0x01
- 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, //左,代碼 0x02
- 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, //右,代碼 0x03
- 0x1f,0x00,0x00,0x00,0x00,0x00,0x00,0x1f, //上下,代碼 0x04
- 0x00,0x00,0x04,0x04,0x00,0x00,0x00,0x00, //點(diǎn)上,代碼 0x05
- 0x00,0x00,0x00,0x00,0x04,0x04,0x00,0x00,//點(diǎn)下,代碼 0x06
- 0x00,0x01,0x00,0x1E,0x10,0x10,0x10,0x1E //度,代碼 0x07
- /*0x00,0x1f,0x00,0x1f,0x10,0x1f,0x10,0x1f,//恒右上,代碼 0x08
- 0x10,0x00,0x1f,0x00,0x00,0x00,0x00,0x00,//恒右下,代碼 0x09
- 0x10,0x18,0x00,0x10,0x10,0x10,0x10,0x10,//恒右上上,代碼 0x0a
- 0x10,0x00,0x18,0x00,0x00,0x00,0x00,0x00,//恒右下下,代碼 0x0b */
- };
- void CgramWrite(void) {// 裝入CGRAM //
- uint8 i;
- LCM2402_WriteCMD(0x06);// CGRAM地址自動(dòng)加1
- LCM2402_WriteCMD(0x40);// CGRAM地址設(shè)為00處
- for(i=0;i<8*8;i++) {
- LCM2402_WriteData(Xword[i]);// 按數(shù)組寫入數(shù)據(jù)
- }
- }
- void LCM2402_Init(void){
- LCM2402_WriteCMD(CMD_set82);//* 顯示模式設(shè)置:顯示2行,每個(gè)字符為5*7個(gè)像素
- LCM2402_WriteCMD(CMD_clear);// 顯示清屏
- LCM2402_WriteCMD(CMD_back);//* 數(shù)據(jù)指針指向第1行第1個(gè)字符位置
- LCM2402_WriteCMD(CMD_add1);// 顯示光標(biāo)移動(dòng)設(shè)置:文字不動(dòng),光標(biāo)右移
- LCM2402_WriteCMD(CMD_dis_gb3); // 顯示開(kāi)及光標(biāo)設(shè)置:顯示開(kāi),光標(biāo)開(kāi),閃爍開(kāi)
- CgramWrite();// 向CGRAM寫入自定義字符
- }
- bit IsLeapYear(void){ //計(jì)算本年是否是潤(rùn)年
- unsigned int a;
- a = 2000+year;//加2000表示成完整的年
- if((a%4==0 && a%100!=0)||(a%400==0)){ //潤(rùn)年的計(jì)算公式
- return 1;//是潤(rùn)年返回1
- }else{
- return 0;//不是潤(rùn)年返回0
- }
- }
- void month_day(void){
- unsigned char mon_day[]={31,28,31,30,31,30,31,31,30,31,30,31};
- day++;
- week++;
- if(week>7){
- week=1;
- }
- if(day > mon_day[month-1]){
- if(IsLeapYear()&&month==2){
- day = 29;
- }else{
- day = 1;
- month++;
- if(month > 12){
- month = 1;
- year++;
- }
- }
- }
- }
- void clear(void){
- print(0x80," ");
- print(0x40," ");
- }
- void change(void){
- bee;
- for(i=light;i>0;i--){
- PWM0_set(i);
- delay(2);
- }
- clear();
- for(i=0;i<0xff;i++){
- PWM0_set(i);
- delay(1);
- }
- for(i=0xff;i>light;i--){
- PWM0_set(i);
- delay(2);
- }
- }
- void jieri(void){
- v=0xff;
- for(i=0;i<38;i++){
- if(fs[i]/31==month && fs[i]%31==day){
- v=i;
- break;
- }
- }
- if(v==0){print(0x40,"Happy New Year! ");}
- if(v==1){print(0x40,"Valentine's Day ");}
- if(v==2){print(0x40," 38-Women's Day ");}
- if(v==3){print(0x40,"China Arbor Day ");}
- if(v==4){print(0x40," White Day ^-^ ");}
- if(v==5){print(0x40,"ConsumerRightDay");}
- if(v==6){print(0x40,"World Forest Day");}
- if(v==7){print(0x40,"World Water Day ");}
- if(v==8){print(0x40,"April Fools' Day");}
- if(v==9){print(0x40,"TombSweeping Day");}
- if(v==10){print(0x40,"World Health Day");}
- if(v==11){print(0x40,"World Earth Day ");}
- if(v==12){print(0x40,"5-1 Labour Day ");}
- if(v==13){print(0x40,"China Youth Day ");}
- if(v==14){print(0x40," Red-Cross Day ");}
- if(v==15){print(0x40," -Milk Day- ");}
- if(v==16){print(0x40,"-Children's Day-");}
- if(v==17){print(0x40,"Environment Day ");}
- if(v==18){print(0x40," Olympic Day ");}
- if(v==19){print(0x40,"Dang De Sheng Ri");}
- if(v==20){print(0x40," Population Day ");}
- if(v==21){print(0x40," the Army Day ");}
- if(v==22){print(0x40,"ChinaTeachersDay");}
- if(v==23){print(0x40," National Day ");}
- if(v==24){print(0x40,"World Animal Day");}
- if(v==25){print(0x40,"WorldTeachersDay");}
- if(v==26){print(0x40," World Post Day ");}
- if(v==27){print(0x40,"UnitedNationsDay");}
- if(v==28){print(0x40,"Mens Healthy Day");}
- if(v==29){print(0x40,"Biodiversity Day");}
- if(v==30){print(0x40," Halloween ");}
- if(v==31){print(0x40,"ChinaReporterDay");}
- if(v==32){print(0x40,"WorldDiabetesDay");}
- if(v==33){print(0x40," World AIDS Day ");}
- if(v==34){print(0x40,"WorldDisabledDay");}
- if(v==35){print(0x40,"WorldFootballDay");}
- if(v==36){print(0x40,"Christmas Night ");}
- if(v==37){print(0x40," Christmas Day ");}
- if(v==38){
- print(0x40," 20");
- print2(0x43,year/10);
- print2(0x44,year%10);
- print(0x45," Last Day ");
- }
- if(v==0xff){
- print(0x40,"Good ");
- if(hour<11){print(0x45,"morning!^_^");
- }else if(hour<13){print(0x45,"noon! ^_^");
- }else if(hour<18){print(0x45,"afternoon(:");
- }else if(hour<21){print(0x45,"evening!^-^");
- }else if(hour<24){print(0x45,"night!-_-zZ");
- }
- }
- }
- void birth(void){
- v=0xff;
- for(i=0;i<3;i++){
- if(br[i]/31==month && br[i]%31==day){
- v=i;
- break;
- }
- }
- if(v==0){print(0x40,"TZR's Birthday! ");}
- if(v==1){print(0x40,"CSJ's Birthday! ");}
- if(v==2){print(0x40,"TXT's Birthday! ");}
- if(v==0xff){
- print(0x40,"^_^ -_- 0_0");
- print(0x4b,":");
- print2(0x4c,sec/10);
- print2(0x4d,sec%10);
- print(0x4e,"s");
- print(0x4f," ");
- }
- }
- void time (void){
- if(sec%30/15==0){
- print2(0x80,C/10);
- print2(0x81,C%10);
- //print(0x82,".");
- //print2(0x83,D/10);
- print3(0x82,0x07);
- print(0x83," ");
- if(month>9){print2(0x85,month/10);}else{print(0x85," ");}
- print2(0x86,month%10);
- print(0x87,"-");
- if(day>9){print2(0x88,day/10);}else{print(0x88," ");}
- print2(0x89,day%10);
- print(0x8a," ");
- }else{
- if(week==1){print(0x80," MonDay ");}
- if(week==2){print(0x80," TuesDay ");}
- if(week==3){print(0x80," WednesDay ");}
- if(week==4){print(0x80," ThursDay ");}
- if(week==5){print(0x80," FriDay ");}
- if(week==6){print(0x80," SaturDay ");}
- if(week==7){print(0x80," SunDay ");}
- }
- print2(0x8b,hour/10);
- print2(0x8c,hour%10);
- if(sec%2==0){
- print(0x8d,":");
- }else{
- print(0x8d,"-");
- }
- print2(0x8e,min/10);
- print2(0x8f,min%10);
- if(sec%20/10==0){
- jieri();
- }else{
- birth();
- }
- if(db == 1){
- month_day();
- db = 0;
- }
- }
- /*void sound (unsigned char v,unsigned char b){
- ET1=1;
- TH1=mh;
- TL1=ml;
- TR1=1;
- } */
- void KEY(void){
- ke=0xff;
- KEYA=1;
- KEYB=1;
- KEYC=1;
- KEYD=1;
- delay(1);
- if(KEYA==0){delay(20);if(KEYA==0){ke=0x0a;while(~KEYA);}}
- if(KEYB==0){delay(20);if(KEYB==0){ke=0x0b;while(~KEYB);}}
- if(KEYC==0){delay(20);if(KEYC==0){ke=0x0c;while(~KEYC);}}
- if(KEYD==0){delay(20);if(KEYD==0){ke=0x0d;while(~KEYD);}}
- if(ke!=0xff){bee;}
- }
- void showbignum(unsigned char hour,unsigned char min){
- unsigned char s1,s2,s3,s4,temp;
- bit a,b,c,d,e,f,g;
- s1=hour/10;
- s2=hour%10;
- s3=min/10;
- s4=min%10;
- temp=nums[s1];
- a=temp/128;
- b=temp/64%2;
- c=temp/32%2;
- d=temp/16%2;
- e=temp/8%2;
- f=temp/4%2;
- g=temp/2%2;
- if(a==1){
- print3(0x81,0);
- }
- if(b==1){
- print3(0x82,2);
- }
- if(c==1){
- print3(0x42,2);
- }
- if(d==1 && g==0){
- print3(0x81,1);
- }
- if(e==1){
- print3(0x40,3);
- }
- if(f==1){
- print3(0x80,3);
- }
- if(g==1){
- print3(0x81,4);
- }
- }
- void init (void) {
- //mh=0x00;
- //ml=0x00; 3.5 3.2 4.7 1.5
- beep=1;
- beepc=0;
- mo=1;
- KEYAG=0;
- KEYBG=0;
- KEYCG=0;
- KEYDG=0;
- TMOD = 0x01;
- TH0 = 0x3c;
- TL0 = 0xb0;
- TH1 = 0x00;
- TL1 = 0x00;
- EA = 1;
- ET0 = 1;
- ET1 = 1;
- TR0 = 1;
- TR1 = 1;
- menu=0;
- P4SW=0x70;
- P2M0=0x02;
- P0M0=0x10;
- /*P3M1=0x24;
- P4M1=0x80;
- P1M1=0x20;*/
- blv=0;
- blg=0;
- vss=0;
- vdd=1;
- vo=0;
- ltv=1;
- P1M1=0x04;
- P1M0=0x02;
- RC=1;
- RP=0;
- //Read_init(1);
- Read_init(2);
- rbit=0;
- if(day==0){
- year=11;
- month=8;
- day=13;
- week=6;
- hour=8;
- min=51;
- sec=50;
- }
- kj=1;
- light=0xa0;
- LCM2402_Init();//LCM2402初始化
- PWM_init();
- PWM0_set(light);
- //sound();
- change();
- autolum=1;
- lm35vcc=1;
- lm35gnd=0;
- P0M0=0x12;
- P0M1=0x01;
- rlv=1;
- rl=0;
- reps=6;
- repe=23;
- }
- void main (void){
- init();
- while (kj){
- /*print3(0x80,0x00);
- print3(0x81,0x02); //永
- print3(0x82,0x04);
- print3(0x40,0x01);
- print3(0x41,0x03);
- print3(0x42,0x05);
-
- print3(0x83,0x06);
- print3(0x84,0x08); //恒
- print3(0x85,0x0a);
- print3(0x43,0x07);
- print3(0x44,0x09);
- print3(0x45,0x0b);
- delay(2000);
- */
- change();
- print(0x80,"Everlasting Time");
- print(0x40," -V3- TZR Studio");
- delay(5000);
- kj=0;
- }
- change();
- while(1){ //主線程//
- //LCM2402_Init();
- if(cou==0){
- C=(ADC_Read()-8)*1000;
- C/=2048;
- }
- if(autolum==1 && rbit==1){
- rbit=0;
- LCM2402_Init();
- //LCM2402_Init();
- if(rl==1){
- light=165;
- PWM0_set(light);
- }else if(rl==0){
- light=45;
- PWM0_set(light);
- }
- }else if(autolum==0 && rbit==1){
- rbit=0;
- LCM2402_Init();
- //LCM2402_Init();
- }/*else if(autolum==2 && rbit==1){
- RC=1;
- rbit=0;
- delay(1);
- RP=ADC_Read();
- /*if(RP*4>245){
- light=RP*4-80*3;
- }else{
- light=5;
- }
- if(RP*4>495){
- light=255;
- }*//*
- light=RP;
- PWM0_set(light);
- RC=0;
- } */
- if(menu==0){
- aln=0xff;
- for(i=0;i<9;i++){
- if(alm[i][0]==hour && alm[i][1]==min && alm[i][2]==1){
- aln=i;
- break;
- }
- }
- if(aln==0xff){
- time();
- }else{
- print(0x80,"Alarm");
- print2(0x85,(i+1));
- print(0x86," ");
- print2(0x87,hour/10);
- print2(0x88,hour%10);
- print(0x89,":");
- print2(0x8a,min/10);
- print2(0x8b,min%10);
- print(0x8c," Pre");
- print(0x40,"ss any keys stop");
- }
- }else if(menu==1){
- print(0x80,"[A B C D]");
- print2(0x8d,mt/10);
- print2(0x8e,mt%10);
- print(0x8f,"s");
- print(0x40,"Alm Time Lum Rep");
- if(mt==0){
- menu=0;
- change();
- }
- }else if(menu==2){
- if(set==0){
- print(0x80,"[+1 -1 SET ESC]");
- print(0x40,"Alm");
- print2(0x43,mo);
- print(0x44," ");
- print2(0x45,alm[mo-1][0]/10);
- print2(0x46,alm[mo-1][0]%10);
- print(0x47,":");
- print2(0x48,alm[mo-1][1]/10);
- print2(0x49,alm[mo-1][1]%10);
- if(alm[mo-1][2]==0){
- print(0x4a," Close");
- }else if(alm[mo-1][2]==1){
- print(0x4a," Open ");
- }else if(alm[mo-1][2]==2){
- print(0x4a," W1-5 ");
- }else if(alm[mo-1][2]==3){
- print(0x4a," W6-7 ");
- }else if(alm[mo-1][2]==4){
- print(0x4a," W 6 ");
- }else if(alm[mo-1][2]==5){
- print(0x4a," W 7 ");
- }else if(alm[mo-1][2]==6){
- print(0x4a," Once ");
- }
- }else{
- print(0x80,"+/-/next/OK ");
- if(mo==0){print(0x8c,"Hour");}
- if(mo==1){print(0x8c,"Mins");}
- if(mo==2){print(0x8c,"Ways");}
- print(0x40,"Alm");
- print2(0x43,set);
- print(0x44," ");
- print2(0x45,alm[set-1][0]/10);
- print2(0x46,alm[set-1][0]%10);
- print(0x47,":");
- print2(0x48,alm[set-1][1]/10);
- print2(0x49,alm[set-1][1]%10);
- if(alm[set-1][2]==0){
- print(0x4a," Close");
- }else if(alm[set-1][2]==1){
- print(0x4a," Open ");
- }else if(alm[set-1][2]==2){
- print(0x4a," W1-5 ");
- }else if(alm[set-1][2]==3){
- print(0x4a," W6-7 ");
- }else if(alm[set-1][2]==4){
- print(0x4a," W 6 ");
- }else if(alm[set-1][2]==5){
- print(0x4a," W 7 ");
- }else if(alm[set-1][2]==6){
- print(0x4a," Once ");
- }
- }
- }else if(menu==3){
- print(0x80,"[+1 -1 next ESC]");
- if(mo==0){
- print(0x40,"Year");
- print2(0x45,2);
- print2(0x46,0);
- print2(0x47,year/10);
- print2(0x48,year%10);
- }else if(mo==1){
- print(0x40,"Month");
- print(0x46,":");
- print2(0x47,month/10);
- print2(0x48,month%10);
- }else if(mo==2){
- print(0x40,"Day ");
- print(0x46,":");
- print2(0x47,day/10);
- print2(0x48,day%10);
- }else if(mo==3){
- print(0x40,"Hour ");
- print(0x46,":");
- print2(0x47,hour/10);
- print2(0x48,hour%10);
- }else if(mo==4){
- print(0x40,"Min ");
- print(0x46,":");
- print2(0x47,min/10);
- print2(0x48,min%10);
- }else if(mo==5){
- if(week==1){print(0x40," MonDay ");}
- if(week==2){print(0x40," TuesDay ");}
- if(week==3){print(0x40," WednesDay ");}
- if(week==4){print(0x40," ThursDay ");}
- if(week==5){print(0x40," FriDay ");}
- if(week==6){print(0x40," SaturDay ");}
- if(week==7){print(0x40," SunDay ");}
- }
- }else if(menu==4){
- PWM0_set(light);
- print(0x80,"[+F -F Auto ESC]");
- print(0x40,"Lum:");
- print2(0x44,light/100%10);
- print2(0x45,light/10%10);
- print2(0x46,light%10);
- print(0x47," Auto:");
- if(autolum==0){
- print(0x4d,"OFF");
- }else if(autolum==1){
- print(0x4d,"ON ");
- }else if(autolum==2){
- print(0x4d,"AS ");
- }
- }else if(menu==5){
- /*print(0x80,"Sorry! This mode");
- print(0x40,"is open up now! ");
- delay(3000);
- menu=0;
- */
- print(0x80,"[St Ed Rep ESC]");
- if(reps!=0xff){
- print2(0x40,reps/10);
- print2(0x41,reps%10);
- print(0x42,":00 to ");
- print2(0x49,repe/10);
- print2(0x4a,repe%10);
- print(0x4b,":00");
- }else{
- print(0x40," -Closed- ");
- }
- }
- /****************************按鈕操作***************************/
- KEY();
- if(menu==0){
- if(ke!=0xff){menu=1;mt=15;change();}
- }else if(menu==1){
- if(ke==0x0a){menu=2;change();mo=1;set=0;}
- if(ke==0x0b){menu=3;change();mo=0;}
- if(ke==0x0c){menu=4;change();}
- if(ke==0x0d){menu=5;change();}
- }else if(menu==2){
- if(set==0){
- if(ke==0x0a){mo++;if(mo==10){mo=1;}}
- if(ke==0x0b){mo--;if(mo==0){mo=9;}}
- if(ke==0x0c){set=mo;mo=0;}
- if(ke==0x0d){menu=0;change();}
- }else{
- if(ke==0x0a){
- if(mo==2){
- alm[set-1][2]++;
- if(alm[set-1][2]==7){
- alm[set-1][2]=0;
- }else if(alm[set-1][2]==0){
- alm[set-1][2]=6;
- }
- }else {
- alm[set-1][mo]++;
- }
- }
- if(ke==0x0b){
- if(mo==2){
- if(alm[set-1][2]>=7){
- alm[set-1][2]=0;
- }else if(alm[set-1][2]==0){
- alm[set-1][2]=7;
- }
- alm[set-1][2]--;
- }else if(alm[set-1][mo]!=0){alm[set-1][mo]--;
- }
- }
- if(ke==0x0c){mo++;if(mo==3){mo=0;}}
- if(ke==0x0d){menu=0;change();}
- if(alm[set-1][0]>23){
- alm[set-1][0]=0;
- }
- if(alm[set-1][0]<0){
- alm[set-1][0]=23;
- }
- if(alm[set-1][1]<0){
- alm[set-1][1]=59;
- }
- }
- }else if(menu==3){
- if(ke==0x0a){
- if(mo==0){year++;}
- if(mo==1){month++;}
- if(mo==2){day++;}
- if(mo==3){hour++;}
- if(mo==4){min++;}
- if(mo==5){week++;}
- if(year>29){
- year=11;
- }
- if(month>12){
- month=1;
- }
- if(day>31){
- day=1;
- }
- if(hour>23){
- hour=0;
- }
- if(min>59){
- min=0;
- }
- if(week>7){
- week=1;
- }
- }
- if(ke==0x0b){
- if(mo==0 && year>11){year--;}
- if(mo==1 && month>1){month--;}
- if(mo==2 && day>1){day--;}
- if(mo==3 && hour>0){hour--;}
- if(mo==4 && min>0){min--;}
- if(mo==5 && week>1){min--;}
- }
- if(ke==0x0c){mo++;if(mo==6){mo=0;}}
- if(ke==0x0d){menu=0;change();}
- }else if(menu==4){
- if(ke==0x0a){
- if(light>0xFE){
- light=0x00;
- }else{
- light+=0x0F;
- }
- }
- if(ke==0x0b){
- if(light<0x0E){
- light=0xFF;
- }else{
- light-=0x0F;
- }
- }
- if(ke==0x0c){
- autolum++;
- if(autolum==2){
- autolum=0;
- }
- }
- if(ke==0x0d){menu=0;change();}
- }else if(menu==5){
- if(ke==0x0a){
- if(reps>9){
- reps=5;
- }else{
- reps++;
- }
- }
- if(ke==0x0b){
- if(repe>23){
- repe=20;
- }else{
- repe++;
- }
- }
- if(ke==0x0c){
- if(reps<0xff){
- reps=0xff;
- }else{
- reps=6;
- }
- }
- if(ke==0x0d){menu=0;change();}
- }
- }
- }
- void tiem0(void) interrupt 1 using 3{
- cou++;
- if(beepc>0){
- beepc--;
- beep=0;
- }else if(beepc==0){
- beep=1;
- beepc=0;
- }
- if(cou > 19){
- cou = 0;
- sec++;
- if(sec%2==0){
- rbit=1;
- }
- if(mt>0){
- mt--;
- }
- if(sec > 59){
- sec = 0;
- min++;
- if(hour>=reps && hour<=repe && reps!=0xff && min==30){
- bee;
- }
- if(min > 59){
- min = 0;
- if(hour>=reps && hour<=repe && reps!=0xff){
- lbee;
- }
- hour++;
- if(hour > 23){
- hour = 0;
- db = 1;
- }
- }
- for(i=0;i<9;i++){
- if(alm[i][0]==hour && alm[i][1]==min && alm[i][2]!=0){
- if(alm[i][2]==1){
- beep=0;
- beepc=20*30;
- break;
- }else if(alm[i][2]==2 && week>=1 && week<=5){
- beep=0;
- beepc=20*30;
- break;
- }else if(alm[i][2]==3 && week>=6 && week<=7){
- beep=0;
- beepc=20*30;
- break;
- }else if(alm[i][2]==4 && week==6){
- beep=0;
- beepc=20*30;
- break;
- }else if(alm[i][2]==5 && week==7){
- beep=0;
- beepc=20*30;
- break;
- }else if(alm[i][2]==6){
- beep=0;
- beepc=20*30;
- alm[i][2]=0;
- break;
- }
- }
- }
- }
- }
- TH0 = 0x3c;
- TL0 = 0xd0;
- }
- void t1(void) interrupt 3 using 2{
- blv=~blv;
- if(blv==0){
- TH1=hh;
- TL1=hh;
- }else{
- TH1=ll;
- TL1=ll;
- }
- }
復(fù)制代碼
CODE代碼.rar
(7.01 KB, 下載次數(shù): 19)
2016-6-20 23:54 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|