The student coded the following two functions to output numeric values to the screen.
// begin example
void LCDPutDWORD(DWORD num, int x, int y, int fColor, int bColor)
{
//Size of a DWORD is as follows
//FFFFFFFF
//4294967295
// 10 places
const int sizeOFDWORD = 10;
char outString[sizeOFDWORD + 1];
outString[sizeOFDWORD] = '\0';
int loopCtr;
for (loopCtr = 0; loopCtr < sizeOFDWORD; loopCtr++)
{
// pull of the last digit and store it
char curDigit = num % 10;
// convert digit to it's ASCII value
curDigit = curDigit + 48;
// store ASCII value into the string in the correct spot
outString[sizeOFDWORD - loopCtr - 1] = curDigit;
// prep number to pull of next digit.
// (0/10 =0) is expected to happen multiple times
num = num / 10;
}
LCDPutStr(outString, x, y, fColor, bColor);
}
void LCDPutWORD(WORD num, int x, int y, int fColor, int bColor)
{
// Size of a WORD is as follows
// FFFF
// 65535
const int sizeOFWORD = 5;
char outString[sizeOFWORD + 1];
outString[sizeOFWORD] = 0x00;
int loopCtr;
for (loopCtr = 0; loopCtr < sizeOFWORD; loopCtr++)
{
// pull of the last digit and store it
char curDigit = num % 10;
// convert digit to it's ASCII value
curDigit = curDigit + 48;
// store ASCII value into the string in the correct spot
outString[sizeOFWORD - loopCtr - 1] = curDigit;
// prep number to pull of next digit.
// (0/10 =0) is expected to happen multiple times
num = num / 10;
}
LCDPutStr(outString, x, y, fColor, bColor);
}
// end example
The functions above allowed the student to output numeric values received as a result of an analog to digital conversion.
No comments:
Post a Comment