Решение задачи 2a):


int mistakes;

int wins;

int correct;

int pressed;


void main(void)

{

/* Define completion code variable. */

unsigned char cc;

int temp = 0;

int delay_dur = 10000000;

int i;

/* Define action expression variable. */

SEM_ACTION_EXPRESSION_TYPE actionExpressNo;

/* Define and initialize. */

SEM_EVENT_TYPE eventNo;

InitDevice();


//AT91SAM7SStartTimer0(); //nap

/* Initialize the VS System. */

SEM_InitAll();

#if (VS_REALLINKMODE == 1)

/* Initialize RealLink communication. */

RealLinkCommInit();

/* Initializing RealLink API. */

VS_RealLinkInit();

#endif

/* Initialize the VS Event queue. */

SEQ_Initialize();

/* Add SE_RESET to initialize system. */

SEQ_AddEvent(SE_RESET);

srand(time(NULL));

/* Do forever: */

for(;;)

{

#if (VS_REALLINKMODE == 1)

VS_WAIT();

#endif


#if 0

//16.11.2021 2a)

mistakes = 0;

wins = 0;

correct = 1;

for(i = 0; i < 20; i++)

{

//randomLamp();

//delay(1000000);

if (correct == 1) {

correct = 0;

pressed = 0;

randomLamp();

// game 2

delay(delay_dur);

if (correct == 0) {

mistakes++;

}

correct = 1;

//

}

if (i%4 == 3)

delay_dur *= 0.8;

}

correct = correct;

#endif //0

}

}


static void ButtonInterrupt()

{

static char catch = 0;


int dummy;

int status;

/* clear the interrupt flag */

dummy = AT91C_BASE_PIOA->PIO_ISR;

/* try to avoid compiler warning */

dummy = dummy;

status = (int)0xFFFFF43C;


// 16.11.2021

/* State of PIO */

status = *(int*)0xFFFFF43C;


if (!pressed) {

if ((dummy & (1<<19)) && !(status & (1<<19)))

{

if (status & (1<<0))

mistakes++;

else {

wins++;

*(int*)0xFFFFF430 = (1<<0);

correct = 1;

}

}else if ((dummy & (1<<20)) && !(status & (1<<20)))

{

if (status & (1<<1)) {

mistakes++;

}else {

wins++;

*(int*)0xFFFFF430 = (1<<1);

correct = 1;

}

}else if ((dummy & (1<<15)) && !(status & (1<<15)))

{

if (status & (1<<2))

mistakes++;

else {

wins++;

*(int*)0xFFFFF430 = (1<<2);

correct = 1;

}

}else if ((dummy & (1<<14)) && !(status & (1<<14)))

{

if (status & (1<<3))

mistakes++;

else {

wins++;

*(int*)0xFFFFF430 = (1<<3);

correct = 1;

}

}

pressed = 1;

}

}


==============================================


Пути решения задачи 2b):



// Функция timer0_interrupt() вызвается из обработчика прерывания от таймера. Если timer_ticks=300, то в «if” попадаем каждые 3 секунды.

int timer_ticks = 300;


void timer0_interrupt() {

if (timer_interrupt_is_needed) {

if (!--timer_ticks)

{

timer_ticks = 300;

}

}

}


Надо разработать код, который будет вызываться внутри «if” и будет проверять, нажата ли нужная кнопка.

С течением времени timer_ticks уменьшаем, чтобы пользователь нажимд на кнопки быстрее.

В функции ButtonInterrupt() по-прежнему проверяется, какая нажата кнопка.