// filename ******** main.C ************** // MC9S12C32 test program for Lab1d // This example accompanies the books // "Embedded Microcomputer Systems: Real Time Interfacing", Brooks-Cole, copyright (c) 2000, // "Introduction to Embedded Microcomputer Systems: // Motorola 6811 and 6812 Simulation", Brooks-Cole, copyright (c) 2002, // Jonathan W. Valvano 9/1/07 // You may use, edit, run or distribute this file // as long as the above copyright notices remain #include /* common defines and macros */ #include /* derivative information */ #include #include "fixed.h" #pragma LINK_INFO DERIVATIVE "mc9s12c32" // const will place these structures in ROM const struct inTestCase{ // used to test Fixed_Str2Fix unsigned char InBuffer[10]; // Input String short CorrectAnswer; // proper result }; typedef const struct inTestCase inTestCaseType; inTestCaseType inTests[34]={ { "0", 0}, // 0.00 { "1", 100}, // 1.00 { ".02", 2}, // 0.02 { "+.1", 10}, // 0.10 { "+1.", 100}, // 1.00 { "12.34", 1234}, // 12.34 { "5.05", 505}, // 5.05 { "10.70", 1070}, // 10.70 { "0.0023", 0}, // 0.00 { "9.994", 999}, // 9.99 { "9.995", 1000}, // 10.00 { "14.595", 1460}, // 14.60 { "14.604", 1460}, // 14.60 { "19.994", 1999}, // 19.99 { "19.995", 2000}, // 20.00 { "-21", -2100}, // -21.00 { "-27.67", -2767}, // -27.67 { "327.67", 32767}, // 327.67 { "-327.67",-32767}, // -327.67 { "-327.69",-32768}, // illegal, too big { "328", -32768}, // illegal, too big { "-500", -32768}, // illegal, too big { "327.700",-32768}, // illegal, too big { "327.675",-32768}, // illegal, too big { "327.8", -32768}, // illegal, too big { "3*2", -32768}, // illegal, illegal character { "3A.769", -32768}, // illegal, illegal character { "32.7b9", -32768}, // illegal, illegal character { "3..767", -32768}, // illegal, two decimal points { "3.2.767",-32768}, // illegal, two decimal points { ".", -32768}, // illegal, no numbers { "-+1", -32768}, // illegal, both signs { "1+", -32768}, // illegal, sign not first { "", -32768} // illegal, no numbers }; const struct outTestCase{ // used to test Fixed_Fix2Str short InNumber; // test input number unsigned char OutBuffer[10]; // Output String }; typedef const struct outTestCase outTestCaseType; outTestCaseType outTests[20]={ { 0, " 0.00" }, // 0.00 { 4, " 0.04" }, // 0.04 { 10, " 0.10" }, // 0.10 { -20, " -0.20" }, // 0.20 { 100, " 1.00" }, // 1.00 { 505, " 5.05" }, // 5.05 { 1070, " 10.70" }, // 10.70 { 1234, " 12.34" }, // 12.34 { -2859, " -28.59" }, // -28.59 { -2999, " -29.99" }, // -29.99 { -3000, " -30.00" }, // -30.00 { -3001, " -30.01" }, // -30.01 { 6460, " 64.60" }, // 64.60 { -9999, " -99.99" }, // -99.99 { 10000, " 100.00" }, // 100.00 {-12345, "-123.45" }, // -123.45 { 32767, " 327.67" }, // 327.67 {-32767, "-327.67" }, // -327.67 { -1, " -0.01" }, // -0.01 { 32768, " ***.**" } // illegal }; short Input; // fixed-point resolution 0.001 short Result; // fixed-point resolution 0.001 unsigned short I; unsigned short Errors,AnError; unsigned char Buffer[10]; void main(void){ // possible main program that tests your functions Errors = 0; asm cli for(I=0; I<34; I++){ strcpy((char *)Buffer,(char *)inTests[I].InBuffer); // input test Result = Fixed_Str2Fix(Buffer); // convert string to fixed point if(Result != inTests[I].CorrectAnswer){ Errors++; AnError = I; } } for(I=0; I<20; I++){ Input = outTests[I].InNumber; Fixed_Fix2Str(Input,Buffer); if(strcmp((char *)Buffer, (char *)outTests[I].OutBuffer)){ Errors++; AnError = I; } } for(;;) {} /* wait forever */ }