#include"iostm8s003f3.h"
#define u8 uint8_t
#define u16 uint16_t
#define u32 uint32_t
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned long uint32_t;
void delay(u16 Count);
void main()
{
asm("sim");
delay(10);
//Preamble_IF=0;
// recstep=0;
// N_preamble=0;
PB_CR1|=0x20;
PB_CR2|=0x20;
PB_DDR_DDR5 = 1;
PB_ODR_ODR5=0;
CLK_CKDIVR=0x00;
TIM1_PSCRH = 0x00;
TIM1_PSCRL = 0x00;
TIM1_CCER1 &= 0xee;//禁止输入捕获1,2
TIM1_ARRH=0xbb;
TIM1_ARRL=0x80; //3ms
TIM1_CCMR1 |= 0x01;// ch1到ti1fp1
TIM1_CCER1 &= 0xFD;//ch1 上升沿触发
TIM1_CCMR2 |= 0x02;// ch2选择 ti1fp2上
TIM1_CCER1 |= 0x20;//ch2 下降沿触发 ic2
TIM1_SMCR |= 0x50;//选源触发源和触发方式 复位
TIM1_SMCR |=0x04;
TIM1_IER|= 0x06;
TIM1_SR1&=0xF9;
TIM1_SR2&=0xFD;
TIM1_CCER1|=0x11;
TIM1_CR1 |= 0x05;
asm("sim");
while(1)
{
};
}
#pragma vector=0x0E
__interrupt void TIM1_CAP_COM_IRQHandler(void)
{
u16 High,Cycle;
//High=0;
// Cycle=0;
PB_ODR_ODR5=1;
if ((TIM1_SR1_CC1IF==1)&&(TIM1_SR1_CC2IF==1))
{
TIM1_SR1_CC1IF=0;
TIM1_SR1_CC2IF=0;
TIM1_SR2_CC1OF=0;
TIM1_SR2_CC2OF=0;
High=(u16)TIM1_CCR2H<<8;
High|=TIM1_CCR2L;
Cycle=(u16)TIM1_CCR1H<<8;
Cycle|=TIM1_CCR1L;
if(((High>3824)&&(High<4176))&&((Cycle-High)>3824)&&((Cycle-High)<4176))
{
PB_ODR_ODR5=1;
}
else
{
PB_ODR_ODR5=0;
}
}
}
void delay(u16 Count)
{
u8 i,j;
while (Count--)
{
for(i=0;i<50;i++)
for(j=0;j<20;j++);
}
}
void assert_failed(u8* file, u32 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)
{
}
}
试过很多遍,没有查到问题,请帮忙看一下,TIM1_CH1捕获上升沿和下降沿,TIM1_SR2=0x06, CC1OF和CC2OF一直为1
|