LCD显示的温度表的设计.docx
-bGN三16D2×LC12 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 & _WDT_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;Strobethe"E'rBitbsfEbcfEENDMCBLOCKOCHTemp;atemporaryvariablecount;counterbin;binarynumbertobeconvertedtoBCDhundreds;BCDhundredsresultlens_and_ones;BCDtensandonesresultsavetmr;usedtosavevalueoftmrdispvalue;usedtoholdtemperaturetobedisplayedtableindex;pointstotablevaluetodisplayENDCORGO;startatlocation0goto main;jumpovertomainroutineDataformessagetobeoutputshomsg:addwfPCL,fmdt"TMROValue:",Omldt"Temperature",O;MessagetoOutput;OutputtheCharactersRatiosofPrescalerpreratio:addwfPCL,f;selectoffsetusingWdtD,2D,4,D,8,D,16',D,32',D'64D,128'InitializetheponsInit:cirfPORTAclrfPORTBmovlwB,00010000,trisPORTAmovlwBWilOOOO'trisPORTBmovlwB1OOl(X)Oir;RA4input,othersoutputs;RB4.RB5input,othersoutputs;pull-upsenabled;prescalerassignedtoRA4;prescalersetto1:16optionreturn;InitializetheLCDinitlcd:movlwD'40'callnmsecbcfRSmovlw0x03callNybbleOutcallDlay5EStrobenopnopEStrobenopnopbcfRSmovlw0x02callNybbleOut;Wait40msecsbeforeReset;sendan8bilinstruction;ResetCommand;SendtheNybble;Wait5msecsbeforeSendingAgain;Wait244useesbeforeSendingtheSecondTime;Wait244useesbeforeSendingtheThirdTime;sendan8bitinstruction;Set4BitModenopnopmovlw0x028callSendINSmovlwOxOlOcallSendINSmovlwOxOOlcallSendINScallDlay5movlw0x006callSendINSmovlwOx(X)C;4bit,2Line,5x7font;displayshiftoff;CleartheDisplayRAM;Note,Cantakeupto4.1msecs;incrementcursor;displayoncursoroffcallSendINSreturnSendthecharacterinWouttotheLCDSendASCIIaddlw'0,SendCHARmovwfTempswapfTemp,wbsfRScallNybbleOutmovfTemp,w;SendnbrasASCIIcharacter;SendtheCharactertotheLCD;SavetheTemporaryValue;SendtheHighNybble;RS=1;SendtheLowNybblebsfRScallNybbleOutreturnSendaninstructioninWouttotheLCDSendINSmovwfTempswapfTemp,wbcfRScallNybbleOutmovfTemp,W;SendtheInstructiontotheLCD;SavetheTemporaryValue;SendtheHighNybble;RS=O;SendtheLowNybblebcfRScallNybbleOutreturnSendthenibbleinWouttotheLCDNybbleOul;SendaNybbletoIheLCDmovwfPORTBEStrobenopnop;StrobeouttheLCDDatareturnOutputthemessageontheLCDOutMessage:movwfFSR;PointatfirstletterOutLoop:movfFSR,w;GetpointerintoWincfFSR,f;Setupfornextlettercallshomsg;Gelcharactertooutputiorlw0;AttheEndoftheMessage?btfscSTATUS,Z;Skipifnotatendreturn;Yes-EqualtoZerocallSendCHAR;OutputtheASCIICharactergotoOutLoop;GetthenextcharacterChangebinarynbrinbintoBCDbinary_to_bcd;byScottDattaloclrfhundredsSWiipfbin,Waddwfbin,WandlwB,0000111skpndcaddlw0x16skpndcaddlw0x06addlw0x06skpdcaddlw-0x06btfscbin,4addlwOx16-1+0x6skpdcaddlw-0x06btfscbin,5addlw0x30btfscbin,6addlw0x60btfscbin,7addlw0x20addlw0x60rlfhundreds,fbtfsshundreds,0addlw-0x60movwftens_and_onesbtfscbin,7incfhundreds,freturnDelayroutinemsec250movlw0;250msecdelay(adjustedtotryand;allowfor2.5%lowlooptime)goto$+2Dlay5movlw5;delayfor5millisecondsnmsec:;delayfor#msecinWonentrynop;eachnopis0.122millisecondsnopnop;eachtotalloopis8X0.122=0.976msecnopaddlwHFF;sameassubtracting1fromWhtfssSTATUS,Z;skipifresultiszerogotonmsec;thisis2X0.122msecreturn;backtocallingpointDisplaybinaryvalueinWindecimalDispDecmovwfbincallbinary_to_bcdmovfhundreds,WcallSendASCIIswapftens_and_ones,WandlwH'F'callSendASCIImovftens_and_ones,WandlwH,F'callSendASCIIreturnTheMainroutinemain:callInit;initializeports,setuptimercallinitlcd;initializetheLCDmovlwH,80'positionat1stlinecolumn0callSendINSmovlwm-2;send'TMR0Value:'messagecallOutMessagemovlwH,C0'callSendINS;positionat2ndlinecolumn0movlwml-2;send'Temperature:'messagecallOutMessagesholoop:movlwH'8C'positionat1stlinecolumn12callSendINSbcfINTCON,TOIFClrfTMROcallmsec250callmsec250callmsec250callmsec250movfTMRO,WmovwfsavetmrbtfscINTCON,TOIFgotooverloadcallDispDecmovlwHCCcallSendINSmovlw2movwfPCLATHmovlwD,64'subwfsavetmr,WmovwftableindexcallIemptablelmovwfdispvalueswapfdispvalue,WandlwH,OF,callSendASCIImovfdispvalue,WandlwH,OF,callSendASCIImovlw'.,callSendCHARmovlw3mo