DIV 态段AB
PUSH ACC
MOV A, B
MOV B, 雹闭银#10
DIV AB
SWAP A
ADD A, B
POP B
RET
END
********************************************************************DS18B20温度计 *
采用4位LED共阳显示器显示测温值,显示精度0.1℃,测温范围-55~+125*
用AT89C2051单片机,12MHZ晶振 *
********************************************************************
***************常数定义********************
TIMEL EQU0E0H 20ms,定时举败器0时间常数
TIMEH EQU0B1H
TEMPHEAD EQU36H
********************工作内存轿答如定义**********************
BITST DATA 20H
TIME1S0K BIT BITST.1
TEMPONEOK BIT BITST.2
TEMPL DATA 26H
TEMPH DATA 27H
TEMPHC DATA 28H
TEMPLC DATA 29H
SCANLEDDATA 2AH
*****************引脚定义*****************************
TEMPDIN BIT P3.7
*****************中断向量区***************************
ORG0000H
LJMP START
ORG000BH
LJMP T01T
***************系统初始化****************************
ORG0030H
START: MOV SP,#60H
CLSMEM: MOV R0,#20H
MOV R1,#60H
CLSMEM1: MOV @R0,#00H
INC R0
DJNZ R1,CLSMEM1
MOV TMOD,#00100001B 定时器0工作方式1(16位)
MOV TH0,#HIGH(65536-5000)
MOV TL0,#LOW(65536-5000)5ms
SJMPINIT
ERROR: NOP
LJMPSTART
NOP
INIT: NOP
SETB ET0
SETB TR0
SETB EA
MOV PSW,#00H
CLR TEMPONEOK
MOV 50H,#10
MOV 51H,#10
MOV 52H,#10
MOV 53H,#10
LJMP MAIN
*******************************************************************
定时器0中断闭启服务程序
*******************************************************************
T01T: CLR TR0
MOV TH0,#HIGH(65536-5000)
MOV TL0,#LOW(65536-5000)5ms
SETB TR0
LEDDIS:
MOV DPTR,#TAB
MOV R1,#50H
MOV A,SCANLED
ADD A,R1
MOV R1,A
MOV A,SCANLED
JNZ LEDDIS1
MOV P3,#08H
SJMP LEDDIS4
LEDDIS1:
DEC A
JNZ LEDDIS2
MOV P3,#04H
SJMP LEDDIS4
LEDDIS2:
DEC A
JNZ LEDDIS3
MOV P3,#02H
SJMP LEDDIS4
LEDDIS3:
MOV P3,#01H
LEDDIS4:
MOV A,@R1
MOVC A,@A+DPTR
MOV P1,A
INC SCANLED
MOV A,SCANLED
CJNE A,#4,T0CNT
MOV SCANLED,#0
T0CNT:
INC R7
CJNER7,#200,T0IT1
MOV R7,#00H
SETB TIME1S0K1s定时到标志
T0IT1: RETI
********************************************************************
主程序
********************************************************************
MAIN:
JNB TIME1S0K,MAIN
CLR TIME1S0K测温每1s一次
LCALL READTEMP读出温度值子程序
LCALL CONVTEMP温度BCD码计算处理子程序
LCALL DISPBCD 显示区BCD码温度值刷新子程序
LJMPMAIN
********************************************************************
子程序区
********************************************************************
***************复位DS18B20*****************************************
INITDS1820: SETB TEMPDIN
NOP
CLRTEMPDIN
MOVR6,#251延时>480μs
DJNZ R6,$
SETB TEMPDIN
MOV R6,#37
LOOP1820: MOVC,TEMPDIN
JC INITDS1820OUT
DJNZ R6,LOOP1820
SJMP INITDS1820
RET
INITDS1820OUT:
MOVR6,#06BH 延时200μs
DJNZ R6,$
SETB TEMPDIN
RET
*******读DS18B20的程序,从DS18B20中读出1字节的数据*****
READDS1820: MOV R7,#08H
READDS1820LOOP: CLR TEMPDIN
NOP
NOP
SETB TEMPDIN
MOV R6,#07延时15μs
DJNZ R6,$
MOV C,TEMPDIN
RRC A
MOV R6,#25
DJNZ R6,$
DJNZ R7,READDS1820LOOP
RET
******写DS18B20的程序,从DS18B20中写1字节数据*****
WRITEDS1820: MOV R7,#08H
WRITEDS1820LOP: CLR TEMPDIN
MOV R6,#07H 延时15μs
DJNZ R6,$
RRC A
MOV TEMPDIN,C
MOV R6,#30延时104μs
DJNZR6,$
SETB TEMPDIN
NOP
DJNZR7,WRITEDS1820LOP
SETB TEMPDIN
RET
******************读TEMP******************88
READTEMP: LCALL INITDS1820
MOV A,#0CCH
LCALLWRITEDS1820 Skip ROM
MOVA, #44H
LCALL WRITEDS1820 开始转换
MOV R6,#250 延时
DJNZ R6,$
READTEMP1: LCALL INITDS1820
MOV A,#0CCH
LCALL WRITEDS1820 SkipROM
MOV A,#0BEH
LCALLWRITEDS1820 中间结果寄存器
MOV R6,#34H 延时104μs
DJNZ R6,$
READTEMP2:LCALL READDS1820
MOVTEMPL,A
LCALL READDS1820
MOVTEMPH,A
READTEMPOUT: RET
**************处理温度BCD码子程序***********
CONVTEMP:MOV A,TEMPH
ANL A,#80H
JZTEMPC1
CLR C
MOV A,TEMPL
CPL A
ADD A,#01H
MOV TEMPL,A
MOVA,TEMPH "-"
CPL A
ADDC A,#00H
MOVTEMPH,A TEMPHC HI=符号位
MOVTEMPHC,#0BH
SJMP TEMPC11
TEMPC1:MOV TEMPHC,#0AH"+"
TEMPC11:
MOV R6,#4H
TEMPC12:
MOV A,TEMPH
RRC A
MOV TEMPH,A
MOV A,TEMPL
RRC A
MOV TEMPL,A
DJNZ R6,TEMPC12
RET
*****************小数部分码表*********
TEMPDOTTAB:DB 00H,01H,01H,02H,03H,03H,04H,04H,05H,06H
DB 06H,07H,08H,08H,09H,09H
************显示区BCD码温度值刷新子程序********
DISPBCD: MOV 53H,TEMPHC
MOV A,TEMPL
MOV B,#10
DIV AB
MOV 50H,B
MOV B,#10
DIV AB
MOV 51H,B
JZ DISPBCD2
MOV 52H,A
RET
DISPBCD2: MOV 52H,#10
RET
TAB: DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H,0FFH,0BFH
共阳段码表 "0","1","2","3","4","5","6","7","8","9","不亮","-"
END
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)