Question: these are the other files timer.c #include timer.h void timer _ init ( void ) { / / Your timer setup code here TCA

these are the other files
timer.c
#include "timer.h"
void timer_init(void){
//Your timer setup code here
TCA0.SINGLE.CTRLA =TCA_SINGLE_CLKSEL_DIV1024_gc |TCA_SINGLE_ENABLE_bm;
TCA0.SINGLE.PERBUF =0;
TCA0.SINGLE.CMP0BUF =0;
}
timer.h
#ifndef TIMERH
#define TIMERH
#include
void timer_init(void);
#endif /*TIMER_H */
spi.c
#include "spi.h"
void spi_init(void){
PORTC.DIRSET =PIN4_bm |PIN5_bm |PIN7_bm;
SPI0.CTRLA =SPI_ENABLE_bm |SPI_MASTER_bm |SPI_MODE_0_gc |SPI_PRESC_DIV4_gc;
SPI0.CTRLB =0;
SPI0.INTCTRL =0;
}
void spi_transfer(uint8_t data){
SPI0.DATA =data;
while (!(SPI0.INTFLAGS & SPI_IF_bm));
}
spi.h
#ifndef SPIH
#define SPIH
#include
void spi_init(void);
void spi_transfer(uint8_t data);
#endif /*SPI_H */
buzzer.c
#include "buzzer.h"
void buzzer_init(void){
PORTA.DIRSET =PIN1_bm;
TCA0.SINGLE.CTRLB =TCA_SINGLE_WGMODE_SINGLESLOPE_gc |TCA_SINGLE_CMP0EN_bm;
TCA0.SINGLE.CTRLA =TCA_SINGLE_CLKSEL_DIV4_gc;
TCA0.SINGLE.PERBUF =0;
TCA0.SINGLE.CMP0BUF =0;
}
void buzzer_play(uint16_t frequency){
uint16_t compareValue =F_CPU /(2*4*frequency);
TCA0.SINGLE.PERBUF =compareValue;
TCA0.SINGLE.CMP0BUF =compareValue /2;
}
void buzzer_stop(void){
TCA0.SINGLE.PERBUF =0;
TCA0.SINGLE.CMP0BUF =0;
}
and buzzer.h
#ifndef BUZZER_H
#define BUZZER_H
#include
#define TONE1_FREQ 1046//E(high)
#define TONE2_FREQ 554//C
#define TONE3_FREQ 440//A
#define TONE4_FREQ 330//E(low)
void buzzer_init(void);
void buzzer_play(uint16_t frequency);
void buzzer_stop(void);
#endif /*BUZZER_H *
main.c
void generateSimonSequence(void);
void playSequence(void);
void getUserInput(void);
void displaySuccess(void);
void displayFail(void);
void increaseSequenceLength(void);
void resetGame(void);
void update_score(void);
void displayHighScores(void);
int main(void){
// Initialize peripherals
timer_init();
spi_init();
buzzer_init();
buzzer_stop();
state_t state = WAIT;
while (1){
switch (state){
case WAIT:
resetGame();
generateSimonSequence();
state = PLAY_SIMON;
break;
case PLAY_SIMON:
playSequence();
state = USER_INPUT;
break;
case USER_INPUT:
getUserInput();
state = CHECK_INPUT;
break;
case CHECK_INPUT:
if (currentStep == sequenceLength){
displaySuccess();
increaseSequenceLength();
state = PLAY_SIMON;
} else {
displayFail();
resetGame();
state = WAIT;
}
break;
}
}
}
void generateSimonSequence(void){
for (uint16_t i =0; i <100; i++){
uint8_t BIT = STATE_LFSR & 1;
STATE_LFSR >>=1;
if (BIT){

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!