Introduction - If you have any usage issues, please Google them yourself
This example describes how to implement a scanning keyboard and then from the pressed key generate a corresponding defined sound frequency. Each time a key is pressed the corresponding frequency value is placed into the timer/counter register. When this counter counts to its maximum value an internal interrupt is generated and the interrupt routine is run. At this point the timer/counter register value is reloaded and the counting continues. In this way, by programming different values into the timer/counter register, different values of frequency can be generated. The internal interrupt routine contains code to change the state of the output port and thus generate the required frequency on a corresponding pin and create the desired note. By adding a suitable amplifier and speaker the system is complete. The important point of the software is to use the timer/counter as a counter to control the output frequency. This frequency has to be calculated.