hi,
this is vicky from india
i am working on the LPC2106 philips ic
I am having problems in executing timer interrupts
the timer interupt doesnt go to the ISR & the system stops responding.
i have attached the source file with the mail
if anybody can help with same program code please help
Regards
Vicky
Send instant messages to your online friends http://in.messenger.yahoo.com
----------
// Copyright (c) 2001-2004 Rowley Associates Limited.
//
// This file may be distributed under the terms of the License Agreement
// provided with this software.
//
// THIS FILE IS PROVIDED AS IS WITH NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
////////////////////////////////////////////////////////////////////////////////
//
// Philips LPC210X - UART Example
//
// Description
// -----------
// This example demonstrates configuring and writing to a UART. It also
// demonstrates how to get printf output over the UART by implementing
// __putchar.
//
// To see output:
// - Connect serial cable from UART0 connector on your target board to your
// host computer.
// - Open CrossStudio's "Terminal Emulator Window". Configure it to 9600 baud,
// 8 data bits, no parity, 1 stop bits. Click "Connect" to start the
// terminal emulator window.
//
////////////////////////////////////////////////////////////////////////////////
#include <targets/LPC210x.h>
#include <stdio.h>
//#include <ctl_api.h>
static int timer0Count, timer1Count;
static unsigned int processorClockFrequency();
static unsigned int peripheralClockFrequency();
static void delay(int n);
static void UARTInitialize(unsigned int baud);
static void UARTWriteChar(unsigned char ch);
static unsigned char UARTReadChar();
static void UARTWriteChar(unsigned char ch);
void __putchar(int ch);
static void ledInit();
static void ledOff();
static void ledOn();
static void tim_init(void);
static unsigned int
processorClockFrequency(void)
{
return 14.7456 * 1000000 * (PLLCON & 1 ? (PLLCFG & 0xF) + 1 : 1);
}
static unsigned int
peripheralClockFrequency(void)
{
unsigned int divider;
switch (VPBDIV & 3)
{
case 0:
divider = 4;
break;
case 1:
divider = 1;
break;
case 2:
divider = 2;
break;
}
return processorClockFrequency() / divider;
}
static void
delay(int n)
{
volatile int i;
for (i = 0; i < n; ++i);
}
static void
UARTInitialize(unsigned int baud)
{
unsigned int divisor = peripheralClockFrequency() / (16 * baud);
U0LCR = 0x83; /* 8 bit, 1 stop bit, no parity, enable DLAB */
U0DLL = divisor & 0xFF;
U0DLM = (divisor >> 8) & 0xFF;
U0LCR &= ~0x80; /* Disable DLAB */
PINSEL0 = PINSEL0 & ~0xF | 0x5;
U0FCR = 1;
}
static void
UARTWriteChar(unsigned char ch)
{
while ((U0LSR & 0x20) == 0);
U0THR = ch;
}
static unsigned char
UARTReadChar(void)
{
while ((U0LSR & 0x01) == 0);
return U0RBR;
}
void
__putchar(int ch)
{
if (ch == '\n')
UARTWriteChar('\r');
UARTWriteChar(ch);
}
static void
ledInit()
{
IODIR |= 0x00000080;
IOSET = 0x00000080;
}
static void
ledOff(void)
{
IOCLR = 0x00000080;
}
static void
ledOn(void)
{
IOSET = 0x00000080;
}
static void timer0ISR(void) __attribute__ ((interrupt ("IRQ")));
static void
timer0ISR(void)
{
if (++timer0Count % 2)
ledOn();
else
ledOff();
/* Clear the timer 0 interrupt */
T0IR = 0xFF;
/* Update VIC priorities */
VICVectAddr = 0;
}
static void timer1ISR(void) __attribute__ ((interrupt ("IRQ")));
static
void
timer1ISR(void)
{
++timer1Count;
/* Clear the timer 1 interrupt */
T1IR = 0xFF;
/* Update VIC priorities */
VICVectAddr = 0;
}
static void
tim_init(void)
{
// T0IR = 0;
// T1IR = 0;
T0IR = 0x00000000;
T1IR = 0x00000000;
T0TC = 0;
T1TC = 0;
/* Timer 0 interrupt is an IRQ interrupt */
VICIntSelect &= ~0x10;
/* Enable timer 0 interrupt */
VICIntEnable = 0x10;
/* Use slot 0 for timer 0 interrupt */
VICVectCntl0 = 0x24;
/* Set the address of ISR for slot 0 */
VICVectAddr0 = (unsigned long)timer0ISR;
/* Timer 1 interrupt is an IRQ interrupt */
VICIntSelect &= ~0x20;
/* Enable timer 1 interrupt */
VICIntEnable = 0x20;
/* Use slot 1 for timer 1 interrupt */
VICVectCntl1 = 0x25;
/* Set the address of ISR for slot 1 */
VICVectAddr1 = (unsigned long)timer1ISR;
/* Reset timer 0 */
T0TCR = 0;//timer Control register
/* Set the timer 0 prescale counter */
T0PR = 2500000;
/* Set timer 0 match register */
T0MR0 = 10;
/* Generate interrupt and reset counter on match */
T0MCR = 3;
/* Start timer 0 */
T0TCR = 1;
/* Reset timer 1 */
T1TCR = 0;
/* Set the timer 1 prescale counter */
T1PR = 2500000;
/* Set timer 1 match register */
T1MR0 = 10;
/* Generate interrupt and reset counter on match */
T1MCR = 3;
/* Start timer 1 */
T1TCR = 1;
T0IR = 0;
T1IR = 0;
}
int
main(void)
{
int i;
unsigned char vic;
tim_init();
UARTInitialize(9600);
ledInit();
delay(1000);
/* Enable Interrupts */
//__ARMLIB_enableIRQ();
for (i = 0; ; ++i)
{
printf("Hello World (%d) (%d) (%d)\n\n", i,T0TC,T1TC);
// printf("Vicky (%d)\n\r",i);
// printf("Kushal (%d)\n\r",i);
// printf("Bimal (%d)\n\r",i);
//vic = UARTReadChar();
//putchar(vic);
if(T0IR != 0 || T1IR != 0)
{
printf("Interrupt (%d) (%d)",T0IR,T1IR);
T0IR = 0x00000000;
T1IR = 0x00000000;
}
ledOff();
delay(100000);
ledOn();
delay(100000);
}
return 0;
}
[Non-text portions of this message have been removed]Message
SOS please help
2006-01-09 by vicky gosar
Attachments
- No local attachments were found for this message.