EMBEDDED FOR US
Would you like to react to this message? Create an account in a few clicks or log in to continue.

8051: 16 bit timer0 overflow using Interrupt service routine.

Go down

8051: 16 bit timer0 overflow using Interrupt service routine. Empty 8051: 16 bit timer0 overflow using Interrupt service routine.

Post  Admin Wed Jul 31, 2013 1:51 am

This example program shows how to configure timer/counter 0 as a
16-bit timer. An interrupt service routine (ISR) is invoked each
time the timer overflows (goes from 0xFFFF to 0x0000). Inside
the ISR, a variable called overflow_count is incremented by one.

To test this program...

1. Start the debugger.
2. Set a breakpoint on the 'overflow_count++' line in the ISR.
3. Run the program.

Each time the interrupt routine is invoked, the debugger will stop
running the program. Position the cursor over 'overflow_count' to
see its current value.








/* Hardware specific header file*/
#include <reg52.h>


/*------------------------------------------------
Timer 0 Interrupt Service Routine.

Set a breakpoint on 'overflow_count++' and run the
program in the debugger. You will see this line
executes every 65536 clock cycles.
------------------------------------------------*/
static unsigned long overflow_count = 0;

void timer0_ISR (void) interrupt 1
{
overflow_count++; /* Increment the overflow count */
}

/*------------------------------------------------
MAIN C function
------------------------------------------------*/
void main (void)
{
/*--------------------------------------
Set Timer0 for 16-bit timer mode. The
timer counts to 65535, overflows, and
generates an interrupt.

Set the Timer0 Run control bit.
--------------------------------------*/
TMOD = (TMOD & 0xF0) | 0x01; /* Set T/C0 Mode */
ET0 = 1; /* Enable Timer 0 Interrupts */
TR0 = 1; /* Start Timer 0 Running */
EA = 1; /* Global Interrupt Enable */

/*--------------------------------------
Do Nothing. Actually, the timer 0
interrupt will occur every 65536 clocks.
--------------------------------------*/
while (1)
{
}
}











Admin
Admin
Admin

Posts : 49
Join date : 2012-08-15
Location : Mumbai,INDIA

http://embeddedforus.com

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum