您当前的位置:五五电子网电子知识单片机-工控设备MSP430单片机MSP430超声波测距 正文
MSP430超声波测距

MSP430超声波测距

点击数:7426 次   录入时间:03-04 11:57:49   整理:http://www.55dianzi.com   MSP430单片机
             MOV .w   #0h, DIGITS             ; Initialise DIGIT to 0
             cmp.w   #0h, Result             ; Check if Result count=0
             jeq     calc_over               ; Exit if 0
             call    #Mul100                 ; Multiply Result count by 100
             call    #Divide                 ; Divide the result with #06d
             call    #Hex2bcd                ; Convert 16bit binary to BCD number
                                             ; Result xx.xx                          
calc_over    ret                             ; Return from subroutine                
;******************************************************************************
Mul100       ;subroutine for multiplying Result with 100d
             ;inputs Result 16bit and constant 64h (100d) 16bit
             ;output 32bit htX100_msw & htX100_lsw
;******************************************************************************             
             MOV .w   #100,IROP1              ; Load IROP1 with 100 (multiplier)
mpyu         clr.w   htX100_lsw              ; Clear buffer for least
                                             ; signifiCANt word
             clr.w   htX100_msw              ; Clear buffer for most
                                             ; significant word
macu         clr.w   IROP2M                  ; Clear multiplier high word
L$002        bit.w   #1,IROP1                ; Test actual bit
             jz      L$01                    ; If 0: do nothing
             add.w   Result,htX100_lsw       ; If 1: Add multiplier to Result
             addc.w  IROP2M,htX100_msw       ;
L$01         rla.w   Result                  ; Multiplier X 2
             rlc.w   IROP2M                  ;
             rrc.w   IROP1                   ; Next bit to test
             jnz     L$002                   ; If bit in carry : finished                                  
             ret
;******************************************************************************
Divide       ;Subroutine for 32/16 bits division
             ;inputs 32bit htX100_msw & htX100_lsw and #06 16bit, output DIGIT 16bit
;******************************************************************************
             clr.w   DIGITS                  ; Clear buffer to hold new Result
             MOV .w   #17,IRBT                ; Initialize loop counter
div1         cmp.w   #06,htX100_msw          ; Compare divisor with dividend high word
             jlo     div2                    ; If less : jump to div2
             sub.w   #06,htX100_msw          ; Subtract 6 from high word  
div2         rlc.w   DIGITS                  ; Rotate result left through carry 1 bit
             jc      div4                    ; If carry set: finished
             dec.w   IRBT                    ; Decrement bit counter
             jz      div3                    ; If counter = 0 : finished
             rla.w   htX100_lsw              ; Dividend X 2
             rlc.w   htX100_msw              ;
             jnc     div1                    ; If carry not set jump to step div1
             sub.w   #06,htX100_msw          ; Subtract 6 from high word
             setc                            ; Set carry
             jmp div2                        ; Jump to repeat
div3         clrc                            ; Clear carry
div4         ret                             ; Return from subroutine

上一页  [1] [2] [3] [4] [5] [6] [7]  下一页


本文关键字:超声波  MSP430单片机单片机-工控设备 - MSP430单片机