www.pudn.com > sound-source-location.rar > voiceinput.c, change:2014-07-29,size:2599b


#include "voiceinput.h" 
 
 
 
 
	//声音传感器 IO初始化 
 
 
void VOIN_Init(void) 
{ 
	GPIO_InitTypeDef GPIO_InitStructure;	 
        
  /* 使能GPIOB时钟 */ 
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); 
 
  /* 配置GPIOA1/2/3为推挽输出模式 */ 
  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 ; 
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; 
  GPIO_Init(GPIOA, &GPIO_InitStructure); 
} 
 
//传感器状态监测 
 
uint32_t decetion(void) 
{ 
	uint8_t tmp; 
	if(VO_In1==1) 
	{  
		tmp=1; 
	} 
	if(VO_In2==1) 
	{ 
		tmp<<=2; 
		tmp+=1; 
	} 
	else 
	{tmp<<=2;} 
	if(VO_In3==1) 
	{ 
		tmp<<=2; 
		tmp+=1; 
	} 
	else 
	{tmp<<=2;} 
	return tmp; 
	 
} 
 
 
//时间计算 
 
uint8_t time_calculate(uint64_t *timedecA,uint64_t *timedecB,uint64_t *timedecC) 
{ 
	unsigned int dec=0xfffffff1,sta=0x0000000e,sw_swap;	 
	uint32_t tmp; 
	Delay_Init(); 
	*timedecA=0; 
	*timedecB=0; 
	*timedecC=0; 
	SysTick->LOAD = (0xFFFFFF) - 1;//加载SysTick重载值 
	SysTick->VAL = 0;//计数值清零 
	SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;//开始倒数计数 
	while(1) 
	{ 
		sw_swap=(GPIOA->IDR|dec)&sta; 
		switch(sw_swap) 
		{ 
			case 0x00000000 :  ;break; 
			case 0x00000002 : sta-=2,*timedecA+=0xffffff-(SysTick->VAL);break; 
			case 0x00000004 : sta-=4,*timedecB+=0xffffff-(SysTick->VAL);break; 
			case 0x00000008 : sta-=8,*timedecC+=0xffffff-(SysTick->VAL);break; 
			case 0x00000006 : sta-=6,*timedecA+=0xffffff-(SysTick->VAL),*timedecB=*timedecA;break; 
			case 0x0000000a : sta-=10,*timedecA+=0xffffff-(SysTick->VAL),*timedecC=*timedecA;break; 
			case 0x0000000c : sta-=12,*timedecB+=0xffffff-(SysTick->VAL),*timedecC=*timedecB;break; 
			case 0x0000000e : sta-=14,*timedecA+=0xffffff-(SysTick->VAL),*timedecB=*timedecA,*timedecC=*timedecA;break; 
			default : break; 
		} 
  	if((SysTick->VAL)>=0xffff00) 
  	{ 
			tmp= SysTick->VAL; 
			SysTick->VAL = 0; 
  		switch(sta) 
	  	{ 
		  	case 0 : break; 
			  case 2 : *timedecA+=0xffffff-tmp;break; 
  			case 4 : *timedecB+=0xffffff-tmp;break; 
	  		case 8 : *timedecA+=0xffffff-tmp;break; 
		  	case 6 : *timedecA+=0xffffff-tmp,*timedecB+=0xffffff-tmp;break; 
  			case 10 : *timedecA+=0xffffff-tmp,*timedecC+=0xffffff-tmp;break; 
	  		case 12 : *timedecB+=0xffffff-tmp,*timedecC+=0xffffff-tmp;break; 
		  	case 14 : *timedecA+=0xffffff-tmp,*timedecB+=0xffffff-tmp,*timedecC+=0xffffff-tmp;break; 
			  default : break; 
	  	} 
 
  	} 
		if(sta==0) 
		{ 
			break; 
		} 
	} 
	SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;//关闭滴答计数器 
	SysTick->VAL = 0x00;//计数器清零 
	return 0; 
}