timers and interrupts without OS problem

Post Reply
kebrzyk
Posts: 8
Joined: Tue Dec 15, 2009 10:50 am

timers and interrupts without OS problem

Post by kebrzyk » Mon Feb 08, 2010 10:30 am

Hi,
I am developing program with Leds (binary counter on leds) and timer with interrupt, but it doesn't work.
Idea is when the timer counted one second then should request interrupt. It's mean that Led must be on. I am writting in Eclipse.

Code: Select all

#include "2440addr.h"
#include "Def.h"


void init_timer (void);
static void timer_handler (void) __attribute__ ((interrupt("IRQ")));
void binary_leds (void);

U16 i=0,tmp=0;	/* temporary needed to binary counter*/

int main (void)
{

	init_timer();
	while (1);

return 0;
}

void init_timer (void)
{
	pISR_TIMER2	= (U32)timer_handler;	/* address of interrupt service routine*/
	pISR_IRQ = (U32)timer_handler;
	ClearPending(BIT_TIMER2);	/* interrupt timer2 requested*/
	EnableIrq(BIT_TIMER2);	/* */


	rGPBCON &= 0xffffcc;	/* mask GPBCON and clear 5th and 4th bits and buzzer off*/
	rGPBCON |= 0x000020;	/* set 5th and  4th bits at 2 binary value,
							//it's mean that GPB2 is configured as TOUT2*/

	rGPBCON&=0xfc03ff; /*Port GPB is configured for leds (GPB5,GPB6,GPB7,GPB8-output)*/
	rGPBCON|=0x0015400;

	rGPBDAT|=0x1e0;		/*LEDs are cleared*/

	rTCFG0 |= 0x0ff00;		/* prescaler configured as 255 value*/
	rTCFG1 |= 0x00300;		/* divider configured as 16 value */

	/******************* timer on ***************************/
	rTCMPB2 = 0;		/* set comparator at 0*/
	rTCNTB2 = 12207;		/* set counter to count 1 sec */
	rTCON = 0x00a000;	/* Auto-reload is on, manual update bit is set*/
	rTCON = 0x009000;	/* manual update bit is cleared, start bit is set */

}

static void timer_handler (void)
{
	ClearPending(BIT_TIMER2);
	binary_leds();
}

void binary_leds (void)
{
	tmp++;
			i=tmp;
			i = (~i)<<5;
			rGPBDAT|=0x1e0;
			rGPBDAT &= i;
}
please help me

Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests