void pixelC_HW_flagLight_Init(void) { RCC->APB2ENR|=1<<2; #if FLAGLIGHT_Pin/8 FLAGLIGHT_GPIOx->CRH&=~((u32)0xf<<((FLAGLIGHT_Pin%8)*4)); FLAGLIGHT_GPIOx->CRH|=(u32)0x3<<((FLAGLIGHT_Pin%8)*4); #else FLAGLIGHT_GPIOx->CRL&=~((u32)0xf<<((FLAGLIGHT_Pin%8)*4)); FLAGLIGHT_GPIOx->CRL|=(u32)0x3<<((FLAGLIGHT_Pin%8)*4); #endif PAout(8)=1; }
int main() { RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE); //初始化管脚 NVIC_InitTypeDef NVIC_InitStructure; NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); //选择中断优先级分组,此处选择0。使0级抢占式优先级,16级亚优先级 NVIC_InitStructure.NVIC_IRQChannel = EXTI2_IRQn; //相应的通道配置,此处选择中断通道 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //抢占式优先级配置 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //亚优先级配置 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //时能通道 NVIC_Init(&NVIC_InitStructure); //使用结构体完成配置 GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); PAout(9)=1; //初始化PA09输出高电平,灭灯 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOD,&GPIO_InitStructure); //初始化PD02输入,浮空 GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource2); //配置中断源 EXTI_DeInit(); EXTI_InitTypeDef EXTI_InitStructure; EXTI_InitStructure.EXTI_Line = EXTI_Line2; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); //配置中断下降沿触发 while(1) { delay(500); } return 0; }
void usb_port_set(u8 enable) { uint16_t value; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE); if(enable) { value = _GetCNTR()&(~(1<<1)); _SetCNTR(value); } else { value = _GetCNTR()|((1<<1)); _SetCNTR(value); GPIOA->CRH&=0XFFF00FFF; GPIOA->CRH|=0X00033000; PAout(12)=0; } }
void EXTI2_IRQHandler(void) { PAout(9)=!PAout(9); EXTI_ClearITPendingBit(EXTI_Line2); }
void EXTI0_IRQHandler(void) { PAout(9)=!PAout(9); // delay(10); EXTI_ClearITPendingBit(EXTI_Line2); }
void pixelC_HW_flagLight_Off(void) { PAout(8)=1; }
void pixelC_HW_flagLight_On(void) { PAout(8)=0; }