📄 temp_adc.asm
字号:
;***Temperature measurement system***
$MOD51 ;variables declaration
aux1 equ 0a2h
count equ 10h
disp_data equ 11h ;lcd data variable
lcdcom equ 12h ;lcd command variable
counter equ 13h
scroll equ 14h
sampleno2 equ 18h ;3 digit sample no variables
sampleno1 equ 19h
sampleno0 equ 1ah
interval1 equ 21h ;2 digit recording interval
interval0 equ 22h
threshold1 equ 23h ;2 digit threshold value in degree celcius
threshold0 equ 24h
tval1 equ 25h ;2 digit temperature value in degree celcius
tval0 equ 26h
temp equ 29h
t3 equ 38h ;temperory variables
t2 equ 39h
t11 equ 3ah
t00 equ 3bh
hex1 equ 3ch
hex0 equ 3dh
m641 equ 3eh
m640 equ 3fh
out7 equ 40h
out6 equ 41h
out5 equ 42h
out4 equ 43h
out3 equ 44h
out2 equ 45h
out1 equ 46h
out0 equ 47h
TMP_3 equ 48h
TMP_2 equ 49h
TMP_1 equ 4ah
TMP_0 equ 4bh
rem1 equ 4ch
rem0 equ 4dh
Ekey equ 0a0h ;input keys address location
dkey equ 0a1h
ukey equ 0a2h
led1 equ 0a3h
buzzer equ 0a4h ;buzzer location
intr equ 0a5h ;ADC handle shake signals address location
wrr equ 0a6h
rdd equ 0a7h
adc_data equ 80h ;ADC data 1 byte bus address
org 0000h
start_program:
mov sp,#50h
clr led1 ;reset leds and buzzer
clr buzzer
mov count,#00h
mov counter,#00h
lcall lcd_initialize ;initialize lcd
lcall delay14m
lcall welcome_msg ;welcome strings display
lcall clear_lcd
mov dptr,#0730h ;string "Enter parameters" display on LCD
lcall display_text
lcall delay1sec
lcall cursoron ;display cursor on LCD
clr ri
mov interval1,#30h
mov interval0,#31h ;Initialize recording interval to 01 sec
lcall clear_lcd ;clear the LCD
mov dptr,#0740h ;string "measuring interval" display on lcd"
lcall display_text
lcall delay14m
mov lcdcom,#0c5h ;set cursor position
lcall command ;routine to command the LCD
mov disp_data,interval1
lcall data_routine ;routine to display a ASCII character on the current LCD cursor position
mov disp_data,interval0
lcall data_routine
mov disp_data,#' '
lcall data_routine
mov disp_data,#'s'
lcall data_routine
mov disp_data,#'e'
lcall data_routine
mov disp_data,#'c'
lcall data_routine
again_keyi:
mov lcdcom,#0c6h
lcall command
setb ukey ;Scanning the input keys
setb dkey
setb Ekey
upi: jb ukey,downi ;UP key
mov a,#01h
lcall intfound ;routine to keep measuring interval in range from 01 to 99 secs
sjmp Enteri
downi: jb dkey,Enteri ;DOWN key
mov a,#02h
lcall intfound
Enteri: jb Ekey,again_keyi ;Enter key
lcall delay140m ;debouncing delay
lcall delay140m
clr ri
mov threshold1,#32h ;initialize threshold value of temperature to 20 degree celcius
mov threshold0,#30h
lcall clear_lcd
mov dptr,#0750h ;string "threshold value" display on LCD
lcall display_text
mov lcdcom,#0c5h
lcall command
mov disp_data,threshold1
lcall data_routine
mov disp_data,threshold0
lcall data_routine
mov disp_data,#' '
lcall data_routine
mov disp_data,#'C'
lcall data_routine
nop
again_keyt:
mov lcdcom,#0c6h
lcall command
setb ukey
setb dkey
setb Ekey
upt: jb ukey,downt
mov a,#01h
lcall thfound ;routine to keep threshold value from 20 to 49 degree celcius
sjmp Entert
downt: jb dkey,Entert
mov a,#02h
lcall thfound
Entert: jb Ekey,again_keyt
lcall delay140m
lcall delay140m
lcall clear_lcd
mov dptr,#0760h ;string "Parameter saved" display on LCD
lcall display_text
lcall delay1sec
start_sample:
mov sampleno0,#30h ;initializing no of samples to zero
mov sampleno1,#30h
mov sampleno2,#30h
lcall clear_lcd
mov dptr,#0770h ;string "temperature" display on LCD
lcall display_text
mov lcdcom,#0c0h
lcall command ;string "samples no." dispaly on LCD
mov dptr,#0780h
lcall display_text
lcall cursoroff ;make cursor off
sample_again: nop
no_Ser: lcall start_adc ;start the adc to measure temp
lcall read_adc ;read adc byte
lcall get_temp ;convert adc byte into temperature and record into the flash
lcall update_sample ;increase no of samples by one
lcall show_temp ;display temp on lcd
lcall check_thsold ;compare the temperature with the threshold value
lcall wait_time ;waiting time according to recording interval
ljmp sample_again
;***SUBROUTINES*** start the conversion of ADC.
start_adc: ;conversion frequency is around 640KHz
clr led1
clr wr
lcall delay14m
setb wr
setb intr
ret
read_adc: ;read the digital output from ADC
mov adc_data,#0ffh
adc_not:lcall delay14m
setb rdd
clr rdd
mov a,adc_data
setb intr
setb rdd
mov temp,a
ret
get_temp:;convert adc digital output into temperature
lcall calculations ;and store its 2 digit value into flash
mov tval1,out2 ;current temp value in tval1 and tval0
mov tval0,out1
gett_over:
ret
update_sample: ;routine increase number of samples by one
anl sampleno0,#0fh
anl sampleno1,#0fh
anl sampleno2,#0fh
mov t3,#00h
mov t2,sampleno2
mov t11,sampleno1
mov t00,sampleno0
lcall dec_to_hex ;convert decimal to hexadecimal value
clr c
mov a,hex0 ;add one to hex value of no of samples
add a,#01h
mov hex0,a
mov a,hex1
addc a,#00h
mov hex1,a
mov t3,#00h
mov t2,#00h
mov t11,hex1
mov t00,hex0
lcall hex_to_dec ;convert hex value to decimal number
mov sampleno2,out2
mov sampleno1,out1
mov sampleno0,out0
ret
show_temp: ;routine to display 2 digit temperature to LCD
mov lcdcom,#8bh
lcall command
mov disp_data,#':'
lcall data_routine
mov disp_data,tval1
lcall data_routine
mov disp_data,tval0
lcall data_routine
mov disp_data,#' '
lcall data_routine
mov disp_data,#'C'
lcall data_routine
mov lcdcom,#0cbh
lcall command
mov disp_data,#':'
lcall data_routine
mov disp_data,sampleno2
lcall data_routine
mov disp_data,sampleno1
lcall data_routine
mov disp_data,sampleno0
lcall data_routine
ret
check_thsold:;routine compare temp value with threshold values
mov a,tval1
anl a,#0fh
mov b,#0ah
mul ab
mov r0,a
mov a,tval0
anl a,#0fh
add a,r0
mov r1,a ;hex value of current temperature
mov a,threshold1
anl a,#0fh
mov b,#0ah
mul ab
mov r0,a
mov a,threshold0
anl a,#0fh
add a,r0 ;hex value of threshold temperature
clr c
subb a,r1
jnc temp_notmore
temp_more:
setb buzzer ;Buzzer on if current temperature more than threshold value
sjmp check_over
temp_notmore: clr buzzer ;Buzzer off if current temperature more than threshold value
check_over: ret
wait_time: ;This routine is used to provide measuring interval delay
clr wrr
clr ri
setb led1
mov a,interval1
anl a,#0fh
cjne a,#00h,not_zero
sjmp lsb_digit
not_zero: mov b,#0ah
mul ab
mov r0,a
setb Ekey
herer0: mov r3,#04h
here1_i1: mov r4,#0E0h
here2_i2: mov r5,#0ffh
here3_i3: nop
nop
nop
djnz r5,here3_i3
djnz r4,here2_i2
djnz r3,here1_i1
djnz r0,herer0
lsb_digit:
mov a,interval0
anl a,#0fh
cjne a,#00h,not_zero1
sjmp wait_over
not_zero1: mov r0,a
herer01:mov r3,#04h
here1_ii1:mov r4,#0e0h
here2_ii2:mov r5,#0ffh
here3_ii3: nop
djnz r5,here3_ii3
djnz r4,here2_ii2
djnz r3,here1_ii1
djnz r0,herer01
wait_over: clr led1
lcall delay140m
lcall delay140m
setb wrr
ret
welcome_msg: ;This routine displays the welcome message at power on
nop
scrolling: ;startting cursor position from where scrolling starts
mov scroll,#8fh
scrollagain:
lcall clear_lcd
lcall cursoroff
mov lcdcom,scroll
lcall command
mov dptr,#700h ;string "Major project" display on LCD
lcall display_text
mov a,scroll
dec a
mov scroll,a
lcall delay140m
cjne a,#7fh,scrollagain
lcall delay1sec
lcall delay1sec
lcall clear_lcd
mov r2,#00h
flash_again:
mov dptr,#710h ;string "Data acquisition" dispaly on LCD
lcall display_text
lcall delay14m
mov lcdcom,#0c0h
lcall command
mov dptr,#0720h ;string "System" display on second line of LCD
lcall display_text
lcall delay1sec
lcall delay140m
lcall clear_lcd
lcall delay140m
lcall delay140m
lcall delay140m
inc r2
mov a,r2
cjne a,#02h,flash_again ;message on LCD blinks fro 2 times
ret
calculations: ;routine converts the adc 8 bit output to 2-digit temperature value in ASCII
mov a,temp
mov b,#0ah
div ab
mov out2,a
mov out1,b
orl out2,#30h
orl out1,#30h
ret
division_16: ;32 bit by 16 bit division
MOV R7,#0 ;msb remiander
MOV R6,#0 ;lsb remiander ;zero out partial remainder
MOV TMP_0,#0
MOV TMP_1,#0
MOV TMP_2,#0
MOV TMP_3,#0
MOV R1,hex1 ;load divisor
MOV R0,hex0
MOV R5,#32 ;loop count
Div_loop:
LCALL Shift_D ;shift the dividend and return MSB in C
MOV A,R6 ;shift carry into LSB of partial remainder
RLC A
MOV R6,A
MOV A,R7
RLC A
MOV R7,A
CLR C
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -