Freescale Semiconductor Microcontrollers Manuel d'utilisateur Page 660

  • Télécharger
  • Ajouter à mon manuel
  • Imprimer
  • Page
    / 892
  • Table des matières
  • DEPANNAGE
  • MARQUE LIVRES
  • Noté. / 5. Basé sur avis des utilisateurs
Vue de la page 659
ColdFire V1 Full Chip Simulation Connection
FCS Tutorials
660
Microcontrollers Debugger Manual
Step 9 - Entering User Code
1. Open the user module MyGuessTheNumber.C
2. Insert the following code before the main routine:
#include <stdlib.h>
void PutChar(unsigned char c) {
while (AS1_SendChar(c) == ERR_TXFULL) {
// could wait a bit here
}
}
void PutString(const char* str) {
while (str[0] != '\0') {
PutChar(str[0]);
str++;
}
}
void GuessTheNumber(void) {
int ran = rand() / (RAND_MAX / 9);
AS1_Init();
PutString("Guess a Number between 0 and 9\n");
PutString("Number: ");
for (;;) {
unsigned char c;
if (AS1_RecvChar(&c) == ERR_OK) {
PutChar(c); PutChar(' ');
if(c < '0' || c > '9') {
PutString("not a number, try again\n");
} else if(c == ran + '0') {
PutString("\nCongratulation! You have found the number!");
PutString("\nGuess a new number\n");
ran = rand() / (RAND_MAX / 9);
} else if(c > ran + '0') {
PutString("lower\n");
} else {
PutString("greater\n");
}
PutString("Number: ");
} else {
// could wait a bit here
}
} // for
}
3. Call the function GuessTheNumber in the main routine.
Vue de la page 659
1 2 ... 655 656 657 658 659 660 661 662 663 664 665 ... 891 892

Commentaires sur ces manuels

Pas de commentaire