⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 st7.txt

📁 st7 mcu programming example
💻 TXT
📖 第 1 页 / 共 2 页
字号:
ld A,tempquot ; Test is left dividend is greater or equal
or A,{tempquot+1} ; to the divisor
jrne dividendlsgreater
ld A,{tempquot+2}
cp A,divisor
jrugt dividendlsgreater
jrult nosubstract
ld A,{tempquot+3}
cp A,{divisor+1}
jrult nosubstract
.dividendlsgreater ; Substract divisor from left dividend
ld A,{tempquot+3}
sub A,{divisor+1}
ld {tempquot+3},A
ld A,{tempquot+2}
sbc A,divisor
ld {tempquot+2},A
ld A,{tempquot+1}
sbc A,#0
ld {tempquot+1},A
ld A,tempquot
sbc A,#0
ld tempquot,A
inc {quotient+1} ; The result cannot be greater than 16 bits
jrne nosubstract ; so we can increment the quotient
inc quotient
.nosubstract
dec X ; Decrement loop counter
jrne execute ; if X = 0 then exit else continue
pop X ; restore contexte before the CALL
pop A ; restore contexte before the CALL
ret ; and go back to main program
;+--------------------------------------------------------------------------
;| ADDITION A + B |
;| |
;| DATE : 22/11/96 |
;| REVISION : V01.00 |
;| |
;| SOFTWARE DESCRIPTION : This routine adds two 16 bit numbers, A and |
;| B, the result is saved in two 8 bits registers.|
;| The carry flag indicates any overflow. |
;| |
;| INPUT PARAMETERS : ADD_A registers contain the number A. |
;| ADD_B registers contain the number B. |
;| |
;| OUTPUT PARAMETERS : RES_ADD register contains the result. |
;| |
;| BYTE : 17 bytes |
;| |
;| EXAMPLE : ;***** program ***** |
;| ld A,#$F3 |
;| ld add_a,A |
;| ld A,#$D3 |
;| ld {add_a+1},A |
;| ld A,#$FC |
;| ld add_b,A |
;| ld A,#$C3 |
;| ld {add_b+1},A |
;| CALL addw |
;| - do... |
;| - do... |
;| ;***** subroutine ***** |
;| . addw |
;| END |
;| |
;+--------------------------------------------------------------------------
.addw
push A ; save Accumulator in stack
push X ; save X register in stack
ld A,{add_a+1} ; get number A’ LSB
add A,{add_b+1} ; add number B’ LSB
ld {res_add+1},A; store LSB
ld A,add_a ; get number A’ MSB
adc A,add_b ; add number B’ MSB with LSB’s carry
ld res_add,A ; store MSB
pop X ; restore context before the CALL
pop A ; restore context before the CALL
ret ; and go back to main program
;+--------------------------------------------------------------------------
;| SUBSTRACTION A - B |
;| |
;| DATE : 22/11/96 |
;| REVISION : V01.00 |
;| |
;| SOFTWARE DESCRIPTION : This routine substracts two 16 bit numbers, A |
;| and B, the result is saved in two 8 bits |
;| registers. The carry flag indicates any |
;| overflow. |
;| |
;| INPUT PARAMETERS : sub_A registers contain the number A. |
;| sub_B registers contain the number B. |
;| |
;| OUTPUT PARAMETERS : RES_sub register contain the result. |
;| |
;| BYTE : 17 bytes |
;| |
;| EXAMPLE : ;***** program ***** |
;| ld A,#$F3 |
;| ld sub_a,A |
;| ld A,#$D3 |
;| ld {sub_a+1},A |
;| ld A,#$FC |
;| ld sub_b,A |
;| ld A,#$C3 |
;| ld {sub_b+1},A |
;| CALL subw |
;| - do... |
;| - do... |
;| ;***** subroutine ***** |
;| .subw |
;| END |
;| |
;+--------------------------------------------------------------------------
.subw
push A ; save Accumulator in stack
push X ; save X register in stack
ld A,{sub_a+1} ; get number A’ LSB
sub A,{sub_b+1} ; sub number B’ LSB
ld {res_sub+1},A; store LSB
ld A,sub_a ; get number A’ MSB
sbc A,sub_b ; sub number B’ MSB with LSB’s carry
ld res_sub,A ; store MSB
pop X ; restore context before the CALL
pop A ; restore context before the CALL
ret ; and go back to main program
;+--------------------------------------------------------------------------
;| CHECK MIN / MAX |
;| |
;| DATE : 22/11/96 |
;| REVISION : V01.00 |
;| |
;| SOFTWARE DESCRIPTION : This routine tests if a 16-bit number |
;| is within a predefined range. |
;| |
;| MIN =< DATA =< MAX |
;| |
;| INPUT PARAMETERS : DATA registers contain the number to test. |
;| MIN registers contain the minimum value. |
;| MAX registers contain the maximum value. |
;[ |
;| OUTPUT PARAMETERS : The C flag is updated according to the result. |
;| C=1 means that the test has failed. |
;| |
;| BYTE : 32 bytes |
;| |
;| EXAMPLE : ;***** program ***** |
;| ld A,#$25 |
;| ld data,A |
;| ld A,#$00 |
;| ld {data+1},A |
;| ld A,#$00 |
;| ld min,A |
;| ld A,#$C3 |
;| ld {min+1},A |
;| ld A,#$CC |
;| ld max,A |
;| ld A,#$05 |
;| ld {max+1},A |
;| CALL check_min_max |
;| - do... |
;| - do... |
;| ;***** subroutine ***** |
;| .check_min_max |
;| END |
;| |
;+--------------------------------------------------------------------------
.check_min_max
push A ; save Accumulator in stack
push X ; save X register in stack
ld X,data ; get DATA MSB in X
ld A,{data+1} ; get DATA LSB in A
cp X,max ; Compare MSB with MAX
jrugt out_of_range ; if greater than exit
jrne comp_min ; else if equals compare LSB
cp A,{max+1}
jrugt out_of_range; LSB greater than exit
comp_min
cp X,min ; same thing with the LSB and the min value
jrult out_of_range
jrne in_range
cp A,{min+1}
jrult out_of_range
in_range
rcf ; Value in range so reset C flag
jra exit ; the value is within the two values
out_of_range
scf ; Value out of range so set C flag
exit
pop X ; restore contexte before the CALL
pop A ; restore contexte before the CALL
ret ; and go back to main program
;+--------------------------------------------------------------------------
;| CHECK RANGE for a WORD |
;| |
;| DATE : 22/11/96 |
;| REVISION : V01.00 |
;| |
;| SOFTWARE DESCRIPTION : This routine tests if a 16-bit number |
;| is within a predefined range |
;| |
;| MEDIAN - DELTA =< DATA =< MEDIAN + DELTA |
;| |
;| INPUT PARAMETERS : DATA registers contain the number to test. |
;| MEDIAN registers contain the median value. |
;| DELTA registers contain the delta value to add |
;| and subtract to the MEDIAN value. |
;[ |
;| OUTPUT PARAMETERS : The C flag is updated according to the result. |
;| C=1 means that the test has failed. |
;| |
;| |
;| NOTES: This routines uses three previous sub routines.|
;| |
;| check_min_max |
;| addw |
;| subw |
;| |
;| |
;| BYTE : 66 bytes |
;| |
;| EXAMPLE : ;***** program ***** |
;| ld A,#$25 |
;| ld data,A |
;| ld A,#$00 |
;| ld {data+1},A |
;| ld A,#$00 |
;| ld delta,A |
;| ld A,#$23 |
;| ld {delta+1},A |
;| ld A,#$CC |
;| ld median,A |
;| ld A,#$05 |
;| ld {median+1},A |
;| CALL check_range |
;| - do... |
;| - do... |
;| ;***** subroutine ***** |
;| .addw |
;| .subw |
;| .check_min_max |
;| .check_range |
;| END |
;+--------------------------------------------------------------------------
.check_range
push X
push A
ld A,median ; get MSB value and store it in
ld add_a,A ; add_a and sub_a for the words
ld sub_a,A ; subroutines (addw and subw)
ld A,{median+1} ; Same thing for the LSB
ld {add_a+1},A
ld {sub_a+1},A
ld A,delta ; The second operand is for delta.
ld add_b,A
ld sub_b,A
ld A,{delta+1}
ld {add_b+1},A
ld {sub_b+1},A
call addw ; Compute Median + delta
jrnc no_ovfmax ; test if an overflow occurred
ld A,#$FF ; if yes then the MAX value is set to FFFFh
ld max,A ; (saturation)
ld {max+1},A
no_ovfmax
ld A,res_add ; else there is no overflow, then
ld max,A ; the computed value is the MAX value to keep.
ld A,{res_add+1}
ld {max+1},A
call subw ; Compute Median - delta
jrnc no_ovfmin ; test if an overflow occured
clr A ; if yes then the MIN value is set to 0000h
ld min,A ; (saturation)
ld {min+1},A
no_ovfmin
ld A,res_sub ; else there is no overflow, then
ld min,A ; the computed value is the MIN value to keep.
ld A,{res_sub+1}
ld {min+1},A
call check_min_max ; Then we check if the value is within the range
; set by max and min.
pop A ; restore context before the CALL
pop X ; restore context before the CALL
ret ; The result depends on the C flag.
;+--------------------------------------------------------------------------
;| Binary to Decimal Conversion |
;| |
;| DATE : 25/11/96 |
;| REVISION : V01.00 |
;| |
;| SOFTWARE DESCRIPTION : This routine performs a BCD (binary to decimal)|
;| conversion. |
;| |
;| |
;| INPUT PARAMETERS : Value (to convert) stored in the accumulator. |
;| |
;| |
;| |
;| OUTPUT PARAMETERS : Hundreds register holds the number of hundreds|
;| Tens register holds the number of both tens |
;| (in the high nibble) and the number of units |
|
;| in the low nibble) |
;| EXAMPLE: If A=D4h (212d) the routine will output the |
;| following results: |
;| |
;| Hundreds: 02 and Tens: 12 |
;| || |
;| tens| |
;| units |
;| |
;| BYTE : 31 bytes |
;| |
;| EXAMPLE : ;***** program ***** |
;| ld A,#$D4 |
;| CALL BtoD |
;| - do... |
;| - do... |
;| ;***** subroutine ***** |
;| .BtoB |
;| END |
;+--------------------------------------------------------------------------
.BtoD
clr hundreds ; clear registers used
clr tens
hund sub A,#100 ; A = A - 100
jrc ten ; Test if A < 100
inc hundreds ; No then hundreds = hundreds + 1
jra hund ; and loop
ten add A,#100 ; Add 100 to set off last subtraction
temp sub A,#10 ; A = A - 10
jrc unit ; Test if A < 10
inc tens ; No then tens = tens + 1
jra temp ; and loop
unit add A,#10 ; Add 10 to set off last subtraction
swap tens ; swap nibbles (MSB nibble = TENS)
OR A,tens ; use mask to keep MSB nibble
ld tens,A ; store the tens/units value (LSB nibble = Units)
; in one byte
ret ; End of sub routine
segment ‘vectit’
DC.W dummy ;FFE0-FFE1h location
DC.W dummy ;FFE2-FFE3h location
.i2c_it DC.W i2c_rt ;FFE4-FFE5h location
DC.W dummy ;FFE6-FFE7h location
DC.W dummy ;FFE8-FFE9h location
DC.W dummy ;FFEA-FFEBh location
DC.W dummy ;FFEC-FFEDh location
.timb_it DC.W timb_rt;FFEE-FFEFh location
DC.W dummy ;FFF0-FFF1h location
.tima_it DC.W tima_rt;FFF2-FFF3h location
.spi_it DC.W spi_rt ;FFF4-FFF5h location
DC.W dummy ;FFF6-FFF7h location
.ext1_it DC.W ext1_rt;FFF8-FFF9h location
.ext0_it DC.W ext0_rt;FFFA-FFFBh location
.softit DC.W sw_rt ;FFFC-FFFDh location
.reset DC.W main ;FFFE-FFFFh location
; This last line refers to the first line.
; It used by the compiler/linker to determine code zone
END ; Be aware of the fact that the END directive should not
; stand on the left of the page like the labels’s names.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -