int main(void) { _U08 i; _U08 u8Array[] = {99,95,90,85,80,75,70,65,60,55,50,45}; ANCON0 = 0XFF; /*Desativamos las entradas analógicas*/ ANCON1 = 0XFF; /*Desativamos las entradas analógicas*/ /*el modulo pwm1 no tiene los pines conectados asi que hay que asignarlos a los pines RPx que deseemos*/ System_PeripheralPinSelect(EnhancedPWMOutputChannel1B, 19); /*PWM1_B en el pin RP19 (D2)*/ Gpios_PinDirection(GPIOS_PORTD, 2, GPIOS_OUTPUT); /*pin RD2 como salida para PWM_1B*/ Pwm_Init(PWM_PORT1, 750); while (1) { for(i=0;i<sizeof(u8Array);i++) { Pwm_DutyCycle(PWM_PORT1, PWM_CHANNEL_B, u8Array[i]); Delays_ms(300); } i--; for(;i<sizeof(u8Array);i--) { Pwm_DutyCycle(PWM_PORT1, PWM_CHANNEL_B, u8Array[i]); Delays_ms(300); } Delays_ms(3000); } }
int main(void) { DDRB = 0xFF; Pwm_Init(PWM_CHANNEL_0,PWM_FAST_MODE,PWM_CH0_PRE_SCALER_64); Pwm_SetPwmDutyCycle(PWM_CHANNEL_0,50); Pwm_SetActivationStatus(PWM_CHANNEL_0,PWM_ENABLE); while(1) { _delay_ms(100); //TODO:: Please write your application code } }
void main(void) { ANCON0 = 0XFF; /*Desativamos las entradas analógicas*/ ANCON1 = 0XFF; /*Desativamos las entradas analógicas*/ /*el modulo pwm1 no tiene los pines conectados asi que hay que asignarlos a los pines RPx que deseemos*/ System_PeripheralPinSelect(CompareOrPWMOutputChannel1A, 2); /*PWM1_A en el pin RP2 (A5)*/ System_PeripheralPinSelect(CompareOrPWMOutputChannel2A, 19); /*PWM2_A en el pin RP19 (D2)*/ Gpios_PinDirection(GPIOS_PORTA, 5, GPIOS_OUTPUT); /*pin RA5 como salida para PWM_1A*/ Gpios_PinDirection(GPIOS_PORTD, 2, GPIOS_OUTPUT); /*pin RD2 como salida para PWM_2A*/ Pwm_Init(PWM_PORT1, 1000); Pwm_Init(PWM_PORT2, 1000); Pwm_DutyCycle(PWM_PORT1, PWM_CHANNEL_A, 40); Pwm_DutyCycle(PWM_PORT2, PWM_CHANNEL_A, 70); while (1) { /*Escribe aqui tu aplicacion*/ } }
void EcuM_Callout_DriverInitListOne(void) { Det_Init(); Dem_PreInit(); Mcu_Init(&McuModuleConfiguration_0); Mcu_AdditionalInit(); Mcl_Init(NULL_PTR); Port_Init(NULL_PTR); Adc_Init(NULL_PTR); Dio_Init(NULL_PTR); Gpt_Init(NULL_PTR); Pwm_Init(NULL_PTR); Icu_Init(NULL_PTR); Spi_Init(NULL_PTR); SpiCtrl_Init(); SwGpt_Init(); pIcomInstBle = ICOM_Create(); ICOMChannelStatus_Init(pIcomInstBle); ICOMChannelDiag_Init(pIcomInstBle); ExtFlashSpiCtrlInit(SpiConf_SpiChannel_Spi_NVM_Command,\ SpiConf_SpiSequence_Spi_Seq_NVM,\ SpiConf_SpiJob_Spi_Job_NVM); CC254xCDD_Init(pIcomInstBle, DioConf_DioChannel_B6_SPI_SRDY_CU_LPCPU,\ SpiConf_SpiChannel_Spi_TICC2540_Command_8,\ SpiConf_SpiSequence_Spi_Seq_Ble_Exchange); /* ******************************************************************* * Wdg must be the latest in the initialization sequence * otherwise the function call Spi_SetAsyncMode(SPI_INTERRUPT_MODE) * returns a negative response when initializing the CC254xCDD_Init *********************************************************************/ Wdg_Init(NULL_PTR); WdgM_Init(NULL_PTR); WdgM_SetMode(1U,0U); }
int Pwm_Start( int channel ) { int status; if ( channel < 0 || channel >= PWM_COUNT ) return CONTROLLER_ERROR_ILLEGAL_INDEX; // Make sure the channel isn't already being used int c = 1 << channel; if ( c & Pwm.channels ) return CONTROLLER_ERROR_CANT_LOCK; // lock the correct select line int io = Pwm_GetChannelIo( channel ); // Try to lock the pin status = Io_Start( io, true ); if ( status != CONTROLLER_OK ) return status; // mark the channel as being used Pwm.channels |= c; // Disable the PIO for the IO Line Io_SetPio( io, false ); Io_SetPeripheralA( io ); if ( Pwm.users++ == 0 ) { status = Pwm_Init(); } // Enable the current channel AT91C_BASE_PWMC->PWMC_ENA = 1 << channel; return CONTROLLER_OK; }
/** * Part of STARTUP I * * @param ConfigPtr */ void EcuM_AL_DriverInitOne(const EcuM_ConfigType *ConfigPtr) { (void)ConfigPtr; #if defined(USE_MCU) Mcu_Init(ConfigPtr->McuConfig); /* Set up default clock (Mcu_InitClock requires initRun==1) */ /* Ignoring return value */ (void) Mcu_InitClock(ConfigPtr->McuConfig->McuDefaultClockSettings); // Wait for PLL to sync. while (Mcu_GetPllStatus() != MCU_PLL_LOCKED) { ; } Mcu_DistributePllClock(); #endif #if defined(USE_DEM) // Preinitialize DEM NO_DRIVER(Dem_PreInit(ConfigPtr->DemConfig)); #endif #if defined(USE_PORT) // Setup Port Port_Init(ConfigPtr->PortConfig); #endif #if defined(USE_DIO) // Setup Dio Dio_Init(ConfigPtr->DioCfg); #endif #if defined(USE_GPT) // Setup the GPT Gpt_Init(ConfigPtr->GptConfig); #endif // Setup watchdog #if defined(USE_WDG) Wdg_Init(ConfigPtr->WdgConfig); #endif #if defined(USE_WDGM) NO_DRIVER(WdgM_Init(ConfigPtr->WdgMConfig)); #endif #if defined(USE_DMA) // Setup DMA Dma_Init(ConfigPtr->DmaConfig); #endif #if defined(USE_ADC) // Setup ADC Adc_Init(ConfigPtr->AdcConfig); #endif #if defined(USE_BSWM) // Setup BSWM - not supporting configustructure for BswM BswM_Init(NULL); #endif // Setup ICU #if defined(USE_ICU) Icu_Init(ConfigPtr->IcuConfig); #endif // Setup PWM #if defined(USE_PWM) // Setup PWM Pwm_Init(ConfigPtr->PwmConfig); #endif // Setup OCU #if defined(USE_OCU) Ocu_Init(ConfigPtr->OcuConfig); #endif #if defined(CFG_SHELL) SHELL_Init(); #endif }
void EcuM_AL_DriverInitOne(const EcuM_ConfigType* configPtr) { /* provide a proper clock */ Mcu_Init(configPtr->bsw_driver.init_one.mcu_cfg); Mcu_InitClock(0); Mcu_DistributePllClock(); /* ----------------------------------------------------------------------- Interrupt System: ----------------------------------------------------------------------- - four arbitration cycles (max. 255 interrupt sources) - two clocks per arbitration cycle */ __mtcr(0xFE2C, 0x00000000); /* load CPU interrupt control register */ __isync(); /* ----------------------------------------------------------------------- Peripheral Control Processor (PCP): ----------------------------------------------------------------------- - the PCP internal clock is always running - use Full Context save area (R[0] - R[7]) - start progam counter as left by last invocation - channel watchdog is disabled - maximum channel number checking is disabled */ /* - four arbitration cycles (max. 255 PCP channels) */ /* - two clocks per arbitration cycle */ PCP_ICR.U = 0x00000000; /* load PCP interrupt control register */ /* - the PCP warning mechanism is disabled */ PCP_ITR.U = 0x00000000; /* load PCP interrupt threshold register */ /* - type of service of PCP node 4 is CPU interrupt */ PCP_SRC4.U = 0x00001000; /* load service request control register 4 */ /* - type of service of PCP node 5 is CPU interrupt */ PCP_SRC5.U = 0x00001000; /* load service request control register 5 */ /* - type of service of PCP node 6 is CPU interrupt */ PCP_SRC6.U = 0x00001000; /* load service request control register 6 */ /* - type of service of PCP node 7 is CPU interrupt */ PCP_SRC7.U = 0x00001000; /* load service request control register 7 */ /* - type of service of PCP node 8 is CPU interrupt */ PCP_SRC8.U = 0x00001000; /* load service request control register 8 */ ts_initGPTAInt(); Port_Init(configPtr->bsw_driver.init_one.port_cfg); Adc_Init(configPtr->bsw_driver.init_one.adc_cfg); Fls_Init(configPtr->bsw_driver.init_one.fls_cfg); Gpt_Init(configPtr->bsw_driver.init_one.gpt_cfg); Pwm_Init(configPtr->bsw_driver.init_one.pwm_cfg); Spi_Init(configPtr->bsw_driver.init_one.spi_cfg); Wdg_Init(configPtr->bsw_driver.init_one.wdg_cfg); #ifdef ECUM_WDGM_INCLUDED WdgM_Init(configPtr->bsw_driver.init_one.wdgm_cfg); #endif /* setup end of init protected registers for OS */ ts_endinit_clear(); osInitProtected(); ts_endinit_set(); /* Overlay Ram: * Init registers and mem areas for switching from * working page (overlay ram) <-> reference page (flash) */ RAM_OverlayRamReset(); /* - the CPU interrupt system is globally disabled */ __enable(); Spi_SetAsyncMode(SPI_INTERRUPT_MODE); Adc_StartGroupConversion(0); Adc_StartGroupConversion(1); EcuM_SelectApplicationMode(OSDEFAULTAPPMODE); }
/** * Part of STARTUP I * * @param ConfigPtr */ void EcuM_AL_DriverInitOne(const EcuM_ConfigType *ConfigPtr) { (void)ConfigPtr; // VALIDATE_STATE( ECUM_STATE_STARTUP_ONE ); //lint --e{715} PC-Lint (715) - ConfigPtr usage depends on configuration of modules #if defined(USE_MCU) Mcu_Init(ConfigPtr->McuConfig); /* Set up default clock (Mcu_InitClock requires initRun==1) */ /* Ignoring return value */ (void) Mcu_InitClock(ConfigPtr->McuConfig->McuDefaultClockSettings); // Wait for PLL to sync. while (Mcu_GetPllStatus() != MCU_PLL_LOCKED) { ; } Mcu_DistributePllClock(); #endif #if defined(USE_DEM) // Preinitialize DEM NO_DRIVER(Dem_PreInit(ConfigPtr->DemConfig)); #endif #if defined(USE_PORT) // Setup Port Port_Init(ConfigPtr->PortConfig); #endif #if defined(USE_GPT) // Setup the GPT Gpt_Init(ConfigPtr->GptConfig); #endif // Setup watchdog #if defined(USE_WDG) Wdg_Init(ConfigPtr->WdgConfig); #endif #if defined(USE_WDGM) NO_DRIVER(WdgM_Init(ConfigPtr->WdgMConfig)); #endif #if defined(USE_DMA) // Setup DMA Dma_Init(ConfigPtr->DmaConfig); #endif #if defined(USE_ADC) // Setup ADC Adc_Init(ConfigPtr->AdcConfig); #endif // Setup ICU // TODO // Setup PWM #if defined(USE_PWM) // Setup PWM Pwm_Init(ConfigPtr->PwmConfig); #endif #if defined(CFG_SHELL) SHELL_Init(); #endif }
/**************************************************************/ //程 序 名: main() //开 发 者: MingH //入口参数: 无 //功能说明: 主函数 //**************************************************************/ int main(void) { unsigned char err_code; RCC_Config(); // 时钟初始化配置 Beep_Init(); // 蜂鸣器初始化配置 Touch_Init(); Pcie_Gpio_Init(); Tim3_Init(); RGB_Init(); //RGB 初始化 RCC_GetClocksFreq(&RCC_ClockFreq); SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK); USB2Serial_Init(); // 串口初始化配置 Pwm_Init(); Adc_Init(); I2C_GPIO_Configuration(); err_code = LIS3DH_Init(); if (NO_ERROR == err_code) { printf("\r\nLIS3DH Init is succeed! \r\n"); } else { printf("\r\nLIS3DH Init is failed! \r\n"); } RTC_Init(); // RTC 初始化配置 if(SD_Init() == SD_OK) { printf ("\r\n发现SD卡!\r\n"); } else { printf("\r\n没有发现 SD 卡设备! \r\n"); } printf("\r\n\r\n"); save_sd_detect = SD_Detect(); //初始化SD卡插入状态 SysTick_Delay_ms(500); TIM_Cmd(TIM1, DISABLE); TIM_CtrlPWMOutputs(TIM1, DISABLE); while (1) { if(read_sd_detect_flag){ if (save_sd_detect != SD_Detect()){ /* 蜂鸣器响 */ TIM_Cmd(TIM1, ENABLE); TIM_CtrlPWMOutputs(TIM1, ENABLE); sd_detect_change = 1; //SD卡插入状态有变 buzzer_delay = 0; if (SD_Detect() != SD_NOT_PRESENT){ if(SD_Init() == SD_OK) { printf ("\r\n发现SD卡!\r\n"); } else { printf("\r\n没有发现 SD 卡设备! \r\n"); } printf("\r\n\r\n"); } } save_sd_detect = SD_Detect(); read_sd_detect_flag = 0; } Time_Show(); Test_Pcie_Gpio(); Touch_Key_Proc(); if (read_lis3dh_flag){ Collect_Data(ACCdata); for (i=0; i<3; i++){ if (oldACCdata[i] < ACCdata[i]){ ACCdiff[i] = ACCdata[i] - oldACCdata[i]; } else{ ACCdiff[i] = oldACCdata[i] - ACCdata[i]; } } RGB_Control(ACCdiff[0]<<1, ACCdiff[1]<<1, ACCdiff[2]<<1); for (i=0; i<3; i++){ oldACCdata[i] = ACCdata[i]; } read_lis3dh_flag = 0; } if (one_second_flag){ printf("X=%d, Y=%d, Z=%d\r\n\r\n", ACCdata[1], ACCdata[0], ACCdata[2]); Adc_Proc(); one_second_flag = 0; } } }