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.
Summary of Contents for Microcontrollers
Page 1: ...Microcontrollers Debugger Manual Revised 22 October 2007 ...
Page 20: ...Table of Contents 20 Microcontrollers Debugger Manual ...
Page 24: ...Book I Contents 24 Microcontrollers Debugger Manual ...
Page 60: ...Debugger Interface Highlights of the User Interface 60 Microcontrollers Debugger Manual ...
Page 156: ...Debugger Components Visualization Utilities 156 Microcontrollers Debugger Manual ...
Page 198: ...Real Time Kernel Awareness OSEK Kernel Awareness 198 Microcontrollers Debugger Manual ...
Page 236: ...Synchronized Debugging Through DA C IDE Troubleshooting 236 Microcontrollers Debugger Manual ...
Page 238: ...Book II Contents 238 Microcontrollers Debugger Manual ...
Page 332: ...HC08 Full Chip Simulation Configuration Procedure 332 Microcontrollers Debugger Manual ...
Page 348: ...MON08 Interface Connection Device Class Description 348 Microcontrollers Debugger Manual ...
Page 364: ...ICS MON08 Interface Connection Device Class Description 364 Microcontrollers Debugger Manual ...
Page 428: ...HC08 FSICEBASE Emulator Bus State Analyzer BSA 428 Microcontrollers Debugger Manual ...
Page 430: ...Book III Contents 430 Microcontrollers Debugger Manual ...
Page 466: ...HCS08 Full Chip Simulation Peripheral Modules Commands 466 Microcontrollers Debugger Manual ...
Page 544: ...HCS08 On Chip DBG Module HCS08 DBG V3 New Features 544 Microcontrollers Debugger Manual ...
Page 546: ...Book IV Contents 546 Microcontrollers Debugger Manual ...
Page 576: ...Book V Contents 576 Microcontrollers Debugger Manual ...
Page 698: ...Book VI Contents 698 Microcontrollers Debugger Manual ...
Page 714: ...Flash Programming NVMC Commands 714 Microcontrollers Debugger Manual ...
Page 730: ...Book VII Contents 730 Microcontrollers Debugger Manual ...
Page 840: ...Book VIII Contents 840 Microcontrollers Debugger Manual ...
Page 864: ...Book IX Contents 864 Microcontrollers Debugger Manual ...
Page 868: ...Legacy Target Interfaces Removed 868 Microcontrollers Debugger Manual ...