📄 subroutine.asm
字号:
;;----------------------------------------------------------------------------
INI_RAM: ;;initial bank 0 of ram
CLR BP.0 ;;bp point to bank 0 of ram
XMOV MP0, 60H ;;ram start address 60h
CLR R0
INC MP0
SZ MP0 ;;ram end address ffh
JMP $-3
XMOV INTC0, 01H ;;enable gloable interrupt
XMOV INTC1, 01H ;;enable timer1 interrupt
XMOV TMR0C, 0A0H ;;timer0 mode:timer mode and select system clock source
XMOV TMR1C, 80H ;;timer1 mode:timer mode&mask option clock source
XMOV R_COUN_8, 8
XMOV R_COUN_4, 4
RET
;-------------------------------------------------------------------------------
INI_LCD_RAM: ;;initial bank 1 of ram
SET BP.0 ;;bp point to bank 1 of ram
XMOV MP1, 40H ;;ram start address 40h
CLR R1
INC MP1
EJMP MP1, 60H ;;ram end address 60h
JMP $-5
XMOV MP1, 46H ;;lighten radix point[46h].1(seg6&com1)
SET R1.1
CLR BP
RET
;;-----------------------------------------------------------------------------
INI_IO: ;;initial io
SET P_A ;;initial i/o input port
SET P_B
SET P_C
RET
;;-----------------------------------------------------------------------------
SBR_RT: ;;get the value of RT
XMOV R_P_C, 06H ;;charge with pc.1
CALL L_TEST_T ;;test charge time(T2)
XMOV DATA0, TO0 ;;the average charge time(T2)(to2 to1 to0)
XMOV DATA1, TO1
XMOV DATA2, TO2 ;;multiplicand(data2 data1 data0)
XMOV DATA4, 0AH ;;multiplier(data6 data5 data4)
CLR DATA5
CLR DATA6
CALL UNBIN_MUL_24 ;;T2*RK(10K)
XMOV DATA0, TO0 ;;the result of multiplication(to3 to2 to1 to0)
XMOV DATA1, TO1
XMOV DATA2, TO2
XMOV DATA3, TO3 ;;multiplicand(data3 data2 data1 data0)
XMOV DATA4, 64H ;;multiplier(data7 data6 data5 data4)
CLR DATA5
CLR DATA6
CLR DATA7
CALL UNBIN_MUL_32 ;;T2*10*100
XMOV R_TO0, TO0 ;;the result of multiplication(to3 to2 to1 to0)
XMOV R_TO1, TO1 ;;save
XMOV R_TO2, TO2
XMOV R_TO3, TO3
;;================================================
CLR R_TMR0
CLR R_TMR1
CLR RC_NUM ;;clear for next use
XMOV R_COUN_8, 8
L_AVER4:
XMOV R_P_C, 05H ;;charge with pc.0
CALL L_TEST_T ;;test charge time(T1)
XMOV DATA4, TO0 ;;the average charge time(T1)(to2 to1 to0)
XMOV DATA5, TO1 ;;divisor(data4 data5 data6 data7)
XMOV DATA6, TO2
CLR DATA7
XMOV DATA0, R_TO0 ;;dividend(data3 data2 data1 data0)
XMOV DATA1, R_TO1
XMOV DATA2, R_TO2
XMOV DATA3, R_TO3
CALL UNBIN_DIV_32 ;;devision T2*10*100/T1=RT*100
XADDM R_RT_L, TO0 ;;summation of RT*100
XADCM R_RT_H, TO1
XADCM R_RT, TO3
XMOV R_COUN_8, 8 ;;for next use
CLR R_TMR0
CLR R_TMR1
CLR RC_NUM ;;clear for next use
SDZ R_COUN_4 ;;for 4 times
JMP SBR_RT
RRC R_RT ;; /2
RRC R_RT_H ;; /2
RRC R_RT_L ;; /2
CLR C
RRC R_RT ;; /2
RRC R_RT_H ;; /2
RRC R_RT_L ;; /2 (r_rt_h,r_rt_l)=RT*100=RT'
RET
;;==================================================
L_TEST_T: ;;test charge time
XMOV P_C, 00H ;;discharge completely
CALL DELAY_2mS ;;delay 2mS
CLR R_NUM
SET TMR1C.4
CLR TMR1C.4
CLR TMR0 ;;clear timer0&timer1 preload registor
CLR TMR1
XMOV P_C, R_P_C ;;charge with PC.x port
SET TMR0C.4 ;;timer0 on
SET TMR1C.4 ;;timer1 on
MOV P_C, A
SNZ P_C.2 ;;wait for charge finished
JMP $-2
CLR TMR0C.4 ;;timer0 off
CLR TMR1C.4 ;;timer1 off
CLR C
XADDM R_TMR0, TMR0 ;;the summation of time
XADCM R_TMR1, TMR1
XADCM RC_NUM, R_NUM
SDZ R_COUN_8 ;;for 8 times
JMP L_TEST_T
XMOV DATA0, R_TMR0 ;;dividend(data2 data1 data0)
XMOV DATA1, R_TMR1
XMOV DATA2, RC_NUM
XMOV DATA4, 8 ;;divisor(data4 data5 data6)
CLR DATA5
CLR DATA6
CALL UNBIN_DIV_24 ;;division
RET
;;==================================================
SBR_TEMP_DISPLAY: ;;chart table to get and display the temperature
CLR BP
XMOV TBLP, TEMP_START_ADDR ;;tblp point to the first address of temperature table
L_TABLE_COMPARE:
TABRDL R_TABLE_L ;;low byte of table code->r_table_l
XMOV R_TBLH, TBLH ;;high byte of table code->r_tblh
EJMP TBLH, R_RT_H ;;if RT' equals to the value of table
JMP L_NEQU
EJMP R_TABLE_L, R_RT_L
JMP L_NEQU
XMOV R_TBLP, TBLP
JMP L_EQU
L_EQU: ;;when RT equals to the value of table
SET FLAG_EQU ;;set equal flag
CLR R_DOT
JMP L_ZERO_COMP
L_NEQU: ;;if unequal
CLR FLAG_EQU ;;clr equal flag
XMOV DATA0, R_TABLE_L ;;minuend
XMOV DATA1, R_TBLH
XMOV DATA4, R_RT_L ;;subtrahend
XMOV DATA5, R_RT_H
CALL UNBIN_SUB_16 ;;compare table value with RT
SZ C
JMP L_NEXT ;;if bigger than RT
NEJMP TBLP, TEMP_START_ADDR ;;if less than RT&if tblp point to the biggest RT
JMP L_TEMP_OVER ;;if over the range of table
JMP L_GET_TEMP ;;if not
L_NEXT: ;;tblp point to the next address
NEJMP TBLP, TEMP_END_ADDR ;;if tblp point to the smallest RT
JMP L_TEMP_OVER ;;if excess the range of table
XMOV R_TO0, TO0 ;;if not and save as r_to0
XMOV R_TO1, TO1 ;;save as r_to1
XMOV R_TBLP, TBLP ;;save tblp
INC TBLP ;;point to the next address
JMP L_TABLE_COMPARE ;;compare again
L_GET_TEMP: ;;figure out the temperature
XMOV DATA0, R_RT_L ;;minuend(data1 data0)
XMOV DATA1, R_RT_H
XMOV DATA4, R_TABLE_L ;;subtrahend(data5 data4)
XMOV DATA5, R_TBLH
CALL UNBIN_SUB_16 ;;subtration
XMOV R_NUM1, TO0 ;;save as r_num1
XMOV R_NUM2, TO1 ;;save as r_num2
XMOV DATA0, R_NUM1 ;;augend(data1 data0)
XMOV DATA1, R_NUM2
XMOV DATA4, R_TO0 ;;addend(data5 data4)
XMOV DATA5, R_TO1
CALL UNBIN_ADD_16 ;;addition(r_num2,r_num1)+(r_to1,r_to0)
XMOV R_SUM1, TO0
XMOV R_SUM2, TO1 ;;(r_num2,r_num1)+(r_to1,r_to0)=(r_sum2,r_sum1)
L_ZERO_COMP: ;;compare with zero
EJMP R_RT_H, ZERO_H
JMP L_UNEQU_ZERO
EJMP R_RT_L, ZERO_L
JMP L_UNEQU_ZERO
L_EQU_ZERO: ;;equal to zero
SET BP.0
XMOV MP1, 46H
CLR R1.0 ;;unlighen the sign '-'([46h].0)
JMP L_OVER_LOOP
L_UNEQU_ZERO: ;;uneaual to zero
XMOV DATA0, R_RT_L
XMOV DATA1, R_RT_H
XMOV DATA4, ZERO_L
XMOV DATA5, ZERO_H
CALL UNBIN_SUB_16 ;;RT compares with 0b3a(T vs. 0 degree)
SZ C
JMP L_LOW_ZERO ;;if lower than zero
JMP L_OVER_ZERO ;;if higher than zero
L_LOW_ZERO: ;;if lower than zero
SET BP.0
XMOV MP1, 46H
SET R1.0 ;;lighen the sign '-'([46h].0)
CLR BP
SZ FLAG_EQU ;;judge if or not integer
JMP L_LOW_lOOP ;;if integer
XMOV DATA0, R_NUM1
XMOV DATA1, R_NUM2
CALL L_DOT ;;if not ,then deal with the decimal(T<0)
XMOV R_TBLP, TBLP ;;if T<0 degree,then the address is the smaller one
L_LOW_lOOP: ;;T<0 degree,then [T]=NUM-r_tblp
MOV A, NUM
SUB A, R_TBLP
MOV R_TBLP, A
CLR R_RT_H ;;for next user
JMP L_16_to_10
L_OVER_ZERO: ;;if higer than zero
SET BP.0
XMOV MP1, 46H
CLR R1.0 ;;unlighen the sign '-'([46h].0)
CLR BP
SZ FLAG_EQU ;;judge if or not integer
JMP L_OVER_LOOP ;;if integer
XMOV DATA0, R_TO0
XMOV DATA1, R_TO1
CALL L_DOT ;;if not,then deal with the decimal(T>0)
L_OVER_LOOP: ;;T>0 degree,then [T]=r_tblp-NUM
NEJMP R_TBLP, TEMP_END_ADDR ;;check if the temperature is 100 degree
JMP L_TEMP_100 ;;if 100,then jump
MOV A, R_TBLP ;;if not ,[T]=r_tblp-NUM
SUB A, NUM
MOV R_TBLP, A
CLR R_RT_H
L_16_TO_10: ;;convert T from hex to decimal
LBERJ R_TBLP, 0AH ;;r_tblp-0ah
JMP $+4 ;;if r_tblp-0ah<0
INC R_RT_H ;;if r_tblp-0ah>0
MOV R_TBLP, A
JMP L_16_to_10 ;;(T)H={r_rt_h,r_tblp}D
SET BP.0
XMOV R_ITEM, R_RT_H ;;the number displayed->r_item
XMOV MP1, 40H ;;the adress displayed
CALL L_TEMP_DISLOOP ;;display
INC MP1 ;;the adress displayed
XMOV R_ITEM, R_TBLP ;;the number displayed->r_item
CALL L_TEMP_DISLOOP ;;display
INC MP1 ;;the adress displayed
XMOV R_ITEM, R_DOT ;;the number displayed->r_item
CALL L_TEMP_DISLOOP ;;display
CLR BP
RET ;;return
L_TEMP_100: ;;if T=100,then display 99.9
SET BP.0
XMOV R_ITEM, 9
XMOV MP1, 40H
CALL L_TEMP_DISLOOP ;;display 9
INC MP1
CALL L_TEMP_DISLOOP ;;display 9
INC MP1
CALL L_TEMP_DISLOOP ;;display 9
CLR BP
RET
;;----------------------------------------------------------------------------
L_TEMP_OVER: ;;if over the testing range,then display '---'
SET BP.0
XMOV MP1, 40H
L4: CLR R1 ;;clear [40h]~[46h]
INC MP1
EJMP MP1, 46H
JMP L4
XMOV MP1, 41H ;;display '---'
SET R1.2
INC MP1
INC MP1
SET R1.2
INC MP1
INC MP1
SET R1.2
CLR BP
RET
;;-----------------------------------------------------------------------------
L_DOT: ;;deal with the decimal (num*10/sum)
XMOV DATA4, 0AH ;;*10
CLR DATA5
CALL UNBIN_MUL_16
XMOV DATA0, TO0
XMOV DATA1, TO1
XMOV DATA4, R_SUM1
XMOV DATA5, R_SUM2
CALL UNBIN_DIV_16 ;;/(sum2,sum1)
XMOV R_DOT, TO0 ;;save as r_dot
RET
;;----------------------------------------------------------------------------
L_TEMP_DISLOOP: ;;display a pointed number at a pointed address
CLR TBLP ;;mp1->the pointed address
XADDM TBLP, R_ITEM ;;number displayed->r_item
TABRDL R_TABLE_L
XAND R_TABLE_L, 0FH
MOV R1, A ;;display the number r_item saved
INC MP1
SWAP R_TABLE_L
XAND R_TABLE_L, 0FH
MOV R1, A
RET
;;---------------------------------------------------------------------------
DELAY_2mS: ;;delay about 2mS
XMOV BUF2, 64 ;;recycle for 64 times
SET BUF1 ;;32uS for one time
SDZ BUF1
JMP $-1
SDZ BUF2
JMP $-4
RET
;;--------------------------------------------------------------------------
TABLE0 .SECTION AT 0F00H 'CODE' ;;the displayed code of number0~9
DC 03FH, 006H, 05BH, 04FH ;;0,1,2,3
DC 066H, 06DH, 07DH, 007H ;;4,5,6,7
DC 07FH, 06FH ;;8,9
TABLE_TEMPERATURE.SECTION AT 0F0AH 'CODE'
DC 22668,21384,20183,19058,18005,17018,16093,15225,14411,13646 ;;-40~-31
DC 12928,12232,11578,10964,10387,09845,09335,08855,08404,07979 ;;-30~-21
DC 07578,07196,06835,06496,06175,05873,05588,05318,05064,04823 ;;-20~-11
DC 04596,04378,04172,03977,03793,03619,03454,03297,03148,03008 ;;-10~-9
DC 02874,02746,02624,02509,02399,02295,02196,02102,02013,01928 ;;0~9
DC 01848,01770,01696,01626,01559,01495,01435,01377,01322,01269 ;;10~19
DC 01219,01171,01125,01082,01040,01000,00962,00925,00890,00856 ;;20~29
DC 00824,00793,00764,00735,00708,00683,00658,00634,00612,00590 ;;30~39
DC 00569,00549,00530,00511,00494,00477,00460,00447,00430,00415 ;;40~49
DC 00402,00388,00375,00362,00350,00339,00328,00317,00307,00297 ;;50~59
DC 00288,00278,00270,00261,00253,00245,00238,00230,00223,00217 ;;60~69
DC 00210,00204,00198,00192,00186,00181,00175,00170,00165,00161 ;;70~79
DC 00156,00152,00147,00143,00139,00135,00131,00128,00124,00121 ;;80~89
DC 00118,00113,00111,00108,00105,00103,00100,00097,00095,00092 ;;90~99
DC 00090 ;;100
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -