实验4:基于RFID的电子钱包综合实验

本文档详细介绍了基于RFID技术的电子钱包实验,包括实验目的、环境、内容和步骤。实验中,使用IAR开发环境,通过MFRC531射频模块与STM8微控制器交互,实现卡片充值和扣款功能。当卡片靠近模块,通过按键操作可以实现金额的增减,并通过串口工具显示卡号、余额等信息。实验结果展示了充值和扣款的具体流程及输出。
摘要由CSDN通过智能技术生成

实验目的

  • 了解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) 输出

  • 使用tag标识不同的输出形式,置1为字符串输出,置0为十六进制输出。
int tag=0;

  • tag为1,使用sprintf()函数对card序列号转十进制,以字符串形式输出card序列值,输出提示“please press the key to charge money.”,输出十六进制的充值金额,再输出十六进制的总额,然后再次使用sprintf()函数将十六进制的总额转换为十进制,再输出十进制的总额数。
    tag为0,则使用UART2_SendString()函数以十六进制形式输出。
   if(tag==1){
      char buf[8] = {0};
      char card[8] = {0}; 

      sprintf(card,"%02x%02x%02x%02x",g_cSNR[0],g_cSNR[1],g_cSNR[2],g_cSNR[3]);
      printf("Card ID: %s\n",card);
      //printf("Card ID: %x %x %x %x\n", g_cSNR[0],g_cSNR[1],g_cSNR[2],g_cSNR[3]);
      printf("please press the key to charge money.\n");
      printf("充值金额:%x %x %x %x\n", money_buf[3], money_buf[2], money_buf[1], money_buf[0]);
      printf("Total Moeny:  %x %x %x %x\n", tx_buf[9], tx_buf[10], tx_buf[11], tx_buf[12]);
      //printf("value: %d%d%d%d\n",tx_buf[9],tx_buf[10],tx_buf[11],tx_buf[12]);
      sprintf(buf,"%02x%02x%02x%02x",tx_buf[9],tx_buf[10],tx_buf[11],tx_buf[12]);
      printf("value: %s\n",buf);
   }
   else UART2_SendString(tx_buf, 14);

  • 以上是以充值金额做举例,扣款同理。应注意buf和card数组的清零。
char buf[8] = {0};
char card[8] = {0};

2) 按键控制

  • 判断是否PC1引脚触发,若是,则实现按键控制,首先设置不接收中断信息,设置rx_buf为CC EE FE 01 01 20 18 42 75 FF,其中,CC EE FE 01为固定值,01为充值命令,20 18 42 75表示一次按键所充值的金额数量,FF表示结束,然后置两个flag为1,表示识别到卡,置tag为1,表示此时的输出形式为字符串形式,最后再打开中断接收信号。
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] = 0x20;
    rx_buf[6] = 0x18;
    rx_buf[7] = 0x42;   
    rx_buf[8] = 0x75;
    rx_buf[9] = 0xFF;
    Uart_RecvFlag = 1;
    Flag=1;
    tag=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个数据位,一个停止位,无校验位,串口开始工作。

实验结果

充值

  • 在感应器上放上卡片,收码区选择字符串,按下按键key,此时输出为“Card ID:6d6d6f51”,这是卡序列号,输出“please press the key to charge money.”,这是按下按键的提醒,输出“充值金额:20 18 42 75”,按下按键就会向卡片中充值20 18 42 75个单位的钱,输出“Total Money: 20 18 42 75”,因为之前卡内余额为0,所以总金额与充值金额一致,输出“value:20184275”输出十进制表示的余额,此处并未严格换算。
    按键充值结果截图

扣款

  • 收码区选择HEX码,发送数据“CC EE FE 01 02 20 18 42 75 FF”,其中,CC EE FE 01为固定数据,02表示扣款,20 18 42 75表示扣款金额,FF表示结束,输出为“EE CC FE 01 02 6D 6D 6F 51 00 00 00 00 FF”,其中,EE CC FE 01为固定数据,02表示扣款,6D 6D 6F 51为卡号,00 00 00 00表示卡内余额,因为扣款金额为余额的总数,所以更新后的卡内余额为0,FF表示结束。
    串口命令扣款结果截图

代码

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; 
int tag=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];
                    if(tag==1){
                        char buf[8] = {0};
                        char card[8] = {0};    
                        sprintf(card,"%02x%02x%02x%02x",g_cSNR[0],g_cSNR[1],g_cSNR[2],g_cSNR[3]);
                        printf("Card ID: %s\n",card);
                        //printf("Card ID: %x %x %x %x\n", g_cSNR[0],g_cSNR[1],g_cSNR[2],g_cSNR[3]);
                        printf("please press the key to charge money.\n");
                        printf("充值金额:%x %x %x %x\n", money_buf[3],money_buf[2],money_buf[1],money_buf[0]);
                        printf("Total Moeny:  %x %x %x %x\n",tx_buf[9],tx_buf[10],tx_buf[11],tx_buf[12]);
                        //printf("value: %d%d%d%d\n",tx_buf[9],tx_buf[10],tx_buf[11],tx_buf[12]);
                        sprintf(buf,"%02x%02x%02x%02x",tx_buf[9],tx_buf[10],tx_buf[11],tx_buf[12]);
                        printf("value: %s\n",buf);
                   }
                    else UART2_SendString(tx_buf, 14);
                }
                else
                {
                    Flag = 0; 
                }
                //printf("Card ID: %x %x %x %x\n", g_cSNR[0],g_cSNR[1],g_cSNR[2],g_cSNR[3]);
                //printf("please press the key to charge money.\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];
                        
                    if(tag==1){
                        char buf[8] = {0};
                        char card[8] = {0};    
                        sprintf(card,"%02x%02x%02x%02x",g_cSNR[0],g_cSNR[1],g_cSNR[2],g_cSNR[3]);
                        printf("Card ID: %s\n",card);
                        //printf("Card ID: %x %x %x %x\n", g_cSNR[0],g_cSNR[1],g_cSNR[2],g_cSNR[3]);
                        printf("please press the key to charge money.\n");
                        printf("扣款金额:%x %x %x %x\n", money_buf[3],money_buf[2],money_buf[1],money_buf[0]);
                        printf("Total Moeny:  %x %x %x %x\n",tx_buf[9],tx_buf[10],tx_buf[11],tx_buf[12]);
                        //printf("value: %d%d%d%d\n",tx_buf[9],tx_buf[10],tx_buf[11],tx_buf[12]);
                        sprintf(buf,"%02x%02x%02x%02x",tx_buf[9],tx_buf[10],tx_buf[11],tx_buf[12]);
                        printf("value: %s\n",buf);
                    }
                    else UART2_SendString(tx_buf, 14);
                    
                }
                else
                {
                    Flag = 0; 
                }
                //printf("Card ID: %x %x %x %x\n", g_cSNR[0],g_cSNR[1],g_cSNR[2],g_cSNR[3]);
                //printf("please press the key to charge money.\n");
               // printf("value:  %x %x %x %x\n",tx_buf[9],tx_buf[10],tx_buf[11],tx_buf[12]);
                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] = 0x20;
        rx_buf[6] = 0x18;
        rx_buf[7] = 0x42;   
        rx_buf[8] = 0x75;
        rx_buf[9] = 0xFF;
        Uart_RecvFlag = 1;
        Flag=1;
        tag=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;
        tag=2;
        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****/

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

路灯谣

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值