《LCD显示的温度表的设计.docx》由会员分享,可在线阅读,更多相关《LCD显示的温度表的设计.docx(8页珍藏版)》请在优知文库上搜索。
1、-bGN三16D2LC12 3 4 5 6 7Ddddddde-oC=33pfJ-JIL.C_C32.768kHzRA2RAIRA3RAORA40SC1MCLR0SC2VssVddRBORB7RB1RB6RB2RB5RB3RB4PIC16F84TemperatureDisplay8TLC555165LCDdisplayOfTemperatureTHERM.ASMShowsTemperaturefromThermistoronLCDLIST P=l6F84;16F84 Runs at 4 MHzINCLUDE pl6f84.inc_CONFIG _PWRTE_0N & _LP_OSC & _WD
2、T_0FF ; uses 32.768 kHz crystalERRORLEVEL -224ERRORLEVEL -302; supress annoying message because of tris ; supress message because of page change;Define Information#DEFINE RS PORTA, 0#DEFINE E PORTA, 1;Macro;RAO is RS line of LCD;RAl is E line OfLCD;RB0-RB3 are D4-D7 of LCDEStrobeMACRO;StrobetheErBit
3、bsfEbcfEENDMCBLOCKOCHTemp;atemporaryvariablecount;counterbin;binarynumbertobeconvertedtoBCDhundreds;BCDhundredsresultlens_and_ones;BCDtensandonesresultsavetmr;usedtosavevalueoftmrdispvalue;usedtoholdtemperaturetobedisplayedtableindex;pointstotablevaluetodisplayENDCORGO;startatlocation0goto main;jump
4、overtomainroutineDataformessagetobeoutputshomsg:addwfPCL,fmdtTMROValue:,OmldtTemperature,O;MessagetoOutput;OutputtheCharactersRatiosofPrescalerpreratio:addwfPCL,f;selectoffsetusingWdtD,2D,4,D,8,D,16,D,32,D64D,128;InitializetheponsInit:cirfPORTAclrfPORTBmovlwB,00010000,trisPORTAmovlwBWilOOOOtrisPORTB
5、movlwB1OOl(X)Oir;RA4input,othersoutputs;RB4.RB5input,othersoutputs;pull-upsenabled;prescalerassignedtoRA4;prescalersetto1:16optionreturn;InitializetheLCDinitlcd:movlwD40callnmsecbcfRSmovlw0x03callNybbleOutcallDlay5EStrobenopnopEStrobenopnopbcfRSmovlw0x02callNybbleOut;Wait40msecsbeforeReset;sendan8bi
6、linstruction;ResetCommand;SendtheNybble;Wait5msecsbeforeSendingAgain;Wait244useesbeforeSendingtheSecondTime;Wait244useesbeforeSendingtheThirdTime;sendan8bitinstruction;Set4BitModenopnopmovlw0x028callSendINSmovlwOxOlOcallSendINSmovlwOxOOlcallSendINScallDlay5movlw0x006callSendINSmovlwOx(X)C;4bit,2Line
7、,5x7font;displayshiftoff;CleartheDisplayRAM;Note,Cantakeupto4.1msecs;incrementcursor;displayoncursoroffcallSendINSreturnSendthecharacterinWouttotheLCDSendASCIIaddlw0,SendCHARmovwfTempswapfTemp,wbsfRScallNybbleOutmovfTemp,w;SendnbrasASCIIcharacter;SendtheCharactertotheLCD;SavetheTemporaryValue;Sendth
8、eHighNybble;RS=1;SendtheLowNybblebsfRScallNybbleOutreturnSendaninstructioninWouttotheLCDSendINSmovwfTempswapfTemp,wbcfRScallNybbleOutmovfTemp,W;SendtheInstructiontotheLCD;SavetheTemporaryValue;SendtheHighNybble;RS=O;SendtheLowNybblebcfRScallNybbleOutreturnSendthenibbleinWouttotheLCDNybbleOul;SendaNy
9、bbletoIheLCDmovwfPORTBEStrobenopnop;StrobeouttheLCDDatareturnOutputthemessageontheLCDOutMessage:movwfFSR;PointatfirstletterOutLoop:movfFSR,w;GetpointerintoWincfFSR,f;Setupfornextlettercallshomsg;Gelcharactertooutputiorlw0;AttheEndoftheMessage?btfscSTATUS,Z;Skipifnotatendreturn;Yes-EqualtoZerocallSen
10、dCHAR;OutputtheASCIICharactergotoOutLoop;GetthenextcharacterChangebinarynbrinbintoBCDbinary_to_bcd;byScottDattaloclrfhundredsSWiipfbin,Waddwfbin,WandlwB,0000111skpndcaddlw0x16skpndcaddlw0x06addlw0x06skpdcaddlw-0x06btfscbin,4addlwOx16-1+0x6skpdcaddlw-0x06btfscbin,5addlw0x30btfscbin,6addlw0x60btfscbin
11、,7addlw0x20addlw0x60rlfhundreds,fbtfsshundreds,0addlw-0x60movwftens_and_onesbtfscbin,7incfhundreds,freturnDelayroutinemsec250movlw0;250msecdelay(adjustedtotryand;allowfor2.5%lowlooptime)goto$+2Dlay5movlw5;delayfor5millisecondsnmsec:;delayfor#msecinWonentrynop;eachnopis0.122millisecondsnopnop;eachtot
12、alloopis8X0.122=0.976msecnopaddlwHFF;sameassubtracting1fromWhtfssSTATUS,Z;skipifresultiszerogotonmsec;thisis2X0.122msecreturn;backtocallingpointDisplaybinaryvalueinWindecimalDispDecmovwfbincallbinary_to_bcdmovfhundreds,WcallSendASCIIswapftens_and_ones,WandlwHFcallSendASCIImovftens_and_ones,WandlwH,F
13、callSendASCIIreturnTheMainroutinemain:callInit;initializeports,setuptimercallinitlcd;initializetheLCDmovlwH,80;positionat1stlinecolumn0callSendINSmovlwm-2;sendTMR0Value:messagecallOutMessagemovlwH,C0callSendINS;positionat2ndlinecolumn0movlwml-2;sendTemperature:messagecallOutMessagesholoop:movlwH8C;p
14、ositionat1stlinecolumn12callSendINSbcfINTCON,TOIFClrfTMROcallmsec250callmsec250callmsec250callmsec250movfTMRO,WmovwfsavetmrbtfscINTCON,TOIFgotooverloadcallDispDecmovlwHCCcallSendINSmovlw2movwfPCLATHmovlwD,64subwfsavetmr,WmovwftableindexcallIemptablelmovwfdispvalueswapfdispvalue,WandlwH,OF,callSendASCIImovfdispvalue,WandlwH,OF,callSendASCIImovlw.,callSendCHARmovlw3mo