#include <LPC2103.H>
#include "tmr0.h"
#include "..\IOCONFIG\ioconfig.h"

/*
***********************************************************************************************************************
* PCKDIV set 4 in system.h, and Fcclk = 1200000*5 in which 1200000 is the external crystal, and 5 is the PLL
* multiplier defined in system.h. As a result, peripheral clock = 60MHz/4 = 15MHz
***********************************************************************************************************************
*/
void DelayMs(unsigned long t)
{
	T0PR = 149;				//Prescale 150 to obtain a tmr0 rate of 100kHz (T=0.01ms)
	T0MCR_bit.MR0INT = 1;	//enable interrupt on MR0
	T0MCR_bit.MR0RES = 1;	//reset on MR0
	T0MR0 = 100*t;			//set match register a value of 100 for exactly 1ms time base, then a factor of 't' applied
	T0TCR = 2;				//reset tmr0, when CR bit 1.
	T0TCR = 1;				//start tmr0, and most importantly to release the CR bit in this instruction
							//because the timer remains in reset until the CR bit returns 0
	while(T0IR_bit.MR0INT==0);
	T0IR_bit.MR0INT = 1;	//clear interrupt flag
}
