We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
This routine runs but it runs fast the crystal is 12Mhz and the configuration
/* *FILE NAME: msecWait.c * *NOTE:Since the counter counts up it is necessarey to * subtract the nuber of counts/millsecnd from the * maximum count for Counter 0 which is 0xFC65) * seperated into bytes(unsigned char) hiByte = * 0xFC and lowByte = 0x65. * *DESCRIPTION: Delays for the input argument number * of miliseconds * *INPUTS: Requested number of miliSeconds (0.001 * Seconds) to delay * *OUTPUTS: processor is on hold for the proscribed * number of milliseconds * #include "F100GlobalDataTypeDefs.h" #include "F100GlobalDef.h" #include "F100GlobalVars.h" #include "F100Functions.h" #include "F100HW.h" #include <stdio.h> void msecWait(unsigned int milliSeconds) { //1000 counts/(milisecond) unsigned char highByte = 0xFC; lowByte = 0x65; // up count, thus count is // from 64286 (FB1E)bit bitET0, bitTR0; // Storage locations bitTR0 = TR0; // Save TR0 // TR0 = 0; // Stop T0 // bitET0 = ET0; // Save ET0 // ET0 = 0; // Disable T0 // while (milliSeconds > NOMILLISECONDS) { TH0 = highByte; TL0 = lowByte; TR0 = 1; //start timer 0 // while (!TF0) {;} // wait for T0 to overflow TR0 = 0 ; // stop timer 0 // TF0 = 0 ; // Reset the overflow milliSeconds--;// Decrement the count } // end while (milliSeconds > NOMILLISECONDS) ET0 = bitET0; // Restore ET0 // TR0 = bitTR0; // Restore TR0 // } // end msecWait(unsigned int milliSeconds)
The FC65 was a leftover from the testing after we found the problem.