📄 adconvert.asm
字号:
;**********************************************
;Name :mnchkad
;Function:use this subroutine to check ad value
; 采样10次,去掉最大值和最小值,求中间8次平均值
;Input :
;Output :
;Register Used:
;***********************************************
mnchkad:
b0bts0 convertingflag
jmp convertagain
bset convertingflag
bclr secondminflag
bclr secondmaxflag
mov a,#10
mov adtimesbuf,a
mov_ tempmaxh,#00h
mov_ tempmaxl,#00h
mov_ tempminh,#0fh
mov_ tempminl,#0ffh
mov_ y,#00h
mov a,#data_addr
mov z_temp,a
mov z,a
;-------------------------------------------------------
convertagain:
mov a,#0
mov y,a
mov a,z_temp
mov z,a
;---------
mov a,#90h
mov adm,a ;enable an0
mov a,#01h
mov p4con,a ;isolate an0
b0bset fads ;start convert
waitadc1:
b0bts1 feoc ;check finish convert or not?
jmp waitadc1
;---
bclr feoc
mov a,adr
and a,#0fh
mov adbbufl,a
mov a,adb
mov adbbufh,a
;----
;set ad11~ad0
swapm adbbufh ;adjust ad_value position
mov a,adbbufh
and a,#0f0h
or adbbufl,a
mov a,adbbufh
mov a,#0fh
and adbbufh,a
;-----
mov a,adbbufh
sub a,tempminh
b0bts0 fc
jmp comparelow
storeminvalue:
b0bts1 secondminflag
jmp reloadminvalue
mov_ @yz,tempminh
incms z
nop
mov_ @yz,tempminl
incms z
nop
mov_ z_temp,z
reloadminvalue:
bset secondminflag
mov_ tempminh,adbbufh
mov_ tempminl,adbbufl
jmp mnchktemp90
;-----
comparelow:
b0bts1 fz
jmp comparemax
mov a,adbbufl
sub a,tempminl
b0bts0 fc
jmp checkfz
jmp storeminvalue
;-----
checkfz:
b0bts1 fz
jmp comparemax
jmp storeminvalue
;-------------------------------
comparemax:
mov a,adbbufh
sub a,tempmaxh
b0bts1 fc
jmp storevalue
b0bts1 fz
jmp storemaxvalue
mov a,adbbufl
sub a,tempmaxl
b0bts1 fc
jmp storevalue
;---
storemaxvalue:
b0bts1 secondmaxflag
jmp reloadmaxvalue
mov_ @yz,tempmaxh
incms z
nop
mov_ @yz,tempmaxl
incms z
nop
mov_ z_temp,z
reloadmaxvalue:
bset secondmaxflag
mov_ tempmaxh,adbbufh
mov_ tempmaxl,adbbufl
jmp mnchktemp90
;----
storevalue:
mov_ @yz,adbbufh
incms z
nop
mov_ @yz,adbbufl
incms z
nop
mov_ z_temp,z
;-----------------------
mnchktemp90:
mov a,adtimesbuf
b0bts0 fz
jmp startchecktemp00
decms adtimesbuf
jmp mnchktemp110
startchecktemp00:
clr z_temp
bclr convertingflag
mov a,#7
b0mov var4,a
mov_ y,#00h
mov_ z,#data_addr
mov_ tempvalueh,@yz
incms z
nop
mov_ tempvaluel,@yz
addnextdata:
incms z
nop
incms z
nop
mov a,@yz
add tempvaluel,a
decms z
nop
mov a,@yz
adc tempvalueh,a
incms z
nop
decms var4
jmp addnextdata
;------
comparevalue:
bclr fc
rrcm tempvalueh
rrcm tempvaluel
;-----
bclr fc
rrcm tempvalueh
rrcm tempvaluel
;-----
bclr fc
rrcm tempvalueh
rrcm tempvaluel
mov a,#11110111b
and tempvaluel,a
;******************************************************
;******************************************************
/*
;开启,每进来一次,新值跟旧值比较,新值=旧值±2,不重新赋值;超出,旧值=新值
b0bts0 checkflag
jmp checkdata00
bset checkflag
mov a,tempvaluel
mov tempolddata,a
jmp mnchktemp110
checkdata00:
mov a,tempvaluel
sub a,tempolddata
b0bts1 fc
jmp checkdata01
b0bts0 fz
jmp checkdata02
sub a,#3
b0bts1 fc
jmp checkdata02
bclr checkflag
jmp mnchktemp110
;---
checkdata01:
add a,#2
b0bts0 fz
jmp checkdata02
sub a,#1
b0bts0 fz
jmp checkdata02
bclr checkflag
jmp mnchktemp110
;----
checkdata02:
mov a,tempolddata
and a,#00000111b
mov temp0,a
mov a,tempvaluel
and a,#11110000b
or a,temp0
mov tempvaluel,a
*/
bclr convertingflag
mnchktemp100:
bset overflag
mnchktemp110:
ret
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -