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)
unsigned char Sta;
void timer0_irq(void) __irq //Timer0 irq interrupt
{
/* Your program Interrupt routine */
if (Sta==0)
{
Sta=1;
LED1_ON();
}
else
{
Sta=0;
LED1_OFF();
}
//*************The most important**********************************
T0IR = 0x00000001; //clear the interrupt flag
// *The interrupt flag must be cleared to repeat the interrupt for the next times.
VICVectAddr = 0x00000000; // *Dummy Wright to signal end of Interrupt
//***************************************************************
}
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;
/************************************************************/
/*************** Timer0 *********************/
PCLKSEL0 &= 0xFFFFFFF3; //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 = 10000; // tpr=(1000+1)/PCLK
T0MCR = 0x00000003; // interrupt and reset TC when TC match with MR0
T0MR0 = 901; // interrupt every 500 ms
T0TCR = 0x00000001; // Enable timer counter
VICVectAddr4 = (unsigned)timer0_irq;
VICVectPriority4 = 0x00000004;
VICIntEnable |=0x00000010; // select timer0 interrupt
LED1_OFF();
LED2_OFF();
Sta=0;
while(1);
}
เดี๋ยวจะลองศึกษาดูครับ
ReplyDeleteThankyou
ยังไม่ได้ลองเลย LPC2368 แต่ถ้าดัดแปลงโค้ดให้เข้ากับ LPC2138 ได้
ReplyDeleteก็น่าจะเอาไปลอง Simulation กับ Proteus v.7 ได้เลย จะช่วยลดปัญหาเรื่อง "คนไม่มีแฟนได้" เฮ้ย อิอิ คนไม่มีตังค์ครับ
อันนี้เป็น code ที่ลองทดสอบ Interrupt เฉยๆ นะครับ แต่เวลายังไม่ได้ปรับให้มีความเที่ยงตรง
ReplyDeleteอันล่าสุดตามลิ้งนี้เลยนะครับ : http://musaho.blogspot.com/2011/04/timer0-interrupt-in-1s-on-arm7-lpc2368.html