Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;; 203 Lab#7 - Spring 2014
- .ORIG X3000
- ;; initially, stop any note playing by setting FGCR to zero
- AND R0 ,R0,#0
- LD R3, ASCII_KEYS
- NOT R3, R3
- ADD R3, R3, #1
- STI R0, FGCR_ADDR ; mem[x440a] = R0 = 0
- ; set FGCR = 0 to stop playing note
- BR WAIT_FOR_KEY
- ;;
- ;; Starting the main loop WAIT_FOR_KEY
- ;; Test KPDR until it is non-zero,
- ;;indicating key pressed
- WAIT_FOR_KEY
- LDI R0,KPDR_ADDR ; R0 = ascii(typed_key),
- ; typed_key ranged from 1 to 9
- ; ascii code will be from x31 to x39
- BRz WAIT_FOR_KEY ; If zero, no key yet. Loop back
- ;;
- ;; Got a key! RO = TYPED KEY.
- ;; Convert the typed ASCII_# into an index (0-8)
- ;; which means that convert "1" to 0, "2" to 1, and etc.
- ;;
- ;; Write your convertion code here!!!!!!!!!!!!!!!
- ;; You will put the converted index number in R0!
- ;; R0 should be in the range of 0-8,
- ;;
- ADD R0, R0, R3
- ;; However, let's doubtcheck it for safety.
- ;; WRITE you codes here to check if R0 is out of range
- ;; If the number is out of range,
- ;; branch back to WAIT_FOR_KEY
- ;;
- BRn WAIT_FOR_KEY
- ADD R2, R0, #-8
- BRp WAIT_FOR_KEY
- ;; now R0 in within 0 and 8, which means that
- ;; the key_in number is within '1' and '9'.
- ;;
- ;; Write the next piece of codes to
- ;; play the note by looking up the frequency.
- ;; Use LEA to load the starting address of note_freq_array
- ;; into a register.
- LEA R1, NOTE_FREQ_ARR
- ADD R1, R1, R0
- LDR R1, R1, #0
- STI R1, FGDR_ADDR
- STI R1, FGCR_ADDR
- ;; Write this frequency to the frequency generator FGDR
- ;; To play this musical note, you need to write any
- ;; non-zero number to FGCR
- ;; Now the note will be played through the speaker!!
- ;;
- ;;
- WAIT_FOR_RELEASE
- LDI R0, KPDR_ADDR
- BRz KEY_RELEASED
- BRnp WAIT_FOR_RELEASE
- KEY_RELEASED
- AND R1, R1, #0
- STI R1, FGCR_ADDR
- STI R1, FGDR_ADDR
- BR WAIT_FOR_KEY ; repeat
- ;;
- HALT
- ;; LABEL DEFINITIONS
- ;; 9 numeric keys
- ASCII_KEYS
- .STRINGZ "123456789"
- ;; KPDR holds the most recent key to be pressed.
- KPDR_ADDR
- .FILL x4400
- ;;KPSR tracks the number of milliseconds since the last key was pressed.
- KPSR_ADDR
- .FILL x4402
- ;; FGDR specifes the frequency for the output tone.
- FGDR_ADDR
- .FILL x4408
- ;; FGCR controls the behavior of the function generator.
- FGCR_ADDR ; If FGCR = 0, stop playing musical notes.
- .FILL x440a ; non-zero FGCR will generate musical notes.
- ;;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; 9 frequencies for 9 key_in numbers
- NOTE_FREQ_ARR
- .FILL 440 ;; x01B8
- .FILL 466 ;; x01D2
- .FILL 493 ;; x01ED
- .FILL 523 ;; x020B
- .FILL 554 ;; x022A
- .FILL 587 ;; x024B
- .FILL 622 ;; x026E
- .FILL 698 ;; x02BA
- .FILL 783 ;; x030F
- ;;
- ;; RESERVE some memory for recording application
- NOTE_ARRAY
- .BLKW 32
- .END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement