⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 interrupt_timer.c

📁 AT91SAM7S64的RTT初始化设置程序
💻 C
字号:
//*----------------------------------------------------------------------------
//*      ATMEL Microcontroller Software Support  -  ROUSSET  -
//*----------------------------------------------------------------------------
//* The software is delivered "AS IS" without warranty or condition of any
//* kind, either express, implied or statutory. This includes without
//* limitation any warranty or condition with respect to merchantability or
//* fitness for any particular purpose, or against the infringements of
//* intellectual property rights of others.
//*----------------------------------------------------------------------------
//* File Name           : interrupt_timer.c
//* Object              : Timer interrupt management
//*                     : Use LED7 & LED8 for status interrupt
//*
//* 1.0 24/Jun/04 JPP   : Creation
//* 1.1 29/Aug/05 JPP   : Update AIC definion
//*----------------------------------------------------------------------------

// Include Standard LIB  files
#include "Board.h"

#define RTTC_INTERRUPT_LEVEL						0
#define ALARM_INC                       4

//*------------------------- Interrupt Function -------------------------------

//*----------------------------------------------------------------------------
//* Function Name       : timerRTT_c_irq_handler
//* Object              : C handler interrupt function called by the interrupts
//*                       assembling routine
//* Output Parameters   : increment count_timer0_interrupt
//*----------------------------------------------------------------------------
__ramfunc void Rttc_handler(void)
{
    unsigned int status;

    status = AT91C_BASE_RTTC->RTTC_RTSR;//读状态

    if ( (status & AT91C_RTTC_ALMS) == AT91C_RTTC_ALMS)//ALMIEN: 中断使能
    {
      
        //* Read the output state
        AT91C_BASE_RTTC->RTTC_RTAR += ALARM_INC+1; //重新更新数值
        if ((AT91F_PIO_GetInput(AT91C_BASE_PIOA) & LED2 ) == LED2 )    
        { 
            AT91F_PIO_ClearOutput( AT91C_BASE_PIOA, LED2 );
        }
         else  
        {
            AT91F_PIO_SetOutput( AT91C_BASE_PIOA, LED2 );
        }   
    }
    if ( (status & AT91C_RTTC_RTTINC) == AT91C_RTTC_RTTINC) //实时定时器增一中断使能
    {
        //* Read the output state
        if ((AT91F_PIO_GetInput(AT91C_BASE_PIOA) & LED3 ) == LED3 )   
            AT91F_PIO_ClearOutput(AT91C_BASE_PIOA, LED3 );
        else  AT91F_PIO_SetOutput( AT91C_BASE_PIOA, LED3 );
    }
}

//*-------------------------- External Function -------------------------------

//*----------------------------------------------------------------------------
//* Function Name       : timer_init
//* Object              : Init timer counter
//* Input Parameters    : none
//* Output Parameters   : TRUE
//*----------------------------------------------------------------------------
void timer_init ( void )
//* Begin
{ 
     unsigned int status;

    ///* Set Timer
    AT91F_AIC_ConfigureIt ( AT91C_BASE_AIC, 
                           AT91C_ID_SYS, 
                           RTTC_INTERRUPT_LEVEL,
                           AT91C_AIC_SRCTYPE_INT_POSITIVE_EDGE, 
                           Rttc_handler);
    //AT91C_AIC_SRCTYPE_INT_POSITIVE_EDGE  (需要设这个,否则AT91C_RTTC_ALMS只触发一次)


    //设置实时闹铃寄存器 4秒后中断一次
    AT91C_BASE_RTTC->RTTC_RTAR = ALARM_INC-1; //ALARM_INC 秒
    //* Set the interrupt
    //使能 ALMS中断  RTTINC中断  重新加载及重新启动时钟分频器  
    //预分频值为0x8000 (慢时钟为32768HZ时) 每秒RTTINC将中断一次
    AT91C_BASE_RTTC->RTTC_RTMR = AT91C_RTTC_ALMIEN | 
                                 AT91C_RTTC_RTTINCIEN | 
                                 AT91C_RTTC_RTTRST | 
                                 0x8000;  //  IRQ enable CPC
    
    status = AT91C_BASE_RTTC->RTTC_RTSR;
    //*中断使能
    AT91F_AIC_EnableIt (AT91C_BASE_AIC, AT91C_ID_SYS);

//* End
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -