研究生
最后登录1970-1-1
在线时间 小时
注册时间2015-10-7
|
楼主 |
发表于 2015-11-22 14:41:41
|
显示全部楼层
/**
******************************************************************************
* @file Project/STM32F10x_StdPeriph_Template/stm32f10x_it.c
* @author MCD Application Team
* @version V3.5.0
* @date 08-April-2011
* @brief Main Interrupt Service Routines.
* This file provides template for all exceptions handler and
* peripherals interrupt service routine.
******************************************************************************
* @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 CONSEQUENTI
AL 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>© COPYRIGHT 2011 STMicroelectronics</center></h2>
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x_it.h"
#include "bsp_usart1.h"
#include "cj.h"
void Delay(__IO uint32_t ncount) //yanshi
{
for(; ncount !=0;ncount--);
}
u8 Flag_Obstruction=0;
u8 TIM8CH2_CAPTURE_STA = 0; //í¨μà2μÄ2¶»ñ±êÖ¾
u16 TIM8CH2_CAPTURE_UPVAL;
u16 TIM8CH2_CAPTURE_DOWNVAL;
u32 tempup2 = 0; //2¶»ñ×üμĸßμçƽμÄê±¼ä
u32 TIM8_T2;
float UltrasonicWave_Distance; //¼ÆËã3ö¾ààë
/** @addtogroup STM32F10x_StdPeriph_Template
* @{
*/
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/******************************************************************************/
/* Cortex-M3 Processor Exceptions Handlers */
/******************************************************************************/
/**
* @brief This function handles NMI exception.
* @param None
* @retval None
*/
void NMI_Handler(void)
{
}
/**
* @brief This function handles Hard Fault exception.
* @param None
* @retval None
*/
void HardFault_Handler(void)
{
/* Go to infinite loop when Hard Fault exception occurs */
while (1)
{
}
}
/**
* @brief This function handles Memory Manage exception.
* @param None
* @retval None
*/
void MemManage_Handler(void)
{
/* Go to infinite loop when Memory Manage exception occurs */
while (1)
{
}
}
/**
* @brief This function handles Bus Fault exception.
* @param None
* @retval None
*/
void BusFault_Handler(void)
{
/* Go to infinite loop when Bus Fault exception occurs */
while (1)
{
}
}
/**
* @brief This function handles Usage Fault exception.
* @param None
* @retval None
*/
void UsageFault_Handler(void)
{
/* Go to infinite loop when Usage Fault exception occurs */
while (1)
{
}
}
/**
* @brief This function handles SVCall exception.
* @param None
* @retval None
*/
void SVC_Handler(void)
{
}
/**
* @brief This function handles Debug Monitor exception.
* @param None
* @retval None
*/
void DebugMon_Handler(void)
{
}
/**
* @brief This function handles PendSVC exception.
* @param None
* @retval None
*/
void PendSV_Handler(void)
{
}
/**
* @brief This function handles SysTick Handler.
* @param None
* @retval None
*/
void SysTick_Handler(void)
{
}
void EXTI15_10_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line13) != RESET) //è·±£êÇ·ñ2úéúáËEXTI LineÖD¶Ï
{
GPIO_SetBits(TRIG_PORT_0,TRIG_PIN_0); //PC8
Delay(20);
GPIO_ResetBits(TRIG_PORT_0,TRIG_PIN_0);
EXTI_ClearITPendingBit(EXTI_Line13); //Çå3yÖD¶Ï±ê־λ
}
}
//¶¨ê±Æ÷8μÄÖD¶Ï·tÎñ3ìDò PC7
void TIM8_CC_IRQHandler(void)
{
if ((TIM8CH2_CAPTURE_STA & 0X80) == 0) //»1Î′3é1|2¶»ñ
{
if (TIM_GetITStatus(TIM8, TIM_IT_CC2) != RESET) //2¶»ñ1·¢éú2¶»ñê¼t
{
TIM_ClearITPendingBit(TIM8, TIM_IT_CC2); //Çå3yÖD¶Ï±êÖ¾
if (TIM8CH2_CAPTURE_STA & 0X40) //2¶»ñμ½ò»¸öϽμÑØ
{
TIM8CH2_CAPTURE_DOWNVAL = TIM_GetCapture2(TIM8);//¼Ç¼ÏÂ′Ëê±μļÆêyÆ÷Öμ
if (TIM8CH2_CAPTURE_DOWNVAL < TIM8CH2_CAPTURE_UPVAL)
{ /* èç1û¼ÆêyÆ÷3õê¼Öμ′óóúÄ©Î2ÖμËμÃ÷¼ÆêyóDÎêìa*/
TIM8_T2 = 65535;
}
else
TIM8_T2 = 0;
tempup2 = TIM8CH2_CAPTURE_DOWNVAL - TIM8CH2_CAPTURE_UPVAL+ TIM8_T2;
//μÃμ½×üμĸßμçƽ걼ä
tempup2 =tempup2 *17/1000;//¼ÆËã¾ààë&&UltrasonicWave_Distance<85
printf(" %d \t",TIM8CH2_CAPTURE_UPVAL);
printf(" %d \t",TIM8CH2_CAPTURE_DOWNVAL);
printf("Channel 2 : %d cm\r\n",tempup2);
TIM8CH2_CAPTURE_STA = 0; //2¶»ñλÇåáã
TIM_OC2PolarityConfig(TIM8, TIM_ICPolarity_Rising); //éèÖÃÎaéÏéyÑØ2¶»ñ
}
else //·¢éú2¶»ñê¼tμ«2»êÇϽμÑØ£¬μúò»′Î2¶»ñμ½éÏéyÑØ£¬¼Ç¼′Ëê±μļÆêyÆ÷Öμ
{
TIM8CH2_CAPTURE_UPVAL = TIM_GetCapture2(TIM8); //»ñè¡éÏéyÑØêy¾Y
TIM8CH2_CAPTURE_STA |= 0X40; //±ê¼ÇòÑ2¶»ñμ½éÏéyÑØ
TIM_OC2PolarityConfig(TIM8, TIM_ICPolarity_Falling);//éèÖÃÎaϽμÑØ2¶»ñ
}
}
}
//TIM_ClearITPendingBit(TIM8,TIM_IT_CC2); //Çå3yÖD¶Ï±ê־λ
}
/******************************************************************************/
/* STM32F10x Peripherals Interrupt Handlers */
/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */
/* available peripheral interrupt handler's name please refer to the startup */
/* file (startup_stm32f10x_xx.s). */
/******************************************************************************/
/**
* @brief This function handles PPP interrupt request.
* @param None
* @retval None
*/
/*void PPP_IRQHandler(void)
{
}*/
/**
* @}
*/
/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
|
|