- int32_t main(void)
- {
- uint8_t VCPReceive[16] = {0};
- uint8_t VCPSend[16] = {0};
-
- SYS_Init();
- USBD_Open(&gsInfo, VCOM_ClassRequest, NULL);
- /* Endpoint configuration */
- VCOM_Init();
- USBD_Start();
- NVIC_EnableIRQ(USBD_IRQn);
- PWM_Init();
- EADC_Init();
- Timer1_Init();
-
- while(1)
- {
- if( VCom_Read( VCPReceive, 16 ) )
- {
- if( VCPReceive[0] == 0x5a )
- {
- VCom_Write("八月,新唐你好!\r\n", 20);
- VCom_Write("Hello, 21ic.com !\r\n", 20);
- VCom_Write("MyID:ysdx06010302\r\n", 20);
-
- VCom_Write("Start\r\n", 8);
-
- gStart = 1;
- }
- }
-
- if( gStart )
- {
- if( nTimerCnt > 100 ) //100ms,读ADC,调整PWM占空比
- {
- nTimerCnt = 0;
- if( EADC_GET_INT_FLAG(EADC, (1<<0)) )
- {
- /* Get the conversion result of the sample module 0 */
- i32ConversionData = EADC_GET_CONV_DATA(EADC, 0);
-
- i32ConversionData *= 3300;
- i32ConversionData /= 4096;
-
- /* trigger sample module 0 to start A/D conversion */
- EADC_START_CONV(EADC, (1<<0));
-
- // 发送AD值
- VCom_Write("AD Value:", 9);
- Int2Str(i32ConversionData, VCPSend);
- VCom_Write(VCPSend, 8);
- }
-
- //调整占空比
- SetPwmPara(1, 125, (DutyBuf[DutyIndex] * 100) >> 8 );
-
- DutyIndex++;
- if( DutyIndex >= 40 )
- {
- DutyIndex = 0;
- }
- }
- }
- }
- }
|