![基于STC89C52單片機的溫濕度傳感器_第1頁](http://file4.renrendoc.com/view11/M03/07/2E/wKhkGWV2ZTyAGIPqAAG2RhLZ4og552.jpg)
![基于STC89C52單片機的溫濕度傳感器_第2頁](http://file4.renrendoc.com/view11/M03/07/2E/wKhkGWV2ZTyAGIPqAAG2RhLZ4og5522.jpg)
![基于STC89C52單片機的溫濕度傳感器_第3頁](http://file4.renrendoc.com/view11/M03/07/2E/wKhkGWV2ZTyAGIPqAAG2RhLZ4og5523.jpg)
![基于STC89C52單片機的溫濕度傳感器_第4頁](http://file4.renrendoc.com/view11/M03/07/2E/wKhkGWV2ZTyAGIPqAAG2RhLZ4og5524.jpg)
![基于STC89C52單片機的溫濕度傳感器_第5頁](http://file4.renrendoc.com/view11/M03/07/2E/wKhkGWV2ZTyAGIPqAAG2RhLZ4og5525.jpg)
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領
文檔簡介
目錄HYPERLINKchapter1Temperatureandhumiditymeasuringprinciple21.1Theschemeselectionoftemperatureandhumiditysensor21.2TheschemeselectionofTemperatureandhumiditydisplay2chapter2Thehardwaredesignofthesystem32.1Theoveralldesignofthesystemhardware32.2Themainschemeselectionanddesignofthecontrolmodule4singlechipSTC89C52introduction6Themaincontrolmodulecircuit72.3TheselectionanddesignOFTheRTCmodulescheme82.4Thedesignofinterfacemodules8chapter3Thedesignofsystemsoftware93.1Systemofthemainprogramandflowchart93.2ThereadoperationflowchartOFDS1302clockchip103.3writeoperationflowchartTheofLCDmodule11chapter4Theexperimentanddebugging124.1Difficultiesandsolutions14chapter5Teamdivisionoflaborandcomments15appendixA:electricschematicdiagram18appendixB:ProgramList19appendixC:externalview32第1章溫濕度測量原理單片機的接口信號是數(shù)字信號。要想用單片機獲取溫濕度這類非電信號的信息,必須將其轉(zhuǎn)換為數(shù)字信號,因為如果電流或電壓輸出是模擬信號,還必須進行A/D轉(zhuǎn)換,以滿足單片機接口的需要。如果是數(shù)字信號就可以直接送往單片機進行數(shù)據(jù)處理。1.1溫濕度傳感器的方案選擇DS18B20+HS1100因為HS1100在網(wǎng)上的資料相當匱乏,以及老師在課程開始前說HS1100輸出為模擬信號,需要加A/D轉(zhuǎn)換。以及,分別采用溫度濕度傳感器的話,占用電路板空間會更大。綜合考慮以上因素,我們認為溫濕度傳感器SHT11/10更好。SHT11/10因為在中發(fā)電子市場,一下子找不到SHT11插針式的傳感器,所以我們選用了精度稍低的SHT10。1.2溫濕度顯示的方案選擇方案一:時鐘的顯示可以用多位七段LED數(shù)碼管顯示,七段LED數(shù)碼管顯示耗能多,而且顯示位數(shù)有限,每增加一位都要在程序設計和硬件設計方面增加很多的工作量,不利于電路的擴展,而且無法顯示年、月、日、星期這些漢字,使得顯示不夠直觀,靈活。但是這種設計方案在顯示位數(shù)比擬少時性價比比擬高,價格廉價,方案二:采用點陣式數(shù)碼管顯示。點陣式數(shù)碼管是由八行八列的發(fā)光二極管組成,對于顯示文字比擬適合,而在本課題設計中的顯示數(shù)字較多字符較少,而且此種方案耗能多,不符合現(xiàn)代的節(jié)能理念,所以不用此種作為顯示。方案三:采用LCD液晶顯示器顯示。而LCD液晶顯示那么耗能少,能夠顯示年、月、日、星期等漢字,在顯示方面更加靈活,而且改變顯示時只要改變軟件設計就可以,不用改變硬件電路的設計,易于電路的功能擴展。電路的軟件設計也很簡單。另外,這種設計硬件更加簡潔。采用LCD液晶顯示方案的缺點是在顯示位數(shù)比擬少時,價格也并不貴。比擬上述兩種方案可以看出方案三耗能少,顯示靈活,易于電路擴展而且不管是軟件設計還是硬件設計都比擬簡單,因此采用第三種設計方案。綜上所述,本設計采用SHT10做溫濕度傳感器,引入DS1302時間模塊的設計方案,顯示使用LCD液晶顯示。其中LCD1602性價比高,自帶字模,選用LCD1602。第2章系統(tǒng)硬件設計根據(jù)溫濕度傳感器的功能要求,基于單片機的設計方案要運用集成SHT10,實現(xiàn)實時數(shù)據(jù)記錄與讀取:〔1〕根本要求具有讀取溫濕度并顯示的功能〔2〕創(chuàng)新要求具高溫報警功能具有日歷功能2.1系統(tǒng)硬件的整體設計主控芯片使用51系列STC89C52單片機,系統(tǒng)由主控制器STC89C52、時鐘芯片DS1302、LCD1602液晶顯示電路LED燈高溫報警電路組成。系統(tǒng)硬件設計框圖:系統(tǒng)硬件設計框圖2.2ThemainschemeselectionanddesignofthecontrolmoduleItwilldefinitelydecreasecomplexityofhardcircuitsifmainfunctionsarerealizedbysoftware.Thuswemadeoursystemamicrocomputer-basedone.Toimplementaskedfunctions,wejustneedasimplefeaturedmicrocomputer.IchosetheSTC89C52toaccomplishthemissioninthelightofitshighcostperformance.2.2.1DescriptionofSTC89C52TheSTC89C52isalow-power,high-performanceCMOS8-bitmicrocomputerwith8KbytesofFlashprogrammableanderasablereadonlymemory(PEROM).ThedeviceismanufacturedusingAtmel’shigh-densitynonvolatilememorytechnologyandiscompatiblewiththeindustry-standard80C51and80C52instructionsetandpinout.Theon-chipFlashallowstheprogrammemorytobereprogrammedin-systemorbyaconventionalnonvolatilememoryprogrammer.Bycombiningaversatile8-bitCPUwithFlashonamonolithicchip,theSTC89C52isapowerfulmicrocomputerwhichprovidesahighly-flexibleandcost-effectivesolutiontomanyembeddedcontrolapplications.PinConfigurationsPDIPSTC89C52PDIPTheAT89C52providesthefollowingstandardfeatures:8KbytesofFlash,256bytesofRAM,32I/Olines,three16-bittimer/counters,asix-vectortwo-levelinterruptarchitecture,afull-duplexserialport,on-chiposcillator,andclockcircuitry.Inaddition,theAT89C52isdesignedwithstaticlogicforoperationdowntozerofrequencyandsupportstwosoftwareselectablepowersavingmodes.TheIdleModestopstheCPUwhileallowingtheRAM,timer/counters,serialport,andinterruptsystemtocontinuefunctioning.ThePower-downmodesavestheRAMcontentsbutfreezestheoscillator,disablingallotherchipfunctionsuntilthenexthardwarereset.ThemaincontrolmodulecircuitTakingthePOportofsinglechipSTC89C52astheinpurport.ConnectingtheP1,theclockofSHT10anddata,takingthetemperatureandhumiditydataacquisitionandconnectingtheDS1302acquisitiontimeinformation;theP0ConnectstheD0~D7pinofLCD1602,TheXTAL1ofsinglechipconnectstheexternalcrystalandOneendofthetrimmercapacitors.Althoughthereisnostrictrequirementsofthevalueofanexternalcapacitor,ThesizeofthecapacitorwillaffectTheoscillatorfrequency、thestabilityofoscillators、therapidityofthevibrationandthestabilityofthetemperature。Therefore,Inthissystemcircuit,Thevalueofcrystaloscillatoris11.0592MHz.Capacitanceshouldasfaraspossiblethechoiceoftheceramiccapacitor.Capacitanceisabout22μF.The9pinisresetinput.Connectingthecapacity,resisterastheresetcircuit.20pinisthegroundterminal,40pinispowerterminal./EApinconnectsthe+5Vvoltage.Fromthis,Theminimumsystemofsingle-chipmicrocomputercontrolmoduleismakedup,asshowninfigure:2.3TheselectionanddesignOFTheRTCmoduleschemeTheDS1302TrickleChargeTimekeepingChipcontainsarealtimeclock/calendarand31bytesofstaticRAM.Itcommunicateswithamicroprocessorviaasimpleserialinterface.Therealtimeclock/calendarprovidesseconds,minutes,hours,day,date,month,andyearinformation.Theendofthemonthdateisautomaticallyadjustedformonthswithlessthan31days,includingcorrectionsforleapyear.Theclockoperatesineitherthe24–houror12–hourformatwithanAM/PMindicator.ComparedwithDS12887,whichdoesn’tneedanyextrabatterybutkindofexpensiveapproaching30RMB,DS1302canbeworkperfectwitha3.6Vbatteryandthesesumuponly5RMB.Accordingtothehighcostperformance,wechooseDS1302tofinishourRTCmodule.ds1302programflowchart2.4ThedesignofinterfacemodulesThedesignschemeusestheLCDliquidcrystaldisplay,becausethedesigndonotneedalotofcontents.WechosethehighperformancecostratioLCD1602。liquidcrystaldisplayLCD1602introductionomitchapter3Thedesignofsystemsoftware3.1SystemofthemainprogramandflowchartThemainfunctionsoftheprogramaretodisplaytemperatureandhumidityinformation.Inthemainprogram,afterthesystemwillautomaticallyreset,theelectricsystemofliquidcrystaldisplayandtheclockchipDS1302initializedandreadandwriteintheinformationsuchastemperatureandhumidity,time,toreadandwritedataafterthedisplayinformation.Themainprogramflowisshowninfigure:Theintroductionofmainprogram,whenrunthemainprogram,toresetthesensorsfirst,thenputtheLCD1602initialization,andthenitwilldisplaytemperatureandhumidityandtime.3.2ThereadoperationflowchartOFDS1302clockchipFirst,InitializingoftheclockchipDS1302,afterjudgingthestatusregister,toreadintheoperationofDS1302,theoperationusingthecharacteristicswhichtheclockcalendaraddresstheadjacent,thenjudgewhetherthedataisfinishedornot.Iffinished,returntothemainprogram;ifnot,continuetoincreasetheaddress,datauntilthereadingisfinished.Asshowninfigure:3.3writeoperationflowchartTheofLCDmoduleTheLCDmodulethiscircuitusesis1602LCDmodule,itcantransposeASCIIanditiseasytooperate.Intheflowchartofdisplay,thereisnocursoronthedisplay.Thedisplayofdateisfromthesecondlineofthefirstcharacter.chapter4TheexperimentanddebuggingThebestwaytoverifythetheoryispractice,sothisdesignusesexperiment,debuggingrealobjecttoverifythefeasibilityoftheabovedesign.Recentdays,althoughalotofdesignsusethesimulationtosimulateresults,therearestillsomegapswiththereality.Andsomepracticalproblemsarenotshowedbythesimulation,sowemetquiteafewproblemswhileconnectingtherealcircuit.Difficultiesandsolutions:1.thepartofsimulationBecausetheversionofprotelistooold,manycomponentsarenotinthecomponentlibrary.Anditisverytroublesometoaddsomethingtothecomponentlibrary.Therefore,wechooseproteustodosimulation.Ofcourse,wemetsomeproblemsintheprocessofsimulation.Forexample,themicrocontrollerweuseisSTC89C52,butthereisonly89C52there.Foranotherexample,weuseLCD1602todisplay,whichisalsonotinthecomponentlibrary.Throughonlineaccess,weknowthatATandSTCmicrocontrollersonlydifferinmanufacturersandburningmethods.AndLCD1602isreplacedbyanothernumberLM016Linthecomponentlibrary.What’smore,LCD1602missestwointerfacesofadjustingLCDbacklightbrightnessinthesimulationdiagram.Throughthechoiceandconnectionofcircuitelement,wehavecompletedthesimulation.Thefollowingcomponentsareusedinthesimulationdiagram:Singlechip——AT89C52,Sensor——SHT10,CLK——DS1302,Resistance——1KΩand10KΩ,ResistersPacks——RESPACK-8,CrystalOscillator——CRYSTAL(32.768Khz),Powersource、Earthingterminal,Sliderheostat、LCDdisplay——LM016L,NPNTransistor——NPN,LEDlight——LED-RED.CommunicationproblemsbetweenLCDdisplayandsinglechipemergedfromthefirsttryofbreadplate.ThisdesignpassedtheProteussimulationsoftwarewithoutanyproblems,thehardwarevalidationcircuitiscompletedbythestudentsresponsiblefortheoryandlapweldingstudentsintheformofmutualsupervision,toensurethatthecircuitisconnectedcompletelyaccordingtothetheory.With5Vvoltagesourceactingaspowersupply,LCDscreenlightsupnormally,displayingarowofsmallblackgrids,thenstopatthisstate.Whenwefirstlyencounteredthiskindofsituation,wefeltitdifficulttounderstand,becauseinthebeginningwegreatlyunderestimatedthedifferencesbetweenthesimulationandreality,throughdataaccess,weknowthiskindofsituationusuallyexiststwopossibilities:TheimproperadjustmentofLCDbacklightcontrastTheabnormalcommunicationofLCDscreenandsinglechipmicrocomputerFirstly,wesawtheLCDlightedinthedark,withdotmatrixclearlydisplayed,soweeliminatedthefirstpossibility.However,westilltrytoadjustthesliderheostatinthe3rdpin,finallydeterminingthatitisnotbacklitcontrastofLCDtoresultinthisproblem.Thesecondsituationmaybemore,thereasonsofabnormalcommunicationofMCUandLCDmaybeaconnectionproblem,orcode,amongthetwocodemayhaveaproblemofshortdelay.BecausetherefreshabilityofLCDscreenisnotconsideredinthesimulation,butinfact,whenthesinglechipmicrocomputerperformswritingoperationstoLCDscreen,itisliketopourabigbarrelofwaterintoasmallmouthbottleofwater,thedataprocessingabilityofsinglechipmicrocomputerismuchbetterthanthereceptivityofLCDscreen,soapropertimedelaymakestheLCDscreentoworknormally.Bylookinguptosomematerials,weaddedsomeappropriatedelay,finallythetimedelaybetweentwocyclesissetto0.8s,butproblemsstillexist.ThenweusethemultimetertomeasurethecommunicationbetweenthesinglechipmicrocomputerandtheD0~D7mouthofLCD1602,findingthatthevoltagevalueofindividualtubesarenotasimagined,soweconsideredthatapoorcontactcausestheproblem,planningtobuildalineoncemore.Theseconddayafterpitchinglineusinganotherpieceofbreadplate,wecanoccasionallyseeflashesofdigitaltemperatureandhumidity,whichletusbefirmthatlapjointonthebreadplateresultedinmanypoorcontacts,sowestartedtoweldthecircuit.3.ProblemsduringformalweldingAfterthefirstformalweldingwascompleted,wefoundthecircuitthatworkedwellinthetestcan'tdisplayproperlyafterrealwelding,butthistimewecanassertdirectlythatisalineproblem,sowereinforcedthesolderjointsforconsolidation,thistimewecanseenormalsteadytemperatureandhumidity.Althoughtherewasaprobleminthedisplayofthetime,everyonewasveryhappy.Thebuzzerdidn'tworkproperlyInthetestofbuzzercircuit,thebuzzerrangaslongasgivenelectricity.Wecheckedwhetherthebuzzertriodewasnormalonebyone,giventherightanswer,weconsulteddataandtheteachertolearnthathighandlowlevelvoltagesofsinglechipmicrocomputer’seachnozzleisnotthesame,undertheteacher'sadvice,wechangedthecommunicationbuzzercircuitof3nozzlewhichwewillnotgenerallyuseto2nozzle,alsomodifiedsomecode.Thenthebuzzerdidn’tring,sodidn’titwhenarrivingatthealarmingtemperature,finallywefoundtheworkingvoltageofthebuzzerweboughtisgreaterthanthepowersupplyvoltageofthecircuit,wealsotookthehigh-temperaturealarminghumanizedproblemintoconsideration,sowechangedthebuzzertoLEDlight,andallworked.DatedisplayisnotcorrectThefinalproblemthatwasnotsolvedofthewholeprocessisthewrongtimedisplay,westilldarenottotellwhattheproblemwas.Ofthetimedisplay,themonthinformationcanbereadanddisplayednormally,butthedaycan’t,whichwasalwaysaccompaniedbysomemessycode.Andeachtimeweresetthemicrocontroller,displayofthedaywouldbedifferent.Thesituationisroughlyshowedasfollows:Afterdoingthecomparisonoftheexistingonlinecalendarprogram,wefoundtheaddresswhilequeryingcalendarchipintheprogramhadnoerrors,andreadanddisplayofmonthisverynormal,alsowiththesimulation.AtstartwethoughtmaybethetwolatticewhichdisplaythedayinformationontheLCDscreenwerebroken,sowechangedthetheirpositions,butstillonlymonthnormallydisplayed.Wereplacedtheclockchiptogetthesameresult.Atlast,wefoundeverythingwouldbeallrightafterjoiningtheinitializationoftimeintheheaderfilesofds1302,thecauseoftheproblemwasthatifds1302wasnotinitialized,thedaywouldbearandomvalueratherthanamorallysystemtime.組員分工及心得體會組員分工及完成情況:我組十一個人,其中電商專業(yè)負責網(wǎng)站設計與制作局部〔3人〕:董笑言郝天琪歐子豪電信工程及管理專業(yè)負責溫濕度傳感器電路局部和外形設計〔8人〕:焊接:商文熙、劉馳、王珂電路設計:周雪、鄒嘉桐、趙舒玄仿真設計:周雪程序設計:石康采購:石康、鄒嘉桐AutoCAD以及外觀設計:郭媛媛
完成情況:除了趙舒玄因赴臺灣交流工程無法完成出勤,其余組員均出勤良好。全組上下齊心協(xié)力,雖然大體分工如上但是每個局部根本都是組員間相互幫助完成的。最終到達老師根本要求溫濕度顯示,完成額外功能高溫報警。其中額外功能日期顯示未完成。心得體會:結(jié)束了緊張的期末考試,我們又迎來了小學期實踐活動。這次小學期需要我們設計,制作一個溫濕度傳感器。從電路設計、電路焊接、材料選購、外觀設計,到網(wǎng)站設計、宣傳出售,全部要我們自己完成。在基于單片機的溫濕度傳感器電路設計過程中,我們學到了很多重要的東西,其中最重要的是如何將實踐和理論相聯(lián)系,怎樣將所學到的知識運用到我以后的工作中去。大學的課堂的學習只是在給我們灌輸專業(yè)知識,而我們應把所學的用到我們現(xiàn)實的生活中去,此次的溫濕度傳感器設計給我奠定了一個實踐根底。本系統(tǒng)的設計應用到了電路分析,模擬電路根底,數(shù)字電路設計,C語言根底等多方面的知識。電路焊接局部聽起來容易,但實際操作起來難度很大。不僅要考慮焊接的牢固程度,還要考慮器件布局,導線連接,焊點大小。最難最麻煩的局部是后期的故障排查,因為在茫茫多的焊點、線路中,任何一個小錯誤都會導致最終電路的工作異常,所以每一個點都要排查,需要極大的耐心。除了耐心,智慧也是必不可少的。有時候,往往多思考一下,改動一個線路的位置,就會大大減少工作量,并且降低電路的錯誤率。因此,電路焊接大大鍛煉了我們的耐心、毅力,而且令我們更深刻的體會到做事要有智慧,有方案,不能頭腦一熱,說做就做。選擇外觀時需要綜合考慮很多因素:如是否好看、是否易實現(xiàn)、是否具有創(chuàng)意、是否利于結(jié)構(gòu)設計等。最后要對外觀進行包裝,確保沒有電路板裸露在外,并加以裝飾。盡量做到外觀美、功能全和易操作的統(tǒng)一。總的來說,這次小學期不得不說是對每一個人的挑戰(zhàn),一切知識都是新的。它考驗的是我們的學習能力,怎么樣快速入門一個自己從未接觸過的知識是需要技巧以及好學的精神的。我們在這次小學期學到的很多,至少每個人都能說出基于單片機的設計是怎樣的工作原理,至少每個人都不會忘了給我們造成無限麻煩的LCD1602是一個2X16液晶屏每個字塊用點陣顯示,至少提到時鐘芯片,晶振大家都會想起這次忙得不可開交的小學期。由于時間比擬倉促,我們只能做到到達現(xiàn)在這樣的水平;其他的希望以后的學習中,能夠再做進一步嘗試。附錄A:電路原理圖附錄B:程序清單main.c/*************端口定義********************P1.0SCK(SHT10) P1.1DATA(SHT10) P0D0~D7(LCD1602)P2.0RS(LCD1602)P2.1RW(LCD1602)P2.2E(LCD1602)*****************************************/#include<reg52.h>#include<intrins.h>#include<stdio.h>#include<string.h>#include<absacc.h>#include<math.h>#include"ds1302.h"#defineucharunsignedchar#defineuintunsignedint//1602液晶端口定義******sbitLcdRs=P2^0;sbitLcdRw=P2^1;sbitLcdEn=P2^2;sbitLED=P2^7;sbitACC0=ACC^0;sbitACC7=ACC^7;ucharstr[7];unsigneddispbuff=0,OldSecond=0; //dispbuff是顯示輸出的臨時變量unsignedintAlarmVal=40; //設置的報警溫度//向LCD寫入命令或數(shù)據(jù)************************************************************#defineLCD_COMMAND 0//Command#defineLCD_DATA 1//Data#defineLCD_CLEAR_SCREEN 0x01//清屏#defineLCD_HOMING 0x02//光標返回原點//設置顯示模式************************************************************#defineLCD_SHOW 0x04//顯示開#defineLCD_HIDE 0x00//顯示關 #defineLCD_CURSOR 0x02 //顯示光標#defineLCD_NO_CURSOR 0x00//無光標 #defineLCD_FLASH 0x01#defineLCD_NO_FLASH 0x00//設置輸入模式************************************************************#defineLCD_AC_UP 0x02#defineLCD_AC_DOWN 0x00//default#defineLCD_MOVE 0x01//畫面可平移#defineLCD_NO_MOVE 0x00//defaultsbitSCK=P1^0;//定義通訊時鐘端口sbitDATA=P1^1;//定義通訊數(shù)據(jù)端口typedefunion{unsignedinti;floatf;}value;enum{TEMP,HUMI};//TEMP=0,HUMI=1#definenoACK0#defineACK1//adrcommandr/w#defineSTATUS_REG_W0x06//00000110#defineSTATUS_REG_R0x07//00000111#defineMEASURE_TEMP0x03//00000011#defineMEASURE_HUMI0x05//00000101#defineRESET0x1e//00011110/****************定義函數(shù)****************/voids_transstart(void);//啟動傳輸函數(shù)voids_connectionreset(void);//連接復位函數(shù)chars_write_byte(unsignedcharvalue);//SHT10寫函數(shù)chars_read_byte(unsignedcharack);//SHT10讀函數(shù)chars_measure(unsignedchar*p_value,unsignedchar*p_checksum,unsignedcharmode);//測量溫濕度函數(shù)voidcalc_dht90(float*p_humidity,float*p_temperature);//溫濕度補償unsignedcharLCD_Wait(void);voidLCD_Write(bitstyle,unsignedcharinput);/***********延時函數(shù)****************/voiddelay(uintz){ uintx,y; for(x=z;x>0;x--) for(y=110;y>0;y--);}/***********LCD寫指令/數(shù)據(jù)****************/voidLCD_Write(bitstyle,unsignedcharinput){ LcdRs=style; //style=0表示寫指令,為1表示寫數(shù)據(jù) P0=input; delay(6); LcdEn=1; delay(6); LcdEn=0; }/***********LCD顯示模式****************/voidLCD_SetDisplay(unsignedcharDisplayMode){ LCD_Write(LCD_COMMAND,0x08|DisplayMode); }/***********LCD輸入模式****************/voidLCD_SetInput(unsignedcharInputMode){ LCD_Write(LCD_COMMAND,0x04|InputMode);}//初始化LCD************************************************************voidLCD_Initial(){ LcdEn=0; LCD_Write(LCD_COMMAND,0x38);//8位數(shù)據(jù)端口,2行顯示,5*7點陣 LCD_Write(LCD_COMMAND,0x38); LCD_SetDisplay(LCD_SHOW|LCD_NO_CURSOR);//開啟顯示,無光標 LCD_Write(LCD_COMMAND,LCD_CLEAR_SCREEN);//清屏 LCD_SetInput(LCD_AC_UP|LCD_NO_MOVE);//AC遞增,畫面不動}//液晶字符輸入的位置************************voidGotoXY(unsignedcharx,unsignedchary){ if(y==0) LCD_Write(LCD_COMMAND,0x80|x); if(y==1) LCD_Write(LCD_COMMAND,0x80|(x-0x40));}//將字符串輸出到液晶顯示voidPrint(unsignedchar*str){ while(*str!='\0') { LCD_Write(LCD_DATA,*str); str++; }}//將字符串輸出到液晶的指定位置顯示voidLCD_WriteString(unsignedcharX,unsignedcharY,char*p){ EA=0;GotoXY(X,Y);//設置XY坐標while(*p){LCD_Write(LCD_DATA,*p); //顯示字符p++;} EA=1;}//將字符輸出到液晶的指定位置顯示voidLCD_SramChar(unsignedcharX,unsignedcharY,unsignedcharp){ EA=0;GotoXY(X,Y);//設置XY坐標LCD_Write(LCD_DATA,p); //顯示字符 EA=1;}voidzhuanhuan(floata)//浮點數(shù)轉(zhuǎn)換成字符串函數(shù){ memset(str,0,sizeof(str)); //字符串清零 sprintf(str,"%f",a); //浮點數(shù)轉(zhuǎn)換成字符串函數(shù)}/*;模塊名稱:delay_n10us();;功能:延時函數(shù),延時約n個10us;*/voiddelay_n10us(uintn)//延時n個10us@12M晶振{uinti;for(i=n;i>0;i--){ _nop_();_nop_();_nop_(); _nop_();_nop_();_nop_(); }}/*;模塊名稱:s_transstart();;功能:啟動傳輸函數(shù);*/voids_transstart(void){DATA=1;SCK=0;//Initialstate_nop_();SCK=1;_nop_();DATA=0;_nop_();SCK=0;_nop_();_nop_();_nop_();SCK=1;_nop_();DATA=1;_nop_();SCK=0;}/*;模塊名稱:s_connectionreset();;功能:連接復位函數(shù);*/voids_connectionreset(void){unsignedchari;DATA=1;SCK=0;//Initialstatefor(i=0;i<9;i++)//9SCKcycles{SCK=1;SCK=0;}s_transstart();//transmissionstart}/*;模塊名稱:s_write_byte();;功能:SHT10寫函數(shù);*/chars_write_byte(unsignedcharvalue)////writesabyteontheSensibusandcheckstheacknowledge{unsignedchari,error=0;for(i=0x80;i>0;i/=2)//shiftbitformasking{if(i&value)DATA=1;//maskingvaluewithi,writetoSENSI-BUSelseDATA=0;SCK=1;//clkforSENSI-BUS_nop_();_nop_();_nop_();//pulswithapprox.3usSCK=0;}DATA=1;//releaseDATA-lineSCK=1;//clk#9forackerror=DATA;_nop_();_nop_();_nop_();SCK=0;DATA=1;//releaseDATA-linereturnerror;//error=1incaseofnoacknowledge//返回:0成功,1失敗}/*;模塊名稱:s_read_byte();;功能:SHT10讀函數(shù);*/chars_read_byte(unsignedcharack)//readsabyteformtheSensibusandgivesanacknowledgeincaseof"ack=1"{unsignedchari,val=0;DATA=1;//releaseDATA-linefor(i=0x80;i>0;i/=2)//shiftbitformasking{SCK=1;//clkforSENSI-BUSif(DATA)val=(val|i);//readbit _nop_();_nop_();_nop_();//pulswithapprox.3usSCK=0;}if(ack==1)DATA=0;//incaseof"ack==1"pulldownDATA-LineelseDATA=1;//如果是校驗(ack==0),讀取完后結(jié)束通訊_nop_();_nop_();_nop_();//pulswithapprox.3usSCK=1;//clk#9forack_nop_();_nop_();_nop_();//pulswithapprox.3usSCK=0;_nop_();_nop_();_nop_();//pulswithapprox.3usDATA=1;//releaseDATA-linereturnval;}/*;模塊名稱:s_measure();;功能:測量溫濕度函數(shù);*/chars_measure(unsignedchar*p_value,unsignedchar*p_checksum,unsignedcharmode){unsignederror=0;unsignedinti;s_transstart();//transmissionstartswitch(mode){//sendcommandtosensorcaseTEMP:error+=s_write_byte(MEASURE_TEMP);break;caseHUMI:error+=s_write_byte(MEASURE_HUMI);break;default:break;}for(i=0;i<65535;i++)if(DATA==0)break;//waituntilsensorhasfinishedthemeasurementif(DATA)error+=1;*(p_value)=s_read_byte(ACK);//readthefirstbyte*(p_value+1)=s_read_byte(ACK);//readthesecondbyte*p_checksum=s_read_byte(noACK);returnerror;}/*;模塊名稱:calc_sht10();;功能:溫濕度補償函數(shù);*/voidcalc_sht10(float*p_humidity,float*p_temperature)//calculatestemperature[C]andhumidity[%RH]//input:humi)//temp//output:humi//temp{constfloatC1=-4.0;constfloatC2=+0.0405;constfloatC3=-0.0000028;constfloatT1=+0.01;constfloatT2=+0.00008;floatrh=*p_humidity;//rh:Humidity[Ticks]12Bitfloatt=*p_temperature;//t:Temperature[Ticks]14Bitfloatrh_lin;//rh_lin:Humiditylinearfloatrh_true;//rh_true:Temperaturecompensatedhumidityfloatt_C;//t_C:Temperature[C]t_C=t*0.01-40;//calc.temperaturefromticksto[C]rh_lin=C3*rh*rh+C2*rh+C1;//calc.humidityfromticksto[%RH]rh_true=(t_C-25)*(T1+T2*rh)+rh_lin-4;//calc.temperaturecompensatedhumidity[%RH]if(rh_true>100)rh_true=100;//cutifthevalueisoutsideofif(rh_true<0.1)rh_true=0.1;//thephysicalpossiblerange*p_temperature=t_C;//returntemperature[C]*p_humidity=rh_true;//returnhumidity[%RH]}//顯示當前時間voidShowTime(void){ unsignedchari=0,j=0,k=0; //EA=0; ds1302_read_time();//讀取時間 if(OldSecond!=time_buf[6]) //判斷當前秒鐘和上次顯示是的秒鐘是否相同,不同,更改顯示 { OldSecond=time_buf[6]; // 保存當前秒鐘時間 dispbuff=(time_buf[0]>>4)+'0'; LCD_SramChar(3,1,dispbuff);//年 dispbuff=(time_buf[0]&0x0F)+'0'; LCD_SramChar(4,1,dispbuff); dispbuff=(time_buf[1]>>4)+'0'; LCD_SramChar(5,1,dispbuff); dispbuff=(time_buf[1]&0x0F)+'0'; LCD_SramChar(6,1,dispbuff); LCD_SramChar(7,1,'/'); dispbuff=(time_buf[2]>>4)+'0'; LCD_SramChar(8,1,dispbuff);//月 dispbuff=(time_buf[2]&0x0F)+'0'; LCD_SramChar(9,1,dispbuff); //LCD_SramChar(10,1,'/'); //dispbuff=(time_buf[3]>>4)+'0'; //LCD_SramChar(11,1,dispbuff);//日 //dispbuff=(time_buf[3]&0x0F)+'0'; //LCD_SramChar(12,1,dispbuff); }}voidmain(void){ valuehumi_val,temp_val; unsignedcharerror,checksum; LcdRw=0;LED=0; s_connectionreset();//復位傳感器 LCD_Initial(); //液晶初始化 while(1) { error=0; error+=s_measure((unsignedchar*)&humi_val.i,&checksum,HUMI);//獲得濕度值 error+=s_measure((unsignedchar*)&temp_val.i,&checksum,TEMP);//獲得溫度值 if(error!=0) { s_
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年度城市生活垃圾處理合同標的處理技術(shù)與資源回收利用
- 2025年度公共安全視頻監(jiān)控合同基本管理制度
- 2025年度農(nóng)業(yè)機械簡易采購合同格式標準版
- 2025年度醫(yī)療器械計量檢定校準服務合同書
- 2025年度冷鏈物流合同書(含溯源管理)
- 2025年度醫(yī)療設備租賃合同結(jié)算協(xié)議
- 2025年度醫(yī)療器械加工及銷售合同范本
- 2025年度大型商場購物卡聯(lián)合采購合同
- 2025年度中小學特色課程輔導合同協(xié)議書
- 2025年度國際旅游業(yè)務合作與推廣合同
- 高考英語語法填空專項訓練(含解析)
- 42式太極劍劍譜及動作說明(吳阿敏)
- 英語完形填空練習題
- 部編版語文小學五年級下冊第一單元集體備課(教材解讀)
- GB/T 10095.1-2022圓柱齒輪ISO齒面公差分級制第1部分:齒面偏差的定義和允許值
- 仁愛英語九年級下冊單詞表(中英文)
- 危險化學品企業(yè)安全生產(chǎn)標準化課件
- 巨鹿二中骨干教師個人工作業(yè)績材料
- 《美的歷程》導讀課件
- 心電圖 (史上最完美)課件
- 建設工程施工合同糾紛處理課件
評論
0/150
提交評論