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

📄 demo_spk.asm

📁 用89S52进行DS1820温度读取程序
💻 ASM
字号:
              ;使用NUL2003做D类放大器,驱动喇叭发声的电子琴实验
              ;将P2.1跳帽选择焊盘位置,再将S51E板的"驱动输入口"的"SPK"接焊盘P2.1
              ;外接喇叭,             
              ;相关知识内容请参阅S51E 文档内容--音乐应用实验。
              Tone_h equ 30h
              Tone_l equ 31h
              Tone_num equ 100
              SPK   BIT  P2.1
              KEY   BIT  P3.4
    ;---------------------------------
            ORG 0000H
            JMP MUSIC
            Org 001bh
            AJmp time1 
MUSIC:   MOV SP,#50H
         Mov tmod,#11h         ;16位定时器
         MOV A,#00H        
         SETB ET1
         SETB EA
key0:    MOV  P2,#0FFH
         CLR  KEY
         MOV  A,P2
Key1:    CJNE A,#01111111B,key2    ;KEY_SW1
         Mov tone_num,#00h
         Mov tone_h,#248
         Mov tone_l,#133
         MOV tl1,tone_l         
         Mov th1,tone_h
         Setb tr1                  ;启动定时器1
         Jmp end_k
Key2:    CJNE A,#10111111B,key3    ;KEY_SW2
         Mov tone_num,#00h
         Mov tone_h,#249
         Mov tone_l,#90
         MOV tl1,tone_l         
         Mov th1,tone_h
         Setb tr1                   ;启动定时器1
         Jmp end_k
Key3:    CJNE A,#11011111B,key4    ;KEY_SW3
         Mov tone_num,#00h
         Mov tone_h,#250
         Mov tone_l,#19
         MOV tl1,tone_l         
         Mov th1,tone_h
         Setb tr1                  ;启动定时器1
         Jmp end_k
Key4:    CJNE A,#11101111B,key5    ;KEY_SW4
         Mov tone_num,#00h
         Mov tone_h,#250
         Mov tone_l,#104
         MOV tl1,tone_l         
         Mov th1,tone_h
         Setb tr1            ;启动定时器1
         Jmp end_k
Key5:    CJNE A,#11110111B,key6    ;KEY_SW5
         Mov tone_num,#00h
         Mov tone_h,#251
         Mov tone_l,#04
         MOV tl1,tone_l         
         Mov th1,tone_h
         Setb tr1            ;启动定时器1
         Jmp end_k
Key6: CJNE A,#11111011B,end_k    ;KEY_SW6
         Mov tone_num,#00h
         Mov tone_h,#251
         Mov tone_l,#144
         MOV tl1,tone_l         
         Mov th1,tone_h
         Setb tr1            ;启动定时器1
      
End_k:  jmp   key0
;------------------------------------------------------------------
Time1: mov th1,tone_h
       Mov tl1,tone_l
       PUSH Acc                  ;定时1中断
       PUSH PSW
       PUSH DPH
       PUSH DPL
       Mov a,tone_num
       Inc acc
       Mov tone_num,a
       Cpl SPK
       Cjne a,#100,end_t         ;发声50次
       Mov tone_num,#00h
       Clr tr1
End_t: pop  dpl
       Pop dph
       Pop psw
       Pop acc
       reti 

 
            END              





⌨️ 快捷键说明

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