// File Name: ASDELAY.C, ASDELAY.H
// Author: Jason Lopez
// Date: 10/22/08
//
// Seconds and Milliseconds Delay Routine for C18
//
// Rev 0:
// Initial Revision.
//
#include "asdelay.h"
unsigned int tempa,tempb,tempc;
void delay_ms(char Time2Delay) // 1ms = 932.600000 uSecs
{
tempa = tempb = tempc = 0;
tempa = (((Time2Delay * SpeedMhz) / 4) / 1000000) - 2;
if (tempa > 255){
tempb = tempa - 255;
Delay1KTCYx(255);
if (tempb > 255){
tempc = tempb - 255;
Delay1KTCYx(255);
Delay1KTCYx(tempc);
} else {
Delay1KTCYx(tempb);
}
} else {
Delay1KTCYx(tempa);
}
return;
}
void delay_s(char Time2Delay) // 1 second = 996.342000 mSec
{
tempa = tempb = tempc = 0;
tempa = (((Time2Delay * SpeedMhz) / 4) / 10000) - 2;
if (tempa > 255){
tempb = tempa - 255;
Delay10KTCYx(255);
if (tempb > 255){
tempc = tempb - 255;
Delay10KTCYx(255);
Delay10KTCYx(tempc);
} else {
Delay10KTCYx(tempb);
}
} else {
Delay10KTCYx(tempa);
}
return;
}