Module 5
Module 5
Match Register
• A Match Register is a Register which contains a specific
value set by the user.
• When the Timer starts – every time after TC is
incremented, the value in TC is compared with match
register. If it matches then it can Reset the Timer or can
generate an interrupt as defined by the user.
Match Registers can be used to:
•Stop Timer on Match(i.e when the value in count register
is same as that in Match register) and trigger an optional
interrupt.
•Reset Timer on Match and trigger an optional interrupt.
•To count continuously and trigger an interrupt on match.
void initTimer0(void)
{
LPC_TIM0->CTCR = 0x0; //timer mode
LPC_TIM0->TCR = 0x02; //Reset Timer
LPC_TIM0->PR = 2; //Increment TC at every 2+1 clock cycles, Tres = 1us
LPC_TIM0->MR0 = 999; // for 1 ms delay TC counts 0 to 999
LPC_TIM0->MCR = 2; // reset TC after 1 ms delay
LPC_TIM0->EMR = 0x20; // when match occurs bit 0 of EMR will set
LPC_TIM0->TCR = 0x01; //enable timer0
}
void delay(void)
{
initTimer0();
while(!(LPC_TIM0->EMR &1));
}