【正文】
MHz。 = GPIO_Mode_Out_PP。 GPIO_Init(GPIOA, amp。GPIO_InitStructure)。 = GPIO_Pin_5。//LED = GPIO_Speed_50MHz。 = GPIO_Mode_Out_PP。 GPIO_Init(GPIOA, amp。GPIO_InitStructure)。 = GPIO_Pin_6。//LED = GPIO_Speed_50MHz。 = GPIO_Mode_Out_PP。 GPIO_Init(GPIOA, amp。GPIO_InitStructure)。 = GPIO_Pin_7。//LED = GPIO_Speed_50MHz。 = GPIO_Mode_Out_PP。 GPIO_Init(GPIOA, amp。GPIO_InitStructure)。 = GPIO_Pin_13。//LED = GPIO_Speed_50MHz。 = GPIO_Mode_Out_PP。 GPIO_Init(GPIOA, amp。GPIO_InitStructure)。 = GPIO_Pin_0。//PWM = GPIO_Speed_50MHz。 = GPIO_Mode_AF_PP。 GPIO_Init(GPIOB, amp。GPIO_InitStructure)。 = GPIO_Pin_6。//fc = GPIO_Mode_IN_FLOATING。 GPIO_Init(GPIOB, amp。GPIO_InitStructure)。}void Write(char data_h,char data_l){ int i。 GPIO_ResetBits(GPIOA, GPIO_Pin_5)。//CS使能(10ns) //data_h=(char)(data8)。 //data_l=(char)data。 for(i=0。i8。i++) { GPIO_ResetBits(GPIOA, GPIO_Pin_6)。//上升沿發(fā)送數(shù)據(jù) if(data_hamp。0x80)//判斷高位是否為1 GPIO_SetBits(GPIOA, GPIO_Pin_7)。 else GPIO_ResetBits(GPIOA, GPIO_Pin_7)。 delay_data(60)。 GPIO_SetBits(GPIOA, GPIO_Pin_6)。 data_h = 1。 } for(i=0。i8。i++) { GPIO_ResetBits(GPIOA, GPIO_Pin_6)。//上升沿發(fā)送數(shù)據(jù) if(data_lamp。0x80)//判斷高位是否為1 GPIO_SetBits(GPIOA, GPIO_Pin_7)。 else GPIO_ResetBits(GPIOA, GPIO_Pin_7)。 delay_data(60)。 GPIO_SetBits(GPIOA, GPIO_Pin_6)。 data_l = 1。 } delay_data(60)。 GPIO_SetBits(GPIOA, GPIO_Pin_5)。}void delay_data(int data){ int i。 for(i=0。idata。i++) { }}void interface_adconfig(void){ DMA_DeInit(DMA1_Channel1)。//設置成CH1 DMA中包含了7個通道(CH1CH7) = ADC1_DR_Address。//給DMA起始地址 = (u32)amp。ADC1ConvertedValue。//DMA連接在內存中的變量地址 = DMA_DIR_PeripheralSRC。//設置DMA傳輸方向 單向傳輸 = 1。//設置DMA在傳輸時緩沖區(qū)的長度 = DMA_PeripheralInc_Disable。//設置DMA的外設遞增模式 = DMA_MemoryInc_Disable。//設置DMA的內存遞增模式 = DMA_PeripheralDataSize_HalfWord。//DMA在訪問時每次操作的數(shù)據(jù)長度 = DMA_MemoryDataSize_HalfWord。 = DMA_Mode_Circular。//DMA的傳輸模式,連續(xù)不斷的循環(huán)模式 = DMA_Priority_VeryHigh。//DMA的優(yōu)先級別:可以分為4級 = DMA_M2M_Disable。//DMA的2個memory中的變量互相訪問的 DMA_Init(DMA1_Channel1, amp。DMA_InitStructure)。 //DMA整個模塊初始化 DMA_Cmd(DMA1_Channel1, ENABLE)。//開啟DMA通道1 = ADC_Mode_Independent。 //ADC1工作在獨立模式 = DISABLE。//使能掃描 = ENABLE。//ADC轉換工作在連續(xù)模式 = ADC_ExternalTrigConv_None。//促發(fā)方式選擇,由軟件控制轉換 = ADC_DataAlign_Right。//轉換數(shù)據(jù)右對齊 = 1。//轉換通道數(shù)目為1 ADC_Init(ADC1, amp。ADC_InitStructure)。 //初始化ADC RCC_ADCCLKConfig(RCC_PCLK2_Div6)。//配置ADC時鐘 ADC_RegularChannelConfig(ADC1, ADC_Channel_0, 1, ADC_SampleTime_28Cycles5)。//ADC1選擇信道0,音序器等級1, ADC_DMACmd(ADC1, ENABLE)。//使能ADC1模塊DMA ADC_Cmd(ADC1, ENABLE)。//打開ADC1 ADC_ResetCalibration(ADC1)。//重置ADC1校準寄存器 while(ADC_GetResetCalibrationStatus(ADC1))。//等待ADC1校準重置完成 ADC_StartCalibration(ADC1)。//開始ADC1校準 while(ADC_GetCalibrationStatus(ADC1))。//等待ADC1校準完成 ADC_SoftwareStartConvCmd(ADC1, ENABLE)。//使能ADC1軟件開始轉換 Pwm_Init()。}void Pwm_Init(void){ TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure。 TIM_OCInitTypeDef TIM_OCInitStructure。 =50001。//自動重裝載寄存器的值 =0。//時鐘預分頻數(shù) =TIM_CKD_DIV1。//采樣分頻 =TIM_CounterMode_Up。//向上計數(shù) =0。//重復寄存器,用于自動更新pwm占空比 TIM_TimeBaseInit(TIM3, amp。TIM_TimeBaseStructure)。 =TIM_OCMode_PWM1。//設置為pwm1輸出模式 =2500。//設置占空比時間 =TIM_OCPolarity_Low。//設置輸出極性 =TIM_OutputState_Enable。//使能該通道輸出 TIM_OC3PreloadConfig(TIM3, TIM_OCPreload_Enable)。//使能TIM3在CCR1上的預裝載寄存器 TIM_OC3Init(TIM3, amp。TIM_OCInitStructure)。 TIM_ARRPreloadConfig(TIM3, ENABLE)。//使能TIMx在ARR上的預裝載寄存器 TIM_Cmd(TIM3,ENABLE)。//打開TIM3}int data_ad(void){ return (int)ADC1ConvertedValue。}void interface_fc(void){ TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure。 GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource6)。//將EXTI線6連接到PB6 = EXTI_Line6。//配置按鈕中斷線觸發(fā)方式 = EXTI_Mode_Interrupt。//配置按鈕中斷線觸發(fā)方式 = EXTI_Trigger_Falling。 //下降沿觸發(fā) = ENABLE。 //中斷線使能 EXTI_Init(amp。EXTI_InitStructure)。 //初始化中斷 EXTI_GenerateSWInterrupt(EXTI_Line6)。 //EXTI_Line6中斷允許 = EXTI9_5_IRQn。 //中斷通道 =0。//搶占優(yōu)先級 =1。//響應優(yōu)先級 = ENABLE。//通道中斷使能 NVIC_Init(amp。NVIC_InitStructure)。//初始化中斷 = (7200 1)。//這個就是自動裝載的計數(shù)值,由于計數(shù)是從0開始的,計數(shù)10000次后為9999 = 0。//(7200 1), 這個就是預分頻系數(shù),當由于為0時表示不分頻所以要減1 = 0。//使用的采樣頻率之間的分頻比例,數(shù)字濾波器的應用 = TIM_CounterMode_Up。//計數(shù)器遞增 TIM_TimeBaseInit(TIM2, amp。TIM_TimeBaseStructure)。//初始化定時器2 TIM_ClearITPendingBit(TIM2, TIM_IT_Update)。//清除定時器2溢出中斷標志 TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE)。//打開溢出中斷 TIM_Cmd(TIM2, ENABLE)。//計數(shù)器使能,開始工作 = TIM2_IRQn。 =0。//第0組,所有4bit用于指定響應優(yōu)先級 = 0。//響應優(yōu)先級是1 = ENABLE。 NVIC_Init(amp。NVIC_InitStructure)。}外文資料Chapter 9USB Device FrameworkA USB device may be divided into three layers:? The bottom layer is a bus interface that transmits and receives packets.? The middle layer handles routing data between the bus interface and various endpoints on the endpoint is the ultimate consumer or provider of data. It may be thought of as a source or sink for data.? The top layer is the functionality provided by the serial bus device, for instance, a mouse or ISDN interface.This chapter describes the mon attributes and operations of the middle layer of a USB device. These attributes and operations are used by the functionspecific portions of the device to municate through the bus interface and ultimately with the host. USB Device StatesA USB device has several possible states. Some of these states are visible to the USB and the host, while others are internal to the USB device. This section describes those states. Visible Device StatesThis section describes USB device states that are externally visible (see Figure 91). Table 91 summarizes the visible device states.Note: USB devices perform a reset operation in response to reset signaling on the upstream facing reset signaling has pleted, the USB device is reset. AttachedA USB device may be attached or detached from the USB. The state of a USB device when it is detached from the