Читаем Встраиваемые системы. Проектирование приложений на микроконтроллерах семейства 68HC12/HCS12 с применением языка С полностью

//*****************************************************************

void display_win {

 LCD_output(" YOU WIN!!! ");

 LCD_output("CONGRATULATIONS ");

}

//********************************************************************

// get_move: ДВИЖЕНИЕ ФИШКИ: задается позиция фишки, выбранной игро-

// ком и направление ее движения

//********************************************************************

void get_move(int* direction, int *row, int *col, int* select) {

 int n = 0;

 int button = 0;

 unsigned char temp = ZERO;

 newline;

 LCD_output("Choose move or ");

 LCD_output("select piece: ");

 while (button == 0) {

  // цикл выполняется, пока нажата кнопка

  temp = PORTS;

  temp = temp 0x7С

  switch (temp) //какая кнопка нажата?

  {

  case L_BUTTON:

   button = LEFT;

   break;

  case R_BUTTON:

   button = RIGHT;

   break;

  case U_BUTTON:

   button = UP;

   break;

  case D_BUTTON:

   button = DOWN;

   break;

  case S_BUTTON:

   button = SELECT;

   break;

  } // конец цикла switch

 }//конец цикла while

 n = 0;

 switch (button) //реакция на нажатие кнопки

 {

 case UP:

  if (*row 1) *row -= 1;

  else display_error(UP);

  break;

 case DOWN:

  if (*row SIZE) *row += 1;

  else display_error(DOWN);

  break;

 case LEFT:

  if (*col 1) *col -= 1;

  else display_error(LEFT);

  break;

 case RIGHT:

  if (*col SIZE) *col += 1

  else display_error(RIGHT);

  break;

 case SELECT:

  *select = 1;

  LCD_output("Pick a direction");

  *direction = 0;

  while (*direction == 0) {

   temp = PORTS;

   temp = temp 0x7C;

   switch (temp) {

   case L_BUTTON:

    *direction = LEFT;

    break;

   case R_BUTTON:

    *direction = RIGHT;

    break;

   case U_BUTTON:

    *direction = UP;

    break;

   case D_BUTTON:

    *direction = DOWN;

    break;

   }

  }

  break;

 }

}

//********************************************************************

// randomize_board: ВЫБОР СЛУЧАЙНОГО ИСХОДНОГО СОСТОЯНИЯ ФИШЕК

//********************************************************************

void randomize_board(int board_array[]) {

 int temp = 0;

 int i;

 unsigned char temp2 = 0x00;

 for (i=0; iARRAY_MAX+1; i++) {

  temp2 = TCNTL;

  temp = mod(temp2,15); //случайное значение using the TCNT counter

  swap2(i,temp, board_array);

 }

}

//********************************************************************

// MOD: МАТЕМАТИЧЕСКАЯ ФУНКЦИЯ

//********************************************************************

unsigned char mod(unsigned char num, int modulus) {

 while ((num - modulus) 0) num = num - modulus;

 return num;

}

//********************************************************************

// display_board2: Выводит табло, как одну колонку значений

//********************************************************************

void display_board2(int board_array[ARRAY_MAX+1]) {

 int = 0;

 int n;

Перейти на страницу:
Нет соединения с сервером, попробуйте зайти чуть позже