实验三:基于RFID的按键控制电子钱包实验

实验目的

  • 了解IAR开发环境的应用
  • 熟悉MFRC531的使用

实验环境

  • 硬件: RFID射频模块,USB仿真器,PC机。
  • 软件:IAR Embedded Workbench for STMicroelectronics STM8 1.30 Evaluation

实验内容

  1. 用IAR环境,在电子标签卡片接触RFID模块时,按KEY按键,电子标签中的数据加1和减1,即充值1和减去1,可通过PC机串口软件观测。
  2. 在串口软件界面输出卡号、余额、小组成员所有学号。

实验步骤

实验代码

1) 输出

  • 此次实验的输出为字符串形式,所以注释掉UART2_SendString()函数,避免输出乱码,三个printf()函数分别输出打印卡ID号、按键提示和余额显示。
   if(MI_OK == status)
   {
       tx_buf[9] = money[3];
       tx_buf[10] = money[2];
       tx_buf[11] = money[1];
       tx_buf[12] = money[0];
         
       //UART2_SendString(tx_buf, 14);
   }
   else
   {
       Flag = 0; 
   }
   printf("ID: %x %x %x %x\n", g_cSNR[0],g_cSNR[1],g_cSNR[2],g_cSNR[3]);
   printf("please press the key,\n");
   printf("value: %x %x %x %x\n",tx_buf[9],tx_buf[10],tx_buf[11],tx_buf[12]);

2) 按键控制

  • 在中断处理中,判断是否PC1引脚触发,若是,则设置不接收中断,将rx_buf设置为CC EE FE 01 01 00 00 00 01 FF,其中,CC EE FE 01为固定的,第二个01为充值命令,00 00 00 01为充值金额,FF表示结束,然后将两个flag置为1(flag为0,表示未识别到卡,为1,表示识别到卡),打开中断接收信号。
INTERRUPT_HANDLER(EXTI_PORTC_IRQHandler, 5)
{
  /* In order to detect unexpected events during development,
     it is recommended to set a breakpoint on the following instruction.
  */
     if ((GPIO_ReadInputData(GPIOC) & GPIO_PIN_1) == 0x00)//判断是否PC1引脚触发
    //实现按键控制
    {
        disableInterrupts();
        rx_buf[0] = 0xCC;
        rx_buf[1] = 0xEE;
        rx_buf[2] = 0xFE;
        rx_buf[3] = 0x01;     
        rx_buf[4] = 0x01;
        rx_buf[5] = 0x00;
        rx_buf[6] = 0x00;
        rx_buf[7] = 0x00;   
        rx_buf[8] = 0x01;
        rx_buf[9] = 0xFF;
        Uart_RecvFlag = 1;
        Flag=1;
        enableInterrupts();
    }
}

3) 蜂鸣声响

  • 读取串口指令完成后,蜂鸣器响100ms。
    BEEP_On();
    delay_ms(100);
    BEEP_Off();

硬件连接

  1. 把RFID模块插到实验箱的主板上的串口
  2. 把ST-Link配合JTAG仿真器插到标有ST-Link标志的串口上
  3. 把仿真器一端的USB线插到PC机的USB端口,通过主板上的“加”“减”按键调整要实验的RFID模块(会有黄色LED灯提示),硬件连接完毕。

编译、烧录并测试

  1. 我们用IAR SWSTM8 1.30软件,打开..\RFID_电子钱包实验\Project\MFRC531_ATM8.eww。
  2. 工程编译:点击“Project”->“Rebuild All”。
  3. 点击“Rebuild All”进行编译。
  4. 将卡片放在烧录板上,把程序烧到模块里,点击“ ”中间的Download and Debug进行烧录,完成后听到蜂鸣器响一声。
  5. 关闭上述已打开程序,打开串口测试软件,将传感器模块连接到串口转USB模块上,将USB2UART模块的USB线连接到PC机的USB端口,然后打开串口工具,配置好串口,波特率115200,8个数据位,一个停止位,无校验位,串口开始工作。

实验结果

截图1

  • 输出“ID:2d d8 49 50”,这是卡序列号;输出“please press the key”,提醒按下按键,输出“value:0 0 0 1”,此时,卡内余额(十六进制)为1,随后,每按下一次按键,向卡内充值1单位的钱,因此,后面输出的value值分别为0 0 0 2、0 0 0 3、0 0 0 4和0 0 0 5。


    按键充值截图1

截图2

  • 输出“ID:fd d3 71 51”,这是卡序列号;输出“please press the key”,提醒按下按键,输出“value:af b7 e3 6a”,此时,卡内余额(十六进制)为af b7 e3 6a,随后,每按下一次按键,向卡内充值1单位的钱,因此,后面输出的value值分别为af b7 e3 6b、af b7 e3 6c、af b7 e3 6d。


    按键充值截图2

标准输出示例

按键控制示例图

代码

main.c

#include "main.h"
#include "stdio.h"


#ifdef _RAISONANCE_
#define PUTCHAR_PROTOTYPE int putchar (char c)
#define GETCHAR_PROTOTYPE int getchar (void)
#elif defined (_COSMIC_)
#define PUTCHAR_PROTOTYPE char putchar (char c)
#define GETCHAR_PROTOTYPE char getchar (void)
#else /* _IAR_ */
#define PUTCHAR_PROTOTYPE int putchar (int c)
#define GETCHAR_PROTOTYPE int getchar (void)
#endif /* _RAISONANCE_ */



u8 rx_buf[10]; //串口输入字符
u8 rx_counter;
u8 Uart_RecvFlag = 0; 

u8 tx_buf[14];
u8 tx_buff[14];
u8 g_cSNR[4];       //M1卡序列号
u8 g_pTagType[2];   // M1卡型号代码
u8 money[16];       //余额
u8 p_KeyA[6] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
u8 p_Key[12];
u8 money_buf[4];
u8 Flag = 0;    //是否发现卡标志



//电子钱包-扇区0 块号1

// 时钟设置,内部时钟16M
void CLK_Config(void)                
{
    CLK_DeInit();
    CLK_HSICmd(ENABLE);
    CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
    CLK_ClockSecuritySystemEnable();
}


void TIM4_Config(void)
{
    TIM4_DeInit();
    TIM4_TimeBaseInit(TIM4_PRESCALER_128,125);  // 1ms 中断
    TIM4_ITConfig(TIM4_IT_UPDATE, ENABLE);
    TIM4_Cmd(ENABLE);
}


void BEEP_Config(void)
{
    BEEP_DeInit();
    BEEP_Init(BEEP_FREQUENCY_4KHZ);
    BEEP_LSICalibrationConfig(LSI_FREQUENCY_MAX);
}

void BEEP_On(void)
{
    BEEP_Cmd(ENABLE);
}


void BEEP_Off(void)
{
    BEEP_Cmd(DISABLE);
}

void EXTI_Config(void)
{
    GPIO_Init(GPIOC, GPIO_PIN_1, GPIO_MODE_IN_PU_IT); 
    EXTI_DeInit();
    EXTI_SetExtIntSensitivity(EXTI_PORT_GPIOC, EXTI_SENSITIVITY_FALL_ONLY);
}


void EEPROM_Config(void)
{
    FLASH_DeInit();
    FLASH_Unlock(FLASH_MEMTYPE_DATA);
    FLASH_SetProgrammingTime(FLASH_PROGRAMTIME_STANDARD);   
}

unsigned char buf[16];


void main(void)
{
    //int value1,value2;
    u8 i = 0;
    u8 buf_temp[16];
    signed char status;
    
    CLK_Config();
    
    Uart2_Init();
    
    LED_Init();
    
    EXTI_Config();
    enableInterrupts();
    
    BEEP_Config();

    delay_ms(50);
    
    for(i = 0;i < 14;i++)
        tx_buf[i] = 0;
    tx_buf[0] = 0xEE;
    tx_buf[1] = 0xCC;
    tx_buf[2] = 0xFE;
    tx_buf[3] = 0x01;
    tx_buf[13] = 0xFF;

    if(MFRC531_Init() == MI_OK)
    {
        BEEP_On();
        delay_ms(200);
        BEEP_Off();
        LED_On();
    }
    else
    {
        BEEP_On();
        delay_ms(200);
        BEEP_Off();
        delay_ms(200);
        BEEP_On();
        delay_ms(200);
        BEEP_Off();
        LED_Off();
        while(1);
    }
    
    MFRC531_CfgISOType('A'); 
    
    rx_counter = 0;
    Uart_RecvFlag = 0;
    Flag = 0;
 
    enableInterrupts();
       
    while (1)
    { 
        if(Flag == 0) // 未发现卡,寻卡
        {

            status = MFRC531_OpenAnt();
            delay_ms(10);
        
            status = PcdRequest(0x52, g_pTagType);
        
            status = PcdAnticoll(g_cSNR);
        
            status = PcdSelect(g_cSNR,&buf_temp[0]);

            if(MI_OK != status)
            {
                Flag = 0;
            }
            else              // 获取卡号和余额
            {
                Flag = 1;
                ChangeCodeKey(p_KeyA,p_Key);    //转换密钥格式
                PcdAuthKey(p_Key);              //传送密钥到RC531 FIFO
                status = PcdAuthState(0x60, 1, g_cSNR);  //验证密钥                            
                status = PcdRead(1, money);
                // 判断是否进行过初始化,如果没有,初始化钱包内的余额为0
                if(money[12] == 0x01)
                {
                    tx_buf[4] = 0x03;
                    tx_buf[5] = g_cSNR[0];
                    tx_buf[6] = g_cSNR[1];
                    tx_buf[7] = g_cSNR[2];
                    tx_buf[8] = g_cSNR[3];
                    tx_buf[9] = money[3];
                    tx_buf[10] = money[2];
                    tx_buf[11] = money[1];
                    tx_buf[12] = money[0];
                    
                    tx_buff[0] = g_cSNR[0];
                    tx_buff[1] = g_cSNR[1];
                    tx_buff[2] = g_cSNR[2];
                    tx_buff[3] = g_cSNR[3];
                    
                }
                else
                {
                    ChangeCodeKey(p_KeyA,p_Key);    //转换密钥格式
                    PcdAuthKey(p_Key);              //传送密钥到RC531 FIFO
                    status = PcdAuthState(0x60, 1, g_cSNR);  //验证密钥 
                    buf_temp[0] = 0;
                    buf_temp[1] = 0;
                    buf_temp[2] = 0;
                    buf_temp[3] = 0;
                    buf_temp[4] = 0xff;
                    buf_temp[5] = 0xff;
                    buf_temp[6] = 0xff;
                    buf_temp[7] = 0xff;
                    buf_temp[8] = 0;
                    buf_temp[9] = 0;
                    buf_temp[10] = 0;
                    buf_temp[11] = 0;
                    buf_temp[12] = 0x01;
                    buf_temp[13] = 0xfe;
                    buf_temp[14] = 0x01;
                    buf_temp[15] = 0xfe;
                    status = PcdWrite(1,buf_temp);
                    
                    
                    tx_buf[4] = 0x03;
                    tx_buf[5] = g_cSNR[0];
                    tx_buf[6] = g_cSNR[1];
                    tx_buf[7] = g_cSNR[2];
                    tx_buf[8] = g_cSNR[3];
                    tx_buf[9] = 0;
                    tx_buf[10] = 0;
                    tx_buf[11] = 0;
                    tx_buf[12] = 0;
                    
                    tx_buff[0] = g_cSNR[0];
                    tx_buff[1] = g_cSNR[1];
                    tx_buff[2] = g_cSNR[2];
                    tx_buff[3] = g_cSNR[3];
                    
                    
                }
            }  
        }

        if(Uart_RecvFlag&Flag)  // 已发现卡,读写
        {
           
            /*读取串口输入指令*/
            money_buf[0] = rx_buf[8];
            money_buf[1] = rx_buf[7];
            money_buf[2] = rx_buf[6];
            money_buf[3] = rx_buf[5];
            
            //读取串口指令完成后,蜂鸣器响100ms
            BEEP_On();
            delay_ms(100);
            BEEP_Off();
            
            
            switch(rx_buf[4])
            {
            case 0x01:  // 充值
                tx_buf[4] = 0x01;
                ChangeCodeKey(p_KeyA,p_Key);    //转换密钥格式
                PcdAuthKey(p_Key);              //传送密钥到RC531 FIFO
                PcdAuthState(0x60, 1, g_cSNR);  //验证密钥 
                status = PcdValue(0xC1, 1, money_buf);
                ChangeCodeKey(p_KeyA,p_Key);    //转换密钥格式
                PcdAuthKey(p_Key);              //传送密钥到RC531 FIFO
                PcdAuthState(0x60, 1, g_cSNR);  //验证密钥
                status = PcdRead(1, money);
                if(MI_OK == status)
                {
                    tx_buf[9] = money[3];
                    tx_buf[10] = money[2];
                    tx_buf[11] = money[1];
                    tx_buf[12] = money[0];
                 
                    //UART2_SendString(tx_buf, 14);
                }
                else
                {
                    Flag = 0; 
                }
                printf("ID: %x %x %x %x\n", g_cSNR[0],g_cSNR[1],g_cSNR[2],g_cSNR[3]);
                printf("please press the key,\n");
                printf("value: %x %x %x %x\n",tx_buf[9],tx_buf[10],tx_buf[11],tx_buf[12]);
                break;
            case 0x02:  // 扣款
                tx_buf[4] = 0x02;
                ChangeCodeKey(p_KeyA,p_Key);    //转换密钥格式
                PcdAuthKey(p_Key);              //传送密钥到RC531 FIFO
                PcdAuthState(0x60, 1, g_cSNR);  //验证密钥 
                status = PcdValue(0xC0, 1, money_buf);
                ChangeCodeKey(p_KeyA,p_Key);    //转换密钥格式
                PcdAuthKey(p_Key);              //传送密钥到RC531 FIFO
                PcdAuthState(0x60, 1, g_cSNR);  //验证密钥
                status = PcdRead(1, money);
                if(MI_OK == status)
                {
                    tx_buf[9] = money[3];
                    tx_buf[10] = money[2];
                    tx_buf[11] = money[1];
                    tx_buf[12] = money[0];
                        
                    //UART2_SendString(tx_buf, 14);
                    
                }
                else
                {
                    Flag = 0; 
                }
                break;   
            default:
                break;   
            }
   
            LED_Toggle();
        Uart_RecvFlag = 0;

        }
    }
}





/**
  * @brief Retargets the C library printf function to the UART.
  * @param c Character to send
  * @retval char Character sent
  */
PUTCHAR_PROTOTYPE
{
  /* Write a character to the UART1 */
  UART2_SendData8(c);
  /* Loop until the end of transmission */
  while (UART2_GetFlagStatus(UART2_FLAG_TXE) == RESET);

  return (c);
}

/**
  * @brief Retargets the C library scanf function to the USART.
  * @param None
  * @retval char Character to Read
  */
GETCHAR_PROTOTYPE
{
#ifdef _COSMIC_
  char c = 0;
#else
  int c = 0;
#endif
  /* Loop until the Read data register flag is SET */
  while (UART2_GetFlagStatus(UART2_FLAG_RXNE) == RESET);
    c = UART2_ReceiveData8();
  return (c);
}


#ifdef USE_FULL_ASSERT

/**
  * @brief  Reports the name of the source file and the source line number
  *   where the assert_param error has occurred.
  * @param file: pointer to the source file name
  * @param line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t* file, uint32_t line)
{ 
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

  /* Infinite loop */
  while (1)
  {
  }
}
#endif



/**
  * @brief Retargets the C library printf function to the UART.
  * @param c Character to send
  * @retval char Character sent
  */



stm8s_it.c

/**
  ******************************************************************************
  * @file     stm8s_it.c
  * @author   MCD Application Team
  * @version  V2.0.1
  * @date     18-November-2011
  * @brief    Main Interrupt Service Routines.
  ******************************************************************************
  * @attention
  *
  * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  *
  * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  ******************************************************************************
  */ 

/* Includes ------------------------------------------------------------------*/
#include "stm8s_it.h"
#include "main.h"

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/

/* Public functions ----------------------------------------------------------*/

/** @addtogroup GPIO_Toggle
  * @{
  */
#ifdef _COSMIC_
/**
  * @brief  Dummy interrupt routine
  * @param  None
  * @retval None
  */
INTERRUPT_HANDLER(NonHandledInterrupt, 25)
{
  /* In order to detect unexpected events during development,
     it is recommended to set a breakpoint on the following instruction.
  */
}
#endif /*_COSMIC_*/

/**
  * @brief  TRAP interrupt routine
  * @param  None
  * @retval None
  */
INTERRUPT_HANDLER_TRAP(TRAP_IRQHandler)
{
  /* In order to detect unexpected events during development,
     it is recommended to set a breakpoint on the following instruction.
  */
}
/**
  * @brief  Top Level Interrupt routine
  * @param  None
  * @retval None
  */
INTERRUPT_HANDLER(TLI_IRQHandler, 0)
{
  /* In order to detect unexpected events during development,
     it is recommended to set a breakpoint on the following instruction.
  */
}

/**
  * @brief  Auto Wake Up Interrupt routine
  * @param  None
  * @retval None
  */
INTERRUPT_HANDLER(AWU_IRQHandler, 1)
{
  /* In order to detect unexpected events during development,
     it is recommended to set a breakpoint on the following instruction.
  */
}

/**
  * @brief  Clock Controller Interrupt routine
  * @param  None
  * @retval None
  */
INTERRUPT_HANDLER(CLK_IRQHandler, 2)
{
  /* In order to detect unexpected events during development,
     it is recommended to set a breakpoint on the following instruction.
  */
}

/**
  * @brief  External Interrupt PORTA Interrupt routine
  * @param  None
  * @retval None
  */
INTERRUPT_HANDLER(EXTI_PORTA_IRQHandler, 3)
{
  /* In order to detect unexpected events during development,
     it is recommended to set a breakpoint on the following instruction.
  */
}

/**
  * @brief  External Interrupt PORTB Interrupt routine
  * @param  None
  * @retval None
  */
INTERRUPT_HANDLER(EXTI_PORTB_IRQHandler, 4)
{
  /* In order to detect unexpected events during development,
     it is recommended to set a breakpoint on the following instruction.
  */
}

/**
  * @brief  External Interrupt PORTC Interrupt routine
  * @param  None
  * @retval None
  */

extern u8 Flag;
INTERRUPT_HANDLER(EXTI_PORTC_IRQHandler, 5)
{
  /* In order to detect unexpected events during development,
     it is recommended to set a breakpoint on the following instruction.
  */
     if ((GPIO_ReadInputData(GPIOC) & GPIO_PIN_1) == 0x00)//判断是否PC1引脚触发
    //实现按键控制
    {
        disableInterrupts();
        rx_buf[0] = 0xCC;
        rx_buf[1] = 0xEE;
        rx_buf[2] = 0xFE;
        rx_buf[3] = 0x01;     
        rx_buf[4] = 0x01;
        rx_buf[5] = 0x00;
        rx_buf[6] = 0x00;
        rx_buf[7] = 0x00;   
        rx_buf[8] = 0x01;
        rx_buf[9] = 0xFF;
        Uart_RecvFlag = 1;
        Flag=1;
        enableInterrupts();
    }
}

/**
  * @brief  External Interrupt PORTD Interrupt routine
  * @param  None
  * @retval None
  */
INTERRUPT_HANDLER(EXTI_PORTD_IRQHandler, 6)
{
  /* In order to detect unexpected events during development,
     it is recommended to set a breakpoint on the following instruction.
  */
}

/**
  * @brief  External Interrupt PORTE Interrupt routine
  * @param  None
  * @retval None
  */
INTERRUPT_HANDLER(EXTI_PORTE_IRQHandler, 7)
{
  /* In order to detect unexpected events during development,
     it is recommended to set a breakpoint on the following instruction.
  */
}
#ifdef STM8S903
/**
  * @brief  External Interrupt PORTF Interrupt routine
  * @param  None
  * @retval None
  */
 INTERRUPT_HANDLER(EXTI_PORTF_IRQHandler, 8)
{
  /* In order to detect unexpected events during development,
     it is recommended to set a breakpoint on the following instruction.
  */
}
#endif /*STM8S903*/

#if defined (STM8S208) || defined (STM8AF52Ax)
/**
  * @brief CAN RX Interrupt routine.
  * @param  None
  * @retval None
  */
 INTERRUPT_HANDLER(CAN_RX_IRQHandler, 8)
{
  /* In order to detect unexpected events during development,
     it is recommended to set a breakpoint on the following instruction.
  */
}

/**
  * @brief  CAN TX Interrupt routine
  * @param  None
  * @retval None
  */
 INTERRUPT_HANDLER(CAN_TX_IRQHandler, 9)
{
  /* In order to detect unexpected events during development,
     it is recommended to set a breakpoint on the following instruction.
  */
}
#endif /*STM8S208 || STM8AF52Ax */

/**
  * @brief  SPI Interrupt routine
  * @param  None
  * @retval None
  */
INTERRUPT_HANDLER(SPI_IRQHandler, 10)
{
  /* In order to detect unexpected events during development,
     it is recommended to set a breakpoint on the following instruction.
  */
}

/**
  * @brief  Timer1 Update/Overflow/Trigger/Break Interrupt routine
  * @param  None
  * @retval None
  */
INTERRUPT_HANDLER(TIM1_UPD_OVF_TRG_BRK_IRQHandler, 11)
{
  /* In order to detect unexpected events during development,
     it is recommended to set a breakpoint on the following instruction.
  */
}

/**
  * @brief  Timer1 Capture/Compare Interrupt routine
  * @param  None
  * @retval None
  */
INTERRUPT_HANDLER(TIM1_CAP_COM_IRQHandler, 12)
{
  /* In order to detect unexpected events during development,
     it is recommended to set a breakpoint on the following instruction.
  */
}

#ifdef STM8S903
/**
  * @brief  Timer5 Update/Overflow/Break/Trigger Interrupt routine
  * @param  None
  * @retval None
  */
 INTERRUPT_HANDLER(TIM5_UPD_OVF_BRK_TRG_IRQHandler, 13)
{
  /* In order to detect unexpected events during development,
     it is recommended to set a breakpoint on the following instruction.
  */
}
/**
  * @brief  Timer5 Capture/Compare Interrupt routine
  * @param  None
  * @retval None
  */
 INTERRUPT_HANDLER(TIM5_CAP_COM_IRQHandler, 14)
{
  /* In order to detect unexpected events during development,
     it is recommended to set a breakpoint on the following instruction.
  */
}

#else /*STM8S208, STM8S207, STM8S105 or STM8S103 or STM8AF62Ax or STM8AF52Ax or STM8AF626x */
/**
  * @brief  Timer2 Update/Overflow/Break Interrupt routine
  * @param  None
  * @retval None
  */
 INTERRUPT_HANDLER(TIM2_UPD_OVF_BRK_IRQHandler, 13)
{
  /* In order to detect unexpected events during development,
     it is recommended to set a breakpoint on the following instruction.
  */
}

