6.1 Setup, Main Loop and Idle Subroutine
When the program is started, the setup of the memory and internal peripherals is initiated. This involves the setup of the following peripherals:
- ADCC for sampling of the microphone
- DAC for output to the speaker
- SPI for interfacing external memory
- PORT settings for button interfacing
- TMR2 and CLC for button debouncing
- TMR0 for correct sampling and playback frequency
- DMA for data transfer between peripherals and memory
- PWM and Comparator for power amplifier
- TMR6 as time base for LED blinking
- TMR1 as time base for button press delays
- UART for debugging
In addition to the peripherals, external memory is also initialized. If the external memory can not be identified, then the program defaults to using the internal program memory as storage.
This is followed by loading the appropriate audio metadata from the EEPROM. The audio metadata contains the memory location where existing audio is stored and the size of the audio. If no audio is stored, the audio size is zero bytes.
The setup and main loop functionality is shown in Figure 6-1.