Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2012
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. timer0:
  2.  
  3. #include <REG8252.H>     ; include CPU definition file (for example, 8052)
  4. #define TONEOUT P1_7     ;auf Port 1 pin 7 kommt der Ton raus
  5. #define reloadvalue 5536
  6.  
  7. ;------------------------------------------------------------------------------
  8. ; Module name (optional)
  9. ;------------------------------------------------------------------------------
  10. NAME            Timer0_Module
  11.  
  12. ;------------------------------------------------------------------------------
  13. ; Here, you may import symbols from other modules.
  14. ;------------------------------------------------------------------------------
  15.  
  16. T0_data_seg   SEGMENT DATA
  17.        
  18.                 RSEG    T0_data_seg     ; switch to this code segment
  19.     t0count:    DS 1
  20.  
  21. ;------------------------------------------------------------------------------
  22. ; Here, you may export symbols to other modules.
  23. ;------------------------------------------------------------------------------
  24. PUBLIC  T0_ISR, T0_INIT, T1_ISR, T1_INIT, PlayTone, PlayNote
  25.  
  26. ;------------------------------------------------------------------------------
  27. ; CODE SEGMENT--Reserves space in CODE ROM for assembler instructions.
  28. ;------------------------------------------------------------------------------
  29. T0_code_seg   SEGMENT CODE
  30.        
  31.                 RSEG    T0_code_seg     ; switch to this code segment
  32.  
  33.                 USING   0               ; state register_bank used
  34.                                         ; for the following program code.  
  35. T0_INIT:
  36. ANL     TMOD, #~(T0_MASK_)
  37. ORL     TMOD, #(T0_M1_)
  38.  
  39. MOV t0count,#0
  40. RET
  41.  
  42. T1_INIT:
  43. ANL     TMOD, #~(T1_MASK_)
  44. ORL     TMOD, #(T1_M0_)
  45. RET
  46.  
  47.  
  48.  
  49. PlayTone:
  50.       CJNE R0,#255,tone
  51.       jmp over
  52. tone: MOV TH0,R0
  53.       MOV TL0,R0
  54.       SETB TR0
  55. over: RET
  56.  
  57. PlayNote:
  58. CALL PlayTone
  59. MOV TL1,#HIGH(reloadvalue)
  60. MOV TH1,#LOW(reloadvalue)
  61. SETB TR1
  62.  
  63. RET
  64.  
  65. ;------------------------------------------------------------------------------
  66. ; T0 Interrupt Sevice Routine
  67. ;------------------------------------------------------------------------------
  68.                 USING   0               ; state register_bank used
  69.                                         ; for the following program code.  
  70.  
  71. T0_ISR:
  72.         PUSH PSW
  73.         PUSH Acc
  74.         MOV  a,#17 
  75.         INC t0count
  76.         CJNE a,t0count,loop
  77.         CPL TONEOUT
  78.         MOV t0count,#0
  79. loop:   POP Acc
  80.         POP PSW
  81.         RETI
  82.  
  83. T1_ISR:        
  84.         PUSH PSW
  85.         PUSH Acc
  86.         MOV TL1,#HIGH(reloadvalue)
  87.         MOV TH1,#LOW(reloadvalue)
  88.         DJNZ R1,loop2
  89.         CLR TR0
  90.         CLR TR1
  91. loop2:  POP Acc
  92.         POP PSW
  93.         RETI
  94.  
  95.         END             ; End Of File
  96.  
  97.  
  98. ;-----------------------------------------------------------------
  99. ;main:
  100.  
  101. #include <REG8252.H>     ; include CPU definition file (for example, 8052)
  102. #include "notedefines.h" ; include notedefines.h
  103.  
  104.  
  105. #define TONEOUT P1_7 ;auf Port 1 pin 7 kommt der Ton raus
  106.  
  107.  
  108.  
  109. ;------------------------------------------------------------------------------
  110. ; Module name (optional)
  111. ;------------------------------------------------------------------------------
  112. NAME            MAIN_Module
  113.  
  114. ;------------------------------------------------------------------------------
  115. ; Here, you may import symbols from other modules.
  116. ;------------------------------------------------------------------------------
  117. EXTRN   CODE    (T0_INIT, T1_INIT, PlayNote, lied)
  118. ;------------------------------------------------------------------------------
  119. ; Here, you may export symbols to other modules.
  120. ;------------------------------------------------------------------------------
  121. PUBLIC  start
  122.  
  123. ;------------------------------------------------------------------------------
  124. ; Put the STACK segment in the main module.
  125. ;------------------------------------------------------------------------------
  126. ?STACK          SEGMENT IDATA           ; ?STACK goes into IDATA RAM.
  127.                 RSEG    ?STACK          ; switch to ?STACK segment.
  128.                 DS      5               ; reserve your stack space
  129.                                         ; 5 bytes in this example.
  130.  
  131. main_code_seg   SEGMENT CODE
  132.        
  133.                 RSEG    main_code_seg   ; switch to this code segment
  134.  
  135.                 USING   0               ; state register_bank used
  136.                                         ; for the following program code.  
  137.            
  138. start:          MOV     SP,#?STACK-1    ; assign stack at beginning
  139.                
  140.                
  141.  
  142.         CALL    T0_INIT
  143.         CALL    T1_INIT
  144.  
  145.         SETB EA  ;enable all interrupts
  146.         SETB ET0 ;enable Timer0
  147.         SETB ET1 ;enable Timer1
  148.  
  149.         MOV DPTR,#lied     ; adresse der jeweiligen tonhoehe bzw. laenge in dtpr kopieren
  150. loop:   CLR A              ; clear akku, wegen movc in der nächsten zeile
  151.         MOVC a,@a+dptr     ; noten-wert bzw. laenge aus cem Codespeicher in den akku speichern
  152.         JZ loop2           ; wenn akku = 0, dann ist das ende des lieds erreicht und er springt auf JMP $
  153.         MOV R0,a           ; die tonhöhe in R0 speichern
  154.         INC DPTR           ; dptr inkrementieren --> nächste adresse, wo sich tonhoehe bzw. laenge befinden, in dtpr kopieren
  155.         CLR A              ; clear akku, wegen movc in der nächsten zeile
  156.         MOVC a,@a+dptr     ; noten-wert bzw. laenge aus cem Codespeicher in den akku speichern
  157.         MOV R1,a           ; die tonlaenge in R1 speichern
  158.         INC DPTR           ; dptr inkrementieren --> nächste adresse, wo sich tonhoehe bzw. laenge befinden, in dtpr kopieren
  159.         CALL PlayNote      ; ruft das unterprogramm PlayNote auf
  160.         JB TR1,$           ; springt auf die selbe Zeile, wenn TR1 gesetzt ist --> geht erst weiter, wenn die Note zu ende gespielt ist
  161.         JMP loop           ; springt zum label loop
  162.  
  163.        
  164. loop2:  JMP $              ;wenn programmende springt es immer auf diese zeile
  165.                
  166. ;------------------------------------------------------------------------------
  167. ; The END directive is ALWAYS required.
  168. ;------------------------------------------------------------------------------
  169.                 END             ; End Of File
  170.  
  171.  
  172. -----------------------------------------------------------------------------------------------
  173. ;BaseMon:
  174.  
  175. ;------------------------------------------------------------------------------
  176. ; set Reset and other Vectors to Monitor needs
  177. ;------------------------------------------------------------------------------
  178.  
  179. ;------------------------------------------------------------------------------
  180. ; Module name (optional)
  181. ;------------------------------------------------------------------------------
  182. NAME            BASE_Module
  183.  
  184. ;------------------------------------------------------------------------------
  185. ; Here, you may import symbols from other modules.
  186. ;------------------------------------------------------------------------------
  187. EXTRN   CODE   (start)      ; May be a subroutine entry declared in
  188.                                 ; CODE segments or with CODE directive.
  189. EXTRN   CODE   (T0_ISR, T1_ISR)
  190.  
  191. ;------------------------------------------------------------------------------
  192. ; Provide an LJMP to start at the reset address (address 0) in the main module.
  193. ; You may use this style for interrupt service routines.
  194. ;------------------------------------------------------------------------------
  195.                 CSEG    AT      0x8000  ; absolute Segment at Address 0x8000
  196.                 JMP     start           ; reset location (jump to start)
  197.  
  198. ;------------------------------------------------------------------------------
  199. ; Provide an LJMP to T0 Interrupt Service Routine
  200. ;------------------------------------------------------------------------------
  201.                 CSEG    AT      0x800B  ; absolute Segment at Address 0x800B
  202.                 JMP     T0_ISR          ; T0 Interrupt Service Routine
  203.  
  204.                 CSEG    AT      0x801B
  205.                 JMP     T1_ISR
  206. ;------------------------------------------------------------------------------
  207. ; The END directive is ALWAYS required.
  208. ;------------------------------------------------------------------------------
  209.                 END             ; End Of File
  210.  
  211.  
  212.  
  213. ;-------------------------------------------------------------------
  214. ;mission impossible
  215.  
  216. ;------------------------------------------------------------------------------
  217. ; Source code template for A251/A51 assembler modules.
  218. ; Copyright (c) 1995-2000 KEIL Software, Inc.
  219. ;------------------------------------------------------------------------------
  220. #include <REG8252.H>     ; include CPU definition file (for example, 8052)
  221.  
  222. ;------------------------------------------------------------------------------
  223. ; Module name (optional)
  224. ;------------------------------------------------------------------------------
  225. NAME            MissionImpossible
  226.  
  227. ;------------------------------------------------------------------------------
  228. ; Here, you may import symbols from other modules.
  229. ;------------------------------------------------------------------------------
  230. #include <notedefines.h>
  231. ;------------------------------------------------------------------------------
  232. ; Here, you may export symbols to other modules.
  233. ;------------------------------------------------------------------------------
  234.  
  235. PUBLIC  lied
  236.  
  237. mission_data        SEGMENT CODE
  238.  
  239.  
  240. // Hier wird der RAM mit den entsprechenden Konstanten für das Lied
  241. // Mission Impossible Theme geladen
  242.          RSEG        mission_data
  243. lied:
  244.                DB C5
  245.                DB Achtel
  246.                DB A4
  247.                DB Achtel
  248.                DB E4
  249.                DB Ganze
  250.                DB C5
  251.                DB Achtel
  252.                DB A4
  253.                DB Achtel
  254.                DB Es4
  255.                DB Ganze
  256.                DB C5
  257.                DB Achtel
  258.                DB A4
  259.                DB Achtel
  260.                DB D4
  261.                DB Ganze
  262.                DB C4
  263.                DB Achtel
  264.                DB D4
  265.                DB Sechzehntel
  266.                DB Pause
  267.                DB Sechzehntel
  268.                DB Pause
  269.                DB Ganze
  270.                DB C4
  271.                DB Achtel
  272.                DB Pause
  273.                DB Viertel
  274.                DB C4
  275.                DB Achtel
  276.                DB Pause
  277.                DB Viertel
  278.                 DB Es4
  279.                 DB Viertel
  280.                 DB F4
  281.                 DB Viertel
  282.                 DB C4
  283.                 DB Achtel
  284.                 Db Pause
  285.                 DB Viertel
  286.                 DB C4
  287.                 DB Achtel
  288.                 DB Pause
  289.                 DB Viertel
  290.  
  291.                 DB  B3
  292.                 DB  Achtel
  293.                 DB  Pause
  294.                 DB  Achtel
  295.                 DB  H3
  296.                 DB  Achtel
  297.                 DB  Pause
  298.                 DB  Achtel
  299.  
  300.  
  301.  
  302.                 DB C4
  303.                DB Achtel
  304.                DB Pause
  305.                DB Viertel
  306.                DB C4
  307.                DB Achtel
  308.                DB Pause
  309.                DB Viertel
  310.                 DB Es4
  311.                 DB Viertel
  312.                 DB F4
  313.                 DB Viertel
  314.                 DB C4
  315.                 DB Achtel
  316.                 Db Pause
  317.                 DB Viertel
  318.                 DB C4
  319.                 DB Achtel
  320.                 DB Pause
  321.                 DB Viertel
  322.  
  323.                // 00 gibt an, dass das Lied zu Ende ist
  324.                 DB        00
  325.            
  326.                        
  327. ;------------------------------------------------------------------------------
  328. ; The END directive is ALWAYS required.
  329. ;------------------------------------------------------------------------------
  330.                 END             ; End Of File
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement