如何在HCS12微控制器上设置扬声器?

时间:2016-05-11 07:23:45

标签: button assembly microcontroller speaker

基本上,我的微控制器应该根据按下按钮(PTH)播放声音,然后按下并点亮LED(PORTB)。我所坚持的是如何设置扬声器按下按钮时输出声音。很多代码都基于此处的代码:http://www.microdigitaled.com/HCS12/Hardware/Dragon12-Plus-Support.htm

特别是关于蜂鸣器的链接。此外,当我使用提供的代码时,我能够听到来自微控制器的声音;但是,当我尝试将按钮包含在代码中时。

我非常感谢任何提示,评论,提示或建议。非常感谢你!

到目前为止,这是我的代码:

;----------------------USE $1000-$2FFF for Scratch Pad
R1      EQU     $1001
R2      EQU     $1002
R3      EQU     $1003
R4      EQU     $1004

;code section
    ORG   $2000     ;Flash ROM address for Dragon12+
Entry:
      LDS     #$2000    ;Stack
      BSET    DDRT,%00100000     ;PTT5 as Output pin for buzzer
      BSET    DDRP,#$0F   ; Set Port P pins 0-3 to output
      BSET    PTP, #$0F     ; Disable 7-Segment Display
      ; LED
      BSET    DDRB,$FF
      BSET    DDRJ,$02
      BCLR    PTJ,$02

      ; PBs
      BCLR    DDRH,$0F
      BCLR    PTH,$FF       ;PORTB as Output

;-------Sound the Buzzer at PTT5

BACK          
;-------Get data from DIP switches connected to PORTH and send it to LEDs of PORTB

 ;how is the speaker supposed to be set up? because when I try the code the speaker does not output any sound.

      LDAA PTH        ;Get data from DIP Switches of PTH
      STAA PORTB      ;and send it to PORTB
      BSET PTT,%00100000     ;PTT5=1
      JSR DELAY        
      BCLR PTT,%00100000     ;PTT5=0
      JSR DELAY        
      BRA BACK              ;Keep toggling buzzer    

我的延迟可以吗?我是在正确的轨道还是有更方便的方式来改变音符?

;----------DELAY
DELAY
    COMA
    TSTA
    CMPA    #$01
    BNE     no_note1
    PSHA        ;Save Reg A on Stack
    LDAA    #7        ;Change this value to hear  
    STAA    R3        ;different Buzzer sounds
;--1 msec delay. The Serial Monitor works at speed of 48MHz with XTAL=8MHz on Dragon12+ board
;Freq. for Instruction Clock Cycle is 24MHz (1/2 of 48Mhz).
;(1/24MHz) x 10 Clk x240x10=1 msec. Overheads are excluded in this calculation.       
L3      LDAA    #10
    STAA    R2    
L2      LDAA    #200
    STAA    R1
L1      NOP         ;1 Intruction Clk Cycle
    NOP         ;1
    NOP         ;1
    DEC     R1  ;4
    BNE     L1  ;3
    DEC     R2  ;Total Instr.Clk=10
    BNE     L2
    DEC     R3
    BNE     L3
    PULA            ;Restore Reg A
no_note1:        
    CMPA    #$02
    BNE     no_note2
    PSHA        ;Save Reg A on Stack
    LDAA    #3        ;Change this value to hear  
    STAA    R3        ;different Buzzer sounds
;--1 msec delay. The Serial Monitor works at speed of 48MHz with XTAL=8MHz on Dragon12+ board
;Freq. for Instruction Clock Cycle is 24MHz (1/2 of 48Mhz).
;(1/24MHz) x 10 Clk x240x10=1 msec. Overheads are excluded in this calculation.       
L9        LDAA    #10
    STAA    R2    
L8        LDAA    #210
    STAA    R1
L7      NOP         ;1 Intruction Clk Cycle
    NOP         ;1
    NOP         ;1
    DEC     R1  ;4
    BNE     L7  ;3
    DEC     R2  ;Total Instr.Clk=10
    BNE     L8
    DEC     R3
    BNE     L9
    PULA            ;Restore Reg A
no_note2:
    CMPA    #$04
    BNE     no_note3
    PSHA        ;Save Reg A on Stack
    LDAA    #2        ;Change this value to hear  
    STAA    R3        ;different Buzzer sounds
;--1 msec delay. The Serial Monitor works at speed of 48MHz with XTAL=8MHz on Dragon12+ board
;Freq. for Instruction Clock Cycle is 24MHz (1/2 of 48Mhz).
;(1/24MHz) x 10 Clk x240x10=1 msec. Overheads are excluded in this calculation.       
L4        LDAA    #15
    STAA    R2    
L5        LDAA    #240
    STAA    R1
L6      NOP         ;1 Intruction Clk Cycle
    NOP         ;1
    NOP         ;1
    DEC     R1  ;4
    BNE     L6  ;3
    DEC     R2  ;Total Instr.Clk=10
    BNE     L5
    DEC     R3
    BNE     L4
    PULA            ;Restore Reg A
no_note3:        
    CMPA    #$08
    BNE     no_note4
    PSHA        ;Save Reg A on Stack
    LDAA    #9        ;Change this value to hear  
    STAA    R3        ;different Buzzer sounds
;--1 msec delay. The Serial Monitor works at speed of 48MHz with XTAL=8MHz on Dragon12+ board
;Freq. for Instruction Clock Cycle is 24MHz (1/2 of 48Mhz).
;(1/24MHz) x 10 Clk x240x10=1 msec. Overheads are excluded in this calculation.       
L30     LDAA    #16
    STAA    R2    
L20     LDAA    #249
    STAA    R1
L10     NOP         ;1 Intruction Clk Cycle
    NOP         ;1
    NOP         ;1
    DEC     R1  ;4
    BNE     L10  ;3
    DEC     R2  ;Total Instr.Clk=10
    BNE     L20
    DEC     R3
    BNE     L30
;--------------        
    PULA            ;Restore Reg A
no_note4:
    RTS
;-------------------

;----------------------------------------------------
; Interrupt Vector
;----------------------------------------------------
      ; Port H Vector
      ; $3E4C = $FFCC - $C180
      ORG     $3E4C
      FDB     DELAY
FINISH:
NOP
    END

0 个答案:

没有答案