// filename ******** Lab1e.C ************** // MC9S12DP512 test program for Lab 1e // Jonathan W. Valvano 8/9/09 // This example accompanies the books // "Embedded Microcomputer Systems: Real Time Interfacing", // Thompson, copyright (c) 2006, // "Introduction to Embedded Systems: Interfacing to the Freescale 9S12", // Cengage Publishing 2009, ISBN-10: 049541137X | ISBN-13: 9780495411376 // Copyright 2009 by Jonathan W. Valvano, valvano@mail.utexas.edu // You may use, edit, run or distribute this file // as long as the above copyright notice remains #include /* common defines and macros */ #include /* derivative information */ #pragma LINK_INFO DERIVATIVE "mc9s12dp512" #include #include "fixed.h" // const will place these structures in ROM const struct inTestCase{ // used to test Fixed_Str2Fix unsigned char InBuffer[10]; // Input String unsigned 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 { "327.67", 32767}, // 327.67 { "327.68", 32768}, // 327.68 { "655.34", 65534}, // 655.34 { "655.36", 65535}, // illegal, too big { "656", 65535}, // illegal, too big { "1000", 65535}, // illegal, too big { "655.75", 65535}, // illegal, too big { "656.00", 65535}, // illegal, too big { "655.8", 65535}, // illegal, too big { "3*2", 65535}, // illegal, illegal character { "3A.769", 65535}, // illegal, illegal character { "32.7b9", 65535}, // illegal, illegal character { "3..767", 65535}, // illegal, two decimal points { "3.2.767", 65535}, // illegal, two decimal points { ".", 65535}, // illegal, no numbers { "-1", 65535}, // illegal, sign not supported { "+1", 65535}, // illegal, sign not supported { "", 65535} // illegal, no numbers }; const struct outTestCase{ // used to test Fixed_Fix2Str unsigned 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 { 32768, "327.68" }, // 327.68 { 65534, "655.34" }, // 655.34 { 65535, "***.**" } // illegal }; unsigned short Result; // fixed-point resolution 0.01 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++){ Result = Fixed_Str2Fix(inTests[I].InBuffer); // convert string to fixed point if(Result != inTests[I].CorrectAnswer){ Errors++; AnError = I; } } for(I=0; I<20; I++){ Fixed_Fix2Str(outTests[I].InNumber,Buffer); if(strcmp((char *)Buffer, (char *)outTests[I].OutBuffer)){ Errors++; AnError = I; } } for(;;) {} /* wait forever */ }