mov
tmr0h,a
;
set
tmr0c.4
;start timer0
key_halt:
;(7)
;check key holding state
mov
a,pa
;test pa
cpl
acc
;
sz
acc
;is holding?
jmp
key_halt
;yes. check again
clr
tmr0c.4
;(8)
;no. stop timer (stop sound two)
clr
pb
;
ret
;
whichkey endp
;
org 0f00h
;sound freq.
dc 21h,0feh,58h,0feh
dc 84h,0feh,99h,0feh
dc 0c1h,0feh,0e3h,0feh
dc 02h,0ffh,11h,0ffh
end
Program description
The program begins (1) by setting all pins on Port A to inputs by setting the
Port A control register PAC high. Port B is setup as outputs by clearing its
control register PBC. After this the program enters a program loop (2) to
detect if a key has been pressed. If a key has been pressed the program
jumps out of this loop otherwise it will remain in this loop until a key is
pressed. The next stage is a program to determine which key was pressed
(3). Determining which key is pressed enables the correct frequency value
to be obtained from the table. This is done by incrementing the table pointer
until the correct location is reached. The value is divided into a high byte
and low byte, these two values have to be placed in the correct high/low byte
position of the timer/counter (5). After the value is placed and counted an
interrupt is generated by the timer/counter and the interrupt routine is run
and the correct output (6) placed on Port B. In this way the correct
frequency can be generated. The Port B output pin is connected to a suitable
amplifier and speaker to generate the correct tone.
After detecting the key and obtaining the correct frequency value the key
is again examined (7) to see if it has been released. This is because the
timer/counter will continue to be reloaded so if the key is not released the
note will continue to appear on Port B. If the key has been released (8) then
the control bit is set to turn off the timer/counter.
Clock
This application shows the use of the 16 bits of the timer counter to
generate internal interrupts and consequently generate a timing function.
HT-IDE User’s Guide
212
Summary of Contents for HT-IDE
Page 11: ...P a r t I Integrated Development Environment Part I Integrated Development Environment 1 ...
Page 12: ...HT IDE User s Guide 2 ...
Page 20: ...Fig 1 6 Fig 1 7 HT IDE User s Guide 10 ...
Page 24: ...HT IDE User s Guide 14 ...
Page 70: ...HT IDE User s Guide 60 ...
Page 76: ...HT IDE User s Guide 66 ...
Page 92: ...HT IDE User s Guide 82 ...
Page 93: ...P a r t I I Development Language and Tools Part II Development Language and Tools 83 ...
Page 94: ...HT IDE User s Guide 84 ...
Page 148: ...HT IDE User s Guide 138 ...
Page 150: ...Fig 12 1 Fig 12 2 HT IDE User s Guide 140 ...
Page 154: ...HT IDE User s Guide 144 ...
Page 192: ...HT IDE User s Guide 182 ...
Page 194: ...HT IDE User s Guide 184 ...
Page 218: ...HT IDE User s Guide 208 ...
Page 235: ...P a r t V Appendix Part V Appendix 225 ...
Page 236: ...HT IDE User s Guide 226 ...
Page 250: ...HT IDE User s Guide 240 ...