/**
  * @brief  Timer2 Capture/Compare Interrupt routine
  * @param  None
  * @retval None
  */
 INTERRUPT_HANDLER(TIM2_CAP_COM_IRQHandler, 14)
{
  /* In order to detect unexpected events during development,
     it is recommended to set a breakpoint on the following instruction.
  */
}
#endif /*STM8S903*/

#if defined (STM8S208) || defined(STM8S207) || defined(STM8S007) || defined(STM8S105) || \
    defined(STM8S005) ||  defined (STM8AF62Ax) || defined (STM8AF52Ax) || defined (STM8AF626x)
/**
  * @brief Timer3 Update/Overflow/Break Interrupt routine.
  * @param  None
  * @retval None
  */
 INTERRUPT_HANDLER(TIM3_UPD_OVF_BRK_IRQHandler, 15)
{
  /* In order to detect unexpected events during development,
     it is recommended to set a breakpoint on the following instruction.
  */
}

/**
  * @brief  Timer3 Capture/Compare Interrupt routine
  * @param  None
  * @retval None
  */
 INTERRUPT_HANDLER(TIM3_CAP_COM_IRQHandler, 16)
{
  /* In order to detect unexpected events during development,
     it is recommended to set a breakpoint on the following instruction.
  */
}
#endif /*STM8S208, STM8S207 or STM8S105 or STM8AF62Ax or STM8AF52Ax or STM8AF626x */

#if defined (STM8S208) || defined(STM8S207) || defined(STM8S007) || defined(STM8S103) || \
    defined(STM8S003) ||  defined (STM8AF62Ax) || defined (STM8AF52Ax) || defined (STM8S903)
/**
  * @brief  UART1 TX Interrupt routine
  * @param  None
  * @retval None
  */
 INTERRUPT_HANDLER(UART1_TX_IRQHandler, 17)
{
  /* In order to detect unexpected events during development,
     it is recommended to set a breakpoint on the following instruction.
  */
}

/**
  * @brief  UART1 RX Interrupt routine
  * @param  None
  * @retval None
  */
 INTERRUPT_HANDLER(UART1_RX_IRQHandler, 18)
{
  /* In order to detect unexpected events during development,
     it is recommended to set a breakpoint on the following instruction.
  */
}


#endif /*STM8S105*/

/**
  * @brief  I2C Interrupt routine
  * @param  None
  * @retval None
  */
INTERRUPT_HANDLER(I2C_IRQHandler, 19)
{
  /* In order to detect unexpected events during development,
     it is recommended to set a breakpoint on the following instruction.
  */
}

#if defined(STM8S105) || defined(STM8S005) ||  defined (STM8AF626x)
/**
  * @brief  UART2 TX interrupt routine.
  * @param  None
  * @retval None
  */
 INTERRUPT_HANDLER(UART2_TX_IRQHandler, 20)
{
    /* In order to detect unexpected events during development,
       it is recommended to set a breakpoint on the following instruction.
    */
  }

/**
  * @brief  UART2 RX interrupt routine.
  * @param  None
  * @retval None
  */
 INTERRUPT_HANDLER(UART2_RX_IRQHandler, 21)
{
    /* In order to detect unexpected events during development,
       it is recommended to set a breakpoint on the following instruction.
    */
    u8 data;
    if(UART2_GetITStatus(UART2_IT_RXNE )!= RESET)  
    {
        disableInterrupts();
        data = UART2_ReceiveData8();
        if (!Uart_RecvFlag)
        {
            rx_buf[rx_counter] = data;
            switch (rx_counter)
            {
                case 0:
                if (data == 0xCC)     rx_counter = 1;
                    break;
                case 1:
                    if (data == 0xEE)     rx_counter = 2;
                    break;
                case 2:
                    if (data == 0xFE)     rx_counter = 3;
                    break;
                case 3:
                case 4:          
                case 5:
                case 6:
                case 7:
                case 8:
                    rx_counter++;
                    break;
                case 9:
                    if (data == 0xFF)  
                        Uart_RecvFlag = 1;
                    rx_counter = 0;
                    break;
                default:
                    rx_counter = 0;
                    break;
            }
        }
        else
            rx_counter = 0;
        enableInterrupts();
    }
  }
#endif /* STM8S105*/

#if defined(STM8S207) || defined(STM8S007) || defined(STM8S208) || defined (STM8AF52Ax) || defined (STM8AF62Ax)
/**
  * @brief  UART3 TX interrupt routine.
  * @param  None
  * @retval None
  */
 INTERRUPT_HANDLER(UART3_TX_IRQHandler, 20)
{
    /* In order to detect unexpected events during development,
       it is recommended to set a breakpoint on the following instruction.
    */
  }

/**
  * @brief  UART3 RX interrupt routine.
  * @param  None
  * @retval None
  */
 INTERRUPT_HANDLER(UART3_RX_IRQHandler, 21)
{
    /* In order to detect unexpected events during development,
       it is recommended to set a breakpoint on the following instruction.
    */
}
#endif /*STM8S208 or STM8S207 or STM8AF52Ax or STM8AF62Ax */

#if defined(STM8S207) || defined(STM8S007) || defined(STM8S208) || defined (STM8AF52Ax) || defined (STM8AF62Ax)
/**
  * @brief  ADC2 interrupt routine.
  * @param  None
  * @retval None
  */
 INTERRUPT_HANDLER(ADC2_IRQHandler, 22)
{

    /* In order to detect unexpected events during development,
       it is recommended to set a breakpoint on the following instruction.
    */
    return;

}
#else /*STM8S105, STM8S103 or STM8S903 or STM8AF626x */
/**
  * @brief  ADC1 interrupt routine.
  * @param  None
  * @retval None
  */
 INTERRUPT_HANDLER(ADC1_IRQHandler, 22)
{

    /* In order to detect unexpected events during development,
       it is recommended to set a breakpoint on the following instruction.
    */
    return;

}
#endif /*STM8S208 or STM8S207 or STM8AF52Ax or STM8AF62Ax */

#ifdef STM8S903
/**
  * @brief  Timer6 Update/Overflow/Trigger Interrupt routine
  * @param  None
  * @retval None
  */
INTERRUPT_HANDLER(TIM6_UPD_OVF_TRG_IRQHandler, 23)
{
  /* In order to detect unexpected events during development,
     it is recommended to set a breakpoint on the following instruction.
  */
}
#else /*STM8S208, STM8S207, STM8S105 or STM8S103 or STM8AF62Ax or STM8AF52Ax or STM8AF626x */
/**
  * @brief  Timer4 Update/Overflow Interrupt routine
  * @param  None
  * @retval None
  */
 INTERRUPT_HANDLER(TIM4_UPD_OVF_IRQHandler, 23)
{
  /* In order to detect unexpected events during development,
     it is recommended to set a breakpoint on the following instruction.
  */
    //TIM4_ClearITPendingBit(TIM4_IT_UPDATE);
}
#endif /*STM8S903*/

/**
  * @brief  Eeprom EEC Interrupt routine
  * @param  None
  * @retval None
  */
INTERRUPT_HANDLER(EEPROM_EEC_IRQHandler, 24)
{
  /* In order to detect unexpected events during development,
     it is recommended to set a breakpoint on the following instruction.
  */
}

/**
  * @}
  */

/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/

————————————————
版权声明:本文为CSDN博主「路灯谣」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/lululumiao/article/details/117182615

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 215,076评论 6 497
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 91,658评论 3 389
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 160,732评论 0 350
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 57,493评论 1 288
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,591评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,598评论 1 293
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,601评论 3 415
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,348评论 0 270
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,797评论 1 307
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,114评论 2 330
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,278评论 1 344
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,953评论 5 339
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,585评论 3 322
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,202评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,442评论 1 268
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,180评论 2 367
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,139评论 2 352

推荐阅读更多精彩内容