สอบถามการ Interrupt ใน arm cortex m3 LPC1756

Started by anon1206, April 17, 2013, 09:31:13 PM

Previous topic - Next topic

anon1206

ต้องเขียนแบบไหนครับ
ผมเคยเขียนแต่ใน PIC เขียนแบบนี้ครับ ไม่ต้องเรียกใน main เรียกอัตโนมัติใน time Interrupt เลยครับ

#INT_TIMER1
void IntTimer1_isr()
   {
      scandisplay();  // ฟังก์ชันที่จะให้เรียกอัตโนมัติ
      set_timer1(65400);
   }
void main(void)
{

   set_tris_b(0x00);
   enable_interrupts(GLOBAL);
   enable_interrupts(INT_TIMER1);   
   setup_timer_1(T1_INTERNAL | T1_DIV_BY_1);
   set_timer1(65451); //    interrupt 34uS


   while(true)
   { 

   }
}

ถ้าจะเขียนใน arm cortex m3 LPC1756 ต้องเขียนแบบไหนครับ  :'(

atlantaman

หน้าตาจะเป็นแบบนี้ครับ
/****************************************************************************
*   $Id:: tmrtest.c 6098 2011-01-08 02:26:20Z nxp12832                      $
*   Project: NXP LPC17xx Timer example
*
*   Description:
*     This file contains Timer test modules, main entry, to test Timer APIs.
*
****************************************************************************
* Software that is described herein is for illustrative purposes only
* which provides customers with programming information regarding the
* products. This software is supplied "AS IS" without any warranties.
* NXP Semiconductors assumes no responsibility or liability for the
* use of the software, conveys no license or title under any patent,
* copyright, or mask work right to the product. NXP Semiconductors
* reserves the right to make changes in the software without
* notification. NXP Semiconductors also make no representation or
* warranty that such application will be suitable for the specified
* use without further testing or modification.
****************************************************************************/
#include <cr_section_macros.h>
#include <NXP/crp.h>

__CRP const unsigned int CRP_WORD = CRP_NO_CRP ;

#include "lpc17xx.h"
#include "type.h"
#include "timer.h"

#define BLINK_INTERVAL  20

extern uint32_t timer0_m0_counter, timer1_m0_counter;
extern uint32_t timer0_m1_counter, timer1_m1_counter;

/*****************************************************************************
**   Main Function  main()
*****************************************************************************/
int main (void)
{         
  uint32_t i;

  /* SystemClockUpdate() updates the SystemFrequency variable */
  SystemClockUpdate();
   
  LPC_GPIO2->FIODIR = 0x000000FF;    /* P2.0..7 defined as Outputs */ //Geändert aufP2.0...5
  LPC_GPIO2->FIOCLR = 0x000000FF;    /* turn off all the LEDs */
   
  for ( i = 0; i < 2; i++ )
  { 
  init_timer( i , TIME_INTERVAL ); 
  enable_timer( i );
  }

  /* Loop forever */
  while (1)
  {          /* Loop forever */
  if ( (timer0_m0_counter > 0) && (timer0_m0_counter <= BLINK_INTERVAL) )
  {
    LPC_GPIO2->FIOSET = 1 << 2;
  }
  if ( (timer0_m0_counter > BLINK_INTERVAL) && (timer0_m0_counter <= (BLINK_INTERVAL * 2)) )
  {
    LPC_GPIO2->FIOCLR = 1 << 2;
  }
  else if ( timer0_m0_counter > (BLINK_INTERVAL * 2) )
  {
    timer0_m0_counter = 0;
  }
  /* Timer 1 blinky LED 1 */
  if ( (timer1_m0_counter > 0) && (timer1_m0_counter <= BLINK_INTERVAL) )
  {
    LPC_GPIO2->FIOSET = 1 << 3;
  }
  if ( (timer1_m0_counter > BLINK_INTERVAL) && (timer1_m0_counter <= (BLINK_INTERVAL * 2)) )
  {
    LPC_GPIO2->FIOCLR = 1 << 3;
  }
  else if ( timer1_m0_counter > (BLINK_INTERVAL * 2) )
  {
    timer1_m0_counter = 0;
  }
  }
}

/*****************************************************************************
**                            End Of File
******************************************************************************/

Source code ฉบับเต็มอยู่ใน Example ที่มากับ LPCXpresso จาก http://lpcxpresso.code-red-tech.com/LPCXpresso/

firmware.c

IAR Embedded Workbench for ARM
AVR-Studio + AVR-GCC
CodeBlocks + MinGw
CodeBlocks + Gtk+


atlantaman

Code จาก LPCXpresso รองรับ CMSIS 2.0 ครับ

anon1206

ช่วยยกตัวอย่างการใช้งานได้ไหมครับ ผมดูแล้วยัง งงๆ ยุนะครับ
เช่น จะให้ฟังก์ชัน scandisplay(); ทำงานอัตโนมัติยุตลอดเวลา ต้องเขียนแบบไหนครับ

crywolf

void Timer0_init()
{
        /* definition for led */
        unsigned long LED_PINS  =  ((uint32_t)1<<2);
    /* LEDs on PORT2.2 defined as Output  */
    GPIO_SetDir(2, LED_PINS, 1);

        TIM_TIMERCFG_Type TMR0_Cfg;
        TIM_MATCHCFG_Type TMR0_Match;
               
        /* On reset, Timer0/1 are enabled (PCTIM0/1 = 1), and Timer2/3 are disabled (PCTIM2/3 = 0).*/
        /* Initialize timer 0, prescale count time of 100uS */
        TMR0_Cfg.PrescaleOption = TIM_PRESCALE_USVAL;
        TMR0_Cfg.PrescaleValue = 100;
        /* Use channel 0, MR0 */
        TMR0_Match.MatchChannel = 0;
        /* Enable interrupt when MR0 matches the value in TC register */
        TMR0_Match.IntOnMatch = ENABLE;         
        /* Enable reset on MR0: TIMER will reset if MR0 matches it */
        TMR0_Match.ResetOnMatch = TRUE;         
        /* Don't stop on MR0 if MR0 matches it*/
        TMR0_Match.StopOnMatch = FALSE;
        /* Do nothing for external output pin if match (see cmsis help, there are another options) */
        TMR0_Match.ExtMatchOutputType = TIM_EXTMATCH_NOTHING;
        /* Set Match value, count value of 10000 (10000 * 100uS = 1000000us = 1s --> 1 Hz) */
        TMR0_Match.MatchValue = 10000;         
        /* Set configuration for Tim_config and Tim_MatchConfig */
        TIM_Init(LPC_TIM0, TIM_TIMER_MODE, &TMR0_Cfg);
        TIM_ConfigMatch(LPC_TIM0, &TMR0_Match);
       
        /* Preemption = 1, sub-priority = 1 */
        NVIC_SetPriority(TIMER0_IRQn, ((0x01<<3)|0x01));
        /* Enable interrupt for timer 0 */
        NVIC_EnableIRQ(TIMER0_IRQn);   
        /* Start timer 0 */
        TIM_Cmd(LPC_TIM0, ENABLE);
}

void TIMER0_IRQHandler (void)
{
        /*  Clear Interrupt */
        TIM_ClearIntPending(LPC_TIM0,TIM_MR0_INT);
        /* Code...*/
        if(0 == temp){
                GPIO_ClearValue(2, 0X14);
                temp = 1;
        }
        else{
                GPIO_SetValue(2, 0X14);
                temp = 0;
        }
        return;
}