@maychang
做减法时当然要将数据放到工作寄存器里,但采样后数据不一定放在工作寄存器里,完全可以放到片内RAM里.两个数据要和一个值比较,这个值是什么类型?如果是立即数,当然是在程序里,也就是在ROM里.
我是将两个A/D口采样的电压值转换成16进制数分高8位,低8位放在4个寄存器里面,再和一个电压(16进制)比较,即相减!
LD Acc1, #1 ; 1th channel
LD Acc0, #6 ; 6 sample times
CALL AdcConvert
LD Acc0, #6 ; 6 adjust number
CALL AdcDataAdjust
CALL AverageValue
LD CellVoltageL, AverageValueL
LD CellVoltageH, AverageValueH
LD Acc9, CellVoltageL
LD Acc10, CellVoltageH
;---------------
LD Acc1, #0 ; 0th channel
LD Acc0, #6 ; 6 sample times
CALL AdcConvert
LD Acc0, #6 ; 6 adjust number
CALL AdcDataAdjust
CALL AverageValue
LD CellVoltageL, AverageValueL
LD CellVoltageH, AverageValueH
LD Acc7, CellVoltageL
LD Acc8, CellVoltageH
SUB Acc9, Acc7
SBC Acc10, Acc8
SUB Acc9, #>41 ; 0.2v
SBC Acc10, #<41
JR ULT, CJV_Down_0v2
INC Counter_Up_0v2
CP Counter_Up_0v2,#2 ;
JR ULT, DCC_Exit
LD Counter_OutputUp, #51h
JR CJV_Exit
CJV_Down_0v2:
CLR Counter_OutputUp
CLR Counter_Up_0v2
CJV_Exit:
RET