void Timer_Wait_onems(unsigned short delay){ unsigned short i; for (i = 0 ; i < delay ; i++){ Timer_Wait(188); } }
/** ****************************************************************************** ** Main application to control the program flow *****************************************************************************/ void main(void) { // Initialize all interrupt levels of resources Vectors_InitIrqLevels(); // Allow all interrupt levels __set_il(7); // Enable interrupts __EI(); Flash_EnableWriting(); InitLCD(); #if ((SMC_TYPE != SMC_TYPE_R200) && (ZPD == ZPD_ENABLE)) ZPD_Init(); //ќжидание окончани¤ ZPD while (m_enSmcMode == Zpd) { WDTCP = 0x00; } #else m_enSmcMode = NormalDriving; #endif InitSMC(20); Timer_Init(); InitADC(); InitRTC(); // ≈сли двигатель R200 или ZPD не активно #if ((SMC_TYPE == SMC_TYPE_R200) || (ZPD == ZPD_DISABLE)) ZeroPosSMC(); Timer_Wait(TIMER_ID_MAIN, 2000, TRUE); #endif ClearPosSMC(); DriverInit(); InitFRTimer0(); InitExtInt0(); //test Init_4_imp(); InitBacklight(); Button_Init(ButtonCallback); CAN_Init(); J1939_init(); InitUsart0(); if (Button_GetCurrentButtonState(BUTTON_ID_B1) == StateLow) SetModePass(); while(1) { WDTCP_ = 0x00; Timer_Main(); } }
/** * @brief Main Program body */ int c_entry(void) { PINSEL_CFG_Type PinCfg; uint32_t adc_value; /* * Initialize debug via UART */ debug_frmwrk_init(); // print welcome screen print_menu(); /* * Init ADC pin connect * AD0.2 on P0.25 */ PinCfg.Funcnum = 1; PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; PinCfg.Pinnum = 25; PinCfg.Portnum = 0; PINSEL_ConfigPin(&PinCfg); /* Configuration for ADC : * Frequency at 1Mhz * ADC channel 2, no Interrupt */ ADC_Init(LPC_ADC, 1000000); ADC_IntConfig(LPC_ADC,ADC_ADINTEN2,DISABLE); ADC_ChannelCmd(LPC_ADC,ADC_CHANNEL_2,ENABLE); while(1) { // Start conversion ADC_StartCmd(LPC_ADC,ADC_START_NOW); //Wait conversion complete while (!(ADC_ChannelGetStatus(LPC_ADC,ADC_CHANNEL_2,ADC_DATA_DONE))); adc_value = ADC_ChannelGetData(LPC_ADC,ADC_CHANNEL_2); //Display the result of conversion on the UART0 _DBG("ADC value on channel 2: "); _DBD32(adc_value); _DBG_(""); //delay 1s Timer_Wait(1000); } ADC_DeInit(LPC_ADC); return 1; }
int c_entry(void) { // Init LED port LED_Init(); /* * Initialize debug via UART */ debug_frmwrk_init(); // print welcome screen print_menu(); // Read back TimeOut flag to determine previous timeout reset if (WDT_ReadTimeOutFlag()){ _DBG_(info1); // Clear WDT TimeOut WDT_ClrTimeOutFlag(); } else{ _DBG_(info2); } // Initialize WDT, IRC OSC, interrupt mode, timeout = 2000000 microsecond WDT_Init(WDT_CLKSRC_IRC, WDT_MODE_RESET); // Start watchdog with timeout given WDT_Start(WDT_TIMEOUT); // set timer 100 ms Timer_Wait(100); while (1){ // Wait for 100 millisecond while ( !(TIM_GetIntStatus(LPC_TIM0,0))); TIM_ClearIntPending(LPC_TIM0,0); //turn on led FIO_ByteSetValue(2, 0, LED_PIN); // Wait for 100 millisecond while ( !(TIM_GetIntStatus(LPC_TIM0,0))); TIM_ClearIntPending(LPC_TIM0,0); //turn off led FIO_ByteClearValue(2, 0, LED_PIN); } return 0; }
//---------------------Timer_Wait_1ms--------------------- //time delay //Input: time in msec increments //Output: none static void Timer_Wait_1ms(unsigned short msec){ for(;msec;msec--){ Timer_Wait(ONE_MS); //1ms wait } }
//---------Timer_Wait10ms------------------ // fixed time delay // inputs: time to wait in 10ms // outputs: none // 15000 cycles equals 10ms void Timer_Wait10ms(unsigned short delay){ for(;delay>0;delay--){ Timer_Wait(15000); } }