12864 液晶 LCD 圖文菜單顯示6.jpg (69.39 KB, 下載次數(shù): 225)
下載附件
2016-5-16 02:22 上傳
12864液晶LCD圖文菜單的實(shí)物圖
12864 液晶 LCD 圖文菜單顯示.jpg (315.57 KB, 下載次數(shù): 204)
下載附件
2016-5-16 02:22 上傳
單片機(jī)12864液晶LCD圖文菜單的電路圖
12864 液晶 LCD 圖文菜單顯示2.jpg (103.48 KB, 下載次數(shù): 161)
下載附件
2016-5-16 02:22 上傳
12864 液晶 LCD 圖文菜單顯示3.jpg (112.35 KB, 下載次數(shù): 162)
下載附件
2016-5-16 02:22 上傳
12864 液晶 LCD 圖文菜單顯示4.jpg (102.13 KB, 下載次數(shù): 181)
下載附件
2016-5-16 02:22 上傳
12864 液晶 LCD 圖文菜單顯示5.jpg (109.81 KB, 下載次數(shù): 162)
下載附件
2016-5-16 02:22 上傳
單片機(jī)12864液晶LCD圖文菜單顯示控制系統(tǒng)程序下載:
單片機(jī)12864液晶LCD圖文菜單顯示控制系統(tǒng)程序.rar
(945.76 KB, 下載次數(shù): 716)
2016-5-13 13:44 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
12864液晶部分菜單程序預(yù)覽(完整代碼請(qǐng)下載附件)
- /**************************************************************************************
- 程序名稱:
- 時(shí)間 溫度控制系統(tǒng)(128*64LCD+ds1302+ds18b20)
- 主要功能:
- 溫度計(jì) 時(shí)鐘 鬧鈴 密碼鎖 籃球器 計(jì)算器 溫度控制 鍵盤鎖 系統(tǒng)設(shè)置等。
- 主要說明:
- 程序全部定義在一個(gè)C文件中。
- 作者:
- LiJH
- 時(shí)間:
- 2008.6.20
- 版本:
- LiJH-V1.0
- **************************************************************************************/
- 本圖文菜單系統(tǒng)技術(shù)交流
- **************************************************************************************/
- #include <at89s53.h>
- #include <intrins.h>
- #define uchar unsigned char
- #define uint unsigned int
- #define time_count 0x3cb0
- #define close 1
- #define open 0
- /*============ 狀態(tài)控制及溫感器總線定義 ==============*/
-
- #define b20_io P0_0 // DS18B20總線
- #define pw_oc P3_7 // 密碼鎖開啟控制(黃燈)
- #define buzzer P0_5 // 蜂鳴器
- #define lcd_bl P0_6 // 背光控制口
- #define als_th P0_4 // 上限溫度警報(bào)(紅燈)
- #define als_tl P3_6 // 下限溫度警報(bào)(綠燈)
- #define keyboard P1 // 鍵盤數(shù)據(jù)口
- /*================= ST7920LCD 定義 ===================*/
- #define comm 0 // lcd指令
- #define dat 1 // lcd數(shù)據(jù)
- #define lcd_rst P0_7 // lcd復(fù)位
- #define lcd_e P3_0 // lcd使能
- #define lcd_rw P3_1 // lcd讀寫
- #define lcd_rs P3_2 // lcd數(shù)據(jù)命令
- #define busy P2_7 // 忙碌位
- #define lcd_data P2 // lcd(8bit)數(shù)據(jù)傳輸
-
- /*=============== DS1302 寄存器地址定義 ===============*/
- #define d02_rst P0_1 // DS1302使能
- #define d02_data P0_2 // DS1302數(shù)據(jù)線
- #define d02_sclk P0_3 // DS1302脈沖
- #define d02_wrc 0x8e // 1302讀寫RAM控制(1允許 0禁止)
- #define d02_year 0x8c // 年
- #define d02_weeks 0x8a // 星期
- #define d02_month 0x88 // 月
- #define d02_day 0x86 // 日
- #define d02_hour 0x84 // 時(shí)
- #define d02_minute 0x82 // 分
- #define d02_second 0x80 // 秒
- #define d02_signs 0xc0 // 系統(tǒng)狀態(tài)(記錄設(shè)置標(biāo)記)
- #define d02_passw 0xc2 // 密碼寄存器首位(有3位下位地址加2,初始值為:741456)
- #define d02_alm 0xc8 // 鬧鈴時(shí)間小時(shí)位(下位為分鐘位加2)
- #define d02_temp 0xcc // 溫度上限警報(bào)(有兩位下位位下限加2)
- #define d02_initsi 0xd4 // 1302初始化標(biāo)記(為0xb4時(shí),說明已經(jīng)初始化)
- #define ret_ds1302() d02_rst=0;d02_sclk=0;d02_rst=1 // 1302讀寫復(fù)位
- #define end_ds1302() d02_sclk=1;d02_rst=0 // 1302讀寫結(jié)束
- /*================================= 全局變量定義 ==================================*/
- typedef struct // 定義時(shí)間類型
- {
- uchar hour;
- uchar minute;
- uchar second;
- }time;
- typedef struct // 定義日期類型
- {
- uchar year;
- uchar month;
- uchar day;
- uchar week;
- }date;
- typedef union // 定義溫度類型
- {
- int temp_data;
- uchar t_data[2];
- }trdata;
- trdata bdata temp; // 溫度警報(bào)值暫存
- date idata today={'8',1,1,1}; // 日期暫存
- time idata now={0x12,0,0} , save_time={0x12,0,0};
- // 時(shí)間暫存(now是讀出時(shí)間暫存 save_time上一時(shí)間暫存)
- uchar idata time_tick=20,time_tick1=20,alarm_time[2],als_temp[2],
- // T0中斷數(shù), T1中斷數(shù), 鬧鈴時(shí)間, 警報(bào)溫度
- bl_delay=15,temp_delay=5,opera[2][12],resu[12],
- // 背光時(shí)間, 溫度更新時(shí)間, 計(jì)算器數(shù)據(jù)寄存, 結(jié)果寄存
- i,j,save1,temp_min=0;
- // 計(jì)算器i/j下標(biāo),中間暫存,溫度更新(分)
- uchar bdata signs=0; // 系統(tǒng)標(biāo)記寄存器
- sbit bl1=signs^7; // bl1,bl0背光選擇位(00 延時(shí),01 常開,10 關(guān)閉)
- sbit bl0=signs^6;
- sbit di1=signs^5; // di1,di0顯示模式(00模式1,01模式2,10模式3)
- sbit di0=signs^4;
- sbit meu=signs^3; // 菜單顯示方式(0 圖片,1 文字)
- sbit keb=signs^2; // 鍵盤鎖(0 無鎖,1加鎖)
- sbit alm=signs^1; // 鬧鐘啟動(dòng)位(0 關(guān)閉,1開啟)
- sbit als=signs^0; // 報(bào)警啟動(dòng)位(0 啟動(dòng),1關(guān)閉)
- uint bdata run_signs=0; // 運(yùn)行標(biāo)記寄存器
- sbit ds18b20=run_signs^0; // 溫感器存在標(biāo)記(0不存在,1存在)
- sbit temp_pn=run_signs^1; // 溫度正負(fù)號(hào)標(biāo)記(0正,1負(fù))
- sbit temprun=run_signs^2; // 溫感器運(yùn)行標(biāo)記(0否,1啟動(dòng))
- sbit nba_tim=run_signs^3; // 籃球計(jì)時(shí)器標(biāo)記(0關(guān)閉,1啟動(dòng))
- sbit adju_si=run_signs^4; // 數(shù)字更改連續(xù)標(biāo)記(1連續(xù))
- sbit cal_del=run_signs^5; // 計(jì)算器顯示點(diǎn)標(biāo)記(0沒有顯示)
- sbit cal_run=run_signs^6; // 計(jì)算完畢標(biāo)記(1有效)
- sbit oth_run=run_signs^7; // 其他標(biāo)記
- sbit alm_run=run_signs^8; // 鬧鐘時(shí)間到達(dá)標(biāo)記(1有效)
- sbit dis_sig=run_signs^9; // 顯示時(shí)間標(biāo)記(1有效)
- sbit lock_op=run_signs^10; // 關(guān)鎖時(shí)間到標(biāo)記(1有效)
- sbit b20time=run_signs^11; // 溫感器重新讀溫度標(biāo)記(1有效)
- sbit t0_isr =run_signs^12; // TO中斷標(biāo)記(1有效(1s)
- sbit thl_als=run_signs^13; // 溫度警報(bào)標(biāo)記
- sbit init_d2=run_signs^14; // 模式2初始顯示
- sbit buzstop=run_signs^15; // 蜂鳴器停止標(biāo)記
- /*================================= 字體顯示代碼 ==================================*/
- uchar code weeks[7][2]={"一","二","三","四","五","六","日"}; // 星期 //圖片中文
- uchar code menu_cn[6][8]={"調(diào) 整","工 具","設(shè) 置","保 密","版 本","退 出"};
- uchar code menu_cn_2[6][6]={"調(diào) 整","工 具","設(shè) 置","保 密","版 本","退 出"};// 菜單文字
- uchar code selected[2][16]={{"進(jìn)入【 】\x04 "},{"設(shè)置【 】\x10 \x04 "}}; // 選框
- uchar code secrets_menu[4][6]={"開 鎖","更 改","初始化","退 出"}; // 保密菜單中文
- uchar code tool_menu[5][6]={"計(jì)算器","溫度計(jì)","鬧 鈴","籃球器","退 出"}; // 工具菜單中文
- uchar code char_num[10]={"0123456789"}; // 數(shù)字顯示代碼 // 每月天數(shù)
- uchar code dayofmonth[12]={0x31,0x28,0x31,0x30,0x31,0x30,0x31,0x31,0x30,0x31,0x30,0x31};
- uchar code key_code[]={0xD7,0x7E,0x7D,0x7B,0xBE,0xBD,0xBB,0xDE,0xDD,0xDB,0xB7,0x77,0xEE,0xED,0xEB,0xE7};
- uchar code ksp[4]={0x7F,0xBF,0xDF,0xEF}; // 按鍵掃描代碼
- uchar code tool_cal[4][2]={"+ ","- ","* ","/ "}; // 運(yùn)算符號(hào)
- uchar code alm_sign[2][2]={"關(guān)","開"}; // 鬧鈴開關(guān)
- uchar code set_bl_dm[2][3][4]={{"30秒","常開","關(guān)閉"},{"模01","模02","模03"}};
- uchar code set_mka[3][2][4]={{"圖片","文字"},{"解鎖","加鎖"},{"開啟","關(guān)閉"}};
- uchar code nba_oppo[8][2]={"紅","白","藍(lán)","綠","紫","灰","黃","黑"};
- uchar code set_menu[6][4]={"背光","顯示","菜單","鍵盤","警報(bào)","退出"};
- uchar code version[10][14]={ // 版本信息
- {"清遠(yuǎn)職業(yè)技術(shù)學(xué)"},
- {" 信息科技學(xué)院"},
- {"08屆畢業(yè)設(shè)計(jì) "},
- {" —05電子02班"},
- {"作者:李錦華 "},
- {"指導(dǎo):李祖明 "},
- {"版本:LIJH-V1.0"},
- {" 2008/06/19"},
- {"謝謝你的使用!"},
- {" (ok)\x10"}};
- uchar code timer_tips[12][16]={ // 籃球器使用說明
- {"使用方法: "},
- {" (+)(-)與(*)(/)"},
- {"分別是兩方的分?jǐn)?shù)"},
- {"加與減,(7)鍵回退"},
- {"一秒,(8)鍵24秒復(fù)"},
- {"位,(9)鍵暫停與開"},
- {"始;暫停狀態(tài)下:"},
- {"按兩次(OK)鍵可返"},
- {"回時(shí)鐘模式-2界面"},
- {",(OK)鍵返回程序"},
- {"界面,(./S)鍵兩次"},
- {"退出程序. \x1f"}};
- /*================================= 操作導(dǎo)航代碼 ==================================*/
-
- typedef struct // 定義主菜單操作索引
- {
- uchar shaft_num;
- uchar left_num;
- uchar right_num;
- }menu_index;
- typedef struct // 定義導(dǎo)航更改索引
- {
- uchar lnum;
- uchar rnum;
- }index;
- menu_index code index_m[6]={{3,5,1},{4,0,2},{5,1,3},{0,2,4},{1,3,5},{2,4,0}}; // 菜單導(dǎo)航
- index code index_t[6]={{4,1},{0,2},{1,3},{2,4},{3,0}}; // 工具導(dǎo)航
- index code index_p[5]={{3,1},{0,2},{1,3},{2,0}}; // 保密導(dǎo)航
- index code index_s[6]={{5,1},{0,2},{1,3},{2,4},{3,5},{4,0}}; // 設(shè)置導(dǎo)航
- index code index_a[7]={{0x81,0x91},{0x83,0x91},{0x85,0x91},{0x89,0x81},
- {0x8b,0x81},{0x8d,0x81},{0x8f,0x91}}; // 調(diào)整下的坐標(biāo)
- index code index_temp_set[3]={{0x8b,0x81},{0x8b,0x91},{0x8f,0x91}}; // 溫度設(shè)定下的坐標(biāo)
- index code index_alm[3]={{0x8c,0x81},{0x8e,0x81},{0x8f,0x91}}; // 鬧鈴更改坐標(biāo)
- index code index_cal[3]={{0x86,0x90},{0x8e,0x80},{0x8e,0x90}}; // 計(jì)算器操作坐標(biāo)
- uchar code index_nba[4]={0x93,0x97,0x8b,0x8f}; // 籃球器設(shè)置導(dǎo)航
- /*========================== 菜單圖片(寬度x高度=32*24)=============================*/
- uchar code menu_pic[6][96]={
- {// 調(diào)整
- 0x00,0x00,0x00,0x00,0x7F,0xFF,0xFF,0xFE,0x40,0x00,0x00,0x02,0x40,0x00,0x00,0x02,
- 0x40,0x00,0x00,0x82,0x47,0xFF,0xE1,0xC2,0x47,0xFF,0xF3,0xE2,0x47,0x38,0x68,0x02,
- 0x46,0xDF,0x68,0x82,0x46,0xDF,0x69,0xC2,0x46,0xDE,0xE8,0x82,0x46,0xDD,0xE8,0x02,
- 0x46,0xDD,0xE8,0x02,0x47,0x3D,0xE8,0x02,0x47,0xFF,0xE8,0x02,0x47,0xFF,0xE9,0xC2,
- 0x42,0x00,0x18,0x02,0x41,0xFF,0xF3,0xE2,0x40,0x00,0x01,0xC2,0x40,0x00,0x00,0x82,
- 0x40,0x00,0x00,0x02,0x40,0x00,0x00,0x02,0x7F,0xFF,0xFF,0xFE,0x00,0x00,0x00,0x00},
-
- {// 工具
- 0x00,0x00,0x00,0x00,0x7F,0xFF,0xFF,0xFE,0x40,0x00,0x00,0x02,0x40,0x00,0x03,0x82,
- 0x41,0xF0,0x07,0xC2,0x43,0xFF,0xCF,0xE2,0x47,0x3F,0xFE,0x02,0x47,0x3F,0xFE,0x02,
- 0x43,0xFF,0xCF,0xE2,0x41,0xF0,0x0F,0xC2,0x40,0x00,0x03,0x82,0x40,0x00,0x00,0x02,
- 0x40,0x00,0x03,0xC2,0x40,0x00,0x03,0xC2,0x41,0x80,0x01,0x82,0x43,0xFF,0xF3,0xC2,
- 0x47,0xFF,0xFF,0xE2,0x47,0xFF,0xFF,0xE2,0x43,0xFF,0xF3,0xC2,0x41,0x80,0x01,0x82,
- 0x40,0x00,0x01,0x82,0x40,0x00,0x00,0x02,0x7F,0xFF,0xFF,0xFE,0x00,0x00,0x00,0x00},
-
- {// 設(shè)置
- 0x00,0x00,0x00,0x00,0x7F,0xFF,0xFF,0xFE,0x40,0x00,0x00,0x02,0x43,0x18,0x00,0x02,
- 0x44,0xA4,0x0E,0x02,0x44,0xA4,0x1F,0x02,0x43,0x24,0x3F,0x02,0x40,0x00,0x7F,0x02,
- 0x40,0xF0,0xFC,0x02,0x43,0xF9,0xF0,0x02,0x43,0x03,0xE0,0x02,0x46,0x77,0x80,0x02,
- 0x46,0x7F,0x00,0x02,0x46,0x7E,0x00,0x02,0x46,0x7C,0x00,0x02,0x47,0x3D,0x00,0x02,
- 0x43,0x1D,0x81,0x22,0x43,0x81,0xB2,0x42,0x41,0xC3,0x4F,0xE2,0x40,0xFE,0x4A,0x42,
- 0x40,0x3C,0x32,0x42,0x40,0x00,0x00,0x02,0x7F,0xFF,0xFF,0xFE,0x00,0x00,0x00,0x00},
-
- {// 保密
- 0x00,0x00,0x00,0x00,0x7F,0xFF,0xFF,0xFE,0x40,0x00,0x00,0x02,0x40,0xFC,0x03,0x02,
- 0x41,0xFE,0x1F,0x02,0x43,0x87,0x03,0x82,0x43,0x03,0x03,0x02,0x43,0x03,0x03,0x02,
- 0x43,0x03,0x0F,0x02,0x43,0x03,0x03,0x02,0x43,0x03,0x03,0x02,0x47,0xFF,0x83,0x02,
- 0x47,0xFF,0x83,0x02,0x47,0xCF,0x83,0x02,0x47,0x87,0x83,0x02,0x47,0xCF,0x83,0x02,
- 0x47,0xCF,0x87,0x82,0x47,0xCF,0x8F,0xC2,0x47,0xCF,0x9C,0xE2,0x47,0xFF,0x8F,0xC2,
- 0x43,0xFF,0x07,0x82,0x40,0x00,0x00,0x02,0x7F,0xFF,0xFF,0xFE,0x00,0x00,0x00,0x00},
-
- {// 版本
- 0x00,0x00,0x00,0x00,0x7F,0xFF,0xFF,0xFE,0x40,0x00,0x00,0x02,0x40,0x00,0x00,0x02,
- 0x40,0x0F,0x00,0x62,0x40,0x1D,0x80,0xF2,0x40,0x38,0x41,0xF2,0x40,0x70,0x23,0xE2,
- 0x40,0xE2,0x17,0xC2,0x41,0xE4,0x4F,0x82,0x41,0xF0,0x9F,0x02,0x41,0x59,0x16,0x02,
- 0x42,0x4C,0x1D,0x02,0x42,0x46,0x20,0x82,0x42,0x47,0x00,0x42,0x44,0x43,0x80,0xC2,
- 0x44,0x44,0xC1,0xC2,0x44,0xC8,0x63,0x82,0x45,0x50,0x37,0x02,0x46,0x60,0x1E,0x02,
- 0x40,0x40,0x0C,0x02,0x40,0x00,0x00,0x02,0x7F,0xFF,0xFF,0xFE,0x00,0x00,0x00,0x00},
-
- {// 退出
- 0x00,0x00,0x00,0x00,0x7F,0xFF,0xFF,0xFE,0x40,0x00,0x00,0x02,0x40,0x40,0xFF,0xE2,
- 0x40,0x60,0x80,0x62,0x43,0xF0,0x80,0xA2,0x43,0xF0,0x81,0x22,0x40,0x60,0x82,0x22,
- 0x40,0x40,0x84,0x22,0x40,0x00,0x88,0x22,0x40,0x00,0x88,0x22,0x47,0xFF,0xF8,0x22,
- 0x47,0xFF,0xF8,0x22,0x46,0x2A,0x2A,0x22,0x46,0xE3,0x78,0x22,0x46,0x77,0x78,0x22,
- 0x46,0xE3,0x78,0x62,0x46,0x2A,0x38,0x82,0x47,0xFF,0xF9,0x02,0x47,0xFF,0xFA,0x02,
- 0x40,0x00,0x0C,0x02,0x40,0x00,0x00,0x02,0x7F,0xFF,0xFF,0xFE,0x00,0x00,0x00,0x00,}};
- /*================ 顯示模式2數(shù)字及溫度符號(hào)圖片(寬度x高度=16*32)=====================*/
- uchar code mode_2num[11][64]={
- {// 圖片數(shù)字0
- 0x00,0x00,0x3F,0xFC,0x5F,0xFA,0x6F,0xF6,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,
- 0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x60,0x06,0x40,0x02,0x00,0x00,
- 0x40,0x02,0x60,0x06,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,
- 0x70,0x0E,0x70,0x0E,0x70,0x0E,0x6F,0xF6,0x5F,0xFA,0x3F,0xFC,0x00,0x00,0x00,0x00},
-
- {// 圖片數(shù)字1
- 0x00,0x00,0x00,0x20,0x00,0x60,0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,0xE0,
- 0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,0x60,0x00,0x20,0x00,0x00,0x00,0x20,
- 0x00,0x60,0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,0xE0,
- 0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,0x60,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00},
-
- {// 圖片數(shù)字2
- 0x00,0x00,0x3F,0xFC,0x1F,0xFA,0x0F,0xF6,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,
- 0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x06,0x1F,0xFA,0x3F,0xFC,
- 0x5F,0xF8,0x60,0x00,0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x00,
- 0x70,0x00,0x70,0x00,0x70,0x00,0x6F,0xF8,0x5F,0xFC,0x3F,0xFE,0x00,0x00,0x00,0x00},
-
- {// 圖片數(shù)字3
- 0x00,0x00,0x7F,0xFC,0x3F,0xFA,0x1F,0xF6,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,
- 0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x06,0x1F,0xFA,0x3F,0xFC,
- 0x1F,0xFA,0x00,0x06,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,
- 0x00,0x0E,0x00,0x0E,0x00,0x0E,0x1F,0xF6,0x3F,0xFA,0x7F,0xFC,0x00,0x00,0x00,0x00},
-
- {// 圖片數(shù)字4
- 0x00,0x00,0x40,0x02,0x60,0x06,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,
- 0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x60,0x06,0x5F,0xFA,0x3F,0xFC,
- 0x1F,0xFA,0x00,0x06,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,
- 0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x06,0x00,0x02,0x00,0x00,0x00,0x00},
-
- {// 圖片數(shù)字5
- 0x00,0x00,0x3F,0xFC,0x5F,0xF8,0x6F,0xF0,0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x00,
- 0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x00,0x60,0x00,0x5F,0xF8,0x3F,0xFC,
- 0x1F,0xFA,0x00,0x06,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,
- 0x00,0x0E,0x00,0x0E,0x00,0x0E,0x0F,0xF6,0x1F,0xFA,0x3F,0xFC,0x00,0x00,0x00,0x00},
-
- {// 圖片數(shù)字6
- 0x00,0x00,0x3F,0xFC,0x5F,0xF8,0x6F,0xF0,0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x00,
- 0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x00,0x60,0x00,0x5F,0xF8,0x3F,0xFC,
- 0x5F,0xFA,0x60,0x06,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,
- 0x70,0x0E,0x70,0x0E,0x70,0x0E,0x6F,0xF6,0x5F,0xFA,0x3F,0xFC,0x00,0x00,0x00,0x00},
-
- {// 圖片數(shù)字7
- 0x00,0x00,0x7F,0xFC,0x3F,0xFA,0x1F,0xF6,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,
- 0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x06,0x00,0x02,0x00,0x00,
- 0x00,0x02,0x00,0x06,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,
- 0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x06,0x00,0x02,0x00,0x00,0x00,0x00},
-
- {// 圖片數(shù)字8
- 0x00,0x00,0x3F,0xFC,0x5F,0xFA,0x6F,0xF6,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,
- 0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x60,0x06,0x5F,0xFA,0x3F,0xFC,
- 0x5F,0xFA,0x60,0x06,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,
- 0x70,0x0E,0x70,0x0E,0x70,0x0E,0x6F,0xF6,0x5F,0xFA,0x3F,0xFC,0x00,0x00,0x00,0x00},
-
- {// 圖片數(shù)字9
- 0x00,0x00,0x3F,0xFC,0x5F,0xFA,0x6F,0xF6,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,
- 0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x60,0x06,0x5F,0xFA,0x3F,0xFC,
- 0x1F,0xFA,0x00,0x06,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,
- 0x00,0x0E,0x00,0x0E,0x00,0x0E,0x1F,0xF6,0x3F,0xFA,0x7F,0xFC,0x00,0x00,0x00,0x00},
-
- {// 溫度符號(hào)
- 0x00,0x00,0x00,0x00,0x70,0xE0,0x53,0xF0,0x77,0xFA,0x0E,0x0E,0x0C,0x06,0x18,0x06,
- 0x18,0x02,0x38,0x02,0x30,0x00,0x30,0x00,0x70,0x00,0x60,0x00,0x60,0x00,0x60,0x00,
- 0x60,0x00,0x60,0x00,0x70,0x00,0x30,0x00,0x30,0x00,0x38,0x00,0x18,0x02,0x18,0x02,
- 0x0C,0x06,0x0E,0x06,0x07,0x0E,0x03,0xFA,0x00,0xF0,0x00,0x60,0x00,0x00,0x00,0x00}};
- /*===================== 顯示模式3數(shù)字圖片(寬度x高度=24*32)=========================*/
- uchar code mode_3num[10][96]={
- {// 圖片數(shù)字0
- 0x00,0x7E,0x00,0x01,0xE7,0x80,0x03,0xC3,0xC0,0x07,0x81,0xE0,0x0F,0x80,0xF0,0x0F,
- 0x00,0xF0,0x1F,0x00,0xF8,0x1E,0x00,0xF8,0x3E,0x00,0x78,0x3E,0x00,0x7C,0x3E,0x00,
- 0x7C,0x3E,0x00,0x7C,0x3E,0x00,0x7C,0x3E,0x00,0x7C,0x3E,0x00,0x7C,0x3E,0x00,0x7C,
- 0x3E,0x00,0x7C,0x3E,0x00,0x7C,0x3E,0x00,0x7C,0x3E,0x00,0x7C,0x3E,0x00,0x7C,0x3E,
- 0x00,0x7C,0x3E,0x00,0x7C,0x3E,0x00,0x78,0x1E,0x00,0xF8,0x1F,0x00,0xF8,0x0F,0x00,
- 0xF0,0x0F,0x81,0xF0,0x07,0x81,0xE0,0x03,0xC3,0xC0,0x01,0xE7,0x80,0x00,0x7E,0x00},
- {// 圖片數(shù)字1
- 0x00,0x0C,0x00,0x00,0x1C,0x00,0x00,0x7C,0x00,0x07,0xFC,0x00,0x00,0x3C,0x00,0x00,
- 0x3C,0x00,0x00,0x3C,0x00,0x00,0x3C,0x00,0x00,0x3C,0x00,0x00,0x3C,0x00,0x00,0x3C,
- 0x00,0x00,0x3C,0x00,0x00,0x3C,0x00,0x00,0x3C,0x00,0x00,0x3C,0x00,0x00,0x3C,0x00,
- 0x00,0x3C,0x00,0x00,0x3C,0x00,0x00,0x3C,0x00,0x00,0x3C,0x00,0x00,0x3C,0x00,0x00,
- 0x3C,0x00,0x00,0x3C,0x00,0x00,0x3C,0x00,0x00,0x3C,0x00,0x00,0x3C,0x00,0x00,0x3C,
- 0x00,0x00,0x3C,0x00,0x00,0x3C,0x00,0x00,0x3E,0x00,0x00,0x7F,0x00,0x07,0xFF,0xF0},
-
- {// 圖片數(shù)字2
- 0x00,0xFF,0x00,0x03,0xC7,0xC0,0x07,0x01,0xE0,0x0E,0x00,0xF0,0x1E,0x00,0xF8,0x1E,
- 0x00,0xF8,0x3E,0x00,0x78,0x3E,0x00,0x78,0x3F,0x00,0x78,0x3F,0x00,0x78,0x1F,0x00,
- 0xF8,0x00,0x00,0xF8,0x00,0x00,0xF0,0x00,0x01,0xF0,0x00,0x03,0xE0,0x00,0x03,0xC0,
- 0x00,0x07,0x80,0x00,0x0F,0x00,0x00,0x1E,0x00,0x00,0x3C,0x00,0x00,0x78,0x00,0x00,
- 0xF0,0x00,0x01,0xE0,0x00,0x03,0xC0,0x00,0x07,0x80,0x1C,0x07,0x00,0x1C,0x0E,0x00,
- 0x38,0x1C,0x00,0x38,0x3C,0x00,0x78,0x3F,0xFF,0xF8,0x3F,0xFF,0xF8,0x3F,0xFF,0xF8},
- {// 圖片數(shù)字3
- 0x00,0xFE,0x00,0x07,0x87,0x80,0x0F,0x03,0xC0,0x1E,0x01,0xE0,0x1E,0x01,0xF0,0x1E,
- 0x01,0xF0,0x1F,0x00,0xF0,0x1F,0x00,0xF0,0x1E,0x00,0xF0,0x00,0x00,0xF0,0x00,0x01,
- 0xF0,0x00,0x01,0xF0,0x00,0x03,0xE0,0x00,0x03,0xC0,0x00,0x0F,0x00,0x00,0xFE,0x00,
- 0x00,0x07,0x80,0x00,0x01,0xE0,0x00,0x00,0xF0,0x00,0x00,0xF8,0x00,0x00,0xF8,0x00,
- 0x00,0x78,0x00,0x00,0x7C,0x1E,0x00,0x7C,0x3F,0x00,0x7C,0x3F,0x00,0x7C,0x3F,0x00,
- 0x78,0x3E,0x00,0xF8,0x1E,0x00,0xF0,0x0F,0x01,0xE0,0x07,0x87,0xC0,0x01,0xFF,0x00},
- {// 圖片數(shù)字4
- 0x00,0x03,0xC0,0x00,0x03,0xC0,0x00,0x07,0xC0,0x00,0x0F,0xC0,0x00,0x0F,0xC0,0x00,
- 0x1F,0xC0,0x00,0x3F,0xC0,0x00,0x3F,0xC0,0x00,0x77,0xC0,0x00,0x77,0xC0,0x00,0xE7,
- 0xC0,0x01,0xC7,0xC0,0x01,0xC7,0xC0,0x03,0x87,0xC0,0x07,0x07,0xC0,0x07,0x07,0xC0,
- 0x0E,0x07,0xC0,0x1E,0x07,0xC0,0x1C,0x07,0xC0,0x38,0x07,0xC0,0x38,0x07,0xC0,0x7F,
- 0xFF,0xFE,0x7F,0xFF,0xFE,0x00,0x07,0xC0,0x00,0x07,0xC0,0x00,0x07,0xC0,0x00,0x07,
- 0xC0,0x00,0x07,0xC0,0x00,0x07,0xC0,0x00,0x07,0xC0,0x00,0x07,0xE0,0x00,0x7F,0xFE},
- {// 圖片數(shù)字5
- 0x0F,0xFF,0xF8,0x0F,0xFF,0xF8,0x0F,0xFF,0xF8,0x0E,0x00,0x00,0x0E,0x00,0x00,0x0E,
- 0x00,0x00,0x0E,0x00,0x00,0x0E,0x00,0x00,0x0E,0x00,0x00,0x0E,0x00,0x00,0x0E,0x00,
- 0x00,0x0E,0x7F,0x00,0x0D,0xFF,0xC0,0x0F,0xC3,0xE0,0x1F,0x01,0xF0,0x1E,0x00,0xF8,
- 0x1E,0x00,0xF8,0x00,0x00,0x78,0x00,0x00,0x7C,0x00,0x00,0x7C,0x00,0x00,0x7C,0x00,
- 0x00,0x7C,0x1E,0x00,0x7C,0x3F,0x00,0x7C,0x3F,0x00,0x78,0x3F,0x00,0x78,0x3E,0x00,
- 0xF8,0x1E,0x00,0xF0,0x1E,0x01,0xF0,0x0E,0x01,0xE0,0x07,0x87,0xC0,0x00,0xFF,0x00},
- {// 圖片數(shù)字6
- 0x00,0x3F,0xC0,0x00,0xF1,0xE0,0x03,0xC1,0xF0,0x07,0x81,0xF8,0x07,0x01,0xF8,0x0F,
- 0x00,0xF0,0x1F,0x00,0x00,0x1E,0x00,0x00,0x1E,0x00,0x00,0x3E,0x00,0x00,0x3E,0x00,
- 0x00,0x3E,0x00,0x00,0x3E,0x3F,0x80,0x3E,0xFF,0xE0,0x3F,0xE3,0xF0,0x3F,0x80,0xF8,
- 0x3F,0x00,0xF8,0x3F,0x00,0x7C,0x3E,0x00,0x7C,0x3E,0x00,0x7C,0x3E,0x00,0x3C,0x3E,
- 0x00,0x3C,0x3E,0x00,0x3C,0x3E,0x00,0x3C,0x3E,0x00,0x7C,0x1E,0x00,0x7C,0x1F,0x00,
- 0x78,0x0F,0x00,0x78,0x0F,0x80,0xF0,0x07,0xC0,0xE0,0x03,0xE3,0xC0,0x00,0xFF,0x00},
- {// 圖片數(shù)字7
- 0x1F,0xFF,0xFC,0x1F,0xFF,0xFC,0x1F,0xFF,0xF8,0x1F,0x00,0x38,0x1C,0x00,0x70,0x1C,
- 0x00,0xE0,0x38,0x00,0xE0,0x38,0x01,0xC0,0x00,0x01,0xC0,0x00,0x03,0x80,0x00,0x03,
- 0x80,0x00,0x07,0x80,0x00,0x07,0x00,0x00,0x0F,0x00,0x00,0x0E,0x00,0x00,0x1E,0x00,
- 0x00,0x1E,0x00,0x00,0x3C,0x00,0x00,0x3C,0x00,0x00,0x3C,0x00,0x00,0x7C,0x00,0x00,
- 0x78,0x00,0x00,0x78,0x00,0x00,0xF8,0x00,0x00,0xF8,0x00,0x00,0xF8,0x00,0x00,0xF8,
- 0x00,0x00,0xF8,0x00,0x00,0xF8,0x00,0x00,0xF8,0x00,0x00,0xF8,0x00,0x00,0x78,0x00},
- {// 圖片數(shù)字8
- 0x00,0xFF,0x00,0x07,0xC3,0xC0,0x0F,0x00,0xE0,0x1E,0x00,0xF0,0x1E,0x00,0x78,0x3C,
- 0x00,0x78,0x3C,0x00,0x78,0x3C,0x00,0x7C,0x3E,0x00,0x78,0x3E,0x00,0x78,0x1F,0x00,
- 0x78,0x1F,0x80,0xF0,0x0F,0xE1,0xE0,0x07,0xFB,0xC0,0x01,0xFF,0x80,0x01,0xFF,0x80,
- 0x07,0xBF,0xC0,0x0F,0x0F,0xE0,0x1E,0x03,0xF0,0x3E,0x01,0xF8,0x3C,0x00,0xF8,0x3C,
- 0x00,0x7C,0x7C,0x00,0x7C,0x78,0x00,0x3C,0x78,0x00,0x3C,0x7C,0x00,0x3C,0x3C,0x00,
- 0x78,0x3C,0x00,0x78,0x1E,0x00,0x70,0x0F,0x00,0xE0,0x07,0xC3,0xC0,0x01,0xFF,0x00},
- {// 圖片數(shù)字9
- 0x01,0xFE,0x00,0x07,0xC7,0x80,0x0F,0x01,0xE0,0x1E,0x01,0xE0,0x1E,0x00,0xF0,0x3E,
- 0x00,0xF8,0x3C,0x00,0x78,0x3C,0x00,0x78,0x7C,0x00,0x7C,0x7C,0x00,0x7C,0x7C,0x00,
- 0x7C,0x7C,0x00,0x7C,0x7C,0x00,0x7C,0x3C,0x00,0xFC,0x3E,0x00,0xFC,0x3E,0x01,0xFC,
- 0x1F,0x03,0xFC,0x1F,0x8F,0xFC,0x0F,0xFF,0x7C,0x03,0xFC,0x7C,0x00,0x00,0x7C,0x00,
- 0x00,0xF8,0x00,0x00,0xF8,0x00,0x00,0xF8,0x00,0x00,0xF0,0x00,0x01,0xF0,0x0F,0x01,
- 0xE0,0x1F,0x01,0xE0,0x1F,0x03,0xC0,0x1F,0x07,0x80,0x0F,0x9F,0x00,0x03,0xFC,0x00}};
- /*========================== 標(biāo)記及點(diǎn)圖片(寬度x高度=16*16)===========================*/
- uchar code running[7][32]={
- {// 警報(bào)標(biāo)記16*16
- 0x00,0x00,0x00,0x39,0x00,0x7B,0x00,0xFE,0x01,0xDC,0x0F,0x98,0x0F,0x18,0x0C,0x1F,
- 0x0C,0x1F,0x0F,0x18,0x0F,0x98,0x01,0xDC,0x00,0xFE,0x00,0x7B,0x00,0x39,0x00,0x00,},
- {// 鬧鈴開啟標(biāo)記16*16
- 0x00,0x00,0x00,0x40,0x00,0xE0,0x01,0xB0,0x01,0xB0,0x03,0x18,0x03,0x18,0x06,0x0C,
- 0x0C,0x06,0x0C,0xE6,0x1B,0x1B,0x0C,0x06,0x06,0x0C,0x03,0xF8,0x00,0xE0,0x00,0x00},
- {// 鍵盤鎖標(biāo)記16*16
- 0x00,0x00,0x01,0xF8,0x03,0xFC,0x03,0x0C,0x03,0x0C,0x03,0x0C,0x03,0xFC,0x06,0x96,
- 0x0E,0xA7,0x0E,0xC7,0x0E,0xA7,0x0E,0x97,0x07,0xFE,0x03,0xFC,0x01,0xF8,0x00,0x00,},
- {// 溫度計(jì)標(biāo)記16*16
- 0x00,0x00,0x1F,0xF8,0x1F,0xF8,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,
- 0x01,0x90,0x01,0x98,0x01,0x9C,0x01,0x9E,0x01,0x9C,0x00,0x18,0x00,0x10,0x00,0x00},
- {// 模式3點(diǎn)16*16
- 0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xC0,0x03,0xC0,0x03,0xC0,0x03,0xC0,0x03,0xC0,
- 0x03,0xC0,0x03,0xC0,0x03,0xC0,0x03,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
- {// 模式2點(diǎn)16*16
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xC0,0x03,0xC0,0x03,0xC0,0x03,0xC0,
- 0x03,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
- {// 籃球器運(yùn)行標(biāo)記16*16
- 0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xF8,0x1F,0xF8,0x01,0x80,0x01,0x80,0x01,0x90,
- 0x01,0x98,0x01,0x9C,0x01,0x9E,0x01,0x9C,0x01,0x98,0x01,0x90,0x00,0x00,0x00,0x00}};
- /*========================== 菜單按鈕圖片(寬度x高度=16*8)============================*/
- uchar code menu_key[]=
- {//菜單按鈕
- 0x7F,0xFE,0x81,0x81,0x83,0xC1,0x87,0xE1,0x8F,0xF1,0x9F,0xF9,0x80,0x01,0x7F,0xFE};
- /*=====================================================================================
- 函數(shù)名稱:定時(shí)器中斷處理與初始化,延時(shí)
- 功能描述:時(shí)鐘更新、籃球器計(jì)時(shí)
- 全局變量:time_tick、time_tick1、resu[2]、resu[3]、resu[4]、temp_delay、temp_min
- 參數(shù)說明:無
- 返回說明:t0_isr(中斷標(biāo)記)、b20time(溫度更新標(biāo)記)
- 設(shè) 計(jì) 人:LIJH
- 版 本:1.0
- 說 明:
- ======================================================================================*/
- /*延時(shí)(一次10個(gè)機(jī)器周期不等) 參數(shù)格式:延時(shí)數(shù)*/
- void delay(unsigned int det)
- {
- while(det--);
- }
- /*1s延時(shí)*/
- void delay_pw()
- {
- delay(60000);
- delay(60000);
- }
- /*6個(gè)周期 6us */
- void delay_b20(uchar n)
- {
- while(n--);
- }
- /*主時(shí)鐘中斷處理*/
- void time0_isr(void) interrupt TF0_VECTOR using 1
- {
- TR0=0;
- TL0=(time_count&0x00FF);
- TH0=(time_count>>8);
- TR0=1;
- if(--time_tick) return;
- time_tick=20;
- t0_isr=1;
- if(nba_tim&!oth_run) // 當(dāng)在籃球器界面時(shí) nba_tim==1、oth_run==0
- {
- if(resu[3]==0)
- {
- resu[3]=59;
- if(resu[2]>0) resu[2]--;
- }
- else resu[3]--;
- if(resu[2]==0&resu[3]==0) // 比賽時(shí)間到后停止
- {
- TR0=0;TR1=0;EA=0;
- }
- return;
- }
- if((++temp_min)==60) // 實(shí)現(xiàn)溫度的更新
- {
- temp_min=0;
- temp_delay--;
- if(temp_delay==0)
- {
- b20time=1;temp_delay=5;
- }
- }
- }
- /*24時(shí)鐘中斷處理*/
- void time1_isr(void) interrupt TF1_VECTOR using 2
- {
- TR1=0;
- TL1=(time_count&0x00FF);
- TH1=(time_count>>8);
- TR1=1;
- if(--time_tick1) return;
- time_tick1=20;
- if(resu[4]>0)resu[4]--; // 籃球器24秒中斷
- t0_isr=1;
- if(resu[4]==0)
- { TR0=0;TR1=0;EA=0;}
- }
- /*定時(shí)器初始化*/
- void time_init()
- {
- EA=0;
- TR0=0;
- TR1=0;
- TMOD=0x11;
- TL0=(time_count&0x00FF);
- TH0=(time_count>>8);
- TL1=(time_count&0x00FF);
- TH1=(time_count>>8);
- IE=0;
- ET0=1;
- ET1=1;
- }
- /*=====================================================================================
- 函數(shù)名稱:LCD驅(qū)動(dòng)
- 功能描述:基本驅(qū)動(dòng)(寫1個(gè)字節(jié)、清屏、初始化)
- 全局變量:無
- 參數(shù)說明:dat_comm(0:命令 1:數(shù)據(jù)),content(數(shù)值)
- 返回說明:無返回值
- 設(shè) 計(jì) 人:LIJH
- 版 本:1.0
- 說 明:
- ======================================================================================*/
- /*檢查忙碌位*/
- void chk_busy (void)
- {
- lcd_data = 0xff;
- lcd_rs = 0; // 命令
- lcd_rw = 1; // 讀
- lcd_e = 1;
- while(busy==1);
- lcd_e = 0;
- }
- /*寫LCD 參數(shù)格式:0:命令,1:數(shù)值 ,數(shù)據(jù)*/
- void wr_lcd (uchar dat_comm,uchar content)
- {
- chk_busy ();
- lcd_rs=dat_comm;
- lcd_rw = 0; // 寫
- lcd_data=content; // 輸出數(shù)據(jù)或命令
- lcd_e=1;
- lcd_e=0;
- }
- /*清繪圖*/
- void clrgdram(void)
- {
- uchar i,j;
- for(j=0;j<32;j++)
- {
- wr_lcd(comm,0x34);
- wr_lcd(comm,0x80+j);
- wr_lcd(comm,0x80);
- wr_lcd(comm,0x30);
- for(i=0;i<32;i++)
- wr_lcd(dat,0x00); // 寫入0x00
- }
- wr_lcd(comm,0x36);
- }
- /*清除顯示*/
- void clear_dis(void)
- {
- wr_lcd(comm,0x30);
- wr_lcd(comm,0x01); // 清屏,地址指針指向00H
- clrgdram(); // 請(qǐng)繪圖RAM
- }
- /*開機(jī)LCD初始化*/
- void init_lcd (void)
- {
- lcd_rst=1;
- wr_lcd(comm,0x30); // 30---基本指令動(dòng)作
- wr_lcd(comm,0x06); // 光標(biāo)的移動(dòng)方向
- wr_lcd(comm,0x0c); // 開顯示,關(guān)游標(biāo)
- clear_dis();
- }
- /*=====================================================================================
- 函數(shù)名稱:DS1302驅(qū)動(dòng)
- 功能描述:基本驅(qū)動(dòng)(讀寫數(shù)據(jù)、讀寫日期,時(shí)間、初始化)
- 全局變量:無
- 參數(shù)說明:w_adder(寫地址),r_adder(讀地址),w_data(寫入數(shù)據(jù))
- 返回說明:返回讀取的數(shù)據(jù)
- 設(shè) 計(jì) 人:LIJH
- 版 本:1.0
- 說 明:上升沿寫入數(shù)值,下降沿讀出數(shù)值,沒用設(shè)立后背電池充電
- ======================================================================================*/
- /*向1302寫數(shù)據(jù) 參數(shù)格式:地址,數(shù)據(jù)*/
- void w1302(uchar w_adder,uchar w_data)
- {
- uchar d;
- ret_ds1302();
- for(d=0;d<16;d++)
- {
- if(d==8) w_adder=w_data;
- d02_data=(bit)(w_adder&0x01);
- d02_sclk=0; // 上升沿
- w_adder>>=1;
- d02_sclk=1;
- }
- end_ds1302();
- }
- /*接收1302一個(gè)字節(jié)的數(shù)據(jù) 參數(shù)格式:讀地址*/
- uchar r1302(uchar r_adder)
- {
- uchar d=0;
- ret_ds1302();
- for(d=0;d<8;d++) // 寫地址
- {
- d02_data=(bit)(r_adder&0x01);
- d02_sclk=0;
- r_adder>>=1;
- d02_sclk=1;
- }
- r_adder=0;
- for(d=0;d<8;d++) // 讀數(shù)據(jù)
- {
- d02_data=1;
- d02_sclk=1; // 下降沿
- r_adder>>=1;
- d02_sclk=0;
- if(d02_data) r_adder|=0x80;
- }
- end_ds1302();
- return(r_adder);
- }
- /*寫入時(shí)間與日期*/
- void wds1302_time_date(void)
- {
- w1302(d02_wrc,0x00); // 寫允許
- w1302(0x90,0xa5); // 單二極管2K電阻充電
- w1302(d02_year,today.year); // 年
- w1302(d02_weeks,today.week); // 星期
- w1302(d02_month,today.month); // 月
- w1302(d02_day,today.day); // 日
- w1302(d02_hour,0x7f&now.hour); // 時(shí)
- w1302(d02_minute,now.minute); // 分
- w1302(d02_second,0x7f&now.second); // 秒
- w1302(d02_wrc,0x80); // 寫禁止
- }
- /*初始化寫DS1302 RAM*/
- void init_wds1302_ram(void)
- {
- w1302(d02_wrc,0x00);
- w1302(0x90,0xa5); // 單二極管2K電阻充電
- w1302(d02_signs,0x00); // 狀態(tài)寄存
- w1302(d02_passw,0x74); // 密碼儲(chǔ)存首位
- w1302(d02_passw+2,0x14); // 初始值為:741456
- w1302(d02_passw+4,0x56); // 密碼最后一位
- w1302(d02_alm,0x12); // 鬧鈴時(shí)(12小時(shí))
- w1302(d02_alm+2,0x00); // 鬧鈴分(0分)
- w1302(d02_temp,0xff); // 溫度上限(255為關(guān)閉)
- w1302(d02_temp+2,0xff); // 溫度下限(關(guān)閉)
- w1302(d02_initsi,0xb4); // 是否要初始化標(biāo)記(0xb4為已經(jīng)初始化)
- w1302(d02_wrc,0x80);
- }
- /*寫DS1302一字節(jié)的RAM*/
- void wds1302_data(uchar adder,uchar _data)
- {
- w1302(d02_wrc,0x00);
- w1302(adder,_data);
- w1302(d02_wrc,0x80);
- }
- /*讀取日期*/
- void rds1302_date(void)
- {
-
- today.year=r1302(d02_year+1);
- today.week=r1302(d02_weeks+1);
- today.month=r1302(d02_month+1);
- today.day=r1302(d02_day+1);
- }
- /*讀取時(shí)間*/
- void rds1302_time(void)
- {
- now.hour=(r1302(d02_hour+1));
- now.minute=r1302(d02_minute+1);
- now.second=r1302(d02_second+1);
- if(now.hour==alarm_time[0]&&now.minute==alarm_time[1]) alm_run=1;
- else // 鬧鈴時(shí)間比較
- {
- alm_run=0;buzstop=0;buzzer=close;
- }
- }
- /*開機(jī)讀數(shù)據(jù)*/
- void rds1302_data(void)
- {
- signs=r1302(d02_signs+1);
- alarm_time[0]=r1302(d02_alm+1);
- alarm_time[1]=r1302(d02_alm+3);
- als_temp[0]=r1302(d02_temp+1);
- als_temp[1]=r1302(d02_temp+3);
- }
-
- /*DS1302初始化*/
- void init_ds1302(void)
- {
- wds1302_time_date();
- init_wds1302_ram();
- }
- /*=====================================================================================
- 函數(shù)名稱:DS18b20驅(qū)動(dòng)
- 功能描述:基本驅(qū)動(dòng)(讀寫數(shù)據(jù)、數(shù)據(jù)轉(zhuǎn)換、初始化)
- 全局變量:無
- 參數(shù)說明:無
- 返回說明:返回讀取的數(shù)據(jù)
- 設(shè) 計(jì) 人:LIJH
- 版 本:1.0
- 說 明:調(diào)試中。。。
- ======================================================================================*/
- /*18B20初始化*/
- void init_ds18b20()
- {
- b20_io=1;
- b20_io=0;
- delay_b20(120); // 延時(shí)≥480us
- b20_io=1;
- delay_b20(12); // 拉高為高電平后在15—60us出現(xiàn)低電平,并維持60—240us
- ds18b20=~b20_io;
- delay_b20(40);
- }
- /*向18B20發(fā)送一個(gè)字節(jié)*/
- void send18b20_byte(uchar data_send)
- {
- uchar d=0;
- for (d=0;d<8;d++)
- {
- b20_io=0; // 拉低電平后向總線寫入一個(gè)位,15us后18B20接收
- b20_io=data_send&0x01;
- delay_b20(10); // 延時(shí)60us后完成一次
- b20_io=1;
- data_send>>=1; // 下位開始
- }
- }
- /*從18B20讀出溫度值 12位分辨率*/
- void receive18b20(void)
- {
- uchar n=1,d;
- for (d=0;d<16;d++)
- {
- if(d==8) n=0;
- b20_io=0; // 拉低總線
- temp.t_data[n]>>=1;
- b20_io=1; // 拉高總線
- if(b20_io) // 讀入總線數(shù)值
- temp.t_data[n]|=0x80;
- delay_b20(10); // 等待60us
- }
- }
- /*數(shù)據(jù)轉(zhuǎn)化*/
- void conversion_t(void)
- {
- uchar save=0,save1=0;
- if(temp.temp_data<0) // 判斷數(shù)值符號(hào)
- {temp_pn=1;temp.temp_data=~temp.temp_data+1;}
- else temp_pn=0;
- if(temp.t_data[1]&0x01==1) save+=6; // 小數(shù)點(diǎn)后的值轉(zhuǎn)變
- if((temp.t_data[1]>>1)&0x01==1) save+=12;
- if((temp.t_data[1]>>2)&0x01==1) save+=25;
- if((temp.t_data[1]>>3)&0x01==1) save+=50;
- temp.temp_data>>=4;
- save1=temp.temp_data&0x00ff; // 整數(shù)部分?jǐn)?shù)值
- temp.t_data[0]=save1;
- temp.t_data[1]=save;
- thl_als=1;
- if(save1>=(als_temp[0]&0x7f)) // 溫度比較
- {
- if(!temp_pn||(temp_pn&(als_temp[0]&0x80)!=0)){ als_th=open;als_tl=close;}
- }
- else if(save1<(als_temp[1]&0x7f)&&als_temp[1]!=255)
- {
- if(!temp_pn||(temp_pn&(als_temp[1]&0x80)!=0)) {als_tl=open;als_th=close;}
- }
- else {als_th=als_tl=close;thl_als=0;buzstop=0;buzzer=close;}
- }
- /*18b20功能*/
- void ds18b20_func(void)
- {
- EA=0;
- TR0=0;
- temp.temp_data=0;
- init_ds18b20();
- send18b20_byte(0xcc); // 跳過ROM
- send18b20_byte(0x44); // 溫度轉(zhuǎn)換
- delay_pw();
- init_ds18b20();
- send18b20_byte(0xcc);
- send18b20_byte(0xbe); // 讀RAM
- receive18b20(); // 讀取溫度值
- conversion_t(); // 數(shù)值轉(zhuǎn)換
- EA=1;
- TR0=1;
- }
- /*=====================================================================================
- 函數(shù)名稱:畫面構(gòu)造
- 功能描述:界面1、2、3,圖片菜單,反白,標(biāo)頭,16*16(32)圖片
- 全局變量:無
- 參數(shù)說明:函數(shù)說明
- 返回說明:無
- 設(shè) 計(jì) 人:LIJH
- 版 本:1.0
- 說 明:X坐標(biāo)每一格每次16點(diǎn)
- ======================================================================================*/
- /*反白或顯示圖片 參數(shù)格式:(H)8bit數(shù)據(jù),(L)8bit數(shù)據(jù),X0坐標(biāo)(16bit),Y0坐標(biāo)(1bit),X坐標(biāo)(16bit),Y坐標(biāo)(1bit)*/
- void con_disp (uchar data1,uchar data2,uchar x0,uchar y0,uchar xl,uchar yl)
- {
- uchar i,j;
- for(j=0;j<yl;j++)
- {
- for(i=0;i<xl;i++)
- {
- wr_lcd(comm,0x34); // 擴(kuò)展功能
- wr_lcd(comm,y0+j); // 寫Y坐標(biāo)
- wr_lcd(comm,x0+i); // 寫X坐標(biāo)
- wr_lcd(comm,0x30); // 普通功能
- wr_lcd(dat,data1);
- wr_lcd(dat,data2);
- }
- }
- wr_lcd(comm,0x36); // 開繪圖顯示
- }
- /*顯示字體 參數(shù)格式: 顯示位置(0x80-0x9f),顯示個(gè)數(shù),顯示內(nèi)容指針*/
- void display_cnasc(uchar dis_bit,uchar num,uchar *cnasc)
- {
- wr_lcd(comm,0x30); // 普通功能
- wr_lcd(comm,dis_bit); // 寫地址
- while(num>0)
- {
- wr_lcd(dat,*(cnasc++));
- wr_lcd(dat,*(cnasc++));
- num--;
- }
- }
- /*導(dǎo)航標(biāo)頭顯示*/
- void dis_title(void)
- {
- display_cnasc(0x80,1,"\x15 ");
- display_cnasc(0x90,1,"┏");
- display_cnasc(0x97,1,"┓");
- display_cnasc(0x98,1,"┗");
- display_cnasc(0x9f,1,"┛");
- display_cnasc(0x92,1,"\x1e ");
- display_cnasc(0x9a,1,"\x1f ");
- con_disp(0xff,0xff,0x80,0x80,3,16);
- con_disp(0xef,0xef,0x83,0x80,1,16);
- con_disp(0xde,0xf7,0x84,0x80,1,16);
- con_disp(0x76,0xdb,0x85,0x80,1,16);
- con_disp(0x55,0x55,0x86,0x80,1,16);
- con_disp(0x55,0x55,0x87,0x80,1,16);
- }
- /*圖片顯示標(biāo)頭*/
- void dis_title_pic(void)
- {
- display_cnasc(0x80,2,"〓〓");
- display_cnasc(0x86,2,"〓〓");
- }
- /*功能實(shí)現(xiàn)顯示標(biāo)頭*/
- void dis_title_e(void)
- {
- display_cnasc(0x80,1," \x15");
- con_disp(0xff,0xff,0x80,0x80,1,16);
- con_disp(0xff,0xc7,0x81,0x80,1,16);
- con_disp(0xff,0xff,0x82,0x80,3,16);
- con_disp(0xe3,0xff,0x85,0x80,1,16);
- con_disp(0xff,0xff,0x86,0x80,2,16);
- }
- /*顯示菜單圖片 格式:圖片反顯(1)或正常顯示(0),顯示圖片的號(hào)碼*/
- void anti_nor_pic (uchar cpl_sign,uchar menu_num)
- {
- uchar i,j,x,y;
- x=menu_num*3; // 計(jì)算圖片顯示坐標(biāo)
- if(x>6) x--;
- if(menu_num<3) y=16; // 上下半屏顯示
- else y=8;
- if(cpl_sign==1) display_cnasc(0x82,4,menu_cn[menu_num]);
- for(j=0;j<24;j++)
- {
- for(i=0;i<2;i++)
- {
- wr_lcd(comm,0x34);
- wr_lcd(comm,0x80+y);
- wr_lcd(comm,0x80+x+i); // 分兩次顯示 16bit
- wr_lcd(comm,0x30);
- if(cpl_sign==1) // 圖片反選
- {
- wr_lcd(dat,~menu_pic[menu_num][j*4+i*2]);
- wr_lcd(dat,~menu_pic[menu_num][j*4+i*2+1]);
- }
- else // 正常顯示
- {
- wr_lcd(dat,menu_pic[menu_num][j*4+i*2]);
- wr_lcd(dat,menu_pic[menu_num][j*4+i*2+1]);
- }
- }
- y++;
- if(y==32&&menu_num<3) {x+=8;y=0;} // 上下屏切換
- }
- wr_lcd(comm,0x36);
- }
- /*狀態(tài)16*16圖片 格式:反色(1)或正常0,X坐標(biāo),Y坐標(biāo),狀態(tài)編碼(16*16)*/
- void dis_run_state(uchar cpl,uchar x0,uchar y0,uchar state_num)
- {
- uchar j;
- for(j=0;j<16;j++)
- {
- wr_lcd(comm,0x34); // 擴(kuò)展功能
- wr_lcd(comm,y0++); // 寫Y地址
- wr_lcd(comm,x0); // 寫X地址
- wr_lcd(comm,0x30); // 普通功能
- if(cpl==1) // 寫數(shù)據(jù)
- {
- wr_lcd(dat,~running[state_num][j*2]);
- wr_lcd(dat,~running[state_num][j*2+1]);
- }
- else
- {
- wr_lcd(dat,running[state_num][j*2]);
- wr_lcd(dat,running[state_num][j*2+1]);
- }
- }
- wr_lcd(comm,0x36);
- }
-
- /*顯示菜單按鈕 參數(shù)格式:反色(1)或正常(0)*/
- void dis_menu_key(uchar d)
- {
- if(d==1)
- {
- for(d=0;d<8;d++) // 顯示菜單按鈕
- con_disp(~menu_key[d*2],~menu_key[d*2+1],0x9f,0x97+d,1,1);
- }
- else
- {
- for(d=0;d<8;d++) // 顯示菜單按鈕
- con_disp(menu_key[d*2],menu_key[d*2+1],0x9f,0x97+d,1,1);
- }
- }
- /*顯示模式3的界面*/
- void dis_mode3(void)
- {
- uchar i,j,h,l,x_0=0x80,y_0=0x90;
- h=now.hour>>4; // 分離十位 個(gè)位
- l=now.hour&0x0f;
- for(j=0;j<2;j++)
- {
- for(i=0;i<32;i++) // 十位個(gè)位一起讀入
- {
- wr_lcd(comm,0x34);
- wr_lcd(comm,y_0++);
- wr_lcd(comm,x_0);
- wr_lcd(comm,0x30);
- wr_lcd(dat,mode_3num[h][i*3]); // 連續(xù)寫數(shù)據(jù),X坐標(biāo)自動(dòng)加1
- wr_lcd(dat,mode_3num[h][i*3+1]);
- wr_lcd(dat,mode_3num[h][i*3+2]);
- wr_lcd(dat,mode_3num[l][i*3]);
- wr_lcd(dat,mode_3num[l][i*3+1]);
- wr_lcd(dat,mode_3num[l][i*3+2]);
- if(y_0==0xa0){x_0=x_0+8;y_0=0x80;}
- }
- x_0=0x84,y_0=0x90;
- h=now.minute>>4; // 分離十位 個(gè)位
- l=now.minute&0x0f;
- }
- dis_run_state(0,0x83,0x90,4); // 顯示點(diǎn)
- dis_run_state(0,0x8b,0x80,4);
- y_0=0x80; // 顯示狀態(tài)標(biāo)記
- if(keb) {dis_run_state(0,0x87,y_0,2);y_0+=16;}
- if(alm) {dis_run_state(0,0x87,y_0,1);y_0+=16;}
- if(y_0<0xa0&&!als){dis_run_state(0,0x87,y_0,0);}
- if(y_0==0xa0&&!als){dis_run_state(0,0x8f,0x80,0);}
- dis_menu_key(0);
- }
- /*顯示模式1和2的共用部分*/
- void mode1_2_union(void)
- {
- uchar x=0x9b;
- display_cnasc(0x98,2,"星期");
- if(nba_tim) dis_run_state(0,x,0x90,6);
- if(keb) {dis_run_state(0,x,0x90,2);x++;} // 顯示標(biāo)記
- if(alm) {dis_run_state(0,x,0x90,1);x++;}
- if(!als){dis_run_state(0,x,0x90,0);}
- dis_menu_key(0); // 顯示菜單按鈕
- }
- /*顯示模式2的日期*/
- void dis_date_mode2(uchar d)
- {
- uchar save[2];
- display_cnasc(d+2,1,"年");
- display_cnasc(d+4,1,"月");
- display_cnasc(d+6,1,"日");
- display_cnasc(0x9a,1,weeks[today.week]); // 顯示星期
- save[0]=char_num[today.year>>4]; // 將顯示的數(shù)值存到數(shù)組中
- save[1]=char_num[today.year&0x0f];
- display_cnasc(d+1,1,save);
- save[0]=char_num[today.month>>4];
- save[1]=char_num[today.month&0x0f];
- display_cnasc(d+3,1,save);
- save[0]=char_num[today.day>>4];
- save[1]=char_num[today.day&0x0f];
- display_cnasc(d+5,1,save);
- }
- /*顯示模式2的時(shí)間數(shù)字顯示 16*32*/
- void num2_asc_dis(uchar num,uchar x_0)
- {
- uchar i,y_0=0x90;
- for(i=0;i<32;i++) // 十位個(gè)位一起讀入
- {
- wr_lcd(comm,0x36);
- wr_lcd(comm,y_0++);
- wr_lcd(comm,x_0);
- wr_lcd(comm,0x30);
- wr_lcd(dat,mode_2num[num][i*2]);
- wr_lcd(dat,mode_2num[num][i*2+1]);
- if(i==15){x_0+=8;y_0=0x80;}
- }
- wr_lcd(comm,0x36);
- }
- /*顯示模式2的時(shí)間*/
- void dis_time_mode2(void)
- {
- uchar h,l;
- if(now.hour!=save_time.hour||init_d2)
- {
- h=now.hour>>4; // 分離十位 個(gè)位
- l=now.hour&0x0f;
- num2_asc_dis(h,0x80);
- num2_asc_dis(l,0x80+1);
- }
- if(now.minute!=save_time.minute||init_d2)
- {
- h=now.minute>>4; // 分離十位 個(gè)位
- l=now.minute&0x0f;
- num2_asc_dis(h,0x83);
- num2_asc_dis(l,0x83+1);
- }
- if(now.second!=save_time.second||init_d2)
- {
- h=now.second>>4; // 分離十位 個(gè)位
- l=now.second&0x0f;
- num2_asc_dis(h,0x86);
- num2_asc_dis(l,0x86+1);
- }
- if(init_d2)
- {
- dis_run_state(0,0x82,0x90,5); // 顯示點(diǎn)
- dis_run_state(0,0x8a,0x80,5);
- dis_run_state(0,0x85,0x90,5); // 顯示點(diǎn)
- dis_run_state(0,0x8d,0x80,5);
- }
- }
- /*顯示模式2的界面*/
- void dis_mode2(void)
- {
- dis_date_mode2(0x81); // 顯示日期
- display_cnasc(0x81,1,"20");
- dis_time_mode2(); // 顯示時(shí)間
- mode1_2_union();
- }
- /*顯示模式1的日期*/
- void dis_date_mode1(void)
- {
- uchar save[2];
- display_cnasc(0x80,3,"日期:");
- display_cnasc(0x90,3,"時(shí)間:");
- display_cnasc(0x88,3,"溫度:");
- display_cnasc(0x9a,1,weeks[today.week]); // 顯示星期
- display_cnasc(0x83,1,"20");
- save[0]=char_num[today.year>>4];
- save[1]=char_num[today.year&0x0f];
- display_cnasc(0x84,1,save);
- save[0]='/';
- save[1]=char_num[today.month>>4];
- display_cnasc(0x85,1,save);
- save[0]=char_num[today.month&0x0f];
- save[1]='/';
- display_cnasc(0x86,1,save);
- save[0]=char_num[today.day>>4];
- save[1]=char_num[today.day&0x0f];
- display_cnasc(0x87,1,save);
- mode1_2_union();
- }
- /*顯示模式1的時(shí)間*/
- void dis_time_mode1(void)
- {
- uchar save[2];
- save[0]=char_num[now.hour>>4];
- save[1]=char_num[now.hour&0x0f];
- display_cnasc(0x93,1,save);
- save[0]=':';
- save[1]=char_num[now.minute>>4];
- display_cnasc(0x94,1,save);
- save[0]=char_num[now.minute&0x0f];
- save[1]=':';
- display_cnasc(0x95,1,save);
- save[0]=char_num[now.second>>4];
- save[1]=char_num[now.second&0x0f];
- display_cnasc(0x96,1,save);
- }
- /*顯示模式1的溫度*/
- void dis_temp_mode1(void)
- {
- uchar save[2];
- if(ds18b20)
- {
- if(temp.t_data[0]>99)
- {
- save[0]=char_num[temp.t_data[0]/100];
- save[1]=char_num[(temp.t_data[0]/10)%10];
- display_cnasc(0x8b,1,save);
- save[0]=char_num[temp.t_data[0]%10];
- save[1]='.';
- display_cnasc(0x8c,1,save);
- save[0]=char_num[temp.t_data[1]/10];
- save[1]=' ';
- display_cnasc(0x8d,1,save);
- display_cnasc(0x8e,1,"℃");
- }
- else
- {
- if(temp_pn) display_cnasc(0x8a,1,":-");
- else display_cnasc(0x8a,1,":");
- save[0]=char_num[temp.t_data[0]/10];
- save[1]=char_num[temp.t_data[0]%10];
- display_cnasc(0x8b,1,save);
- save[0]='.';
- save[1]=char_num[temp.t_data[1]/10];
- display_cnasc(0x8c,1,save);
- display_cnasc(0x8d,1,"℃");
- }
- }
- else display_cnasc(0x8b,3,"FF.F℃");
- }
- /*顯示模式1的界面*/
- void dis_mode1(void)
- {
- dis_date_mode1();
- dis_time_mode1();
- dis_temp_mode1();
- }
- /*籃球器時(shí)間顯示*/
- void nba_dis_time(void)
- {
- uchar d,dis[2];
- for(d=2;d<4;d++)
- {
- dis[0]=char_num[resu[d]/10];
- dis[1]=char_num[resu[d]%10];
- display_cnasc(0x81+d*2,1,dis);
- }
- display_cnasc(0x86,1,": ");
- if(resu[0]==1)
- {
- dis[0]='\x07';
- dis[1]=char_num[resu[4]/10];
- display_cnasc(0x93,1,dis);
- dis[1]='\x07';
- dis[0]=char_num[resu[4]%10];
- display_cnasc(0x94,1,dis);
- }
- }
- /*=====================================================================================
- 函數(shù)名稱:鍵盤掃描
- 功能描述:讀取鍵盤操作數(shù)據(jù)及部分狀態(tài)的實(shí)現(xiàn)
- 全局變量:dis_sig t0_isr temprun b20time alm_run als_temp buzstop als
- lock_op nba_tim
- 參數(shù)說明:無
- 返回說明:鍵盤鎖與密碼鎖時(shí)間到達(dá)后返回 255
- 設(shè) 計(jì) 人:LIJH
- 版 本:1.0
- 說 明:
- ======================================================================================*/
- /*掃描鍵盤*/
- uchar keypad_scan()
- {
- uchar key,dis[2];
- keyboard=0xf0;
- while (keyboard==0xf0) // 等待按鍵按下
- {
-
- /*--------------------- 背光燈關(guān)閉延時(shí) -----------------------*/
-
- delay(1000);
- if((++dis[0])==0&&bl_delay!=0) bl_delay--; // 當(dāng)有按鍵按下bl_delay重新賦值
- if(bl_delay==0&&!bl0) lcd_bl=close; // 背光時(shí)間到且不是常開模式時(shí)關(guān)閉背光
-
- /*----------------------- 鍵盤鎖延時(shí) -------------------------*/
- if(keb&&dis_sig&&bl_delay==0&&resu[11]<2) resu[11]++; // 當(dāng)有按鍵按下j清零
- if(bl_delay==0) bl_delay=15;
- /*--------------------- 密碼鎖30秒鎖延時(shí) ---------------------*/
- if(lock_op)
- {
- if((++i)==0) save1++;
- if(save1==15) return(255);
- }
-
- /*---------------------- 時(shí)鐘界面時(shí)間顯示 ---------------------*/
-
- if(dis_sig&&t0_isr||nba_tim&&oth_run) // 正常時(shí)鐘界面與籃球器返回時(shí)鐘界面顯示
- {
- rds1302_date(); // 讀出日期
- rds1302_time(); // 讀出時(shí)間
- if(di0) // 模式2
- {
- dis_time_mode2();
- if(now.hour==0&&now.minute==0&&now.second==0) dis_date_mode2(0x81);
- }
- else if(di1) // 模式3
- {
- if(now.hour!=save_time.hour||now.minute!=save_time.minute) // 時(shí),分變化后顯示
- dis_mode3();
- }
- else
- {
- dis_time_mode1(); // 模式1
- if(now.hour==0&&now.minute==0&&now.second==0) dis_date_mode1();
- }
- save_time=now; // 重新記錄作下次比較
- t0_isr=0;
- }
-
-
- /*-------------------- 溫度計(jì)提示按鍵操作 ----------------------*/
-
- if(temprun)
- {
- if(!oth_run)
- {
- display_cnasc(0x96,2," key"); // 溫度計(jì)時(shí)提示按鍵操作
- for(dis[1]=0;dis[1]<250;dis[1]++)
- {
- delay(1000);
- if(keyboard!=0xf0)
- {
- keyboard=0x7f;
- if(keyboard==0x7d) return 0x7d;
- else keyboard=0xf0;
- }
- }
- oth_run=1;
- display_cnasc(0x96,2," ");
- }
- }
-
-
- /*------------------------ 蜂鳴器警報(bào) --------------------------*/
-
- if(((alm_run&&alm)||thl_als)&&!buzstop) // 溫度,鬧鈴蜂鳴器警報(bào)
- { // 有按鍵按下時(shí)停止
- if(now.second==0) lcd_bl=close;
- delay(15000); // 讀出溫度時(shí)間比較
- if(keyboard!=0xf0) break;
- delay(15000);
- if(keyboard!=0xf0) break;
- delay(15000);
- if(keyboard!=0xf0) break;
- delay(15000);
- if(alm_run) lcd_bl=!lcd_bl; // 只在鬧鈴功能閃
- if(!als)buzzer=!buzzer; // 警報(bào)開啟后蜂鳴器開啟
- }
- /*----------------------- 溫度刷新顯示 -------------------------*/
-
- if((temprun&&oth_run)||(b20time&&!di0&&!di1&&dis_sig)) // 溫度計(jì)功能于模式1界面
- {
-
- ds18b20_func(); // 溫度檢測(cè)功能
- oth_run=0; // 作交替標(biāo)記用
- if(temprun) return 20; // 溫度計(jì)開啟后返回
- if(b20time){ dis_temp_mode1();b20time=0;} // 時(shí)鐘界面5分鐘更新一次,T0計(jì)時(shí)
- }
-
-
- /*------------------------ 籃球器顯示時(shí)間 ------------------------*/
-
- if(nba_tim&!oth_run) // 當(dāng)籃球器模式下 oth_run==0為籃球器計(jì)時(shí)狀態(tài)
- {
- if(EA) display_cnasc(0x8b,2," R\x10 "); // 顯示運(yùn)行狀態(tài)
- else display_cnasc(0x8b,2," S! ");
- if(t0_isr)
- { // 更新時(shí)間
- nba_dis_time();
- if(resu[2]==0&&resu[3]==0) // 判斷比賽情況
- {
- resu[6]++;
- if(resu[6]<resu[1]) display_cnasc(0x85,3,"休息 ");
- else display_cnasc(0x85,3,"完結(jié) ");
- }
- if(resu[4]==0||(resu[2]==0&&resu[3]==0)) // 時(shí)間到達(dá)警報(bào)
- {
- buzzer=open;
- delay_pw();
- if(resu[2]==0&&resu[3]==0) // 24秒 總時(shí)間警報(bào)
- {
- delay_pw();
- }
- buzzer=close;
- if(resu[4]==0) resu[4]=24; // 重新賦值
- }
- t0_isr=0; // 清零等下次中斷產(chǎn)生
- }
- }
- }
-
- /*===== 以上等待按鍵 =====*/
- /*------------------------- 按鍵按下后 --------------------------*/
-
- delay(8000); // 消抖振
- if(!lock_op)bl_delay=15; // 背光時(shí)間賦值
- if(bl1) lcd_bl=close; // 不在背光燈關(guān)閉時(shí)亮起
- else lcd_bl=open;
- if(alm_run|thl_als) {buzstop=1;buzzer=close;}
- if(keb&&dis_sig)
- {
- if(resu[11]==2) return 255; // 要求輸入密碼
- else resu[11]=0; // 時(shí)間不到時(shí)重新計(jì)時(shí)
- }
- do
- {
- for(dis[0]=0;dis[0]<=3;dis[0]++)
- {
- keyboard=ksp[dis[0]];
- if(keyboard!=ksp[dis[0]])
- {
- key=keyboard;
- if(key!=ksp[dis[0]]) return(key);
- }
- }
- }while(1);
- }
-
- /*讀鍵盤數(shù)據(jù)*/
- uchar gotkey()
- {
- uchar save,n;
- keyboard=0xf0;
- while(keyboard!=0xf0); // 等待鍵盤松開
- delay(5000); // 消抖陣
- if(adju_si) // 連寫輸入
- {
- adju_si=0;
- for(n=0;n<60;n++)
- {
- delay(2000);
- if(keyboard!=0xf0)
- {
- adju_si=1; // 在更改時(shí),在此時(shí)間內(nèi)可連成多位數(shù)
- break;
- }
- }
- }
- save=keypad_scan(); // 掃描鍵盤
- if(save==255) return 255; // 要求輸入鍵盤鎖密碼或延時(shí)時(shí)間到達(dá)
- for (n=0;n<16;n++)
- {
- if(save==key_code[n])
- return(n);
- }
- return(20);
- }
- /*=====================================================================================
- 函數(shù)名稱:導(dǎo)航
- 功能描述:主菜單 工具導(dǎo)航 保存提示
- 全局變量:無
- 參數(shù)說明:
- 返回說明:無
- 設(shè) 計(jì) 人:LIJH
- 版 本:1.0
- 說 明:
- ======================================================================================*/
- /*按鍵按下顯示 參數(shù)格式:k 按鈕的顯示地址*/
- void key_dis(uchar k)
- {
- display_cnasc(k,1,"\x04 ");
- delay(10000);
- if(k==0x92||k==0x96) display_cnasc(k,1,"\x1e ");
- else display_cnasc(k,1,"\x1f ");
- }
- /*確定按鍵按下顯示*/
- void enter_dis(void)
- {
- display_cnasc(0x8f,1," \x09");
- delay(15000);
- }
- /*主菜單導(dǎo)航*/
- uchar dis_menu(void)
- {
- uchar d,save,key;
- if(meu)
- {
- display_cnasc(0x81,2,"菜單");
- dis_title();
- display_cnasc(0x88,8,selected[0]);
- con_disp(0xff,0xff,0x8a,0x80,5,16);
- }
- else // 顯示圖片菜單
- {
- dis_title_pic();
- for(d=0;d<6;d++)
- anti_nor_pic(0,d);
- anti_nor_pic(1,0);
- }
- save=d=0;
- do
- {
- if(meu) // 操作指示更新
- {
- display_cnasc(0x93,3,menu_cn_2[index_m[save].left_num]);
- display_cnasc(0x8b,3,menu_cn_2[save]);
- display_cnasc(0x9b,3,menu_cn_2[index_m[save].right_num]);
- }
- else
- {
- anti_nor_pic(0,d);
- anti_nor_pic(1,save);
- }
- d=save; // 保存上一索引
- while(1)
- {
- key=gotkey();
- if(key==11||(key==3&&meu))
- {
- if(meu) enter_dis();
- break;
- }
- else if(meu)
- {
- if(key==2)
- {
- save=index_m[d].right_num;
- key_dis(0x9a);
- break;
- }
- if(key==5)
- {
- save=index_m[d].left_num;
- key_dis(0x92);
- break;
- }
- if((key==1&&meu))
- {
- d=5;
- break;
- }
- }
- else
- {
- if(key==3){save=index_m[d].right_num; break;} // 根據(jù)導(dǎo)航鍵尋找索引
- if(key==1){save=index_m[d].left_num; break;}
- if(key==2||key==5){save=index_m[d].shaft_num; break;}
- }
- }
- if(key==11||((key==1|key==3)&&meu)) break;
- }while(1);
- return d;
- }
- /*工具導(dǎo)航*/
- uchar tool_func(void)
- {
- uchar save,d,key;
- display_cnasc(0x81,2,"工具");
- dis_title();
- display_cnasc(0x88,8,selected[0]);
- con_disp(0xff,0xff,0x8a,0x80,5,16);
- d=0;
- save=0;
- do
- {
- display_cnasc(0x93,3,tool_menu[index_t[save].lnum]);
- display_cnasc(0x8b,3,tool_menu[save]);
- display_cnasc(0x9b,3,tool_menu[index_t[save].rnum]);
- d=save;
- while(1)
- {
- key=gotkey();
- if(key==1){ d=4;break;} // 根據(jù)按鍵尋找索引
- if(key==11||key==3){enter_dis();break;}
- if(key==2){save=index_t[d].rnum; key_dis(0x9a);break;}
- if(key==5){save=index_t[d].lnum; key_dis(0x92);break;}
- }
- if(key==11||key==3||key==1) break;
- }while(1);
- return d;
- }
- /*更改后提示保存*/
- void save_y_or_n(void)
- {
- uchar key;
- clear_dis();
- oth_run=0;
- display_cnasc(0x92,5,"是否保存? ");
- display_cnasc(0x89,6,"Y(OK)\\N(./S)");
- while(1)
- {
- key=gotkey();
- if(key==11)
- {
- display_cnasc(0x9a,5,"保存成功! ");
- delay(50000);
- oth_run=1; // 要求保存時(shí)oth_run標(biāo)記為1
- return;
- }
- if(key==10) return;
- }
- }
- /*=====================================================================================
- 函數(shù)名稱:調(diào)整功能
- 功能描述:時(shí)間日期調(diào)整
- 全局變量:today now
- 參數(shù)說明:見函數(shù)
- 返回說明:無
- 設(shè) 計(jì) 人:LIJH
- 版 本:1.0
- 說 明:
- ======================================================================================*/
- /*調(diào)整功能顯示時(shí)間*/
- void asjust_time()
- {
- uchar save[2];
- display_cnasc(0x8a,1,"時(shí)");
- display_cnasc(0x8c,1,"分");
- display_cnasc(0x8e,1,"秒");
- save[0]=char_num[now.hour>>4];
- save[1]=char_num[now.hour&0x0f];
- display_cnasc(0x89,1,save);
- save[0]=char_num[now.minute>>4];
- save[1]=char_num[now.minute&0x0f];
- display_cnasc(0x8b,1,save);
- save[0]=char_num[now.second>>4];
- save[1]=char_num[now.second&0x0f];
- display_cnasc(0x8d,1,save);
- }
- /*調(diào)整功能月天數(shù)比較*/
- uchar monthday(uchar year,uchar month)
- {
- if(month==2&&year%4==0)
- return(29);
- else
- { year=month&0x0f;
- month>>=4;
- month=month*10+year;
- return(dayofmonth[month-1]);}
- }
- /*星期推算*/
- void weeks_day()
- {
- uchar d,buffer,day=4;
- if(today.month>1)
- {
- buffer=(today.month>>4); // 將BCD碼轉(zhuǎn)為十進(jìn)制
- buffer=buffer*10;
- buffer+=(today.month&0x0f);
- for(d=0;d<buffer-1;d++)
- {
- today.week=(dayofmonth[d]>>4);
- today.week=today.week*10;
- today.week+=(dayofmonth[d]&0x0f);
- day+=(today.week%7);
- }
- }
- buffer=(today.year>>4);
- buffer*=10;
- buffer+=(today.year&0x0f);
- if(today.year!=0)
- {
- day+=((buffer-1)/4)+buffer+1;
- }
- if(buffer%4==0&&today.month>2) day++;
- buffer=today.day>>4;
- buffer*=10;
- buffer+=(today.day&0x0f);
- today.week=(day+buffer)%7;
- }
- /*調(diào)整功能*/
- void adjust_func(void)
- {
- uchar d,save,b=0;
- dis_title_e();
- display_cnasc(0x82,3,menu_cn_2[0]);
- rds1302_date();
- rds1302_time();
- dis_date_mode2(0x90);
- display_cnasc(0x9a,1," ");
- asjust_time();
- display_cnasc(0x9f,1,"→");
- display_cnasc(0x90,1,"『");
- display_cnasc(0x8f,1,"』");
- d=0;save=0;
- adju_si=0;
- do
- {
- con_disp(0x00,0x00,index_a[d].lnum,index_a[d].rnum,1,13);
- con_disp(0xff,0xff,index_a[save].lnum,index_a[save].rnum,1,13);
- d=save;
- while(1)
- {
- save=gotkey();
- if(save>=0&&save<10)
- {
- switch(d)
- {
- case 0: if(adju_si) // adju_si==1時(shí)兩次輸入連成一個(gè)數(shù)
- {
- today.year<<=4;
- today.year+=save;adju_si=0;
- }
- else
- {
- today.year=save;adju_si=1;
- }
- break;
- case 1: if(adju_si)
- {
- today.month<<=4;today.month+=save;
- if(today.month>0x12) today.month=save;
- else adju_si=0;
- }
- else
- {
- today.month=save;adju_si=1;
- }
- break;
- case 2: if(adju_si)
- {
- today.day<<=4;today.day+=save; // 月天數(shù)比較
- if(today.year%4==0&&today.month==2&&today.day==29) ;
- else if(today.day>monthday(today.year,today.month))
- today.day=save;
- else adju_si=0;
- }
- else {today.day=save;adju_si=1;}
- break;
- case 3: if(adju_si)
- {
- now.hour<<=4;now.hour+=save;
- if(now.hour>0x23) now.hour=save;
- else adju_si=0;
- }
- else {now.hour=save;adju_si=1;}
- break;
- case 4: if(adju_si)
- {
- now.minute<<=4;now.minute+=save;
- if(now.minute>0x59) now.minute=save;
- else adju_si=0;
- }
- else {now.minute=save;adju_si=1;}
- break;
- case 5: if(adju_si)
- {
- now.second<<=4;now.second+=save;
- if(now.second>0x59) now.second=save;
- else adju_si=0;
- }
- else {now.second=save;adju_si=1;}
- break;
- }
- if(today.day>monthday(today.year,today.month)) today.day=1; // 更改月份時(shí)判斷天數(shù)
- if(today.month==0) today.month=1;
- if(today.day==0) today.day=1;
- if(d<3) dis_date_mode2(0x90); // 更新顯示
- else asjust_time();
- display_cnasc(0x9a,1," "); // 消去星期顯示
- }
- if(save==11){save=d+1;adju_si=0;break;}
- if(save==10&&d!=0){save=d-1;adju_si=0;break;}
- }
- if(save==7&d==6) break;
- }while(1);
- weeks_day(); // 計(jì)算星期
- save_y_or_n(); // 需要保存時(shí)oth_run設(shè)為1
- if(oth_run) wds1302_time_date();
- }
- /*=====================================================================================
- 函數(shù)名稱:計(jì)算器功能
- 功能描述:10位帶符號(hào)數(shù)的加減乘除運(yùn)算
- 全局變量:opera resu i j
- 參數(shù)說明:見函數(shù)
- 返回說明:無
- 設(shè) 計(jì) 人:LIJH
- 版 本:1.0
- 說 明:
- ======================================================================================*/
- /*清寄存器 參數(shù)格式:m=2時(shí)結(jié)果寄存器,當(dāng)m=1時(shí)操作數(shù)1,當(dāng)m=0時(shí)操作數(shù)0(1),
- n=1時(shí),只清寄存器不清顯示, 0兩清*/
- void removal_data(uchar m,uchar n)
- {
- uchar l; // 當(dāng)n=1時(shí),只清寄存器不清顯示, 0兩清
- if(m==2) // 當(dāng)m=2時(shí)結(jié)果寄存器
- { // 當(dāng)m=1時(shí)操作數(shù)1
- if(n==0) // 當(dāng)m=0時(shí)操作數(shù)0 ,1
- for(l=0;l<6;l++)
- display_cnasc(0x98+l,1," ");
- for(l=0;l<12;l++)
- resu[l]=0;
- }
- while(m<2)
- {
- if(n==0)
- {
- if(m==0)
- {
- for(l=0;l<6;l++)
- display_cnasc(0x90+l,1," ");
- display_cnasc(0x95,1," 0");
- }
- else
- for(l=0;l<6;l++)
- display_cnasc(0x88+l,1," ");
- }
- for(l=0;l<12;l++)
- opera[m][l]=0;
- m++;
- }
- }
- /*顯示數(shù)值 參數(shù)格式:顯示首地址*/
- void dis_cdata(uchar ass)
- {
- uchar p,d,save[2];
- if(i==0&&opera[0][0]==1) // 顯示符號(hào)
- {
- if(cal_run) display_cnasc(0x98,1,"=-");
- else display_cnasc(0x90,1," -");
- }
- d=opera[i][11]; // 計(jì)算位數(shù)
- if(opera[i][10]!=0&&opera[i][10]!=opera[i][11]+1) d++;
- save[0]=d/2;ass=ass-save[0]+5; // 計(jì)算顯示的開始位置
- p=1;
- cal_del=0; // 顯示點(diǎn)標(biāo)記 (0為沒有顯示)
- if(d%2==1) // 對(duì)位數(shù)位奇數(shù)先處理首位
- {
- save[0]=' ';
- save[1]=char_num[opera[i][1]];
- display_cnasc(ass,1,save);
- p++;
- }
- ass++; // 顯示地址加一
- while(p<=opera[i][11])
- {
- if(opera[i][10]==p&&(!cal_del)) { // 顯示點(diǎn)且作標(biāo)記
- save[0]='.';cal_del=1;}
- else {
- save[0]=char_num[opera[i][p]]; p++;}
- if(opera[i][10]==p&&(!cal_del)) {
- save[1]='.';cal_del=1;}
- else{
- save[1]=char_num[opera[i][p]];p++;}
- display_cnasc(ass,1,save);
- ass++;
- }
- }
- /*從鍵盤中寫入數(shù)據(jù)*/
- char input_data()
- {
- uchar save=20,c;
- for(;i<2;i++)
- {
- while(1)
- {
- pp: save=gotkey(); // 讀鍵盤
- if(save==20) continue;
- if(save==11) // 按鍵為確定時(shí),選擇計(jì)算或刪除
- {
- c=save=0;
- while(1) // 反色選擇
- {
- con_disp (0x00,0x00,index_cal[save].lnum,index_cal[save].rnum,2,16);
- con_disp (0xff,0xff,index_cal[c].lnum,index_cal[c].rnum,2,16);
- save=gotkey();
- if(save==10)
- {
- save=c;
- if(++c==3) c=0;
- }
- else if(save==11)
- {
- if(c==0) save=11;
- else if(c==1) save=16;
- else return 0;
- break;
- }
- else break;
- }
- con_disp (0x00,0x00,index_cal[c].lnum,index_cal[c].rnum,2,16);
- }
- if(save>=0&&save<=9&&j<10)
- {
- if(i==1&&opera[1][0]==15&&j>8) goto pp;
- if(j==2&&opera[i][1]==0&&opera[i][10]==0)
- opera[i][1]=save; // 防止小數(shù)位不在時(shí)首位為零
- else{
- opera[i][j]=save;opera[i][11]=j;j++;}
- if(i==0) // 顯示
- dis_cdata(0x90);
- else
- dis_cdata(0x88);
- }
- else if(save==10&&j<10)
- {
- if(opera[i][10]==0) // 小數(shù)點(diǎn)空時(shí)保存
- {
- if(opera[i][11]==0) {opera[i][10]=2;j++;}
- else opera[i][10]=j;
- }
- }
- else if(save==16)
- { // 刪除數(shù)據(jù)
- removal_data(i,0);j=1;
- if(i!=0){i--;j=10;}
- }
- else if(i==1&&opera[1][11]!=0&&save>11&&save<16)
- { save1=save;break; } // 連續(xù)計(jì)算時(shí)保存運(yùn)算符
- else if(save==11&&opera[1][11]==0) continue;// 操作數(shù)1為0時(shí)不理會(huì)
- else if(save==11&&opera[1][11]!=0) break;
- else if((i==0||i==1&&j==1)&&save>11&&save<16){i=0; break;}
- // 當(dāng)操作數(shù)0由運(yùn)算符結(jié)束輸入,再按符號(hào)鍵更改
- else continue;
- }
- if(opera[i][10]>opera[i][11]||opera[i][10]==0)
- opera[i][10]=opera[i][11]+1; // 整數(shù)時(shí)小數(shù)位保存到最后
- while(opera[i][11]>=opera[i][10]&&opera[i][opera[i][11]]==0)
- opera[i][11]--; // 去除小數(shù)點(diǎn)后多余的0
- if(i==0)
- {
- opera[1][0]=save; // 保存運(yùn)算符并顯示
- display_cnasc(0x88,1,tool_cal[save-12]);
- }
- if(opera[0][11]==0) display_cnasc(0x95,1," 0");
- j=1;
- while(j<=opera[i][11]&&opera[i][j]==0) j++;//判斷是否操作數(shù)是否全為0
- j--;
- if(j==opera[i][11]) opera[i][11]=0;
- j=1;
- }
- return 1;
- }
- /****************************************************************************************
- 功能: 乘法運(yùn)算
- 描述: 結(jié)果由右到左保存
- 參數(shù): i , j , opera[i][j],p,q,r,k,save1
- 返回值:1(成功),0(結(jié)果位0),-1(溢出)
- /****************************************************************************************/
- char multiplication()
- {
- uchar p,q,r,k,save1=0; // p指向操作數(shù)0 ,q指向操作數(shù)1,r指向結(jié)果
- if(opera[0][11]==0||opera[1][11]==0) return 0;
- resu[10]=opera[0][11]+opera[1][11]-opera[0][10]-opera[1][10]+2; // RESU記錄小數(shù)點(diǎn)后的位數(shù)
- q=opera[1][11]; // 記錄操1的位數(shù)
- r=9;
- opera[1][11]=1;
- k=1;
- while(opera[1][k]==0) {opera[1][11]=opera[1][11]+1;k++;} // 去除前端的0
- k=1;
- while(opera[0][k]==0) k++; // 去除前端的0
- resu[11]=9;
- for(resu[0]=9;q>=opera[1][11];q--,resu[0]--)
- {
- if(opera[1][q]==0) continue; // 操1此位數(shù)為0時(shí)直接比較
- for(p=opera[0][11],r=resu[0];p>=k;p--)
- {
- save1=opera[0][p]*opera[1][q]; // 將相乘后的數(shù)保存
- resu[r]+=(save1%10);//將緩存中的數(shù)取余后加到結(jié)果中R指向的位
- save1/=10;
- save1=save1+(resu[r]/10); // 保存進(jìn)位的數(shù)
- resu[r]%=10; // 重新寫入
- if(r==1) //結(jié)果有溢出時(shí)移位
- {
- if(save1==0&&p==k) break; // 計(jì)算到最后位且沒進(jìn)位跳出
- else if(resu[10]>0) // 要求有小數(shù)存在
- {
- for(r=9;r>1;r--) resu[r]=resu[r-1];
- r=1;
- resu[r]=save1;
- resu[11]=1;
- resu[10]--;
- resu[0]++;
- }
- else return -1; // 否則溢出
- }
- if(r>1&&(r-1)<resu[11]) // 保存結(jié)果位的最高位
- {
- if(save1!=0) resu[11]=r-1;
- else resu[11]=r;
- }
- if(r>1){ r--;resu[r]+=save1;}// 當(dāng)R為1時(shí)只需要移位記錄結(jié)果
- }
- }
- while(resu[resu[11]]==0) resu[11]++; // 去除前端的0
- resu[0]=opera[0][0]; // 保存符號(hào)位
- removal_data(0,1); // 清數(shù)據(jù)不清顯示
- if(resu[10]>8) //如果小數(shù)點(diǎn)后的數(shù)有9 位或以上時(shí),需后移到使小數(shù)點(diǎn)放到2的位置
- {
- save1=resu[10]-10+resu[11]; // 記錄后移位數(shù)
- if(save1>7) return 0; //當(dāng)后移的數(shù)大于有效數(shù)字的位數(shù)時(shí)結(jié)果為0
- else // 否則按需移位
- {
- for(p=save1+2,r=resu[11];p<10;p++,r++) opera[0][p]=resu[r];
- opera[0][10]=2;opera[0][11]=9;opera[0][0]=resu[0];
- } // 因有效數(shù)小于小數(shù)點(diǎn)后的數(shù),所以首位為0
- }
- else //如果小數(shù)點(diǎn)后的數(shù)在8位以內(nèi)時(shí)分兩種情況
- {
- opera[0][0]=resu[0];
- save1=10-resu[11]; // 記錄有效位數(shù)
- if(resu[10]>=save1) // 小數(shù)的在有效數(shù)字的左邊
- {
- for(p=resu[10]+1,r=9;r>=resu[11];p--,r--)
- opera[0][p]=resu[r]; // 從小數(shù)點(diǎn)的最后一位開始
- opera[0][10]=2;opera[0][11]=resu[10]+1;
- }
- else // 小數(shù)點(diǎn)在有效數(shù)字內(nèi)
- {
- for(p=1,r=resu[11];r<10;p++,r++) opera[0][p]=resu[r];
- opera[0][11]=10-resu[11];
- if(resu[10]==0) opera[0][10]=opera[0][11]+1;
- else opera[0][10]=opera[0][11]-resu[10]+1;
- }
- }
- while(opera[0][11]>=opera[0][10]&&opera[0][opera[0][11]]==0)
- opera[0][11]--; // 去除小數(shù)點(diǎn)后多余的0
- return 1;
- }
- /****************************************************************************************
- 功能: 除法運(yùn)算
- 描述: 結(jié)果由左到右保存
- 參數(shù): i , j , opera[i][j]
- p,q,r, remainde, divisor, decimal
- 返回值:1(成功),0(結(jié)果位0),-1(溢出)
- *****************************************************************************************/
- char divider()
- {
- unsigned long int divisor=0,remainder=0;
- uchar p,q,r;
- char decimal=0;
- if(opera[1][11]==0) return -1;
- if(opera[0][11]==0) return 0;
- for(r=1;r<12;r++) // 判斷兩數(shù)是否相等
- {
- if(opera[0][r]!=opera[1][r]) break;
- }
- if(r==12)
- {
- p=opera[0][0];
- removal_data(0,1);
- opera[0][0]=r;
- opera[0][1]=1;
- opera[0][10]=2;
- opera[0][11]=1;
- return 1;
- }
- decimal=(opera[0][11]-opera[0][10])-(opera[1][11]-opera[1][10]);
- // 記錄兩操作數(shù)小數(shù)點(diǎn)后位數(shù)的差
- if(decimal>0) // 若操0大于操1時(shí)重新記錄小數(shù)點(diǎn)的位置
- {
- opera[0][10]=opera[0][11]-decimal+1;
- resu[10]=opera[0][10];
- }
- else // 否則小數(shù)點(diǎn)后沒有數(shù),記錄有效數(shù)的位數(shù)
- {
- opera[0][11]-=decimal;
- opera[0][10]=opera[0][11]+1;
- resu[10]=opera[0][10];
- }
- q=1;
- divisor=0;
- while(q<=opera[1][11]) // 將操1的數(shù)整形化
- {
- divisor=divisor*10+opera[1][q];q++;
- }
- if(divisor==1)
- {
- if(resu[10]>10) return -1;
- else return 1;
- }
- r=1;p=1;
- remainder=(unsigned long int)opera[0][1]; // 先對(duì)余數(shù)寄存器附初值
- do
- {
- if(r>9) // 結(jié)果位已經(jīng)到達(dá)最后1位
- {
- if(resu[1]==0&&resu[10]!=2) // 判斷是否有得移位
- {
- for(r=1;r<9;r++) resu[r]=resu[r+1];
- resu[9]=0;
- if(resu[10]!=0) resu[10]--;
- r=9;
- }
- else if(p>=opera[0][11]||p>=opera[0][10]) break; // 如果計(jì)算到最后一位,或者有小數(shù)點(diǎn)存在時(shí)結(jié)束
- else return -1; // 否則錯(cuò)誤
- }
- resu[r]=(uchar)(remainder/divisor); // 保存結(jié)果
- remainder=(remainder%divisor); // 重新寫入余數(shù)
- p++;r++;
- if(p>opera[0][11]&&remainder==0) break; // 除盡后跳出
- else if(p<=opera[0][11]&&p<10) // 余數(shù)*10后加后一位
- {remainder=remainder*10+opera[0][p];}
- else remainder=remainder*10; //超出后余數(shù)*10
- }while(1);
- resu[11]=r-1;
- resu[0]=opera[0][0];
- removal_data(0,1);
- r=1;
- while(resu[r]==0&&resu[10]!=(r+1)&&r<resu[11]) r++;
- //去除結(jié)果前端的0
- if(r==resu[11]) return 0;
- resu[10]=resu[10]-r+1;
- p=1;
- while(r<=resu[11]){opera[0][p]=resu[r];r++;p++;}
- opera[0][0]=resu[0];opera[0][10]=resu[10];opera[0][11]=p-1;
- while(opera[0][11]>=opera[0][10]&&opera[0][opera[0][11]]==0)
- opera[0][11]--;
- return 1;
- }
- /****************************************************************************************
- 功能: 加法運(yùn)算
- 描述: 以小數(shù)點(diǎn)位中心兩邊相加
- 參數(shù): i , j , opera[i][j],p,q,r
- 返回值:1(成功),0(結(jié)果位0),-1(溢出)
- /****************************************************************************************/
- char adder()
- {
- uchar p,q,r;
- if(opera[0][11]==0&&opera[1][11]==0) return 0;
- else if(opera[0][11]==0)
- {for(q=0;q<12;q++) opera[0][q]=opera[1][q];return 1;}
- else if(opera[1][11]==0) return 1;
- else
- {
- p=opera[0][10]-1;
- q=opera[1][10]-1;
- p>q?(r=p):(r=q);
- resu[10]=r+1; // 小數(shù)點(diǎn)位保存
- resu[0]=opera[0][0]; // 保存符號(hào)位
- while(r>0) // 將小數(shù)點(diǎn)前的數(shù)相應(yīng)相加后放到結(jié)果中
- {
- if(p>0&&q>0){resu[r]=opera[0][p]+opera[1][q];p--;q--;}
- else if(p>0&&q==0){resu[r]=opera[0][p];p--;}
- else {resu[r]=opera[1][q];q--;}
- r--;
- }
- r=resu[10];
- p=opera[0][10];
- q=opera[1][10];
- while(r<10) // 將小數(shù)點(diǎn)后的數(shù)放到結(jié)果中
- {
- if(p>opera[0][11]&&q>opera[1][11]) break;
- else if(p<=opera[0][11]&&q<=opera[1][11])
- {resu[r]=opera[0][p]+opera[1][q];p++;q++;}
- else if(p<=opera[0][11]&&q>opera[1][11])
- {resu[r]=opera[0][p];p++;}
- else {resu[r]=opera[1][q];q++;}
- r++;
- }
- r--;
- resu[11]=r;
- p=0;
- while(r>0) // 由右到左將大于9的數(shù)進(jìn)位
- {
- resu[r]+=p; // p為進(jìn)位標(biāo)記
- p=0;
- if(resu[r]>9) {resu[r]-=10;p=1;}
- r--;
- }
- if(p==1) // 溢出移位
- {
- if(resu[10]==10) return -1;
- else {
- for(r=9;r>1;r--) resu[r]=resu[r-1];
- resu[1]=1;resu[10]++;}
- }
- removal_data(0,1);
- r=0;
- while(r<12){opera[0][r]=resu[r];r++;}
- while(opera[0][11]>=opera[0][10]&&opera[0][opera[0][11]]==0)
- opera[0][11]--;
- return 1;
- }
- }
- /****************************************************************************************
- 功能: 減法運(yùn)算
- 描述: 先比較兩操作數(shù)的大小用one ,two互換
- 參數(shù): i , j , opera[i][j],p,q,r,one,two
- 返回值:1(成功),0(結(jié)果位0),-1(溢出)
- /****************************************************************************************/
- char subtraction()
- {
- uchar p,q,r,one,two;
- if(opera[0][11]==0&&opera[1][11]==0) return 0;
- else if(opera[0][11]==0)
- {
- for(q=1;q<12;q++)
- opera[0][q]=opera[1][q];
- opera[0][0]=!opera[0][0];return 1;
- }
- else if(opera[1][11]==0) return 1;
- else
- { // 比較大小(大放到one)
- if(opera[0][10]>opera[1][10]){one=0;two=1;}
- else if(opera[1][10]>opera[0][10]) {one=1;two=0;}
- else
- {
- r=1;
- while(r<10&&opera[0][r]==opera[1][r]) r++;
- if(r==10) {removal_data(0,1);return 0;}
- opera[0][r]>opera[1][r]?(one=0,two=1):(one=1,two=0);
- }
- p=opera[one][10]-1;
- q=opera[two][10]-1;
- r=p; // 保存小數(shù)點(diǎn)前的數(shù)
- resu[10]=r+1; // 保存小數(shù)點(diǎn)位
- resu[0]=0; // 用作借位標(biāo)記
- while(r>0) // 小數(shù)點(diǎn)前相減
- {
- if(p>0&&q>0)
- {
- opera[two][q]+=resu[0];
- resu[0]=0;
- if(opera[one][p]>=opera[two][q])
- resu[r]=opera[one][p]-opera[two][q];
- else
- {
- resu[0]=1;
- resu[r]=10+opera[one][p]-opera[two][q];
- }
- p--;q--;
- }
- else
- {
- if(opera[one][p]<resu[0])
- {resu[r]=10+opera[one][p]-resu[0];}
- else
- {resu[r]=opera[one][p]-resu[0];resu[0]=0;p--;}
- }
- r--;
- }
- r=resu[10];
- p=opera[one][10];
- q=opera[two][10];
- while(r<10) // 將小數(shù)點(diǎn)后的數(shù)放到結(jié)果中
- {
- if(p>opera[one][11]&&q>opera[two][11]) break;
- else if(p<=opera[one][11]&&q<=opera[two][11])
- {
- if(opera[one][p]>=opera[two][q]) resu[r]=opera[one][p]-opera[two][q];
- else
- {
- resu[r]=10+opera[one][p]-opera[two][q];
- resu[0]=r;
- for(r-=1;r>0;r--) // 向前借位
- {
- if(resu[r]==0) resu[r]=9;
- else{resu[r]-=1;break;}
- }
- r=resu[0];
- }
- p++;q++;
- }
- else if(p<=opera[one][11]&&q>opera[two][11])
- {resu[r]=opera[one][p];p++;}
- else
- {
- resu[r]=10-opera[two][q];
- resu[0]=r;
- for(r-=1;r>0;r--)
- {
- if(resu[r]==0) resu[r]=9;
- else{ resu[r]-=1;break;}
- }
- r=resu[0];
- q++;
- }
- if(r==9) // 結(jié)果溢出移位
- {
- if(resu[1]==0&&resu[10]!=2)
- {
- for(r=1;r<9;r++) resu[r]=resu[r+1];
- resu[10]--;resu[9]=0;r=8;
- }
- }
- r++;
- }
- r--;
- resu[11]=r;
- if(one==0)resu[0]=opera[0][0]; // 符號(hào)位寫入
- else resu[0]=!opera[0][0];
- removal_data(0,1);
- r=1;
- while(resu[r]==0&&resu[10]!=(r+1)) r++; // 去除前端0
- resu[10]=resu[10]-r+1; // 重新寫入小數(shù)點(diǎn)
- p=1;
- while(r<=resu[11]){opera[0][p]=resu[r];r++;p++;}
- opera[0][0]=resu[0];opera[0][10]=resu[10];opera[0][11]=p-1;
- while(opera[0][11]>=opera[0][10]&&opera[0][opera[0][11]]==0) opera[0][11]--;
- return 1;
- }
- }
- /****************************************************************************************
- 功能: 計(jì)算器主函數(shù)
- 描述: 根據(jù)符號(hào)位,運(yùn)算符調(diào)用函數(shù)
- 參數(shù): state,save
- 返回值:無
- ****************************************************************************************/
- void calculator(void)
- {
- char data state;
- uchar data save;
- save1=0;
- dis_title_e();
- display_cnasc(0x82,3,tool_menu[0]);
- display_cnasc(0x96,2,"等于");
- display_cnasc(0x8e,2,"刪除");
- display_cnasc(0x9e,2,"退出");
- removal_data(2,0); // 0為清除顯示
- removal_data(0,0);
- i=0;j=1;
- while(1)
- {
- cal_run=0;
- state=input_data();
- if(state==1) // 根據(jù)opera[1][0]的數(shù)值調(diào)用程序
- {
- if(opera[1][0]==12&&opera[0][0]==0||opera[1][0]==13&&opera[0][0]==1)
- state=adder();
- else if(opera[1][0]==12&&opera[0][0]==1||opera[1][0]==13&&opera[0][0]==0)
- state=subtraction();
- else if(opera[1][0]==14) state=multiplication();
- else state=divider();
- }
- if(state==0) return;
- i=0;j=1;
- cal_run=1;
- switch(state)
- {
- case -1: // 結(jié)果溢出
- removal_data(2,0);
- removal_data(0,0);
- display_cnasc(0x8a,3,"溢出!!");
- save1=0;
- break;
- case 0: // 結(jié)果為零
- if(save1==0)
- {
- removal_data(2,1);
- removal_data(0,1);
- display_cnasc(0x98,1,"= ");
- display_cnasc(0x9d,1," 0");
- }
- break; // 結(jié)果顯示
- case 1:
- if(save1==0)
- {
- cal_run=1;
- display_cnasc(0x98,1,"= ");
- dis_cdata(0x98);
- }
- break;
- }
- if(save1==0) save=gotkey(); // save1記錄連續(xù)計(jì)算符
- cal_run=0;
- if((save>11&&save<16&&state==1)||save1!=0)
- {
- removal_data(2,0);
- removal_data(1,0);
- display_cnasc(0x90,6," ");
- if(opera[0][11]==0) display_cnasc(0x95,1," 0");
- else dis_cdata(0x90);
- if(save1!=0)save=save1;
- save1=0;
- display_cnasc(0x88,1,tool_cal[save-12]);
- opera[1][0]=save;
- i=1;j=1;
- }
- else if(save>=0&&save<10&&state==1)
- {
- removal_data(2,0);
- removal_data(0,0);
- opera[0][1]=save;
- opera[0][11]++;
- dis_cdata(0x90);
- i=0;j=2;
- }
- else if(save==10)
- {
- removal_data(2,0);
- removal_data(0,0);
- opera[i][10]=2;
- opera[i][11]=1;
- j=2;
- }
- else
- {
- removal_data(2,0);
- removal_data(0,0);
- }
- }
- }
-
- /*=====================================================================================
- 函數(shù)名稱:溫度功能
- 功能描述:連續(xù)檢查溫度
- 全局變量:temprun oth_run als_temp adju_si
- 參數(shù)說明:見函數(shù)
- 返回說明:無
- 設(shè) 計(jì) 人:LIJH
- 版 本:1.0
- 說 明:
- ======================================================================================*/
- /*溫度顯示*/
- uchar temp_func_dis(void)
- {
- uchar save[2],k;
- clear_dis();
- dis_title_e();
- display_cnasc(0x82,3,"溫度計(jì)");
- display_cnasc(0x98,3,"設(shè)定");
- display_cnasc(0x9e,3,"退出");
- display_cnasc(0x8e,1," \x1f");
- num2_asc_dis(10,0x85);
- temprun=1;
- while(1)
- {
- if(ds18b20)
- {
- if(temp.t_data[0]>99) // 溫度值大于99時(shí)
- {
- save[0]=temp.t_data[0]/100;
- save[1]=(temp.t_data[0]/10)%10;
- num2_asc_dis(save[0],0x80);
- num2_asc_dis(save[1],0x81);
- save[0]=char_num[temp.t_data[0]%10];
- num2_asc_dis(save[0],0x82);
- }
- else // 溫度小于100
- {
- con_disp(0x00,0x00,0x80,0x90,1,16);
- con_disp(0x00,0x00,0x88,0x90,1,16);
- if(temp_pn) con_disp(0x3f,0xfc,0x80,0x9d,1,3);
- else con_disp(0x00,0x00,0x80,0x9d,1,3);
- save[0]=temp.t_data[0]/10;
- save[1]=temp.t_data[0]%10;
- num2_asc_dis(save[0],0x81);
- num2_asc_dis(save[1],0x82);
- }
- save[0]='.';
- save[1]=char_num[temp.t_data[1]/10];
- display_cnasc(0x8b,1,save);
- save[0]=char_num[temp.t_data[1]%10];
- if(save[0]=='1') save[1]='2'; // 補(bǔ)償精度
- else if(save[0]=='7') save[1]='5';
- else if(save[0]=='8'||save[0]=='1') save[1]='7';
- else save[1]='0';
- display_cnasc(0x8c,1,save);
- }
- else
- {
- clear_dis();
- display_cnasc(0x92,4,"沒有發(fā)現(xiàn)");
- display_cnasc(0x8c,4,"溫感器!");
- delay_pw();
- temprun=0;
- return 0;
- }
- k=gotkey();
- if(k==2) // 進(jìn)入設(shè)置菜單
- {
- display_cnasc(0x8e,1," \x04");
- delay(35000);
- display_cnasc(0x8e,1," \x1e");
- display_cnasc(0x9a,4,"\x11 (ok) \x10");
- return 1;
- }
- }
- }
- /*警報(bào)溫度設(shè)置*/
- uchar temp_func_set(void)
- {
- uchar save[2];
- temprun=0;
- oth_run=0;
- rds1302_data();
- while(1)
- {
- if(oth_run)
- {
- con_disp (0x00,0x00,0x88,0x90,2,16);
- con_disp (0xff,0xff,0x8e,0x90,2,16);
- }
- else
- {
- con_disp (0xff,0xff,0x88,0x90,2,16);
- con_disp (0x00,0x00,0x8e,0x90,2,16);
- }
- save[0]=gotkey();
- if(save[0]==1||save[0]==3) oth_run=!oth_run;
- if(save[0]==5) return 1;
- if(save[0]==11)
- {
- if(oth_run) return 0;
- else
- {
- clear_dis();
- dis_title_e();
- save[1]=save[0]=0;
- oth_run=0;
- dis_title_e();
- display_cnasc(0x82,3,"設(shè) 定");
- display_cnasc(0x90,5,"警報(bào)溫度:");
- display_cnasc(0x88,7,"高于【 】℃");
- display_cnasc(0x98,8,"低于【 】℃ \x10");
- while(1)
- {
- if(save[1]==2) con_disp(0x00,0x00,index_temp_set[save[1]].lnum,index_temp_set[save[1]].rnum,2,13);
- else con_disp(0x00,0x00,index_temp_set[save[1]].lnum,index_temp_set[save[1]].rnum,2,13);
- if(save[0]==2) con_disp(0x0f,0xff,index_temp_set[save[0]].lnum,index_temp_set[save[0]].rnum,1,13);
- else con_disp(0xff,0xff,index_temp_set[save[0]].lnum,index_temp_set[save[0]].rnum,2,13);
- save[1]=save[0];
- adju_si=0;
- oth_run=0;
- while(1)
- {
- for(i=0;i<2;i++)
- {
- j=0x8b+i*16;
- if(als_temp[i]==255) display_cnasc(j,2," off"); // 255值為關(guān)閉值
- else
- {
- save1=save[1];
- if(als_temp[i]>127) // 當(dāng)數(shù)值大于127時(shí)溫度值為負(fù)數(shù)
- {
- display_cnasc(j,1,"- ");
- save[0]=char_num[(als_temp[i]-128)/10];
- save[1]=char_num[(als_temp[i]-128)%10];
- display_cnasc(j+1,1,save);
- }
- else
- {
- save[0]=' ';
- save[1]=char_num[als_temp[i]/100];
- if(save[1]=='0') save[1]=' ';
- display_cnasc(j,1,save);
- save[0]=char_num[als_temp[i]/10%10];
- save[1]=char_num[als_temp[i]%10];
- display_cnasc(j+1,1,save);
- }
- save[1]=save1;
- }
- }
- save[0]=gotkey();
- do // 輸入符號(hào)等待數(shù)值輸入或下一位
- {
- if(save[0]==13){ oth_run=1;display_cnasc(0x8b+save[1]*16,2,"- ");}
- else if(save[0]==12){ oth_run=0;display_cnasc(0x8b+save[1]*16,2," ");}
- else break;
- save[0]=gotkey();
- if(save[0]>=0&&save[0]<10||save[0]==11) break;
- }while(1);
- if(save[0]==14){ als_temp[save[1]]=255;} // 乘號(hào)直接將警報(bào)溫度關(guān)閉
- if(save[0]>=0&&save[0]<10&&save[1]<2)
- {
- if(adju_si)
- {
- adju_si=0;
- if(oth_run) als_temp[save[1]]&=0x7f; // 消去符號(hào)位
- if(als_temp[save[1]]>24&&!oth_run) als_temp[save[1]]=240;
- else als_temp[save[1]]=als_temp[save[1]]*10+save[0];
- if(oth_run&&als_temp[save[1]]>50) als_temp[save[1]]=50;
- if(!oth_run&&als_temp[save[1]]>120) als_temp[save[1]]=120;
- if(!oth_run&&als_temp[save[1]]<100) adju_si=1; // 根據(jù)數(shù)值打開連寫
- if(oth_run&&als_temp[save[1]]<10) adju_si=1;
- }
- else
- {
- als_temp[save[1]]=save[0];
- adju_si=1;
- }
- if(oth_run) als_temp[save[1]]=als_temp[save[1]]|0x80; // 寫入符號(hào)
- else als_temp[save[1]]=als_temp[save[1]]&0x7f;
- }
- if(save[0]==11)
- {
- if(als_temp[1]!=255&&als_temp[0]!=255) // 上下限溫度調(diào)整
- {
- if(save[1]==0&&als_temp[0]<als_temp[1]){als_temp[0]=als_temp[1];}
- if(save[1]==1&&als_temp[1]>als_temp[0]){als_temp[1]=als_temp[0];}
- }
- save[0]=save[1]+1;adju_si=0;break;}
- if(save[0]==10&&save[1]!=0) {save[0]=save[1]-1;adju_si=0;break;}
- }
- oth_run=0;
- if(save[0]==3&&save[1]==2) break;
- }
- save_y_or_n();
- if(oth_run)
- {
- wds1302_data(d02_temp,als_temp[0]);
- wds1302_data(d02_temp+2,als_temp[1]);
- }
- return 1;
- }
- }
- }
- }
-
-
- /*溫度計(jì)主函數(shù)*/
- void temp_func(void)
- {
- uchar t;
- while(1)
- {
- oth_run=1;
- t=temp_func_dis();
- if(t==1)
- {
- t=temp_func_set();
- if(t==0) return;
- }
- else return;
- }
- }
- /*=====================================================================================
- 函數(shù)名稱:鬧鈴功能
- 功能描述:設(shè)定鬧鈴
- 全局變量:alarm_time adju_si
- 參數(shù)說明:見函數(shù)
- 返回說明:無
- 設(shè) 計(jì) 人:LIJH
- 版 本:1.0
- 說 明:
- ======================================================================================*/
- void alarm_func(void)
- {
- uchar save[2],a,d;
- clear_dis();
- dis_title_e();
- display_cnasc(0x82,3,"鬧 鐘");
- display_cnasc(0x91,6,"狀態(tài):\x11 \x10");
- display_cnasc(0x89,3,"鬧鈴:");
- display_cnasc(0x9f,1,"→");
- display_cnasc(0x90,1,"『");
- display_cnasc(0x8f,1,"』");
- adju_si=0;
- a=0;d=0;
- save[0]=char_num[alarm_time[0]>>4];
- save[1]=char_num[alarm_time[0]&0x0f];
- display_cnasc(0x8c,1,save);
- display_cnasc(0x8d,1,": ");
- save[0]=char_num[alarm_time[1]>>4];
- save[1]=char_num[alarm_time[1]&0x0f];
- display_cnasc(0x8e,1,save);
- do
- {
- if(a==0)
- {
- display_cnasc(0x95,1,alm_sign[alm]);
- display_cnasc(0x94,1,"\x11 ");
- display_cnasc(0x96,1," \x10");
- con_disp(0x00,0x00,index_alm[d-1].lnum,index_alm[d-1].rnum,1,14);
- }
- if(a>0&&a<4)
- {
- if(d==0)
- {
- display_cnasc(0x94,1," ");
- display_cnasc(0x96,1," ");
- }
- else
- con_disp(0x00,0x00,index_alm[d-1].lnum,index_alm[d-1].rnum,1,14);
- con_disp(0xff,0xff,index_alm[a-1].lnum,index_alm[a-1].rnum,1,14);
- }
- d=a;
- while(1)
- {
- a=gotkey();
- if((a==1||a==3)&&d==0)
- {
- alm=!alm;
- if(a==1) display_cnasc(0x94,1,"\x09 ");
- else display_cnasc(0x96,1," \x09");
- delay(35000);
- if(a==1) display_cnasc(0x94,1,"\x11 ");
- else display_cnasc(0x96,1," \x10");
- display_cnasc(0x95,1,alm_sign[alm]);
- }
- if(d>0&&d<3&&a>=0&&a<10)
- {
- if(adju_si)
- {
- alarm_time[d-1]<<=4;alarm_time[d-1]+=a;
- if(d==1&&alarm_time[0]>0x23) alarm_time[0]=a;
- else if(d==2&&alarm_time[1]>0x59) alarm_time[1]=a;
- else adju_si=0;
- }
- else
- {
- alarm_time[d-1]=a;adju_si=1;
- }
- save[0]=char_num[alarm_time[d-1]>>4];
- save[1]=char_num[alarm_time[d-1]&0x0f];
- display_cnasc(0x8c+(d-1)*2,1,save);
- }
- if(a==11){a=d+1;break;}
- if(a==10&&d!=0){a=d-1;break;}
- }
- adju_si=0;
- if(a==4)
- {
- save_y_or_n();
- wds1302_data(d02_signs,signs);
- wds1302_data(d02_alm,alarm_time[0]);
- wds1302_data(d02_alm+2,alarm_time[1]);
- return;
- }
- }while(1);
- }
- /*=====================================================================================
- 函數(shù)名稱:籃球器功能
- 功能描述:分?jǐn)?shù) 時(shí)間 24秒
- 全局變量:resu opera
- 參數(shù)說明:見函數(shù)
- 返回說明:無
- 設(shè) 計(jì) 人:LIJH
- 版 本:1.0
- 說 明:
- ======================================================================================*/
- /*比賽設(shè)置*/
- void nba_set(void)
- {
- uchar nba,save1,key,save[2];
- clear_dis();
- dis_title_e();
- if(resu[7]==1) display_cnasc(0x82,3,"加 時(shí)");
- else
- {
- display_cnasc(0x82,3,"設(shè) 定");
- opera[0][0]=0;
- opera[1][0]=1;
- }
- resu[6]=0; // 賦初值
- resu[0]=1;
- resu[1]=4;
- resu[2]=12;
- resu[3]=0;
- resu[4]=24;
- display_cnasc(0x90,7,"隊(duì)1:紅 隊(duì)2:白");
- display_cnasc(0x88,7,"24秒:Y 節(jié)數(shù):4");
- display_cnasc(0x98,8,"每節(jié)時(shí)間: 12分鐘");
- save1=0;nba=0;
- while(1)
- {
- if(save1==4) display_cnasc(0x9c,1,":");
- else display_cnasc(index_nba[save1],1," ");
- if(nba==4) display_cnasc(0x9c,1,":\x10");
- else display_cnasc(index_nba[nba],1,"\x11 ");
- save1=nba;
- key=gotkey();
- if(key==1||key==3)
- {
- switch(nba) // 導(dǎo)航更改數(shù)據(jù)
- {
- case 0:
- case 1:
- if(key==1){if(opera[nba][0]>0) opera[nba][0]--;
- else opera[nba][0]=7;}
- if(key==3){if(opera[nba][0]<7) opera[nba][0]++;
- else opera[nba][0]=0;}
- display_cnasc(index_nba[nba]-1,1,nba_oppo[opera[nba][0]]);
- break;
- case 2:
- if(resu[0]>0) resu[0]=0;
- else resu[0]=1;
- if(resu[0]>0) display_cnasc(0x8a,1,":Y");
- else display_cnasc(0x8a,1,":N");
- break;
- case 3:
- if(key==1){if(resu[1]>1) resu[1]--;
- else resu[1]=4;}
- if(key==3){if(resu[1]<4) resu[1]++;
- else resu[1]=1;}
- save[0]=':';
- save[1]=char_num[resu[1]];
- display_cnasc(0x8e,1,save);
- break;
- case 4:
- if(key==1){if(resu[2]>0) resu[2]--;
- else resu[2]=60;}
- if(key==3){if(resu[2]<60) resu[2]++;
- else resu[2]=0;}
- save[0]=char_num[resu[2]/10];
- save[1]=char_num[resu[2]%10];
- display_cnasc(0x9d,1,save);
- resu[5]=resu[2];
- break;
- }
- }
- if(key==11)
- {
- nba++; if(nba==5) return;
- }
- if(key==10&&nba!=0) nba--;
- }
- }
- /*界面其他元素*/
- void nba_oth_dis(void)
- {
- uchar save[2];
- if(resu[7]==1) display_cnasc(0x80,5,"加時(shí)時(shí)間:");
- else display_cnasc(0x80,5,"比賽時(shí)間:");
- display_cnasc(0x98,1,nba_oppo[opera[0][0]]);
- display_cnasc(0x9e,1,nba_oppo[opera[1][0]]);
- display_cnasc(0x99,1,"隊(duì)");
- display_cnasc(0x9f,1,"隊(duì)");
- save[0]='0';
- save[1]=char_num[resu[6]+1];
- display_cnasc(0x9b,1,save);
- display_cnasc(0x9c,1,"st");
- con_disp(0xff,0xff,0x83,0x90,2,1); // 畫正方框
- con_disp(0xff,0xff,0x8b,0x8f,2,1);
- con_disp(0x80,0x00,0x83,0x91,1,15);
- con_disp(0x00,0x01,0x84,0x91,1,15);
- con_disp(0x80,0x00,0x8b,0x80,1,15);
- con_disp(0x00,0x01,0x8c,0x80,1,15);
- nba_dis_time();
- if(resu[0]==0) display_cnasc(0x93,2,"\x07--\x07");
- display_cnasc(0x8b,2," S! ");
- }
- /*籃球器主函數(shù)*/
- void nba_timer(void)
- {
- uchar save,key,nba=0;
- als=di0=1;alm=keb=di1=oth_run=0;
- time_init();
- display_cnasc(0x82,3,"籃球器");
- dis_title_e();
- removal_data(0,1);
- while(1) // 使用說明
- {
- display_cnasc(0x90,8,timer_tips[nba]);
- display_cnasc(0x88,8,timer_tips[nba+1]);
- display_cnasc(0x98,8,timer_tips[nba+2]);
- key=gotkey();
- if(key==11)
- {
- nba+=3;
- if(nba>9) break;
- }
- if(key==10)
- {
- if(nba>0) nba-=3 ;
- }
- }
- nn:
- nba_set();
- clear_dis();
- nba_oth_dis();
- nba_tim=1;
- while(1)
- {
- for(save=0x80,nba=0;nba<2;nba++)
- {
- if(opera[nba][1]>99) // 分?jǐn)?shù)顯示
- {
- num2_asc_dis(opera[nba][1]/100,save);
- num2_asc_dis(opera[nba][1]/10%10,save+1);
- num2_asc_dis(opera[nba][1]%10,save+2);
- }
- else
- {
- num2_asc_dis(opera[nba][1]/10,save);
- num2_asc_dis(opera[nba][1]%10,save+1);
- }
- if(opera[1][1]>99) save=0x85;
- else save=0x86;
- }
-
- do
- {
- key=gotkey();
- ss:
- switch(key)
- {
- case 12:
- case 13:
- if(key==12)
- {if(opera[0][1]<250) opera[0][1]++;}
- else
- {if(opera[0][1]>0) opera[0][1]--;}
- save=110;
- break;
- case 14:
- case 15:
- if(key==14)
- {if(opera[1][1]<250) opera[1][1]++;}
- else
- {if(opera[1][1]>0) opera[1][1]--;}
- save=110;
- break;
- case 7:
- TR1=TR0=EA=0;
- if((++resu[3])>59)
- {
- resu[3]=0;
- if((++resu[2])>59)
- {
- resu[3]=0;
- if(++resu[2]>60) resu[2]=0;
- }
- }
- if(resu[4]<24) resu[4]++;
- nba_dis_time();
- break;
- case 8:
- if(resu[0]==1)
- {
- TL1=(time_count&0x00FF);
- TH1=(time_count>>8);
- resu[4]=24; nba_dis_time();
- TR0=TR1=EA=1;
- }
- break;
- case 9:
- if(resu[2]==0&&resu[3]==0)
- {
- resu[2]=resu[5];resu[4]=24;
- if(resu[6]==resu[1])
- { // 判斷比分進(jìn)行加時(shí)賽
- if(opera[0][1]==opera[1][1]){nba_tim=0;resu[7]=1; goto nn;}
- while(gotkey()!=10); // 否則只能退出
- signs=r1302(d02_signs+1);
- nba_tim=0;
- return;
- }
- else nba_oth_dis();
- break;
- }
- if(EA) {TR0=TR1=EA=0;break;}
- if(!EA&resu[4]!=0){ EA=TR0=1;if(resu[0]==1) TR1=1;}
- break;
- case 10:
- case 11:
- if(!EA) // 暫停狀態(tài)下 ok鍵兩次返回時(shí)鐘界面
- { // ./s 鍵兩次退出
- delay(6000);
- save=gotkey();
- if(save==key)
- {
- if(key==11)
- {
- clear_dis();oth_run=1;
- rds1302_time();
- init_d2=1;
- dis_mode2();
- init_d2=0;
- while(gotkey()!=11);
- oth_run=0;
- save=110;
- clear_dis();
- nba_oth_dis();
- }
- else{ signs=r1302(d02_signs+1); nba_tim=0;return;}
- }
- else{ key=save;goto ss;}
- }
- break;
- }
- if(save==110) break;
- }while(1);
- }
- }
-
- /*=====================================================================================
- 函數(shù)名稱:設(shè)置功能
- 功能描述:系統(tǒng)狀態(tài)設(shè)置
- 全局變量:signs
- 參數(shù)說明:見函數(shù)
- 返回說明:無
- 設(shè) 計(jì) 人:LIJH
- 版 本:1.0
- 說 明:
- ======================================================================================*/
- /*設(shè)置調(diào)整內(nèi)容 參數(shù)格式:選中設(shè)置項(xiàng),設(shè)置項(xiàng)子值*/
- uchar set_dis(uchar menu,uchar sub)
- {
- uchar save;
- con_disp(0xff,0xff,0x8e,0x80,2,16);
- con_disp(0x00,0x00,0x8a,0x80,4,16);
- display_cnasc(0x96,1,"\x1e ");
- display_cnasc(0x9e,1,"\x1f ");
- display_cnasc(0x92,1," ");
- display_cnasc(0x9a,1," ");
- display_cnasc(0x8d,1,"\x11 ");
- display_cnasc(0x8a,1," ");
- while(1)
- {
-
- if(menu<2)
- display_cnasc(0x8e,2,set_bl_dm[menu][sub]);
- else
- display_cnasc(0x8e,2,set_mka[menu-2][sub]);
- save=gotkey();
- if(save==5)
- {
- key_dis(0x96);
- if(sub==0&&menu<2) sub=2;
- else if(sub==0&&menu>1) sub=1;
- else sub--;
- }
- if(save==2)
- {
- key_dis(0x9e);
- if(sub==2&&menu<2) sub=0;
- else if(sub==1&&menu>1) sub=0;
- else sub++;
- }
- if(save==1||save==11)
- {
- display_cnasc(0x8d,1,"\x04 ");
- delay(30000);
- con_disp(0x00,0x00,0x8e,0x80,2,16);
- con_disp(0xff,0xff,0x8a,0x80,4,16);
- display_cnasc(0x92,1,"\x1e ");
- display_cnasc(0x9a,1,"\x1f ");
- display_cnasc(0x96,1," ");
- display_cnasc(0x9e,1," ");
- display_cnasc(0x8a,1,"【");
- display_cnasc(0x8d,3,"】\x10 \x04 ");
- return(sub); // 返回設(shè)置值
- }
- }
- }
- /*設(shè)置調(diào)整*/
- void set_func(void)
- {
- uchar d,key,save;
- display_cnasc(0x81,2,"設(shè)置");
- dis_title();
- display_cnasc(0x88,8,selected[1]);
- con_disp(0xff,0xff,0x8a,0x80,4,16);
- save=d=0;
- do
- {
- display_cnasc(0x93,2,set_menu[index_s[save].lnum]);
- display_cnasc(0x8b,2,set_menu[save]);
- display_cnasc(0x9b,2,set_menu[index_s[save].rnum]);
- d=save;
- while(1)
- {
- key=gotkey();
- if(key==11||key==3){ enter_dis();break;}
- if(key==5){save=index_s[d].lnum;key_dis(0x92); break;}
- if(key==2){save=index_s[d].rnum;key_dis(0x9a); break;}
- if(key==1){ wds1302_data(d02_signs,signs); return;}
- }
- if(key==11||key==3)
- {
- save=0;
- for(key=0;key<2;key++) // 進(jìn)行兩次比較 首次為現(xiàn)時(shí)值 其次為設(shè)定置更改
- {
- switch(d)
- {
- case 0:
- if(key==1)
- {
- bl0=bl1=0;
- if(save==1) bl0=1;
- if(save==2) bl1=1;
- }
- else
- {if(bl0) save=1; if(bl1) save=2;}
- if(bl1) lcd_bl=close;
- else lcd_bl=open;
- break;
- case 1:
- if(key==1)
- {
- di0=di1=0;
- if(save==1) di0=1;
- if(save==2) di1=1;
- }
- else {if(di0) save=1; if(di1) save=2;}
- break;
- case 2:
- if(key==1) meu=(bit)save;
- else {if(meu) save++;}
- break;
- case 3:
- if(key==1) keb=(bit)save;
- else{if(keb) save++;}
- break;
- case 4:
- if(key==1) als=(bit)save;
- else{if(als) save++;}
- break;
- case 5: wds1302_data(d02_signs,signs);
- return;
- }
- if(key==0) save=set_dis(d,save);
- }
- save=d;
- }
- }while(1);
- }
- /*=====================================================================================
- 函數(shù)名稱:保密功能
- 功能描述:系統(tǒng)重設(shè) 密碼鎖 密碼更改
- 全局變量:resu
- 參數(shù)說明:見函數(shù)
- 返回說明:無
- 設(shè) 計(jì) 人:LIJH
- 版 本:1.0
- 說 明:
- ======================================================================================*/
- /*密碼整理*/
- void passwork_finish()
- {
- uchar i;
- for(i=0;i<6;i+=2)
- {
- resu[i]<<=4;
- resu[i]+=resu[i+1];
- }
- }
- /*讀取密碼*/
- uchar input_passwork()
- {
- uchar i,save[2];
- save[0]=' ';
- display_cnasc(0x9d,3,"(./S)\x10");
- for(i=0;i<6;i++)
- {
- while(1)
- {
- resu[i]=gotkey();
- if(resu[i]>=0&&resu[i]<10) break;
- if(resu[i]==10) return 10;
- }
- save[1]=char_num[resu[i]];
- display_cnasc(0x89+i,1,save);
- delay(20000);
- display_cnasc(0x89+i,1," *");
- }
- return 11;
- }
- /*密碼確認(rèn)*/
- void input_second_passwork()
- {
- uchar i,save[2];
- save[0]=' ';
- display_cnasc(0x89,6," ");
- for(i=0;i<6;i++)
- {
- if(resu[i]!=gotkey()) break;
- save[1]=char_num[resu[i]];
- display_cnasc(0x89+i,1,save);
- delay(20000);
- display_cnasc(0x89+i,1," *");
- }
- if(i!=6)
- {
- display_cnasc(0x89,6,"密碼不相同!");
- delay(50000);
- display_cnasc(0x9a,6,"任意鍵 \x10 ");
- while(gotkey()==0xf0);
- return;
- }
- else
- {
- passwork_finish();
- for(i=0;i<6;i+=2)
- wds1302_data(d02_passw+i,resu[i]);
- for(i=0;i<6;i+=2)
- if(resu[i]!=r1302(d02_passw+i+1)) break;
- if(i==6)
- {display_cnasc(0x98,8,"\x10 更改成功!(OK) ");
- while(gotkey()!=11);return;}
- else
- display_cnasc(0x9a,6,"更改失! ");
- }
- delay_pw();
- }
- /*密碼比較*/
- uchar passwork_comp()
- {
- uchar i;
- passwork_finish();
- for(i=0;i<6;i+=2)
- if(resu[i]!=r1302(d02_passw+i+1)) break;
- if(i==6) return 1;
- else
- {
- display_cnasc(0x89,6," 密碼錯(cuò)誤!");
- delay_pw();
- display_cnasc(0x89,6," ");
- return 110;
- }
- }
- /*保密導(dǎo)航*/
- void passw_func(void)
- {
- uchar save,d,key;
- d=0;save=0;
- do
- {
- clear_dis();
- display_cnasc(0x81,2,"保密");
- dis_title();
- display_cnasc(0x88,8,selected[0]);
- con_disp(0xff,0xff,0x8a,0x80,5,16);
- do
- {
- display_cnasc(0x93,3,secrets_menu[index_p[save].lnum]);
- display_cnasc(0x8b,3,secrets_menu[save]);
- display_cnasc(0x9b,3,secrets_menu[index_p[save].rnum]);
- d=save;
- while(1)
- {
- key=gotkey();
- if(key==11||key==3){enter_dis();break;}
- if(key==2){save=index_p[d].rnum; key_dis(0x9a);break;}
- if(key==5){save=index_p[d].lnum; key_dis(0x92);break;}
- if(key==1){return;}
- }
- if(key==11||key==3)
- {
- if(d==3) return;
- clear_dis();
- dis_title_e();
- switch(d)
- {
- case 0:
- display_cnasc(0x82,3,"密碼鎖");
- display_cnasc(0x90,5,"輸入密碼:");
- while(1)
- {
- key=input_passwork();
- if(key==10) break;
- key=passwork_comp();
- if(key==1)
- {
- display_cnasc(0x90,8,"處開啟狀態(tài),按鍵");
- display_cnasc(0x88,8,"□1-常開□2-關(guān)閉");
- display_cnasc(0x98,8,"■自動(dòng)延時(shí)30秒 ");
- pw_oc=open;
- save1=i=0;
- lock_op=1; // 開啟標(biāo)記等待延時(shí)
- while(1)
- {
- key=gotkey(); // 返回255為延時(shí)時(shí)間到達(dá)
- if(key==255){ lock_op=0;pw_oc=close;break;}
- if(key==1)
- {
- display_cnasc(0x88,1,"■");
- display_cnasc(0x98,1,"□");
- lock_op=0;
- }
- if(key==2)
- {
- display_cnasc(0x88,1,"□");
- display_cnasc(0x98,1,"□");
- display_cnasc(0x8c,1,"■");
- delay(60000);
- clear_dis();
- dis_title_e();
- display_cnasc(0x82,3,"密碼鎖");
- display_cnasc(0x90,5,"密碼鎖將在");
- display_cnasc(0x8a,6," 5秒后關(guān)閉:");
- for(save=0;save<5;save++)
- {
- display_cnasc(0x99+save,1,"→");
- delay_pw();
- }
- display_cnasc(0x9e,1,"√");
- pw_oc=open;
- delay(30000);
- pw_oc=close;
- lock_op=0;
- break;
- }
- }
- break;
- }
- }
- break;
- case 1:
- display_cnasc(0x82,3,"更 改");
- display_cnasc(0x90,6,"輸入舊密碼:");
- while(1)
- {
- key=input_passwork();
- if(key==10) break;
- key=passwork_comp();
- if(key==1)
- {
- display_cnasc(0x92,1,"新");
- display_cnasc(0x89,6," ");
- key=input_passwork();
- if(key==10) break;
- display_cnasc(0x90,6,"確認(rèn)密碼: ");
- input_second_passwork();
- break;
- }
- }
- break;
- case 2:
- display_cnasc(0x82,3,"初始化");
- display_cnasc(0x91,6,"是否初始化? ");
- display_cnasc(0x89,6,"Y(OK)\\N(./S)");
- while(1)
- {
- key=gotkey();
- if(key==11)
- {
- clear_dis();
- dis_title_e();
- display_cnasc(0x82,3,"初始化");
- display_cnasc(0x90,5,"輸入密碼:");
- do
- {
- key=input_passwork();
- if(key==10) break;
- key=passwork_comp();
- if(key==1)
- {
- display_cnasc(0x90,5,"密碼正確!");
- display_cnasc(0x89,7,"\x10 初始化中... ");
- init_ds1302();
- rds1302_data();
- delay_pw();
- display_cnasc(0x9a,6,"\x10 完成!(OK)");
- while(gotkey()!=11);
- key=10;
- break;
- }
- }while(1);
- }
- if(key==10) break;
- }
- break;
- }
- key=99;save=d;
- }
- if(key==99) break;
- }while(1);
- }while(1);
- }
- /*=====================================================================================
- 函數(shù)名稱:版本信息
- 功能描述:
- 全局變量:
- 參數(shù)說明:見函數(shù)
- 返回說明:無
- 設(shè) 計(jì) 人:LIJH
- 版 本:1.0
- 說 明:
- ======================================================================================*/
- void version_func(void)
- {
- uchar save,v=0;
- display_cnasc(0x82,3,"版 本");
- dis_title_e();
- do
- {
- display_cnasc(0x90,7,version[v]);
- display_cnasc(0x88,7,version[v+1]);
- display_cnasc(0x98,7,version[v+2]);
- if(v!=0) display_cnasc(0x97,1," \x1e");
- else if(v==0)
- display_cnasc(0x97,1,"院");
- else display_cnasc(0x97,1," ");
- if(v!=7) display_cnasc(0x9f,1," \x1f");
- else display_cnasc(0x9f,1," ");
- save=gotkey();
- if(save==2&&v<7)
- {
- display_cnasc(0x9f,1," \x04");
- delay(30000);
- v++;
- }
- if(save==5&&v>0)
- {
- display_cnasc(0x97,1," \x04");
- delay(30000);
- v--;
- }
- if(save==1) return;
- if((save==11||save==3)&&v==7)
- {
- display_cnasc(0x9e,2,") \x09 ");
- delay(30000);
- return;
- }
- }while(1);
- }
- /*=====================================================================================
- 函數(shù)名稱:系統(tǒng)主函數(shù)
- 功能描述:
- 全局變量:
- 參數(shù)說明:見函數(shù)
- 返回說明:無
- 設(shè) 計(jì) 人:LIJH
- 版 本:1.0
- 說 明:
- ======================================================================================*/
- main()
- {
- uchar key;
- init_lcd(); // 初始化lcd
- lcd_bl=als_tl=als_th=buzzer=pw_oc=close;
- key=r1302(d02_initsi+1); // 讀出1302初始化標(biāo)記位
- if(bl1) lcd_bl=close;
- else lcd_bl=open;
- display_cnasc(0x92,4,"歡迎使用"); // 顯示開機(jī)畫面“歡迎使用”
- display_cnasc(0x9d,3,"—LiJH");
- if(key!=0xb4) init_ds1302(); // DS1302初始化
- rds1302_data(); // 開機(jī)讀回設(shè)置數(shù)據(jù)
- rds1302_date();
- rds1302_time(); // 讀日期時(shí)間
- if(!ds18b20) init_ds18b20(); // 初始化18b20
- if(ds18b20)
- {
- ds18b20_func(); // 讀出溫度
- }
- time_init(); // 定時(shí)器初始化
- delay_pw();resu[11]=0;
- while(1)
- {
- EA=1;
- TR0=1;
- dis_sig=1;
- clear_dis();
- if(di0){init_d2=1;dis_mode2();init_d2=0;}
- else if(di1) dis_mode3();
- else dis_mode1();
- do
- {
- key=gotkey();
- if(key==255) // 鍵盤密碼輸入
- {
- TR0=0;
- dis_sig=0;
- clear_dis();
- dis_title_e();
- display_cnasc(0x82,3,"鍵盤鎖");
- display_cnasc(0x90,5,"輸入密碼:");
- while(1)
- {
- keb=0;
- key=input_passwork();
- if(key==10) {keb=1;resu[11]=2;break;}
- key=passwork_comp();
- if(key==1) {keb=1;resu[11]=0;break;}
- }
- rds1302_date();
- rds1302_time();
- save_time=now;
- break;
- }
- if(key==11)
- {
- dis_menu_key(1);
- delay(35000);
- do
- {
- dis_sig=0;
- TR0=0;
- clear_dis();
- key=dis_menu();
- clear_dis();
- if(key==0) adjust_func();
- else if(key==1) // 調(diào)用相應(yīng)程序功能S
- {
- while(1)
- {
- clear_dis();
- key=tool_func();
- if(key==4) break;
- clear_dis();
- switch(key)
- {
- case 0: calculator();
- break;
- case 1: temp_func();
- break;
- case 2: alarm_func();
- break;
- case 3: nba_timer();
- break;
- }
- }
- }
- else if(key==2) set_func();
- else if(key==3) passw_func();
- else if(key==4) version_func();
- else
- {
- rds1302_date();
- rds1302_time();
- save_time=now;
- resu[11]=0;
- dis_sig=1;
- break;
- }
- }while(1);
- }
- if(dis_sig) break;
- }while(1);
- }
- }
復(fù)制代碼
|