📄 prog44b.asm
字号:
; PROG44b - Run through the Tones
;
; Simple Application to Run Through Each Tone Twice a Second
;
; This Application after power up, Sets up Timer 0 to Interrupt at
; 880 Hz and Outputs a 440 Hz Tone, Waits one Second and then Goes
; to the Next Tone Up, Up to "HighD"
;
; Myke Predko
; 98.05.30
;
; Hardware Notes:
; AT89C2051 is used as the Microcontroller
; - Oscillator Speed is 1.8432 MHz
; P1.7 is Connected to a 8 Ohm Speaker Through 0.47 uF Cap
; Constant Declarations
LA EQU 81 ; A - 880 Hz
LAS EQU 91 ; A# - 932 Hz
LB EQU 101 ; B - 988 Hz
LC EQU 109 ; C - 1046 Hz
LCS EQU 117 ; C# - 1108 Hz
LD EQU 125 ; D - 1174 Hz
LDS EQU 133 ; D# - 1249 Hz
LE EQU 139 ; E - 1318 Hz
LF EQU 146 ; F - 1396 Hz
LFS EQU 152 ; F# - 1480 Hz
LG EQU 158 ; G - 1568 Hz
LGS EQU 164 ; G# - 1662 Hz
HA EQU 169 ; A - 1760 Hz
HAS EQU 174 ; A# - 1873 Hz
HB EQU 178 ; B - 1976 Hz
HC EQU 183 ; C - 2094 Hz
HCS EQU 187 ; C# - 2218 Hz
HD EQU 191 ; D - 2350 Hz
; Variable Declarations
Flags EQU 020h ; Bit 0 Is Set for a "Pause"
; Macros
; Mainline
org 0 ; Execution Starts Here
ajmp Mainline
org 00Bh ; Timer0 Interrupt
Timer0:
jb 0,Timer0End ; If a Pause, Don't Trigger the Timer
cpl P1.7 ; Toggle the Timer
Timer0End:
reti
org 01Bh
Timer1: ; Interrupt Every 0.02 Seconds
djnz R0,Timer1End ; If Not Zero, Then Don't Change Note
mov R0,#9 ; Reset the Note Timer
inc R1 ; Point to the Next Value
clr 0 ; Can Output the Note
mov A,R1 ; Can We Get the Note?
acall GetNote ; Get the Next Note
mov TL0,A ; Save the Next Note
mov TH0,A
jc Timer1End ; Did We Go Too Far?
mov R1,#0 ; Yes, Reset the Timer
setb 0 ; Execute a Pause
Timer1End: ; Timer1 Interrupt Handler Finished
reti
MainLine: ; Mainline of the Program
mov R0,#9 ; R0 is the Beat Timer
mov R1,#1 ; R1 is the Note Counter
clr 0 ; No Pause
mov TMOD,#%00000010 ; Run Timer0 in Mode 2 and Timer1 in Mode 1
mov A,#1 ; Get the First Note
acall GetNote
mov TH0,A ; Enable the Timer to Reload at 880 Hz.
mov TL0,A
orl TCON,#050h ; Enable Timer0 to Run
mov IE,#%10001010 ; Enable Timer0 Interrupt
Loop:
ajmp Loop
GetNote: ; Return the Note Value for the Index in "A"
clr C ; Do We Have a Valid Note?
subb A,#19
jnc InitNoteTable ; If Carry NOT Set, then "NO" Value to Get
add A,#(19+NoteTable-InitNoteTable) ; Restore the Table Position with Note
movc A,@A+PC ; Get the Table Value
InitNoteTable: ; Table Offset to Display
ret
NoteTable: ; Table of Notes
db 1 ; First Value is a "Pause"
db LA
db LAS
db LB
db LC
db LCS
db LD
db LDS
db LE
db LF
db LFS
db LG
db LGS
db HA
db HAS
db HB
db HC
db HCS
db HD
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -