您好,欢迎访问三七文档
当前位置:首页 > 电子/通信 > 综合/其它 > 单片机温度计完整汇编语句
单片机温度计完整汇编语句汇编程序;================================================================;;============================常数定义=============================TIMELEQU0E0H;20ms,定时器0时间常数TIMEHEQU0B1HTEMPHEADEQU36H;==========================工作内存定义============================BITSTDATA20HTIME1SOKBITBITST.1TEMPHDATA27HTEMPHCDATA28HTEMPLCDATA29H;=============================引脚定义===========================TEMPDINBITP3.7;=============================中断向量区=========================ORG0000HLJMPSTARTORG00BHLJMPT0IT;=============================系统初始化==========================ORG100HSTART:MOVSP,#60HCLSMEM:MOVR0,#20HMOVR1,#60HCLSMEM1:MOV@R0,#00HSJMPINITERROR:NOPLJMPSTARTNOPINIT:NOPSETBET0SETBTR0SETBEAMOVPSW,#00HCLRTEMPONEOKLJMPMAIN;======================定时器0中断服务程序=======================T0IT:PUSHPSWCJNER7,#32H,T0IT1MOVR7,#00HSETBTIME1SOK;1s定时到标志T0IT1:POPPSWRETI;=============================主程序=============================MAIN:LCALLDISP1序JNBTIME1SOK,MAINCLRTIME1SOKJNBTEMPONEOK,MAIN2LCALLREADTEMP1;LCALLCONVTEMPLCALLDISPBCDLCALLDISP1MAIN2:LCALLREADTEMP;SETBTEMPONEOKLJMPMAIN;=============================子程序区===========================;RESETDS18B20;================================================================INITDS1820:SETBTEMPDINNOPNOPCLRTEMPDINMOVR6,#0A0H;DELAY480usDJNZR6,$MOVR6,#0A0HDJNZR6,$DJNZR6,LOOP1820MOVR6,#064HDJNZR6,$SJMPINITDS1820RETINITDS1820OUT:SETBTEMPDINRET;======读DS18B20的程序,从DS18B20中读出一个字节的数据=============READDS1820:MOVR7,#08HSETBTEMPDINNOPNOPREADDS1820LOOP:CLRTEMPDINNOPNOPSETBTEMPDINDJNZR7,READDS1820LOOPMOVR6,#3CH;DELAY120usDJNZR6,$RET;========写DS18B20的程序,从DS18B20中写一个字节的数据=============WRITEDS1820:MOVR7,#08HSETBTEMPDINNOPNOPWRITEDS1820LOP:CLRTEMPDIN04usDJNZR6,$SETBTEMPDINDJNZR7,WRITEDS1820LOPRET;=========================READTEMP===========================READTEMP:LCALLINITDS1820MOVA,#0CCHLCALLWRITEDS1820;SKIPROMMOVR6,#34H;DELAY104usDJNZR6,$MOVA,#44HLCALLWRITEDS1820;STARTCONVERSIONMOVR6,#34H;DELAY104DJNZR6,$RETREADTEMP1:LCALLINITDS1820MOVA,#0CCHLCALLWRITEDS1820;SKIPROM04usDJNZR6,$MOVR5,#09HMOVR0,#TEMPHEADMOVB,#00HREADTEMP2:LCALLREADDS1820MOV@R0,AINCR0READTEMP21:LCALLCRC8CALDJNZR5,READTEMP2MOVA,BJNZREADTEMPOUTMOVA,TEMPHEAD+0MOVTEMPL,AMOVA,TEMPHEAD+1MOVTEMPH,AREADTEMPOUT:RET;==================处理温度BCD码子程序==========================CONVTEMP:MOVA,TEMPHANLA,#80HJZTEMPC1CLRCMOVA,TEMPLCPLAADDA,#01HMOVTEMPL,AMOVA,TEMPH;-CPLAADDCA,#00HMOVTEMPH,A;TEMPHCHI=符号位MOVTEMPHC,#0BHSJMPTEMPC11TEMPC1:MOVTEMPHC,#0AH;+TEMPC11:MOVA,TEMPHCSWAPAMOVTEMPHC,AMOVA,TEMPLANLA,#0FH;乘0.0625MOVDPTR,#TEMPDOTTABMOVCA,@A+DPTRMOVTEMPLC,A;TEMPLCLOW=小数部分BCDMOVA,TEMPL;整数部分ANLA,#0F0HSWAPAMOVTEMPL,AMOVA,TEMPHANLA,#0FHSWAPAORLA,TEMPLLCALLHEX2BCD1MOVTEMPL,AANLA,#0F0HSWAPAORLA,TEMPHC;TEMPHCLOW=十位数BCDMOVTEMPHC,AMOVA,TEMPLANLA,#0FHSWAPA;TEMPLCHI=个位数BCDORLA,TEMPLCMOVTEMPLC,AMOVA,R7MOVR7,AMOVA,TEMPHC;TEMPLCHI=百位数BCDANLA,#0FHORLA,R7MOVTEMPHC,ATEMPC12:RET;=========================小数部分码表===========================TEMPDOTTAB:DB00H,01H,01H,02H,03H,03H,04H,04H,05H,06HDB06H,07H,08H,08H,09H,09H;======================显示区BCD码温度值刷新子程序===============DISPBCD:MOVA,TEMPLCMOV71H,AMOVA,TEMPHCANLA,#0FHMOV72H,AMOVA,TEMPHCSWAPAANLA,#0FHMOV73H,AMOVA,TEMPHCANLA,#0F0HCJNEA,#010H,DISPBCD0SJMPDISPBCD2DISPBCD0:MOVA,TEMPHCANLA,#0FHJNZDISPBCD2;十位数是0MOVA,TEMPHCSWAPAANLA,#0FHMOV73H,#0AH;符号位不显示MOV72H,A;十位数显示符号DISPBCD2:RET;=======================显示子程序===============================;显示数据在70H~73H单元内,用4位LED共阳数码管显示,P1口输出段码数据,;P3口做扫描控制,每个LED数码管亮1ms时间再逐位循环。DISP1:MOVR1,#70H;指向显示数据首址MOVR5,#0FEH;扫描控制字初值PLAY:MOVP0,#0FFHMOVP0,A;段码放入P0口MOVA,R5JBACC.1,LOOP5;小数点处理CLRP0.7LOOP5:LCALLDL1MS;显示1msINCR1;指向下一地址MOVA,R5;扫描控制字放入AJNBACC.3,ENDOUT;ACC.3=0时一次显示结束RLA;A中数据循环左移MOVR5,A;放回R5内AJMPPLAY;跳回PLAY循环ENDOUT:MOVP0,#0FFH;一次显示结束,P0口复位MOVP3,#0FFH;P3口复位RET;子程序返回TADL1:MOVR7,#19HDL2:DJNZR7,DL2DJNZR6,DL1RET;=====================单字节十六进制转BCD=======================HEX2BCD1:MOVB,#064H;十六进制-BCDDIVAB;B=A%100MOVR7,A;R7=百位数MOVA,#0AHXCHA,BDIVAB;B=A%BSWAPAORLA,BRET;================================================================;CalculateCRC-8Values.UsesTheCCITT-8Polynomial,ExpressedAs;X^8+X^5+X^4+1;================================================================CRC8CAJNCCRC8LOOP2;SkipIfData==0XRLA,#18H;UpdataTheNewCRCCRC8LOOP2:RRCA;PositionTheNewCRCMOVB,A;StoreTheNewCRCPOPACC;GetTheRemainingBitsRRA;PositionTheNextBitPUSHACC;SaveTheRemainingBitsDJNZR7,CRC8LOOP1;RepeatFor8BitsPOPACCRET
本文标题:单片机温度计完整汇编语句
链接地址:https://www.777doc.com/doc-3174918 .html