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

📄 emis1.asm

📁 胎压检测发送端汇编源码-tpms-transmitters
💻 ASM
字号:
;/*****************************************************************************/
;/* PROJECT : RF key demonstrator (FSK)                                       */
;/* Functions: Wake_up_Rx                                                     */
;/*  Transmit_1                                                               */
;/*  Init_timer0                                                              */
;/*  tempo                                                                    */
;/*  Transmit                                                                 */
;/*  Tx_Uhf_ISR                                                               */
;/*****************************************************************************/


;/*****************************************************************************/
;/* Transmit_1                                                                */
;/* Description : it transmits a tone at 9600 bauds for the programmed time   */
;/* In :                                                                      */
;/* Out : nb_1                                                                */
;/* local variables :                                                         */
;/*****************************************************************************/

Transmit_1:

        lda     TSC0            ; initial output = H
        and     #%11100011
        ;             \\\_______;Pin under port control,
        ;              \________;Initial output = High
        sta     TSC0
        bsr     Init_Timer0

        rts

;/*****************************************************************************/
;/* Init_timer0:                                                              */
;/* Description : it initializes the timer for PWM output at 9600 bauds       */
;/*       with DATACLK as Tclk                                                */
;/* In :                                                                      */
;/* Out : TSC, TSC0, TMOD, TCH0                                               */
;/* local variables : H:X                                                     */
;/*****************************************************************************/

Init_Timer0:

        pshh                    ; save h & x
        pshx

        mov     #1,current_tx_bit
        mov     #1,next_tx_bit

        lda     TSC
        mov     #$37,TSC        ; counter stopped & cleared, tof clear, TOF_ISR disabled
                                ; DATACLK = Timer Clock
        lda     TSC0
        mov     #$54,TSC0       ; Timer Channel 0 : PWM output with toggle
                                ; on compare; Tx_Uhf_ISR enabled

;        mov     #$30,tsc        ; Use this if you want fcpu=TCLK (less precise)

        ldhx    #UHF_period     ; PWM period = period UHF
        sthx    TMODH
        ldhx    #UHF_duty_cycle ; PWM duty cycle = 50%
        sthx    TCH0H

        bclr    5,TSC           ; Start the timer

        pulx                    ; restore h & x
        pulh

        rts

;/*****************************************************************************/
;/* Wake_up_Rx                                                                */
;/* Description : it starts the transmission of a tone at 9600 bauds for 64 ms*/
;/* In :                                                                      */
;/* Out : nb_1                                                                */
;/* local variables : H:X                                                     */
;/*****************************************************************************/

Wake_up_Rx:

        pshh
        pshx

        bset    Enable,PORTB

        ldhx    #wait_1_8ms     ; wait for Tango3 PLL being settled
        jsr     Tempo

        ldhx    #nb_wake_up_bit
        sthx    nb_1            ; transmit the tone
        jsr     transmit_1

        pulx
        pulh

        rts

;/*****************************************************************************/
;/* Tx_UHF_ISR                                                                */
;/* Description : it decides what to do on timer overflow                     */
;/*      if current = next, then toggle on timer overflow, else no toggle     */
;/* In : Next_Tx_bit, Current_Tx_Bit                                          */
;/* Out : TSC0, nb_1                                                          */
;/* local variables :                                                         */
;/*****************************************************************************/

Tx_Uhf_ISR:

        pshh

        ldhx    nb_1            ; if nb_1 = 0, do not decrement nb_1
        cphx    #0000
        beq     reenable_Tx_ISR
        lda     nb_1+1          ;          else decrement nb_1
        sub     #1
        sta     nb_1+1
        lda     nb_1
        sbc     #0
        sta     nb_1

reenable_Tx_ISR:
        lda     tsc0            ; reenable next input capture isr by reading tsc0
        and     #$7f            ; &
        sta     tsc0            ; clearing input capture flag

        lda     Next_Tx_Bit     ; if next_tx_bit not equal to Current_tx_bit
        cbeq    Current_Tx_Bit,Tovf
No_tovf:
        bclr    1,TSC0          ;    then no toggle on overflow
        jmp     End_Tx_UHF_ISR  ;
Tovf:
        bset    1,TSC0          ;    else toggle on overflow

End_Tx_UHF_ISR:
        pulh

        rti

;/*****************************************************************************/
;/* Transmit                                                                  */
;/* Description : it transmits data at 9600 bauds in Manchester               */
;/* In : Tx_byte                                                              */
;/* Out :                                                                     */
;/* local variables : H:X, current_tx_bit,next_tx_bit,current_tx_byte         */
;/*****************************************************************************/

Transmit:

        ldhx    #Tx_byte

Transmit_Downlink:

        mov     x+,current_tx_byte
        lda     #$8             ; a = bit pointer

Transmit_Byte:
        psha                    ; save a
        mov     Next_Tx_bit,Current_Tx_Bit  ;
        lsl     current_Tx_Byte ; move next bit in carry
        bcs     Next_1          ;   if carry not set
next_0:
        clr     Next_Tx_bit     ;      then next_bit = 0
        bra     Next            ;
Next_1:
        mov     #$1,Next_Tx_Bit ;      else next_bit =1
Next:
        wait                    ; half bit
                                ; wait until next_bit is transmitted
        pula                    ; restore a
        dbnza   Transmit_Byte   ; repeat until the 8 bits are transmitted

        cbeqx   #Last_byte,transmit_last_bit
        bra     Transmit_downlink
                                ; repeat byte transmit loop until the last byte

transmit_last_bit:
        mov     Next_Tx_bit,Current_Tx_Bit
        mov     #$0,next_tx_bit
        wait                    ; exit milieu bit : wait for the half lsb

        lda     TSC
        bclr    7,TSC
        brclr   7,TSC,*
        bclr    DATA_RF,PORTB
        clr     TSC0

        bclr    DATA_RF,PORTB

        ldhx    #UHF_period     ; wait for EOM
        jsr     Tempo
        ldhx    #UHF_period
        jsr     Tempo
        ldhx    #UHF_period
        jsr     Tempo

        mov     #$01,PORTB      ; shut down the RF, keep at 315/434MHz
        lda     TSC
        mov     #$30,TSC        ; stop & clear the timer, fcpu = tclk.

        rts

⌨️ 快捷键说明

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