/** ****************************************************************************** ** 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(); } }
void setup(void) { #if defined(lpc11c14) || defined(lpc1768) GPIO_Init(); GPIO_SetDir(RED_LED_PORT, RED_LED_BIT, 1); GPIO_SetDir(YELLOW_LED_PORT, YELLOW_LED_BIT, 1); // Register the GPS timer sync GPIO_SetFunction(2, 10, GPIO_PIO, GPIO_MODE_NONE); GPIO_SetDir(2, 10, 0); GPIO_RegisterInterruptHandler(2, 10, 0, 0, 1, &gps_timer_handler); InitRTC(); SetTime("000000"); // FOR DEBUG PURPOSE, REMOVE LATER scandal_naive_delay(100000); // StartOsc(); #else #ifdef msp43f149 init_clock(); P1OUT = 0x00; P1SEL = 0x00; P1DIR = 0x00; P1IES = 0x00; P1IE = 0x00; P2OUT = 0x00; P2SEL = 0x00; P2DIR = 0x00; P2IES = CAN_INT; P2IE = 0x00; P3OUT = 0x00; P3SEL = TX | RX; P3DIR = TX; P4OUT = 0x00; P4SEL = 0x00; P4DIR = 0x00; P5OUT = CAN_CS; P5SEL = SIMO1 | SOMI1 | UCLK1; P5DIR = CAN_CS | SIMO1 | UCLK1 | YELLOW_LED_BIT | RED_LED_BIT; P6SEL = MEAS_12V_PIN; #endif // msp430f149 #endif // lpc1768 || lpc11c14 } // setup
int main(void) { uint8_t count, second=0; uint32_t val; InitUART0 (); InitRTC(); UART0_dbg_msg ( "********************************************************************************\n\r" " Internal DAC test of LPC1788\n\r" "\t - UART Comunication: 9600 bps \n\r" " Write to debug console current voltage on AD[2]-AD[3]\n\r" "********************************************************************************\n\r"); if (!InitADC (2)) { UART0_dbg_msg ("InitADC exception, channel must be 0..7\n\r"); while (1); } InitDAC (0x03FF); while (1) { //input DAC value do { UART0_dbg_msg ("Input DAC value in range 0..1023, as a sample 0983\n\r"); while (!UART0_get_dec (&val,4)) UART0_dbg_msg ("DAC value is 10-bit number\n\r"); if (val>1024) { UART0_dbg_msg ("DAC value isn't in range 0..1023\n\r"); UART0_clear_rx_buffer(); } } while (val>1024); count=0; //Set DAC value SetDAC(val); //Convert DAC value through ADC 5 times while(count<5) { if (second != LPC_RTC->SEC) { second=LPC_RTC->SEC; ADC_dbg(GetADC()); count++; } } } }
int main( void ) { InitVFD(); InitISD(); InitI2C(); InitADC(); InitRTC(); InitDS75(); InitKeys(); InitUART(); InitRFM(); InitAlarm(); sei(); wdt_enable(WDT_DEFAULT); UI(); return 0; }
//========================================================================= //----- (00000148) -------------------------------------------------------- __myevic__ void Main() { InitDevices(); InitVariables(); // Enable chip temp sensor sampling by ADC if ( ISRX300 ) { SYS->IVSCTL |= SYS_IVSCTL_VTEMPEN_Msk; } InitHardware(); myprintf( "\n\nJoyetech APROM\n" ); myprintf( "CPU @ %dHz(PLL@ %dHz)\n", SystemCoreClock, PllClock ); SetBatteryModel(); gFlags.sample_vbat = 1; ReadBatteryVoltage(); gFlags.sample_btemp = 1; ReadBoardTemp(); InitDisplay(); MainView(); SplashTimer = 3; CustomStartup(); if ( !PD3 ) { DrawScreen(); while ( !PD3 ) ; } while ( 1 ) { while ( gFlags.playing_fb ) { // Flappy Bird game loop fbCallTimeouts(); if ( gFlags.tick_100hz ) { // 100Hz gFlags.tick_100hz = 0; ResetWatchDog(); TimedItems(); SleepIfIdle(); GetUserInput(); if ( !PE0 ) SleepTimer = 3000; } if ( gFlags.tick_10hz ) { // 10Hz gFlags.tick_10hz = 0; DataFlashUpdateTick(); } } if ( gFlags.firing ) { ReadAtoCurrent(); } if ( gFlags.tick_5khz ) { // 5000Hz gFlags.tick_5khz = 0; if ( gFlags.firing ) { RegulateBuckBoost(); } } if ( gFlags.tick_1khz ) { // 1000Hz gFlags.tick_1khz = 0; if ( gFlags.firing ) { ReadAtomizer(); if ( ISMODETC(dfMode) ) { if ( gFlags.check_mode ) { CheckMode(); } TweakTargetVoltsTC(); } else if ( ISMODEVW(dfMode) ) { TweakTargetVoltsVW(); } } if ( dfStatus.vcom ) { VCOM_Poll(); } } if ( gFlags.tick_100hz ) { // 100Hz gFlags.tick_100hz = 0; ResetWatchDog(); if ( gFlags.read_battery ) { gFlags.read_battery = 0; } TimedItems(); SleepIfIdle(); ReadBatteryVoltage(); ReadBoardTemp(); if ( gFlags.firing && BoardTemp >= 70 ) { Overtemp(); } if ( ISVTCDUAL ) { BatteryChargeDual(); } else if ( ISCUBOID || ISCUBO200 || ISRX200S || ISRX23 || ISRX300 ) { BatteryCharge(); } if (( gFlags.anim3d ) && ( Screen == 1 ) && ( !EditModeTimer )) { anim3d( 0 ); } if ( Screen == 60 ) { AnimateScreenSaver(); } if ( gFlags.firing ) { if ( gFlags.read_bir && ( FireDuration > 10 ) ) { ReadInternalResistance(); } if ( PreheatTimer && !--PreheatTimer ) { uint16_t pwr; if ( dfMode == 6 ) { pwr = dfSavedCfgPwr[ConfigIndex]; } else { pwr = dfPower; } if ( pwr > BatteryMaxPwr ) { gFlags.limit_power = 1; PowerScale = 100 * BatteryMaxPwr / pwr; } else { gFlags.limit_power = 0; PowerScale = 100; } } } if ( KeyTicks >= 5 ) { KeyRepeat(); } GetUserInput(); } if ( gFlags.tick_10hz ) { // 10Hz gFlags.tick_10hz = 0; DataFlashUpdateTick(); LEDTimerTick(); if ( gFlags.firing ) { ++FireDuration; if ( gFlags.monitoring ) { Monitor(); } } if ( ShowWeakBatFlag ) --ShowWeakBatFlag; if ( ShowProfNum ) --ShowProfNum; if ( !( gFlags.firing && ISMODETC(dfMode) ) ) { DrawScreen(); } if ( KeyTicks < 5 ) { KeyRepeat(); } } if ( gFlags.tick_5hz ) { // 5Hz gFlags.tick_5hz = 0; if ( !gFlags.rtcinit && NumBatteries ) { InitRTC(); } if ( gFlags.firing ) { if ( TargetVolts == 0 ) { ProbeAtomizer(); } } else { if ( !dfStatus.off && Event == 0 && ( AtoProbeCount < 12 ) && ( Screen == 0 || Screen == 1 || Screen == 5 ) ) { ProbeAtomizer(); } } if ( IsClockOnScreen() ) { static uint8_t u8Seconds = 61; S_RTC_TIME_DATA_T rtd; GetRTC( &rtd ); if ( (uint8_t)rtd.u32Second != u8Seconds ) { u8Seconds = (uint8_t)rtd.u32Second; gFlags.refresh_display = 1; } } } if ( gFlags.tick_2hz ) { // 2Hz gFlags.tick_2hz = 0; gFlags.osc_1hz ^= 1; if ( gFlags.firing ) { if ( ISMODETC(dfMode) ) { DrawScreen(); } } else { if ( !dfStatus.off && Event == 0 && ( AtoProbeCount >= 12 ) && ( Screen == 0 || Screen == 1 || Screen == 5 ) ) { ProbeAtomizer(); } if ( gFlags.monitoring ) { Monitor(); } } } if ( gFlags.tick_1hz ) { // 1Hz gFlags.tick_1hz = 0; if ( SplashTimer ) { --SplashTimer; if ( !SplashTimer ) { MainView(); } } if ( !gFlags.firing && !dfStatus.off && !EditModeTimer ) { if ( HideLogo ) { if ( Screen == 1 ) { --HideLogo; if ( !HideLogo ) { gFlags.refresh_display = 1; } } } } } EventHandler(); } }