📄 lf_pwm.asm
字号:
; |
; Calls subroutines: |
; LF.Send_Clamp_One |
; AFE.SendCMDClampON |
; SPI.Write |
; Delay.WaitFor |
; AFE.SendCMDClampOFF |
; SPI.Write |
; LF.Send_Clamp_Zero |
; AFE.SendCMDClampON |
; SPI.Write |
; Delay.WaitFor |
; AFE.SendCMDClampOFF |
; SPI.Write |
; |
; |
; Stacklevel: 3 |
; |
;------------------------------------------------------------------------------+
LF.Send8
banksel LF.Buffer
movwf LF.Buffer
movlw .8 ; number of bits to receive
movwf LF.COUNTER ; load number of bits into counter register
SendNext
btfsc LF.Buffer,0 ; Check if Data Bit = 1
Call LF.Send_Clamp_One ; ... Yes, then send LF Clamp One
banksel LF.Buffer
btfss LF.Buffer,0 ; Check if Data Bit = 0
Call LF.Send_Clamp_Zero ; ... Yes, then send LF Clamp Zero
banksel LF.Buffer
rrf LF.Buffer,1 ; Right Rotate Data Register to get next bit
decfsz LF.COUNTER, f ; Decrement receive count register by one
goto SendNext ; ... no, then receive next bit
AFE.SendCMDClampOFF
return
;------------------------------------------------------------------------------+
; |
; LF.SendBuffer( w FSR ) |
; |
;------------------------------------------------------------------------------+
; |
; This function sends a complete data buffer to the air. |
; The Buffer has to be on Bank0 or Bank1 |
; |
; |
; Parameters: |
; w - The amount of bytes to be sent |
; FSR - The start address of the buffer |
; |
; |
; |
; Used SFRs: Delay.Returned |
; |
; |
; Calls subroutines: |
; LF.Send8 |
; LF.Send_Clamp_One |
; AFE.SendCMDClampON |
; SPI.Write |
; Delay.WaitFor |
; AFE.SendCMDClampOFF |
; SPI.Write |
; LF.Send_Clamp_Zero |
; AFE.SendCMDClampON |
; SPI.Write |
; Delay.WaitFor |
; AFE.SendCMDClampOFF |
; SPI.Write |
; |
; |
; Stacklevel: 4 |
; |
; |
; Example: |
; movlw SerialNumber ;move start address to w |
; movwf FSR ;write start address to fsr |
; movlw 0x04 ;move number of bytes to transmit to w |
; call AFE.SendBuffer ;send it via LF-Talkback |
; |
; |
; Description: |
; This sends 4 bytes of the buffer "SerialNumber" to the air |
; |
;------------------------------------------------------------------------------+
LF.SendBuffer
banksel LF.TEMP
movwf LF.TEMP
LF.SendBuffer.loop
bankisel PORTA
movf INDF,w
call LF.Send8
incf FSR,f
decfsz LF.TEMP,f
goto LF.SendBuffer.loop
return
;------------------------------------------------------------------------------+
; |
; LF.DetectFalling() |
; |
;------------------------------------------------------------------------------+
; |
; Internal use only. |
; This function detects a falling edge on the LF input pin. |
; It will debounce this pin with the given timing constants. |
; |
; |
; |
; Used SFRs: TMR0 |
; |
; |
; Stacklevel: 1 |
; |
;------------------------------------------------------------------------------+
LF.DetectFalling
banksel Counter
movlw (LF.T_NOISE_MAX/(LF.T_INST*.9))+1
movwf Counter ; initialize debounce counter
movlw (.115*LF.T_PERIOD_MAX/(.100*LF.T_INST*PRESCALER))+1 ;
banksel TMR0
subwf TMR0,w ; over maximum period time?
btfsc STATUS,C
goto Return.Fail ; yes, then return 0
btfsc INTCON,T0IF ; As there is a resonant frequency in this routine
goto Return.Fail ; Check also absolute timing
LF.DetectFalling.Debounce
banksel LF.PORT
btfsc LFDATA ; is pin low?
goto LF.DetectFalling ; no, then start from beginning
banksel Counter
decfsz Counter,f ; was the pin low for T_NOISE_MAX?
goto LF.DetectFalling.Debounce ; no, then test again
banksel TMR0
movf TMR0,w ; store TMR0 value
banksel Time
movwf Time
bcf STATUS,Z
return
;------------------------------------------------------------------------------+
; |
; LF.DetectRising() |
; |
;------------------------------------------------------------------------------+
; |
; Internal use only. |
; This function detects a rising edge on the LF input pin. |
; It will debounce this pin with the given timing constants. |
; |
; |
; |
; Used SFRs: TMR0 |
; |
; |
; Stacklevel: 1 |
; |
;------------------------------------------------------------------------------+
LF.DetectRising
banksel Counter
movlw (LF.T_NOISE_MAX/(LF.T_INST*.9))+1
movwf Counter ; initialize debounce counter
movlw (.115*LF.T_PERIOD_MAX/(.100*LF.T_INST*PRESCALER))+1 ;
banksel TMR0
subwf TMR0,w ; over maximum period time?
btfsc STATUS,C
goto Return.Fail ; yes, then return 0
btfsc INTCON,T0IF ; As there is a resonant frequency in this routine
goto Return.Fail ; Check also absolute timing
LF.DetectRising.Debounce
banksel LF.PORT
btfss LFDATA ; is pin low?
goto LF.DetectRising ; no, then start from beginning
banksel Counter
decfsz Counter,f ; was the pin low for T_NOISE_MAX?
goto LF.DetectRising.Debounce ; no, then test again
banksel TMR0
movf TMR0,w ; store TMR0 value
clrf TMR0
banksel Time
movwf Time
bcf STATUS,Z
return
Return.Fail
bsf STATUS,Z
return
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -