STM32F030控制蜂鸣器定时响和控制LED亮

 一:STM32F030控制蜂鸣器定时响

(1)main.c中:
u16  StartTime=0;
void main()
{
	StartTime=500;//蜂鸣器响的时长
	SPEEK(1);    
}

void SPEEK(u8 num)
{
  TIM_Cmd(TIM2, ENABLE); //开启时钟
}
(2)hardware_conf.h中:
#define  Speak(tmp)  GPIOB->ODR=tmp?(GPIOB->ODR|1<<8):(GPIOB->ODR&(~(1<<8)))
(3)stm32f10x_it.c中:
extern void SPEEK(u8 num);

void SysTick_Handler(void)  
{ 
	if(StartTime>0)
	  {
	    StartTime--;
	    if(StartTime==0)
	    {
	      Speak(1);
	      TIM_Cmd(TIM2, DISABLE); //ژҕ
	    }
	  }

}

STM32F030控制LED亮

(1)main.c中:

void Leddisp(u8 tempvalue,u8 state)
{
  u8 sendnumber;
  if(displaying==0)
  {
    displaying=1;
    switch(tempvalue)
    {
    case HEAT_TEMP60:   LED_Buff[2]=state?0xDF:0x1f;break;
    case HEAT_TEMP70:   LED_Buff[3]=state?0xDF:0x1f;break;
    case HEAT_TEMP80:   LED_Buff[0]=state?0xDF:0x1f;break;
    case HEAT_TEMP90:   LED_Buff[5]=state?0xDF:0x1f;break;
    case HEAT_TEMP100:  LED_Buff[4]=state?0xDF:0x1f;break;
    case WARM_KEY:      LED_Buff[1]=state?0xDF:0x1f;break;
    case WIFI_KEY:      LED_Buff[6]=state?0xDF:0x1f;break;
    case All_LIGHT_ON:  memset(LED_Buff,0xDF,8);break;
    case ALL_LIGHT_OFF: memset(LED_Buff,0x1f,8);break;
    case SIX_LIGHT_ON:  memset(LED_Buff,0xDF,6);break;
    case SIX_LIGHT_OFF: memset(LED_Buff,0x1F,6);break;
    default: break;
    }   
    EXTI->IMR &= ~EXTI_Line0;
    EXTI->EMR &= ~EXTI_Line0;
    delay(20);//需要改小  2016-3-10
    while(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0)==1);  
    sendnumber=20;
    while(I2C1_Write_NBytes(IQS333_ADDR, PWM_DUTY, 8, &LED_Buff[0])!=0)
    {
      I2C_StopModeCmd(I2C1,ENABLE);
      //I2C_GenerateSTOP(I2C1,ENABLE);
      sendnumber--;
      if(sendnumber==0)
        break;
    }
    EXTI->IMR |= EXTI_Line0;
    EXTI->EMR |= EXTI_Line0;
    displaying=0;
  }
  else
  {
    sendnumber=0;
  }
}


void delay(u16 num)
{
  u16 i,j;
  for(i=0;i
u8  LED_Buff[8]={
    0x1f,
    0x1f,
    0x1f,
    0x1f,
    0x1f,
    0x1f,
    0x1f,
    0x1f,};


(2)hardware_conf.h中:
#define WARM_KEY      1
#define WIFI_KEY      2
#define All_LIGHT_ON  3
#define ALL_LIGHT_OFF 4
#define SIX_LIGHT_ON  5
#define SIX_LIGHT_OFF 6
#define HEAT_TEMP60   60
#define HEAT_TEMP70   70
#define HEAT_TEMP80   80
#define HEAT_TEMP90   90
#define HEAT_TEMP100  100







你可能感兴趣的:(STM32)