void opendoor(void) { int i; TIM_OC3PreloadConfig(TIM3, TIM_OCPreload_Enable);//开信号时钟PB0 //TIM3_Mode_Config(180);//开门转角 for(i=0;i<=46;i++) { TIM3_Mode_Config(180+10*i); if(i==0) { GPIO_ResetBits(GPIOA, GPIO_Pin_2);//启动舵机电源 delay_ms(10); } delay_ms(25); } beep_done(); delay_ms(5000);//开门等待 TIM3_Mode_Config(180);//关门转角 delay_ms(800);//关门等待 GPIO_SetBits(GPIOA, GPIO_Pin_2);//关舵机电源 TIM_OC3PreloadConfig(TIM3, TIM_OCPreload_Disable);//关信号时钟PB0 }
void Accept_to_complete(uint32_t *hour,uint32_t *min) { uint32_t one=0,two=0,three=0,four=0; switch(receive[1]) { case '1': one = (receive[2]-'0')*10+(receive[3]-'0'); two = (receive[4]-'0')*10+(receive[5]-'0'); three = (receive[7]-'0')*10+(receive[6]-'0'); four = (receive[8]-'0')*10+(receive[9]-'0'); *hour = one; *min = two; setTime[3] = three; setTime[4] = four; USART2_SendStringData("0101"); break; case '2': one = (receive[2]-'0')*10+(receive[3]-'0'); setPwm = one; /*** 设置pwm,改变灯的亮度 ***/ CCR4_Val= one*100; TIM3_Mode_Config(); printf("0101"); break; case '3': one = (receive[2]-'0')*10+(receive[3]-'0'); //一键闹醒 if(one==1) { BEEP(1); Delay(500000); BEEP(0); } printf("0101"); break; case '4': printf("03%03d55aa",vTemp/1000); break; default : printf("0202"); break; } }
/* * 函数名:TIM3_PWM_Init * 描述 :TIM3 输出PWM信号初始化,只要调用这个函数 * TIM3的四个通道就会有PWM信号输出 * 输入 :无 * 输出 :无 * 调用 :外部调用 */ void TIM3_PWM_Init(void) { TIM3_GPIO_Config(); TIM3_Mode_Config(); }
/** * @brief TIM3 呼吸灯初始化 * 配置PWM模式和GPIO * @param 无 * @retval 无 */ void TIM3_Breathing_Init(void) { TIM3_GPIO_Config(); TIM3_Mode_Config(); }
//***************************************************************************** // //! init_spi //! //! @param none //! //! @return none //! //! @brief initializes an SPI interface // //***************************************************************************** int init_spi(void) { GPIO_InitTypeDef gpio; EXTI_InitTypeDef exti; NVIC_InitTypeDef nvic; SPI_InitTypeDef spi; RCC_APB2PeriphClockCmd(IRQ_CLOCK, ENABLE); RCC_APB2PeriphClockCmd(SPI_CS_CLOCK, ENABLE); RCC_APB2PeriphClockCmd(SPI_CLOCK, ENABLE); //Config GPIO - IRQ pin gpio.GPIO_Mode = GPIO_Mode_IPU; gpio.GPIO_Pin = IRQ_PIN; gpio.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(IRQ_BASE, &gpio); //Connect EXTIx Line to GPIO pin GPIO_EXTILineConfig(IRQ_INT_PORT, IRQ_INT_PIN); //Config External Interrupt exti.EXTI_Line = IRQ_INT_LINE; exti.EXTI_Mode = EXTI_Mode_Interrupt; exti.EXTI_Trigger = EXTI_Trigger_Falling; exti.EXTI_LineCmd = ENABLE; EXTI_Init(&exti); // Enable interrupt for WLAN_IRQ pin nvic.NVIC_IRQChannel = IRQ_INT_CHANNEL; nvic.NVIC_IRQChannelPreemptionPriority = 0x0F; nvic.NVIC_IRQChannelSubPriority = 0x0F; nvic.NVIC_IRQChannelCmd = ENABLE; NVIC_ClearPendingIRQ(IRQ_INT_CHANNEL); NVIC_Init(&nvic); //Config GPIO - CS pin // gpio.GPIO_Mode = GPIO_Mode_Out_OD; gpio.GPIO_Mode = GPIO_Mode_Out_PP; //for test 硬件上有电平转换芯片 gpio.GPIO_Pin = SPI_CS_PIN; gpio.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(SPI_CS_BASE, &gpio); // Disable WLAN CS with pull up Resistor GPIO_SetBits(SPI_CS_BASE, SPI_CS_PIN); //Init SCK pin //gpio.GPIO_Mode = GPIO_Mode_AF_OD; gpio.GPIO_Mode = GPIO_Mode_AF_PP; //for test 硬件上有电平转换芯片 gpio.GPIO_Pin = SPI_SCK_PIN; gpio.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(SPI_PIN_BASE, &gpio); //Init MOSI pin // gpio.GPIO_Mode = GPIO_Mode_AF_OD; gpio.GPIO_Mode = GPIO_Mode_AF_PP; //for test 硬件上有电平转换芯片 gpio.GPIO_Pin = SPI_MOSI_PIN; gpio.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(SPI_PIN_BASE, &gpio); //Init MISO pin gpio.GPIO_Mode = GPIO_Mode_IN_FLOATING; gpio.GPIO_Pin = SPI_MISO_PIN; gpio.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(SPI_PIN_BASE, &gpio); //Init SPI spi.SPI_Direction = SPI_Direction_2Lines_FullDuplex; spi.SPI_Mode = SPI_Mode_Master; spi.SPI_DataSize = SPI_DataSize_8b; //SPI MODE: 1 //Clock polarity = Negetive //Clock phase = 2nd edge (launch on rising edge, capture on falling edge) spi.SPI_CPOL = SPI_CPOL_Low; spi.SPI_CPHA = SPI_CPHA_2Edge; spi.SPI_NSS = SPI_NSS_Soft; //Prescaler = 8, clock freq = 36MHz / 4 = 9MHz spi.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8; //MSB first spi.SPI_FirstBit = SPI_FirstBit_MSB; spi.SPI_CRCPolynomial = 7; //Apply this config SPI_Cmd(SPI_BASE, DISABLE); SPI_Init(SPI_BASE, &spi); SPI_Cmd(SPI_BASE, ENABLE); // SpiCC3000DMAInit(); delay(20); RCC_APB2PeriphClockCmd(CC3000_EN_CLOCK, ENABLE); RCC_APB2PeriphClockCmd(WL_EN_CLOCK, ENABLE); //Config GPIO - EN pin gpio.GPIO_Mode = GPIO_Mode_Out_PP; gpio.GPIO_Pin = CC3000_EN_PIN; gpio.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(CC3000_EN_BASE, &gpio); //WL_EN gpio.GPIO_Mode = GPIO_Mode_Out_OD; gpio.GPIO_Pin = WL_EN_PIN; gpio.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(WL_EN_BASE, &gpio); //SET WL_EN low GPIO_ResetBits(WL_EN_BASE, WL_EN_PIN); // Disable WLAN chip GPIO_SetBits(CC3000_EN_BASE, CC3000_EN_PIN); RCC_APB2PeriphClockCmd(PWM_32K_CLOCK, ENABLE); //PWM_32K_OUTPUT gpio.GPIO_Mode = GPIO_Mode_AF_OD; gpio.GPIO_Pin = PWM_32K_PIN; gpio.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(PWM_32K_BASE, &gpio); TIM3_Mode_Config(); return (ESUCCESS); }
void Motor_Init(void) { TIM3_GPIO_Config(); TIM3_Mode_Config(); }
void TIM_Init(void) { TIM3_Mode_Config(); }