MSP430中断参数

MSP430中断参数

1.中断向量入口参数

typedef enum
{
  VECTOR_RTC      =41u, /*  RTC */
  VECTOR_PORT2        , /*  Port 2 */
  VECTOR_TIMER2_A1    , /*  Timer0_A5 CC1-4, TA */
  VECTOR_TIMER2_A0    , /*  Timer0_A5 CC0 */
  VECTOR_USCI_B1      , /*  USCI B1 Receive/Transmit */
  VECTOR_USCI_A1      , /*  USCI A1 Receive/Transmit */
  VECTOR_PORT1        , /*  Port 1 */
  VECTOR_TIMER1_A1    , /*  Timer1_A3 CC1-2, TA1 */
  VECTOR_TIMER1_A0    , /*  Timer1_A3 CC0 */
  VECTOR_DMA          , /*  DMA */
  VECTOR_USB_UBM      , /*  USB Timer / cable event / USB reset */
  VECTOR_TIMER0_A1    , /*  Timer0_A5 CC1-4, TA */
  VECTOR_TIMER0_A0    , /*  Timer0_A5 CC0 */
  VECTOR_ADC12        , /*  ADC */
  VECTOR_USCI_B0      , /*  USCI B0 Receive/Transmit */
  VECTOR_USCI_A0      , /*  USCI A0 Receive/Transmit */
  VECTOR_WDT          , /*  Watchdog Timer */
  VECTOR_TIMER0_B1    , /*  Timer0_B7 CC1-6, TB */
  VECTOR_TIMER0_B0    , /*  Timer0_B7 CC0 */
  VECTOR_COMP_B       , /*  Comparator B */
  VECTOR_UNMI         , /*  User Non-maskable */
  VECTOR_SYSNMI       , /*  System Non-maskable */
  VECTOR_RESET        , /*  Reset [Highest Priority] */
  /************************为使用方便,下面对部分常用功能进行定义**************************************************/
  //IO口
  VECTOR_P1            = VECTOR_PORT1,
  VECTOR_P2            = VECTOR_PORT2,
  //SPI
  VECTOR_SPI0          = VECTOR_USCI_A0,
  VECTOR_SPI1          = VECTOR_USCI_A1,
  VECTOR_SPI2          = VECTOR_USCI_B0,
  VECTOR_SPI3          = VECTOR_USCI_B1,
  //I2C
  VECTOR_I2C0          = VECTOR_USCI_B0,
  VECTOR_I2C1          = VECTOR_USCI_B1,
  //UART
  VECTOR_UART0         = VECTOR_USCI_A0,
  VECTOR_UART1         = VECTOR_USCI_A1,
  //TIMER,注意定时器有两个中断向量,CCR0单独占用一个中断向量,其他中断源共同使用一个中断向量
  VECTOR_TIMER_A0      = VECTOR_TIMER0_A1,
  VECTOR_TIMER_A0_CCR0 = VECTOR_TIMER0_A0,
  VECTOR_TIMER_A1      = VECTOR_TIMER1_A1,
  VECTOR_TIMER_A1_CCR0 = VECTOR_TIMER1_A0,
  VECTOR_TIMER_A2      = VECTOR_TIMER2_A1,
  VECTOR_TIMER_A2_CCR0 = VECTOR_TIMER2_A0,
  VECTOR_TIMER_B0      = VECTOR_TIMER0_B1,
  VECTOR_TIMER_B0_CCR0 = VECTOR_TIMER0_B0,
}VECTORn;         //中断向量

2.设置中断向量地址

/*******************************************************************************
*  函数名称:Set_Vector_Handler(VECTORn vector,__interrupt void pfunc_handler(void))
*  功能说明:设置中断向量地址
*  参数说明:
            VECTORn vector  :中断向量(枚举变量,见.h文件)
            __interrupt void pfunc_handler(void)  : 中断服务函数
*  函数返回:无
********************************************************************************/
void Set_Vector_Handler(VECTORn vector, __interrupt void pfunc_handler(void))
{
  if(SYSX->RIVECT == DISABLE)        //如果没有设置中断向量表到RAM,则设置
  {
    Set_VectorTable_To_RAM();                       //设置中断向量表到RAM
  }
  //此处若有警告可忽略
  __VECTOR_RAM[vector] = (ISR_TYPE)pfunc_handler;     //设置该中断向量地址
}

3.使用实例

3.1 GPIO实例

Set_Vector_Handler(VECTOR_PORT1,GPIO_IRQ_Handler);    
//设置PPORT1中断服务函数为GPIO_IRQ_Handler,需要先定义中断服务函数,另外最好先设置中断向量,再开启中断

3.2 定时器实例

Set_Vector_Handler(VECTOR_TIMER0_B0,TIMER_TB0_IRQ_Handler);    //设置中断向量,最好先设置中断向量,在开启中断

__interrupt void TIMER_TB0_IRQ_Handler()
{
  LED_Turn(LED1);               //指示灯闪烁
}

3.3 ADC中断实例

ADC_Init(ADC_CH2,ADC_VREF_3_3V,ADC_10bit);       //初始化通道,P6.2
Set_Vector_Handler(VECTOR_ADC12,ADC_IRQ_Handler);
ADC_ITConfig (ADC_CH2,ENABLE);

ADC_StartConv();
OLED_PrintfAt(FONT_ASCII_6X8,0,0,"ADValue:\n%f V",ad);         //在指定位置打印

__interrupt void ADC_IRQ_Handler()
{
   if(ADC_GetITStatus(ADC_CH2) == TRUE)
   {
      ad = ADC_ReadChanelValue (ADC_CH2)*3.3/1023;   //读取后会自动清除标志位
      ADC_ClearITPendingBit(ADC_CH2);
   }
}

你可能感兴趣的:(MSP430,MSP430F5529入门介绍)