Testing of Timer0 and Interrupt in 1 second on ARM7-LPC2368. By using CP-JR ARM7 LPC2368 develop board from ETT. Co., LTD. The CCLK has a speed of 48MHz, PCLK is set as CCLK/4=12MHz. Two signals are measured from P1.24 and P1.25 as shown in the figure.
Thanks: ฝากรูป
/****************************************************/
/* Examples Program For "CP-JR ARM7 LPC2368" */
/* Target MCU : Philips ARM7-LPC2368 */
/* : X-TAL : 12.00 MHz */
/* : PLL Setup = MSEL(12),NSEL(1) */
/* Keil Editor : uVision3 V4.13a */
/* Compiler : Keil Realview MDK V4.13 */
/* Create By : Musa */
/* Last Update : 30/March/2011 */
/* Function : TimerInterrupt.c/TimerInterrupt.hex */
/****************************************************/
#include "LPC23xx.H"
#define LED1 0x02000000 // P3.25(0000 00x0 0000 0000 0000 0000 0000 0000)
#define LED2 0x04000000 // P3.26(0000 0x00 0000 0000 0000 0000 0000 0000)
#define LED1_ON() FIO3CLR = LED1 // LED1 Pin = 0 (ON LED)
#define LED1_OFF() FIO3SET = LED1 // LED1 Pin = 1 (OFF LED)
#define LED2_ON() FIO3CLR = LED2 // LED2 Pin = 0 (ON LED)
#define LED2_OFF() FIO3SET = LED2 // LED2 Pin = 1 (OFF LED)
#define Logic_ON() FIO0SET = 0x04000000
#define Logic_OFF() FIO0CLR = 0x04000000
#define IO0CLR = 0xE002800C
#define IO0SET = 0xE0028004
int Sta,Sta2;
void timer0_irq(void) __irq //Timer0 irq interrupt
{
/* Your program Interrupt routine */
FIO1PIN |= 0x02000000; //Program interrupt example
//******** It is very important for every interrupt routine******************
T0IR = 0x00000001; //clear the interrupt flag *
// *The interrupt flag must be cleared to reset interruption. *
VICVectAddr = 0x00000000; // *Dummy Wright to signal end of Interrupt
//***************************************************************
}
void delay_ms(long int ms)
{
long int i,j;
for(i=0;i<ms;i++)
for(j=0;j<3999;j++);
}
void Int_PLL(void)
{
CLKSRCSEL |= 0x00000001; //Select the main oscillator as the PLL clock source.
PLLCFG |= 0x0001000B; //M=(Fcco*N)/(2*main_OSC), M=(288MHz*1)/(2*12MHz)=12, MSEL=M-1=12-1=11=0x0B, NSEL=N=1
CCLKCFG |= 0x00000003; //Set Clock divider CCLK=PLLCLK/(CCLKSEL), CCLK=12*12MHz/(3), CCLK=48MHz, CCLKSEL=3,
//PLLCLK=M*main_OSC=12*12MHz=144MHz
//If CCLKSEL is even, the CCLKCFG will be equal to CCLKSEL.
//If CCLKSEL is odd, the CCLKCFG will be equalt to CCLKSEL+1.
//Thus, The CCLK has a speed of 48MHz. The PCLK of timer0 is set as CCLK/4=12MHz.
PLLCON |= 0x00000001; //PLL Enable.
PLLFEED |= 0x000000AA;
PLLFEED |= 0x00000055;
while(!(PLLSTAT & 0x04000000));
PLLCON |= 0x00000003; //PLL connect.
PLLFEED |= 0x000000AA;
PLLFEED |= 0x00000055;
return;
}
int main(void)
{
/************************************************************/
/*************** Initial FGPIO LED port *********************/
PINSEL7 &= 0xFFC3FFFF; // P3[26:25] = GPIO Function(xxxx xxxx xx00 00xx xxxx xxxx xxxx xxxx)
PINMODE7 &= 0xFFC3FFFF; // Enable Puul-Up on P3[26:25]
FIO3DIR |= LED1; // Set GPIO-3[26:25] = Output(xxxx x11x xxxx xxxx xxxx xxxx xxxx xxxx)
FIO3DIR |= LED2;
//**********************************************************/
//***************** Initial FGPIO 0 Port 0 *****************/
SCS |= 0x01; // For using GPIO-0 and GPIO-1
PINSEL1 &= 0xFFAFFFFF; // &= xxxx xxxx xx00 xxxx xxxx xxxx xxxx xxxx
PINMODE1 &= 0xFFAFFFFF; // Enable Pull-up on P0.26
FIO0DIR |= 0x04000000; // Set GPIO-0[26] = Output(xxxx x1xx xxxx xxxx xxxx xxxx xxxx xxxx)
FIO0DIR |= 0x02000000;
//**********************************************************************
//***************** Initial GPIO 1 Port 1 *****************************
PINSEL3 &= 0xFFF0FFFF;
PINMODE3 &= 0xFFF0FFFF;
FIO1DIR |= 0x03000000; //P1.25 and P1.24 are Outputs.
FIO1PIN |=0x00000000;
/************************************************************/
/*************** Timer0 *********************/
PCLKSEL0 &= 0xFFFFFFF9; //clear PCLK_TIMER0 Config
PCLKSEL0 |= 0x00000000; //set PCLK_TIMER0 PCLK=CCLK/4
T0CTCR = 0x00000000; // Timer mode every rising PCLK edge
T0TCR = 0x00000002; // reset timer counter and prescale counter
T0TC = 0x00000000; // clear timer counter
T0PC = 0x00000000; // clear prescale counter
T0PR = 11999; // 12000-1=11999 = 1ms
T0MCR = 0x00000003; // interrupt and reset TC when TC match with MR0
T0MR0 = 1000; // interrupt every 500 ms
//T0TCR = 0x00000001; // Enable timer counter
VICVectAddr4 = (unsigned)timer0_irq;
VICVectPriority4 = 0x00000000;
VICIntEnable |= 0x00000010; // select timer0 interrupt
//
LED1_ON();
LED2_OFF();
Int_PLL();
delay_ms(1000);
FIO1PIN |=0x01000000;
T0TCR = 0x00000001; //Enable Timer Counter
while(1);
// In testing, You must press the Reset button on the develop board.
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment