隨著經(jīng)濟(jì)不斷發(fā)展以及人們生活節(jié)奏的不斷加快,人們?cè)絹?lái)越重視身心健康。目前我國(guó)的“亞健康”人群的比重已達(dá)到70%左右,超過(guò)了9億人,而用推拿按摩進(jìn)行保健是我國(guó)中華醫(yī)學(xué)的傳統(tǒng)項(xiàng)目,因?yàn)槔嫌捉砸耍瑧?yīng)用范圍十分廣泛。隨著具有保健功能的各種按摩器等產(chǎn)品出現(xiàn)。也因?yàn)樵谑婢弶毫?,緩解疲勞等方面的效果顯著而備受處于“亞健康”生活狀態(tài)的消費(fèi)者歡迎。巨大的需求與發(fā)展空間一定會(huì)讓各種類(lèi)型的家用按摩機(jī)械發(fā)展勢(shì)頭強(qiáng)勁,成為健康產(chǎn)業(yè)的新的增長(zhǎng)點(diǎn)。在豐厚的利潤(rùn)和發(fā)展空間的吸引下,我國(guó)的不少企業(yè)紛紛涉足按摩器具生產(chǎn)領(lǐng)域。因社會(huì)節(jié)奏和工作壓力的逐漸增大,人民需要放松自己來(lái)緩減工作的壓力和身心疲憊,因此各種人體保健機(jī)械走入大眾家庭。人民在長(zhǎng)時(shí)間的看書(shū)、寫(xiě)字或在電腦前工作時(shí),常常感到頸部肌肉酸痛,嚴(yán)重時(shí)還導(dǎo)致頸部不能轉(zhuǎn)動(dòng),領(lǐng)用戶甚為煩惱和痛苦,因此,頸部按摩器應(yīng)運(yùn)而生。目前,對(duì)于人體的頸部的按摩主要有人為按摩和機(jī)械按摩,人為按摩為人工勞動(dòng),其受人為因素影響較大,按摩質(zhì)量上很難到達(dá)保證,而且需要到制定的服務(wù)場(chǎng)所,且還需要有專業(yè)的人士方可,不能隨時(shí)隨地的按摩,便攜式的頸部按摩儀產(chǎn)品繼而產(chǎn)生。
本設(shè)計(jì)主要針對(duì)長(zhǎng)時(shí)間伏案工作的人,尤其是電腦使用者。頸部按摩器可在工作時(shí)使用,要求安全、輕便、舒適;由于是針對(duì)頸部,因此按摩器工作時(shí)還必須輕柔、舒緩,且不影響使用者低頭工作。
本設(shè)計(jì)主要解決的技術(shù)問(wèn)題是提供一種基于單片機(jī)控制的頸部按摩儀,其結(jié)構(gòu)簡(jiǎn)單,按摩電機(jī)通過(guò)不同信號(hào)實(shí)現(xiàn)不同按摩模式,振動(dòng)電機(jī)根據(jù)供電開(kāi)關(guān)頻率的不同實(shí)現(xiàn)振動(dòng)的不同模式,加熱模塊根據(jù)檢測(cè)的溫度值進(jìn)行升降溫;根據(jù)按鍵輸入的不同模式,控制模塊輸出不同的信號(hào)控制相應(yīng)的電機(jī)實(shí)現(xiàn)不同的按摩模式。
技術(shù)要求:
(1)按摩儀熱敷恒溫最高50℃。
(2)恒溫溫度范圍40~50℃,恒溫溫度控制精度±1℃。
(3)通過(guò)直流電機(jī)實(shí)現(xiàn)推拿、針刺、捶打三種按摩模式。
(4)控制振動(dòng)電機(jī)的頻率實(shí)現(xiàn)高、中、低三擋力度。
熱敷、按摩的時(shí)間分為固定時(shí)長(zhǎng)30min、45min、60min或自己設(shè)置任意時(shí)長(zhǎng)
本設(shè)計(jì)采用模塊化設(shè)計(jì)法,以51單片機(jī)為核心設(shè)計(jì)的一款頸部按摩儀,當(dāng)按摩儀放置在脖頸上時(shí),溫度傳感器將物體的溫度轉(zhuǎn)換成一定函數(shù)關(guān)系的電信號(hào)。該電信號(hào)先通過(guò)前端信號(hào)處理電路,然后經(jīng)過(guò)A/D轉(zhuǎn)換電路轉(zhuǎn)換成數(shù)字信號(hào)送入到主控電路的單片機(jī)中,單片機(jī)通過(guò)掃描鍵盤(pán)和各種功能開(kāi)關(guān),根據(jù)鍵盤(pán)輸入內(nèi)容和各種功能開(kāi)關(guān)的狀態(tài)進(jìn)行判斷、分析和控制,來(lái)完成按摩、加熱以及顯示功能。
其硬件結(jié)構(gòu)主要包括:溫度檢測(cè)模塊、輸入模塊、控制模塊、電源模塊、按摩模塊、加熱模塊和顯示模塊。其中,最小系統(tǒng)部分主要包括STC89C52RC、晶振電路和復(fù)位電路;鍵盤(pán)由4X4位矩陣鍵盤(pán)組成,可以選擇不同的功能、控制按摩力度及按摩時(shí)間;顯示部分由OLED組成。軟件部分由C語(yǔ)言編程,實(shí)現(xiàn)對(duì)各部分的控制。
按摩功能實(shí)現(xiàn):由單片機(jī)發(fā)出三種波形(正弦波、方波、三角波)驅(qū)動(dòng)電機(jī),實(shí)現(xiàn)對(duì)人體的多種按摩模式。
熱敷功能實(shí)現(xiàn):經(jīng)過(guò)三極管控制加熱片,當(dāng)其導(dǎo)通后,電阻絲發(fā)熱。
溫度檢測(cè)功能:由DS18B20傳入數(shù)據(jù)后進(jìn)行分析,得到精確到每一攝氏度的當(dāng)前溫度。
按鍵交互:?jiǎn)纹瑱C(jī)不斷檢測(cè)矩陣鍵盤(pán)的被按下的鍵值,調(diào)整系統(tǒng)的時(shí)間、溫度檔位等。
屏幕顯示:在OLED屏幕上顯示當(dāng)前按摩力度檔位、按摩和熱敷剩余時(shí)間、按摩模式、當(dāng)前溫度。
設(shè)計(jì)一個(gè)頸部按摩儀,即基于單片機(jī)的多功能按摩儀系統(tǒng)。該系統(tǒng)包括直流電機(jī)、振動(dòng)電機(jī)、溫度傳感器、矩陣按鍵、加熱片、OLED屏幕多個(gè)部分。
由DS18B20與矩陣按鍵向單片機(jī)內(nèi)傳入數(shù)據(jù)或觸發(fā)程序中斷,經(jīng)過(guò)內(nèi)部處理后對(duì)直流電機(jī)、振動(dòng)電機(jī)、加熱片和OLED屏幕實(shí)現(xiàn)不同的控制和顯示功能,以完成本次設(shè)計(jì)內(nèi)容。
2.2總流程圖
當(dāng)上電開(kāi)始運(yùn)行時(shí),進(jìn)入模式選擇界面,此時(shí)按鍵被輪流掃描,按下某個(gè)按鍵時(shí),單片機(jī)獲取該按鍵的鍵值進(jìn)行分析,判斷是選擇的哪個(gè)模式,并繼續(xù)按照該模式對(duì)應(yīng)的程序繼續(xù)運(yùn)行。
(1)按摩功能
在按摩模式下,首先會(huì)進(jìn)行按摩方式的選擇,通過(guò)對(duì)不同方式的選擇,單片機(jī)會(huì)發(fā)出對(duì)應(yīng)的正弦波、方波、三角波去驅(qū)動(dòng)電機(jī),來(lái)完成對(duì)脖頸的按摩放松。不同類(lèi)型的波形會(huì)產(chǎn)生針刺、捶打、推拿三種形式的按摩;接著,對(duì)按摩力度的選擇,有高、中、低三檔力度,使用者可根據(jù)自己的喜好來(lái)進(jìn)行選擇。
按摩模式選擇完后會(huì)進(jìn)行時(shí)間的選擇,可以選擇固定的時(shí)長(zhǎng)30min、45min、60min,也可以自己設(shè)置任意時(shí)長(zhǎng),當(dāng)按下開(kāi)始鍵后,進(jìn)入按摩狀態(tài),屏幕實(shí)時(shí)顯示當(dāng)前剩余時(shí)間,直至中途按下停止按鍵或到達(dá)設(shè)定時(shí)長(zhǎng)自動(dòng)停止。
(2)熱敷功能
在熱敷模式下,首先進(jìn)入對(duì)溫度的選擇,初始默認(rèn)是40℃,最高溫度是50℃,用戶可根據(jù)個(gè)人需求使用按鍵對(duì)設(shè)定溫度進(jìn)行調(diào)整;選擇溫度后進(jìn)入時(shí)間的選擇,默認(rèn)可選30/45/60min,也可自由任意設(shè)置時(shí)間,按下開(kāi)始按鍵后,進(jìn)入熱敷狀態(tài),屏幕將會(huì)顯示當(dāng)前剩余時(shí)間與當(dāng)前溫度,中途按下停止鍵或時(shí)間到達(dá)會(huì)自動(dòng)停止運(yùn)行。
在熱敷狀態(tài)中,如果溫度低于設(shè)定的溫度區(qū)間,單片機(jī)將會(huì)控制加熱片開(kāi)始工作,實(shí)現(xiàn)對(duì)按摩儀的審問(wèn),直至滿足要求,以此往復(fù)盡量保持在溫度區(qū)間,實(shí)現(xiàn)動(dòng)態(tài)調(diào)節(jié)保持恒溫。
#include #define uchar unsigned char #define uint unsigned int sbit DQ=P1^3; //數(shù)據(jù)傳輸線接單片機(jī)的相應(yīng)的引腳 unsigned char tempL=0; //設(shè)全局變量 unsigned char tempH=0; unsigned int sdata; //測(cè)量到的溫度的整數(shù)部分 unsigned char xiaoshu1; //小數(shù)第一位 unsigned char xiaoshu2; //小數(shù)第二位 unsigned char xiaoshu; //兩位小數(shù) bit fg=1; //溫度正負(fù)標(biāo)志 sbit wr=P2^0; //數(shù)據(jù)寫(xiě) sbit rd=P2^1; //數(shù)據(jù)讀 sbit ce=P2^2; //片選 sbit cd=P2^3; //指令數(shù)據(jù)通道,1指令,0數(shù)據(jù) sbit rst=P2^4; //復(fù)位信號(hào) sbit LED = P1^0; sbit MOT = P1^1; sbit BEEP = P1^2; sbit KEY1 = P3^0; sbit KEY2 = P3^1; sbit KEY3 = P3^2; sbit KEY4 = P3^3; sbit KEY5 = P3^4; sbit KEY6 = P3^5; sbit KEY7 = P3^6; uchar Set_temp = 45; uchar Set_mode = 1; uchar Set_power = 1; uchar Sec = 0; uchar Min = 20; uchar flag; void delay_18(unsigned char i) { for(i;i>0;i--); } void delay_ms(uint c) //誤差 0us { uchar a,b; for (; c>0; c--) { for (b=199;b>0;b--) { for(a=1;a>0;a--); } } } uchar code HZ0[][32]={ {0x00,0x00,0x7E,0xFE,0x04,0x10,0x08,0x20,0x18,0x7C,0x24,0x44,0x42,0x54,0x81,0x54, 0x00,0x54,0x7E,0x54,0x08,0x54,0x08,0x54,0x08,0x28,0x0E,0x24,0xF0,0x42,0x40,0x82},/*"頸",0*/ {0x10,0x00,0x08,0x3E,0x7F,0xA2,0x00,0x24,0x21,0x24,0x12,0x28,0xFF,0xE4,0x00,0x24, 0x00,0x22,0x3F,0x22,0x21,0x22,0x21,0x34,0x21,0x28,0x3F,0x20,0x21,0x20,0x00,0x20},/*"部",1*/ {0x10,0x40,0x10,0x20,0x10,0x20,0x13,0xFE,0xFA,0x02,0x14,0x44,0x10,0x40,0x1B,0xFE, 0x30,0x88,0xD0,0x88,0x11,0x08,0x10,0xD0,0x10,0x20,0x10,0x50,0x50,0x88,0x23,0x04},/*"按",2*/ {0x00,0x80,0x3F,0xFE,0x24,0x10,0x3F,0x7C,0x26,0x38,0x2D,0x54,0x34,0x12,0x20,0x38, 0x27,0xC0,0x20,0x40,0x27,0xF8,0x20,0x40,0x2F,0xFE,0x40,0x40,0x41,0x40,0x80,0x80},/*"摩",3*/ {0x08,0x80,0x08,0x48,0x0A,0x48,0x12,0x08,0x12,0x08,0x31,0x10,0x31,0x10,0x51,0x10, 0x90,0xA0,0x10,0xA0,0x10,0x40,0x10,0x40,0x10,0xA0,0x11,0x10,0x12,0x08,0x14,0x06},/*"儀",4*/ {0x01,0x00,0x21,0x08,0x11,0x08,0x09,0x10,0x09,0x20,0x01,0x00,0x7F,0xF8,0x00,0x08, 0x00,0x08,0x00,0x08,0x3F,0xF8,0x00,0x08,0x00,0x08,0x00,0x08,0x7F,0xF8,0x00,0x08},/*"當(dāng)",5*/ {0x10,0x10,0x08,0x10,0x08,0x20,0xFF,0xFE,0x00,0x00,0x3E,0x08,0x22,0x48,0x22,0x48, 0x3E,0x48,0x22,0x48,0x22,0x48,0x3E,0x48,0x22,0x08,0x22,0x08,0x2A,0x28,0x24,0x10},/*"前",6*/ {0x10,0x20,0x11,0x24,0x10,0xA4,0x10,0xA4,0xFC,0xA8,0x10,0x20,0x33,0xFC,0x38,0x04, 0x54,0x04,0x50,0x04,0x91,0xFC,0x10,0x04,0x10,0x04,0x10,0x04,0x13,0xFC,0x10,0x04},/*"檔",7*/ {0x08,0x80,0x08,0x40,0x08,0x40,0x10,0x00,0x17,0xFC,0x30,0x00,0x30,0x08,0x52,0x08, 0x92,0x08,0x11,0x10,0x11,0x10,0x11,0x10,0x11,0x20,0x10,0x20,0x1F,0xFE,0x10,0x00},/*"位",8*/ {0x00,0x00,0x23,0xF8,0x12,0x08,0x12,0x08,0x83,0xF8,0x42,0x08,0x42,0x08,0x13,0xF8, 0x10,0x00,0x27,0xFC,0xE4,0xA4,0x24,0xA4,0x24,0xA4,0x24,0xA4,0x2F,0xFE,0x00,0x00},/*"溫",9*/ {0x01,0x00,0x00,0x80,0x3F,0xFE,0x22,0x20,0x22,0x20,0x3F,0xFC,0x22,0x20,0x22,0x20, 0x23,0xE0,0x20,0x00,0x2F,0xF0,0x24,0x10,0x42,0x20,0x41,0xC0,0x86,0x30,0x38,0x0E},/*"度",10*/ {0x11,0x10,0x11,0x10,0x17,0xFC,0x11,0x10,0xFC,0x00,0x13,0xF8,0x32,0x08,0x3B,0xF8, 0x56,0x08,0x53,0xF8,0x90,0x40,0x17,0xFC,0x10,0xA0,0x11,0x10,0x12,0x08,0x14,0x06},/*"模",11*/ {0x00,0x48,0x00,0x44,0x00,0x44,0x00,0x40,0xFF,0xFE,0x00,0x40,0x00,0x40,0x3E,0x40, 0x08,0x40,0x08,0x40,0x08,0x20,0x08,0x22,0x0F,0x12,0x78,0x0A,0x20,0x06,0x00,0x02},/*"式",12*/ {0x00,0x00,0x21,0xF0,0x11,0x10,0x11,0x10,0x01,0x10,0x02,0x0E,0xF4,0x00,0x13,0xF8, 0x11,0x08,0x11,0x10,0x10,0x90,0x14,0xA0,0x18,0x40,0x10,0xA0,0x03,0x18,0x0C,0x06},/*"設(shè)",13*/ {0x02,0x00,0x01,0x00,0x7F,0xFE,0x40,0x02,0x80,0x04,0x00,0x00,0x3F,0xF8,0x01,0x00, 0x01,0x00,0x11,0x00,0x11,0xF8,0x11,0x00,0x11,0x00,0x29,0x00,0x47,0xFE,0x80,0x00},/*"定",14*/ }; uchar code SZ[][16]={ {0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x18,0x00,0x00},/*"0",0*/ {0x00,0x00,0x00,0x08,0x38,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x3E,0x00,0x00},/*"1",1*/ {0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x02,0x04,0x08,0x10,0x20,0x42,0x7E,0x00,0x00},/*"2",2*/ {0x00,0x00,0x00,0x3C,0x42,0x42,0x02,0x04,0x18,0x04,0x02,0x42,0x42,0x3C,0x00,0x00},/*"3",3*/ {0x00,0x00,0x00,0x04,0x0C,0x0C,0x14,0x24,0x24,0x44,0x7F,0x04,0x04,0x1F,0x00,0x00},/*"4",4*/ {0x00,0x00,0x00,0x7E,0x40,0x40,0x40,0x78,0x44,0x02,0x02,0x42,0x44,0x38,0x00,0x00},/*"5",5*/ {0x00,0x00,0x00,0x18,0x24,0x40,0x40,0x5C,0x62,0x42,0x42,0x42,0x22,0x1C,0x00,0x00},/*"6",6*/ {0x00,0x00,0x00,0x7E,0x42,0x04,0x04,0x08,0x08,0x10,0x10,0x10,0x10,0x10,0x00,0x00},/*"7",7*/ {0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x24,0x18,0x24,0x42,0x42,0x42,0x3C,0x00,0x00},/*"8",8*/ {0x00,0x00,0x00,0x38,0x44,0x42,0x42,0x42,0x46,0x3A,0x02,0x02,0x24,0x18,0x00,0x00},/*"9",9*/ {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*" ",10*/ {0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00},/*":",11*/ {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"-",12*/ }; void delay(uint t) //延時(shí)函數(shù) { uint i,j; for(i=0;i1;i++); } uchar read_status() //讀取lcd12864的狀態(tài) { uchar status; P0=0;//端口b置為輸入 rd=0; wr=1; ce=0; cd=1; status=P1; return status; } void check_status()//檢查lcd12864的狀態(tài) { uchar s; P0=0Xff;//端口b置為輸出 while((s&0x80)!=0x80) s=read_status();//等待位1,2置為。命令讀寫(xiě)準(zhǔn)備好。數(shù)據(jù)讀寫(xiě)準(zhǔn)備好 } void write_data(uchar dat)//寫(xiě)數(shù)據(jù) { rd=1; cd=0; ce=0; wr=0; P0=dat; delay(1); wr=1; ce=1; cd=1; } void write_cmd1(uchar cmd)//寫(xiě)數(shù)據(jù)1 { rd=1; cd=1; ce=0; wr=0; P0=cmd; delay(1); wr=1; ce=1; cd=0; } //先送參數(shù),再送指令 void write_cmd2(uchar dat,uchar cmd) { check_status(); write_data(dat); check_status(); write_cmd1(cmd); } void write_cmd3(uchar data1,uchar data2,uchar cmd)//發(fā)送參數(shù)并發(fā)指令再發(fā)送數(shù)據(jù) { check_status(); write_data(data1); check_status(); write_data(data2); check_status(); write_cmd1(cmd); } void init()//LCD12864的初始化 { rst=1; delay(10); rst=0; wr=1; rd=1; ce=1; cd=1; rst=1; check_status(); write_cmd3(0x01,0x00,0x21);//光標(biāo)指針設(shè)置 check_status(); write_cmd3(0x00,0x00,0x42);//圖形區(qū)首地址 check_status(); write_cmd3(16,0x00,0x43);//圖形區(qū)寬度 check_status(); write_cmd1(0x80);//顯示方式設(shè)置,正常顯示 check_status(); write_cmd1(0x98);//圖形方式顯示,不顯示字母,只打點(diǎn) check_status(); write_cmd1(0xa0);//光標(biāo)形狀設(shè)置1 0 1 0 0 N2 N1 N0 } //漢字顯示函數(shù),處在x y處顯示漢字 void display_HZ(uchar x,uchar y,uchar *hz)////x 0-3 y 0-7 { uchar i,j=0; for(i=0;i16;i++) { write_cmd3(((j/2)<4)|(y*2),x,0x24);//地址指針設(shè)置..低地址,高地址,命令 write_cmd2(hz[j++],0xc0); write_cmd2(hz[j++],0xc0); } } void display_SZ(uchar x,uchar y,uchar *hz)////x 0-3 y 0-14 { uchar i,j=0; for(i=0;i16;i++) { write_cmd3(((j)<4)|y,x,0x24);//地址指針設(shè)置..低地址,高地址,命令 write_cmd2(hz[j++],0xc0); } } void CLear_N(uchar num) { uchar i; for(i=0;i15;i++) { display_HZ(num,i,SZ[10]); } } //display_SZ(0,0,SZ[0]); //display_HZ(0,0,HZ0[0]); void Init_DS18B20(void) { unsigned char x=0; DQ=1; //DQ先置高 delay_18(8); //稍延時(shí) DQ=0; //發(fā)送復(fù)位脈沖 delay_18(80); //延時(shí)(?>480us) DQ=1; //拉高數(shù)據(jù)線 delay_18(5); //等待(15~60us) x=DQ; //用X的值來(lái)判斷初始化有沒(méi)有成功,18B20存在的話X=0,否則X=1 delay_18(20); } //讀一個(gè)字節(jié) ReadOneChar(void) //主機(jī)數(shù)據(jù)線先從高拉至低電平1us以上,再使數(shù)據(jù)線升為高電平,從而產(chǎn)生讀信號(hào) { unsigned char i=0; //每個(gè)讀周期最短的持續(xù)時(shí)間為60us,各個(gè)讀周期之間必須有1us以上的高電平恢復(fù)期 unsigned char dat=0; for (i=8;i>0;i--) //一個(gè)字節(jié)有8位 { DQ=1; delay_18(1); DQ=0; dat>>=1; DQ=1; if(DQ) dat|=0x80; delay_18(4); } return(dat); } //寫(xiě)一個(gè)字節(jié) void WriteOneChar(unsigned char dat) { unsigned char i=0; //數(shù)據(jù)線從高電平拉至低電平,產(chǎn)生寫(xiě)起始信號(hào)。15us之內(nèi)將所需寫(xiě)的位送到數(shù)據(jù)線上, for(i=8;i>0;i--) //在15~60us之間對(duì)數(shù)據(jù)線進(jìn)行采樣,如果是高電平就寫(xiě)1,低寫(xiě)0發(fā)生。 { DQ=0; //在開(kāi)始另一個(gè)寫(xiě)周期前必須有1us以上的高電平恢復(fù)期。 DQ=dat&0x01; delay_18(5); DQ=1; dat>>=1; } delay_18(4); } //讀溫度值(低位放tempL;高位放tempH;) void ReadTemperature(void) { Init_DS18B20(); //初始化 WriteOneChar(0xcc); //跳過(guò)讀序列號(hào)的操作 WriteOneChar(0x44); //啟動(dòng)溫度轉(zhuǎn)換 delay_18(125); //轉(zhuǎn)換需要一點(diǎn)時(shí)間,延時(shí) Init_DS18B20(); //初始化 WriteOneChar(0xcc); //跳過(guò)讀序列號(hào)的操作 WriteOneChar(0xbe); //讀溫度寄存器(頭兩個(gè)值分別為溫度的低位和高位) tempL=ReadOneChar(); //讀出溫度的低位LSB tempH=ReadOneChar(); //讀出溫度的高位MSB if(tempH>0x7f) //最高位為1時(shí)溫度是負(fù) { tempL=~tempL; //補(bǔ)碼轉(zhuǎn)換,取反加一 tempH=~tempH+1; fg=0; //讀取溫度為負(fù)時(shí)fg=0 } sdata = tempL/16+tempH*16; //整數(shù)部分 xiaoshu1 = (tempL&0x0f)*10/16; //小數(shù)第一位 xiaoshu2 = (tempL&0x0f)*100/16%10; //小數(shù)第二位 xiaoshu=xiaoshu1*10+xiaoshu2; //小數(shù)兩位 } void KEY_scan() { if(KEY1 == 0) { delay(20); if(KEY1 == 0) { while(KEY1 == 0); Set_temp++; } } if(KEY2 == 0) { delay(20); if(KEY2 == 0) { while(KEY2 == 0); Set_temp--; } } if(KEY3 == 0) { delay(20); if(KEY3 == 0) { while(KEY3 == 0); if(Set_mode != 3) { Set_mode++; }else { Set_mode = 0; } } } if(KEY4 == 0) { delay(20); if(KEY4 == 0) { while(KEY4 == 0); if(Set_power != 3) { Set_power++; }else { Set_power = 0; } } } if(KEY5 == 0) { delay(20); if(KEY5 == 0) { while(KEY5 == 0); if(flag==0) { Min++; } } } if(KEY6 == 0) { delay(20); if(KEY6 == 0) { while(KEY6 == 0); if(flag == 0) { Min--; } } } if(KEY7 == 0) { delay(20); if(KEY7 == 0) { while(KEY7 == 0); if(flag==0) { flag=1; MOT = 1; }else { flag = 0; MOT = 0; LED = 0; Sec = 0; Min = 20; } } } } void main() { TMOD |= 0x01; //開(kāi)啟定時(shí)器0 0x10時(shí)使用定時(shí)器1 0x11時(shí)啟動(dòng)兩個(gè) TH0=0XFC; //給定時(shí)器賦初值,定時(shí)1ms TH1 TL0=0X18; //TL1 EA=1; //總中斷打開(kāi) ET0=1; //定時(shí)器0中斷打開(kāi) ET1 TR0=1; //定時(shí)器0開(kāi)關(guān)打開(kāi) TR1 init(); Init_DS18B20(); display_HZ(0,0,HZ0[0]); display_HZ(0,1,HZ0[1]); display_HZ(0,2,HZ0[2]); display_HZ(0,3,HZ0[3]); display_HZ(1,0,HZ0[5]); display_HZ(1,1,HZ0[6]); display_HZ(1,2,HZ0[9]); display_HZ(1,3,HZ0[10]); display_SZ(1,8,SZ[11]); display_SZ(1,11,SZ[12]); display_HZ(2,0,HZ0[5]); display_HZ(2,1,HZ0[6]); display_HZ(2,2,HZ0[11]); display_HZ(2,3,HZ0[12]); display_SZ(2,8,SZ[11]); display_HZ(3,0,HZ0[5]); display_HZ(3,1,HZ0[6]); display_HZ(3,2,HZ0[7]); display_HZ(3,3,HZ0[8]); display_SZ(3,8,SZ[11]); display_SZ(0,13,SZ[11]); LED = 0; MOT = 0; BEEP = 1; while(1) { delay_ms(10); ReadTemperature(); delay_ms(10); display_SZ(1,9,SZ[sdata/10]); display_SZ(1,10,SZ[sdata%10]); display_SZ(1,12,SZ[Set_temp/10]); display_SZ(1,13,SZ[Set_temp%10]); display_SZ(2,9,SZ[Set_mode]); display_SZ(3,9,SZ[Set_power]); display_SZ(2,9,SZ[Set_mode]); display_SZ(3,9,SZ[Set_power]); display_SZ(0,11,SZ[Min/10]); display_SZ(0,12,SZ[Min%10]); display_SZ(0,14,SZ[Sec/10]); display_SZ(0,15,SZ[Sec%10]); KEY_scan(); if(sdata < Set_temp && flag == 1) { LED = 1; }else if(sdata > Set_temp && flag == 1) { LED = 0; } } } void Timer0() interrupt 1 //參考上圖 定時(shí)器1時(shí)為3 { static uint i; //定義一個(gè)自變形變量 TH0=0XFC; //給定時(shí)器賦初值,定時(shí)1ms TH1 TL0=0X18; //TL1 i++; if(i==1000) { i=0; if(flag == 1) { if(Sec != 0 && Min != 0) { Sec--; }else if(Sec == 0 && Min != 0) { Sec = 59; Min--; }else if(Sec == 0 && Min == 0) { flag = 0; BEEP = 0; MOT = 0; } } } }
-
OLED
+關(guān)注
關(guān)注
119文章
6171瀏覽量
223679 -
Proteus
+關(guān)注
關(guān)注
79文章
1692瀏覽量
106288 -
按摩儀
+關(guān)注
關(guān)注
0文章
11瀏覽量
167
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
評(píng)論