📄 tempuart.asm
字号:
;====================================================================
;
; Author : ADI - Apps
;
; Date : August 2000
;
; File : TempUart.asm
;
; Hardware : ADuC824
;
; Description : This Program takes a temperature measurement every
; second from the on-chip temp sensor and sends the
; temp in degrees Celcius up the UART to the PC where
; it can be read using hyperterminal
;====================================================================
;
$MOD824 ; Use 8052 / ADuC824 predefined Symbols
LED EQU P3.4
FLAG EQU 00h
;____________________________________________________________________
; DEFINE VARIABLES IN INTERNAL RAM
DSEG
ORG 0033h
COUNT1: DS 1
COUNT2: DS 1
COUNT3: DS 1
DIG1: DS 1
DIG2: DS 1
DIG3: DS 1
;____________________________________________________________________
; BEGINNING OF CODE
CSEG
ORG 0000H
JMP MAIN
;====================================================================
ORG 0060H ; Start code at address above interrupts
MAIN: ; Main program
MOV RCAP2H,#0FFh ; config UART for 9830baud
MOV RCAP2L,#-5 ; (close enough to 9600baud)
MOV TH2,#0FFh
MOV TL2,#-5
MOV SCON,#52h
MOV T2CON,#34h
; Configure ADC
MOV ADCMODE, #10H ; ENABLE AUX Mode - Power down
MOV ADC1CON, #20H ; USE INTERNAL REFERENCE
; PTAT(+) --> PTAT(-)
; BIPOLAR MODE
; Fixed +/- 2.5V range
MOV DPTR, #TITLE
CALL SENDSTRING ; write title block on screen
;____________________________________________________________________
; TEMP MEASURE LOOP
TEMPLOOP:
MOV ADCMODE, #12H ; INITIATE A SINGLE AUX CONV
JNB RDY1,$ ; Wait for conversion results
; conversion result ready
; a value of 80h in AD1H=0degC
MOV A, ADC1H ; 80h=0, FFh=+127, 00h=-128
CLR C
SUBB A, #80H ; convert to 2's comp
; FFh=-1, 80h=-128, 00h=0, 7Fh=+127
SENDDECs: ; SENDs the signed decimal number in Acc up UART
; -128->127
PUSH B
PUSH ACC
JNB ACC.7, HUNDREDS
MOV A, #'-' ; transmit minus sign
CALL SENDCHAR
POP ACC ; restore original value of A
PUSH ACC ; remember original value of A
CPL A
INC A
HUNDREDS: ; check #hundreds
MOV B, #100 ; divide remainder by 100
DIV AB ; A receives integer quotient
; B receives the remainder
SETB F0
JZ TENS ; if ACC=0 then num=0xx
CLR F0
ADD A, #'0'
LCALL SENDCHAR
TENS: ; check tens
MOV A,B
MOV B,#10
DIV AB ; divide remainder by 10
JNB F0, SEND0 ; if F0 is cleared the a number
; exists in the 100s
JZ UNITS
SEND0: ADD A, #'0' ; only send a zero if number
CALL SENDCHAR ; existed in the 100s
UNITS: MOV A,B ; send remainder (even if 0)
ADD A, #'0'
CALL SENDCHAR
POP ACC
POP B
MOV DPTR, #DEGREES
CALL SENDSTRING
MOV A, #01
CALL DELAY
JMP TEMPLOOP
;____________________________________________________________________
; DELAY
DELAY: ; Delays by 100ms * A
; 100mSec based on 1.573MHZ Core Clock
MOV R2,A ; Acc holds delay variable
DLY0: MOV R3,#50 ; Set up delay loop0
DLY1: MOV R4,#131 ; Set up delay loop1
DJNZ R4,$ ; Dec R4 & Jump here until R4 is 0
; wait here for 131*15.3us=2ms
DJNZ R3,DLY1 ; Dec R3 & Jump DLY1 until R3 is 0
; Wait for 50*2ms
DJNZ R2,DLY0 ; Dec R2 & Jump DLY0 until R2 is 0
; wait for ACC*100ms
RET ; Return from subroutine
;____________________________________________________________________
; SENDCHAR
SENDCHAR: ; sends ASCII value contained in A to UART
JNB TI,$ ; wait til present char gone
CLR TI ; must clear TI
MOV SBUF,A
RET
;____________________________________________________________________
; SENDSTRING
SENDSTRING: ; sends ASCII string to UART starting at location
; DPTR and ending with a null (0) value
PUSH ACC
PUSH B
CLR A
MOV B,A
IO0010: MOV A,B
INC B
MOVC A,@A+DPTR
JZ IO0020
CALL SENDCHAR
JMP IO0010
IO0020: POP B
POP ACC
RET
;____________________________________________________________________
DEGREES: DB ' degrees C',10,13,0
TITLE: DB 10,10,13,'____________________________________',10,13
DB 'Analog Devices MicroConverter ADuC824',10,13
DB ' Temp Sensor Demo Routine',10,13,0
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -