int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer LedInit(); PWMInit(); while(1){ } }
int main() { long lRetVal = -1; val=0; BoardInit(); PinMuxConfig(); LedInit(); //create OS tasks lRetVal = osi_TaskCreate(PushButtonHandler, (signed char*) "PushButtonHandler", OSI_STACK_SIZE, NULL, 2, &g_PushButtonTask); if(lRetVal < 0) { ERR_PRINT(lRetVal); LOOP_FOREVER(); } lRetVal = osi_TaskCreate(MainLoop, (signed char*)"MainLoop", OSI_STACK_SIZE, NULL, 1, NULL ); if(lRetVal < 0) { ERR_PRINT(lRetVal); LOOP_FOREVER(); } osi_start(); for(;;) { } return 0; }
/******************************************** 飞控主函数入口 功能: 1.初始化各个硬件 2.初始化系统参数 3.开定时器4等待数据中断到来 4.开定时器3串口广播实时姿态以及相关信息 ********************************************/ int main(void) { //int i; SystemClock_HSE(9); //系统时钟初始化,时钟源外部晶振HSE //SystemClock_HSI(4); //系统时钟初始化,时钟源内部HSI UART1_init(SysClock,115200); //串口1初始化 NVIC_INIT(); //中断初始化 STMFLASH_Unlock(); //内部flash解锁 LedInit(); //IO初始化 delay_init(SysClock); //滴答延时初始化 BT_PowerInit(); //蓝牙电源初始化完成,默认关闭 MotorInit(); //马达初始化 BatteryCheckInit(); //电池电压监测初始化 IIC_Init(); //IIC初始化 MPU6050_DMP_Initialize(); //初始化DMP引擎 //HMC5883L_SetUp(); //初始化磁力计HMC5883L PID_INIT(); //PID参数初始化 ParameterRead(); //Flash参数读取 NRF24L01_INIT(); //NRF24L01初始化 SetRX_Mode(); //设无线模块为接收模式 PowerOn(); //开机等待 BT_on(); //蓝牙开 TIM3_Init(SysClock,10); //定时器3初始化,调试串口输出 TIM4_Init(SysClock,50); //定时器4初始化,定时采样传感器数据,更新PID输出 while (1); //等待数据更新中断到来 }
void BoardInit( void ) { uint8_t i; /* Setup SysTick Timer for 1 us interrupts ( not too often to save power ) */ if( SysTick_Config( SystemCoreClock / 1000 ) ) { /* Capture error */ while (1); } // Initialize unused GPIO to optimize power consumption InitUnusedGPIO( ); // Initialize Selector SelectorInit( ); // Initialize SPI SpiInit( ); // Initialize LED for( i = 0; i < LED_NB; i++ ) { LedInit( ( tLed )i ); } LedOn( LED1 ); LedOn( LED2 ); LedOn( LED3 ); LongDelay( 1 ); LedOff( LED1 ); LedOff( LED2 ); LedOff( LED3 ); }
int main(void) { /* Watchdog timer disabled */ WDTCTL = WDTPW + WDTHOLD; BspInit(); DioInit(); DioSet(BUTTON0); UartInit(9600, UartCallback); LedInit(); ButtonInit(); ButtonSetup(0, Button0Cbf, 20); LedOn(0); SchedulerInit(100, 1, 2); // 1ms tick, 1 timed task, 2 loop task SetSchedulerTimedTask(LedRedFlash, 0, 500, 0); // schedule timed_task[0] as led_red_flash, set off every 500ms SetSchedulerLoopTask(ButtonLoop, 0); // schedule loop_task[0] as button_loop SetSchedulerLoopTask(UartManage, 1); // schedule loop_task[1] as uart_loop __eint(); SchedulerRun(); while(1) { } }
void HAL_MspInit(void) { LedInit(LED_ALL); Tim4Init(); Spi2Init(); GpioPushButtonInit(); GpioSpi2Init(); }
int main(void) { tm gmt; WatchDogDisable(); NutDelay(100); SysInitIO(); SPIinit(); LedInit(); LcdLowLevelInit(); Uart0DriverInit(); Uart0DriverStart(); LogInit(); LogMsg_P(LOG_INFO, PSTR("-----------------------------------------------------------------------------------------------")); CardInit(); X12Init(); if (X12RtcGetClock(&gmt) == 0) { LogMsg_P(LOG_INFO, PSTR("RTC time [%02d:%02d:%02d]\n"), gmt.tm_hour, gmt.tm_min, gmt.tm_sec ); } if (At45dbInit() == AT45DB041B) { } RcInit(); KbInit(); SysControlMainBeat(ON); // enable 4.4 msecs hartbeat interrupt NutThreadSetPriority(1); NutTimerInit(); sei(); printf("\nreading EEPROM\n"); NutSleep(1000); readEEPROM(); printf("UTC: %d\n",IMCconfig.UTC); NutSleep(1000); IMCconfig.UTC++; printf("na ophoging UTC: %d\n",IMCconfig.UTC); saveEEPROM(); NutSleep(1000); readEEPROM(); printf("na saving en reading UTC: %d\n",IMCconfig.UTC); printf("\nResetting EEPROM\n"); NutSleep(1000); resetEEPROM(); NutSleep(1000); readEEPROM(); for (;;) { } return(0); // never reached, but 'main()' returns a non-void, so..... }
void BspInit(void) { AdcInit(); // BeepInit(); KeyInit(); LedInit(); // MotorInit(); UartInit(); // InitEEPROM(); }
/************************************************************************************//** ** \brief Initializes the microcontroller. ** \return none. ** ****************************************************************************************/ static void Init(void) { /* initialize the system and its clocks */ SystemInit(); /* init the led driver */ LedInit(); /* init the timer driver */ TimerInit(); /* enable IRQ's, because they were initially disabled by the bootloader */ IrqInterruptEnable(); } /*** end of Init ***/
/******************************************************************************* * Function Name :void SystemConfig(void) * Description :系统初始化 * Input : * Output : * Other : * Date :2011.10.27 13:14:59 *******************************************************************************/ void BspInit(void) { RCC_Configuration(); NVIC_Configuration(); //中断优先级设置 GPIO_Configuration(); //端口初始化,所有端口关 LedInit(); BspTim2Init(); BspTim3Init(); BspUsart1Init(); }
void initHw(){ LedInit(); GenTimInit(); delay_us(500e3); sens9DInit(); USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID,&USR_desc,&USBD_CDC_cb,&USR_cb); NVIC_SetPriority(SysTick_IRQn, 0); }
void DispatcherTask ( void * pvParameters ) { struct ADispatcherMessage *pxDispatcherMessage; struct ALCDMessage xLCDMessage, *pxLCDMessage = & xLCDMessage; UB_RTC_Init ( ); LedInit ( ); xDispatcherQueue = xQueueCreate ( 8, sizeof ( unsigned long ) ); while ( 1 ) { SendTimeToLCD ( pxLCDMessage ); if ( xQueueReceive ( xDispatcherQueue, & ( pxDispatcherMessage ), 250 / portTICK_RATE_MS ) ) { if ( !strnicmp ( pxDispatcherMessage->Domain, "HELP", 3 ) ) { PrintHelp ( ); } else if ( !strnicmp ( pxDispatcherMessage->Domain, "RTC", 3 ) ) { if ( !strnicmp ( pxDispatcherMessage->Command, "SET", 3 ) ) { SetRTCTime ( pxDispatcherMessage->Parameter ); } else if ( !strnicmp ( pxDispatcherMessage->Command, "GET", 3 ) ) { GetRTCTime ( ); }; } else if ( !strnicmp ( pxDispatcherMessage->Domain, "AUDIO", 5 ) ) { ForwardAudioMessage ( pxDispatcherMessage->Command, pxDispatcherMessage->Parameter ); } else if ( !strnicmp ( pxDispatcherMessage->Domain, "LED", 3 ) ) { if ( !strnicmp ( pxDispatcherMessage->Command, "SET", 3 ) ) { LedSet ( pxDispatcherMessage->Parameter ); } else if ( !strnicmp ( pxDispatcherMessage->Command, "GET", 3 ) ) { LedGet ( pxDispatcherMessage->Parameter ); }; } else { }; }; }; };
int main(void) { tm gmt; WatchDogDisable(); NutDelay(100); SysInitIO(); SPIinit(); LedInit(); LcdLowLevelInit(); Uart0DriverInit(); Uart0DriverStart(); LogInit(); LogMsg_P(LOG_INFO, PSTR("-----------------------------------------------------------------------------------------------")); CardInit(); X12Init(); if (X12RtcGetClock(&gmt) == 0) { LogMsg_P(LOG_INFO, PSTR("RTC time [%02d:%02d:%02d]\n"), gmt.tm_hour, gmt.tm_min, gmt.tm_sec ); } if (At45dbInit() == AT45DB041B) { } RcInit(); KbInit(); SysControlMainBeat(ON); // enable 4.4 msecs hartbeat interrupt initMenu(); sei(); NutTimerInit(); NutThreadSetPriority(1); int keyvalue = KbGetKey(); int old; LcdBackLight(LCD_BACKLIGHT_ON); if(NutRegisterDevice(&DEV_ETHER, 0x8300, 5))printf("Error: No LAN device\n"); else printf("Lan device initialized\n"); for (;;) { keyvalue = KbGetKey(); if(old != keyvalue){ stateMenu(keyvalue); old = keyvalue; } NutSleep(100); WatchDogRestart(); } return(0); // never reached, but 'main()' returns a non-void, so..... }
/** * @brief Program entry point. * @param none * @retval 0 */ int main(void) { RCC_ClocksTypeDef RCC_Clocks; SystemInit(); // Get the clock rate so we can set the sampling rate correctly. RCC_GetClocksFreq(&RCC_Clocks); ClockRate = RCC_Clocks.HCLK_Frequency; // NOTE: STM generic // Our timer (TIM2) uses the APB1 (PCLK1) clock. TimerBaseClockRate = RCC_Clocks.PCLK1_Frequency; // Set the SysTick interrupt to fire once every millisecond. SysTick_Config(RCC_Clocks.SYSCLK_Frequency / 1000); LedInit(); // Turn the Orange LED on, signifying WAIT... LedSet(LED_ORANGE, LED_MODE_ON); UsartInit(); Copyright(); uint32_t commandTicks = Ticks; LedSet(LED_ORANGE, LED_MODE_OFF); // Loop forever... while (1) { if (SamplingActive) { LedSet(LED_RED, LED_MODE_OFF); // Turn the Blue LED on when sampling. LedSet(LED_BLUE, LED_MODE_ON); SampleLoop(); LedSet(LED_BLUE, LED_MODE_OFF); } // Check for commands every 1/10 second. if ((Ticks - commandTicks) >= 100) { ProcessCommands(); commandTicks = Ticks; } } return 0; }
uint32_t SystemInit(void) { uint32_t result; uint32_t unixTime; SetRebootFlag(); LedInit(); //DisplayStart(); RTC_WDT_Init(); InitNetwork(); GateInit(); InitBuff(); BattADC_Init(); /* Enable global interrupts */ CyGlobalIntEnable; /*sync real time*/ unixTime = DS1307_GetUnixTime(); // unixTime = 1485184625 ; if(unixTime > 0) { RTC_SetUnixTime(unixTime); result = DataBaseStart(); if(result == DB_NO_ERROR) { Display("System init..."); result = NO_ERROR; } else { Display("Please insert SD"); result = ERROR; SendFinStatus(FIN_NO_READY); MyDelay(300); } } else { Display("Error sync time"); result = ERROR; SendFinStatus(FIN_NO_READY); MyDelay(500); } return result; }
/******************************************** 飞控主函数入口 功能: 1.初始化各个硬件 2.初始化系统参数 3.开定时器4等待数据中断到来 4.开定时器3串口广播实时姿态以及相关信息 ********************************************/ int main(void) { SystemClock(9); //系统时钟初始化 UART1_init(SysClock,115200); //串口1初始化 NVIC_INIT(); //中断初始化 STMFLASH_Unlock(); //内部flash解锁 LedInit(); //IO初始化 delay_init(SysClock); //滴答延时初始化 BT_PowerInit(); //蓝牙电源初始化完成,默认关闭 MotorInit(); //马达初始化 BatteryCheckInit(); //电池电压监测初始化 IIC_Init(); //IIC初始化 MPU6050_DMP_Initialize(); //初始化DMP引擎 PID_INIT(); //PID参数初始化 ParameterRead(); //Flash参数读取 NRF24L01_INIT(); //NRF24L01初始化 SetRX_Mode(); //设无线模块为接收模式 PowerOn(); //开机等待 BT_on(); //蓝牙开 TIM3_Init(36,2000); //定时器3初始化,调试串口输出 TIM4_Init(36,1000); //定时器4初始化,定时采样传感器数据,更新PID输出 while (1) //等待数据更新中断到来 { // switch(UART1_Get_Char())//检测串口发送数据,做相应处理 // { // case 'w': // LedA_on;LedB_on;LedC_on;LedD_on; // //TxBuf[0]++; // //UART1_Put_Package(TxBuf); // LedA_on;LedB_on;LedC_on;LedD_on; // MotoPWM+=10; // UART1_Put_Char(0x5a); // break; // case 's': // LedA_off;LedB_off;LedC_off;LedD_off; // UART1_Put_Char(0xaa); // MotoPWM-=10; // break; // default :break; // } // MotorPwmFlash(MotoPWM,MotoPWM,MotoPWM,MotoPWM); // } }
void BoardInit() { MicrowireInit(); MW_LE_DDR |= (1 << MW_LE_LMX2531) | (1 << MW_LE_LMK0X0XX); MW_LE_PORT &= ~((1 << MW_LE_LMX2531) | (1 << MW_LE_LMK0X0XX)); LmxCeInit(); LmxCeClear(); LmkCeInit(); LmkSyncClear(); LmkGoeClear(); LedInit(); LedClear(); }
int main (int argc, char* argv[]) { (void) argc; (void) argv; Timebase.TB1Sec = 0; GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2); // Light sensor initialized. LightSensorInit(); // 7 Segment Init LedInit(); SystemTickInit(); // Enable interrupt IntMasterEnable(); //Write7SegRam(TestNum); while(1); }
/** Configures the board hardware and chip peripherals for the demo's functionality. */ void SetupHardware(void) { /* Disable watchdog if enabled by bootloader/fuses */ MCUSR &= ~(1 << WDRF); wdt_disable(); /* Disable clock division */ clock_prescale_set(clock_div_1); /* Configure all button pins to use internal pullup */ PORTD |= (1<<7) | (1<<4) | (1<<2) | (1<<0) | (1<<6) | (1<<1); PORTE |= (1<<2); PORTB |= (1<<0) | (1<<4) | (1<<5) | (1<<7); /* Subsystem Initialization */ EncoderInit(); DebounceInit(); LedInit(); USB_Init(); }
void BoardInit( void ) { uint8_t i; /* Setup SysTick Timer for 1 us interrupts ( not too often to save power ) */ if( SysTick_Config( SystemCoreClock / 1000 ) ) { /* Capture error */ while (1); } // Initialize SPI SpiInit( ); // Initialize LED for( i = 0; i < LED_NB; i++ ) { LedInit( ( tLed )i ); } LedOff( LED_RED ); LedOff( LED_GREEN ); }
/************************************************************************************//** ** \brief Initializes the microcontroller. ** \return none. ** ****************************************************************************************/ static void Init(void) { /* initialize the system and its clocks */ SystemInit(); /* handle chip errate workarounds */ CHIP_Init(); /* enable the low frequency crystal oscillator */ CMU_OscillatorEnable(cmuOsc_LFXO, true, true); /* turn on clocking of all the modules */ CMU->HFCORECLKEN0 |= 0x0F; CMU->HFPERCLKEN0 |= 0xFFFF; /* disable clocking of the modules that are not in use */ CMU_ClockEnable(cmuClock_AES, false); CMU_ClockEnable(cmuClock_DMA, false); CMU_ClockEnable(cmuClock_EBI, false); CMU_ClockEnable(cmuClock_PRS, false); CMU_ClockEnable(cmuClock_USART0, false); CMU_ClockEnable(cmuClock_USART1, false); CMU_ClockEnable(cmuClock_USART2, false); CMU_ClockEnable(cmuClock_UART0, false); CMU_ClockEnable(cmuClock_ACMP0, false); CMU_ClockEnable(cmuClock_ACMP1, false); CMU_ClockEnable(cmuClock_DAC0, false); CMU_ClockEnable(cmuClock_ADC0, false); CMU_ClockEnable(cmuClock_I2C0, false); CMU_ClockEnable(cmuClock_VCMP, false); #if (BOOT_COM_UART_ENABLE > 0) /* enable power to U2 (RS232_PWR_E) */ GPIO_PinModeSet(gpioPortB, 9, gpioModePushPullDrive, 1); /* set port B outputs to drive up to 20 mA */ GPIO_DriveModeSet(gpioPortB, gpioDriveModeHigh); #endif /* init the led driver */ LedInit(); /* init the timer driver */ TimerInit(); /* enable IRQ's, because they were initially disabled by the bootloader */ IrqInterruptEnable(); } /*** end of Init ***/
int main(void) { SystemClock_HSI(9); //系统时钟设置,9倍频,36M LedInit(); //LED 初始化 Adc_Init(); //摇杆AD初始化 NRF24L01_Init(); //无线模块初始化 TX_Mode(); //发送模式 TIM4_Init(); //定时器初始化,定时周期为1ms,1ms发送一次摇杆AD值 KeyInit(); //按键初始化 TxBuf[30]=0xA5; //对应遥控器,该位写0xA5,保证飞机能在开机的时候能收到一个完整的32字节的数据包 GetAD(R_Mode); /*******************************************************/ //以下为遥控解锁段 /*******************************************************/ while((Throttle>5)||(Roll>5))//解锁条件:油门拉到最低,方向打到最左解锁 { GetAD(R_Mode);//得到各路AD值并显示 } TxBuf[28]=0; //对应遥控器,该字节写0,使飞机跳过写参数那一步 TxBuf[27]=0xA5;//解锁飞机 TxBuf[31]=0xA5;//解锁成功,使能飞控 /*******************************************************/ //解锁完成 /*******************************************************/ Led1=1; Led2=1; Led3=1; Led4=1; Led5=0; while(1) { GetAD(R_Mode); //得到各路AD值并显示 if(Key1==0){TxBuf[10]=0xA5;Led1=1; }//按键子程序,用于设置一键操作,如一键翻滚,一键返航等 else {TxBuf[10]=0;Led1=0;} } }
void BoardInitPeriph( void ) { /*GpioInit( &Sel1, SEL_1, PIN_OUTPUT, PIN_OPEN_DRAIN, PIN_NO_PULL, 0 ); GpioInit( &Sel2, SEL_2, PIN_OUTPUT, PIN_OPEN_DRAIN, PIN_NO_PULL, 0 ); GpioInit( &Sel3, SEL_3, PIN_OUTPUT, PIN_OPEN_DRAIN, PIN_NO_PULL, 0 ); GpioInit( &Sel4, SEL_4, PIN_OUTPUT, PIN_OPEN_DRAIN, PIN_NO_PULL, 0 );*/ /*GpioInit( &Led1, LED_1, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 1 ); GpioInit( &Led2, LED_2, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 1 ); GpioInit( &Led3, LED_3, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 1 ); GpioInit( &Led4, LED_4, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 1 );*/ /*GpioInit( &Btn1, BTN_1, PIN_INPUT, PIN_PUSH_PULL, PIN_NO_PULL, 1 ); GpioInit( &Btn2, BTN_2, PIN_INPUT, PIN_PUSH_PULL, PIN_NO_PULL, 1 );*/ // Init temperature, pressure and altitude sensor //MPL3115Init( ); // Init Leds LedInit(); // Init Buttons ButtonInit(); }
int main ( void ) { printf("Game!\n"); // Init devices ButtonInit(); LedInit(); Screen screen = ScreenNew(320, 240); Canvas canvas = CanvasNew( &screen ); // Init game Controller ctrl = ControllerNew( &canvas ); onGameInit( &ctrl ); // Main loop static tick_delay = 0; while(ctrl.running) { if ( tick_delay++ == 20000 ) { tick_delay = 0; onTick( &ctrl ); } ButtonPoll(); } onGameExit( &ctrl ); ButtonDestroy(); LedDestroy(); ScreenDestroy( &screen ); return 0; }
int main(int argc, char* argv[]) { /* get option */ int opt= 0; char *token = NULL; char *guid = NULL; char *host = NULL; WORD port = 0; // specific the expected option static struct option long_options[] = { {"id", required_argument, 0, 'i' }, {"token", required_argument, 0, 't' }, {"host", required_argument, 0, 'H' }, {"port", required_argument, 0, 'p' }, {"help", no_argument, 0, 'h' } }; int long_index; /* Process option */ while ((opt = getopt_long(argc, argv,":hi:t:H:p:", long_options, &long_index )) != -1) { switch (opt) { case 'h' : printf("using: LedActor --<token> --<id> --<host> --port<>\n" "id: guid of the actor\n" "token: password of the actor\n" "host: mqtt server address, if omitted using local host\n" "port: mqtt port, if omitted using port 1883\n"); return (EXIT_SUCCESS); break; case 'i': guid = StrDup(optarg); break; case 't': token = StrDup(optarg); break; case 'H': host = StrDup(optarg); break; case 'p': port = atoi(optarg); break; case ':': if (optopt == 'i') { printf("invalid option(s), using --help for help\n"); return EXIT_FAILURE; } break; default: break; } } if (guid == NULL) { printf("invalid option(s), using --help for help\n"); return EXIT_FAILURE; } LedInit(); /* start actor process */ ACTOROPTION actorOpt; actorOpt.guid = guid; actorOpt.psw = token; actorOpt.port = port; actorOpt.host = host; LedActorStart(&actorOpt); LedDeinit(); return EXIT_SUCCESS; }
int main( void ) { SysInit(); LedInit(); BatteryInit(); ComInit(); TimerInit(); INTEN while(1) { if(TimerGetTimeFlag() > 10) { TimerClearTimeFlag(); BattertSleep(); } if(TimerGetBatteryFlag() > 0x01) { TimerClearBatteryFlag(); if(BatterGetFlag() == 0) { BatterSetFlag(1); BattertGet(); ComWatchSendCmd(dce_powe,BattertGetLevel(),0x00,0x00); } } LedTimeService(); if(ComWatchGetFlag() == 0x80) { ComWatchClearFlag(); TimerClearTimeFlag(); BattertOpen(); BatterSetFlag(0);//可以获取电量 if(ComWatchGetData(0) != 0x00) { BattertOpen(); } LedSetModeFlicker(1); if(BattertGetLevel() > 0) { switch(ComWatchGetData(0)) {//电量不足 case front: switch(ComWatchGetData(1)) { case add_stal:ComRearSendCmd(add_stal,0x00,0x00,0x00);break; case sub_stal:ComRearSendCmd(sub_stal,0x00,0x00,0x00);break; case add_setp:ComRearSendCmd(add_setp,0x00,0x00,0x00);break; case sub_setp:ComRearSendCmd(sub_setp,0x00,0x00,0x00);break; case set_inti:ComRearSendCmd(set_inti,0x00,0x00,0x00);break; } break; case behind: switch(ComWatchGetData(1)) { case exchange_stal: ComBehindSendCmd(exchange_stal,0x00,0x00,0x00);break; case add_setp:ComBehindSendCmd(add_setp,0x00,0x00,0x00);break; case sub_setp:ComBehindSendCmd(sub_setp,0x00,0x00,0x00);break; case set_inti:ComBehindSendCmd(set_inti,0x00,0x00,0x00);break; } break; default:break; } } else { } } if(ComRearGetFlag() == 0x80) { ComRearClearFlag(); switch(ComRearGetData(0)) { case dce_gear: ComBehindSendCmd(ask_rear,ComRearGetData(1),0x00,0x00); ComWatchSendCmd(behind,dce_gear,ComRearGetData(1),BattertGetLevel()); break; case stuck: ComWatchSendCmd(stuck,dce_gear,ComRearGetData(1),BattertGetLevel()); break; default:break; } } if(ComBehindGetFlag() == 0x80) { ComBehindClearFlag(); switch(ComBehindGetData(0)) { case dce_gear: ComWatchSendCmd(front,dce_gear,ComBehindGetData(1),BattertGetLevel()); break; case stuck: ComWatchSendCmd(stuck,dce_gear,ComBehindGetData(1),BattertGetLevel()); break; default:break; } } } }
int main(void) { //audioInit(); //setVolume(254); WatchDogDisable(); //disable watchdog NutDelay(100); //wait for it to disable SysInitIO(); //initialise input and output SPIinit(); //initialise SPI-registers (speed, mode) LedInit(); //initialise led initLCD(); //initialise lcd Uart0DriverInit(); //initialise Universal asynchronous receiver/transmitter Uart0DriverStart(); //start Uart printf("\n\n\n\nHardware initialization done\n\n"); LogInit(); //initialise ability to log CardInit(); //initialise cardreader printf("\n----------------------------------------------START OF PROGRAM------------------------------------------------------------\n"); if (NutSegBufInit(8192) == 0) { puts("NutSegBufInit: Fatal error"); } /* * Initialize the MP3 decoder hardware. */ if (VsPlayerInit() || VsPlayerReset(0)) { puts("VsPlayer: Fatal error"); } if(X12Init() == -1){ printf("error initializing RTC"); //initialise X12RTC } tm gmt; if (X12RtcGetClock(&gmt) == 0) { LogMsg_P(LOG_INFO, PSTR("local storage time [%02d:%02d:%02d] (in RTC)\n"), gmt.tm_hour, gmt.tm_min, gmt.tm_sec); } if (At45dbInit() == AT45DB041B) { // ...... } RcInit(); //Initialise the Remote Control module KbInit(); //Initialise keyboard initMenu(); //Initialise menu NutThreadCreate("Bh", ButtonHandlerThread, NULL, 512); //create thread to handle button presses printf("\nInitialization done.\n"); initAlarms(); SysControlMainBeat(ON); //enable 4.4 msecs heartbeat interrupt printf("Heartbeat on.\n"); NutThreadSetPriority(1); //Increase our priority so we can feed the watchdog. sei(); //enable global interrupts NutThreadCreate("Bg", TimeSyncThread, NULL, 512); NutThreadCreate("Bq", RefreshSceenThread, NULL, 512); NutThreadCreate("Bl", AlarmCheckerThread, NULL, 512); printf("\nEntering main loop.\n"); LcdBackLight(LCD_BACKLIGHT_ON); for(;;){ NutSleep(100); WatchDogRestart(); //restart watchdog } return(0); }
int main( void ) { SysInit(); EeepromInit(); TimerInit(); ComInit(); Ds1302Init(); HtlcdInit(); BottonInit(); LedInit(); MenuInit(); INTEN while(1) { u8 botton_bit = 0; if(TimerGetSec() > 20) { TimerSetSec(0); SysSleep(); } if(TimerGetTimeFlag() > 0x01) { TimerSetTimeFlag(0); MenuRefreshTime(); } MenuFlickerServerTime(); botton_bit = BottonRead(); if(botton_bit > 0x01) { TimerSetSec(0); SysOpen(); } switch(botton_bit) { case 0x01: MenuSetFeatures(7); break;//后减档 case 0x02: MenuSetFeatures(5); break;//后加档 case 0x03: MenuSetFeatures(4); break;//前换挡 case 0x11: MenuSetFeatures(1); break;//区域3 case 0x12: MenuSetFeatures(6);//1 break;//区域2 case 0x13: MenuSetFeatures(8); break;//区域1 case 0x14: MenuSetFeatures(2); break;//区域1 case 0x15: MenuSetFeatures(3); break;//放开信号 } if(ComGetFlag() == 0x80) { ComClearFlag(); LedSet(0); switch(ComGetData(0)) { case front: switch(ComGetData(1)) { case dce_gear: MenuSetStalls(front,ComGetData(2)+1); MenuSetBattery(ComGetData(3)); break; } break; case behind: switch(ComGetData(1)) { case dce_gear: MenuSetStalls(behind,ComGetData(2)); MenuSetBattery(ComGetData(3)); break; } break; case dce_powe: MenuSetBattery(ComGetData(1)); break; } } } }
/////////////////////////////////////////////////////////////////////////////// // Program Entry Point /////////////////////////////////////////////////////////////////////////////// void main(void) { //clear interrupts just in case DCC has messed with them HW_ICLENABLE0R.I = 0; HW_ICLENABLE1R.I = 0; HW_ICLSTEER0R.I = 0; HW_ICLSTEER1R.I = 0; HW_ICLSTEER2R.I = 0; #pragma asm include "regsicoll.inc" include "regscore.inc" include "systimers.inc" include "regstimer.inc" ;stmp6550 extern Const_ffffff move y:<Const_ffffff,x0 move x0,x:HW_ICLPRIOR0R move x0,x:HW_ICLPRIOR2R move x0,x:HW_ICLPRIOR3R move #>$1FFFFF,a0 ;set the priority for the MS Timer to highest move a0,x:HW_ICLPRIOR1R move #$003000,a0 ;setup the IPR register for interrupt enabling move a0,x:HW_IPR #pragma endasm //setup the vector table for Timer2 VECTOR(HW_IVECTIMER2,(int)SysTimeIsr); SysResetAllTimers(); SysTimeInit(); #pragma asm ; Set the SR bits move sr,x0 bclr #HW_SR_IM0_BITPOS,x0 bclr #HW_SR_IM1_BITPOS,x0 move x0,sr ;enable the timer2 interrupt bset #>15,X:HW_ICLENABLE0R #pragma endasm SysTime = 0; ShortestTime = -1; LedInit(); while(1){ //loop forever SysPostMessage(5,LED_CONTROL,0,LED_BLINK_ON_TIME,LED_BLINK_OFF_TIME); //blink all LEDs SysPostMessage(5,LED_CONTROL,1,LED_BLINK_ON_TIME,LED_BLINK_OFF_TIME); SysPostMessage(5,LED_CONTROL,2,LED_BLINK_ON_TIME,LED_BLINK_OFF_TIME); SysPostMessage(5,LED_CONTROL,3,LED_BLINK_ON_TIME,LED_BLINK_OFF_TIME); SysPostMessage(5,LED_CONTROL,4,LED_BLINK_ON_TIME,LED_BLINK_OFF_TIME); Wait(2000); SysPostMessage(6,LED_DLY_ON_CONTROL,0,LED_SEQ_ON_TIME,LED_SEQ_OFF_TIME,0); //Set the firing sequence SysPostMessage(6,LED_DLY_ON_CONTROL,1,LED_SEQ_ON_TIME,LED_SEQ_OFF_TIME,LED_DLY_TIME1); SysPostMessage(6,LED_DLY_ON_CONTROL,2,LED_SEQ_ON_TIME,LED_SEQ_OFF_TIME,LED_DLY_TIME2); SysPostMessage(6,LED_DLY_ON_CONTROL,3,LED_SEQ_ON_TIME,LED_SEQ_OFF_TIME,LED_DLY_TIME3); SysPostMessage(6,LED_DLY_ON_CONTROL,4,LED_SEQ_ON_TIME,LED_SEQ_OFF_TIME,LED_DLY_TIME4); Wait(6000); SysPostMessage(5,LED_CONTROL,0,LED_BLINK_ON_TIME,LED_BLINK_OFF_TIME); //blink all LEDs SysPostMessage(5,LED_CONTROL,1,LED_BLINK_ON_TIME,LED_BLINK_OFF_TIME); SysPostMessage(5,LED_CONTROL,2,LED_BLINK_ON_TIME,LED_BLINK_OFF_TIME); SysPostMessage(5,LED_CONTROL,3,LED_BLINK_ON_TIME,LED_BLINK_OFF_TIME); SysPostMessage(5,LED_CONTROL,4,LED_BLINK_ON_TIME,LED_BLINK_OFF_TIME); Wait(2000); SysPostMessage(6,LED_DLY_ON_CONTROL,4,LED_SEQ_ON_TIME,LED_SEQ_OFF_TIME,0); //Alternate the firing sequence SysPostMessage(6,LED_DLY_ON_CONTROL,3,LED_SEQ_ON_TIME,LED_SEQ_OFF_TIME,LED_DLY_TIME1); SysPostMessage(6,LED_DLY_ON_CONTROL,2,LED_SEQ_ON_TIME,LED_SEQ_OFF_TIME,LED_DLY_TIME2); SysPostMessage(6,LED_DLY_ON_CONTROL,1,LED_SEQ_ON_TIME,LED_SEQ_OFF_TIME,LED_DLY_TIME3); SysPostMessage(6,LED_DLY_ON_CONTROL,0,LED_SEQ_ON_TIME,LED_SEQ_OFF_TIME,LED_DLY_TIME4); Wait(6000); SysPostMessage(5,LED_CONTROL,0,LED_BLINK_ON_TIME,LED_BLINK_OFF_TIME); //blink all LEDs SysPostMessage(5,LED_CONTROL,1,LED_BLINK_ON_TIME,LED_BLINK_OFF_TIME); SysPostMessage(5,LED_CONTROL,2,LED_BLINK_ON_TIME,LED_BLINK_OFF_TIME); SysPostMessage(5,LED_CONTROL,3,LED_BLINK_ON_TIME,LED_BLINK_OFF_TIME); SysPostMessage(5,LED_CONTROL,4,LED_BLINK_ON_TIME,LED_BLINK_OFF_TIME); Wait(2000); SysPostMessage(6,LED_DLY_ON_CONTROL,4,LED_SEQ_ON_TIME,LED_SEQ_OFF_TIME,200); //exploding SysPostMessage(6,LED_DLY_ON_CONTROL,3,LED_SEQ_ON_TIME,LED_SEQ_OFF_TIME,100); SysPostMessage(6,LED_DLY_ON_CONTROL,2,LED_SEQ_ON_TIME,LED_SEQ_OFF_TIME,0); SysPostMessage(6,LED_DLY_ON_CONTROL,1,LED_SEQ_ON_TIME,LED_SEQ_OFF_TIME,100); SysPostMessage(6,LED_DLY_ON_CONTROL,0,LED_SEQ_ON_TIME,LED_SEQ_OFF_TIME,200); Wait(6000); SysPostMessage(5,LED_CONTROL,0,LED_BLINK_ON_TIME,LED_BLINK_OFF_TIME); //blink all LEDs SysPostMessage(5,LED_CONTROL,1,LED_BLINK_ON_TIME,LED_BLINK_OFF_TIME); SysPostMessage(5,LED_CONTROL,2,LED_BLINK_ON_TIME,LED_BLINK_OFF_TIME); SysPostMessage(5,LED_CONTROL,3,LED_BLINK_ON_TIME,LED_BLINK_OFF_TIME); SysPostMessage(5,LED_CONTROL,4,LED_BLINK_ON_TIME,LED_BLINK_OFF_TIME); Wait(2000); SysPostMessage(6,LED_DLY_ON_CONTROL,4,LED_SEQ_ON_TIME,LED_SEQ_OFF_TIME,0); //imploding SysPostMessage(6,LED_DLY_ON_CONTROL,3,LED_SEQ_ON_TIME,LED_SEQ_OFF_TIME,100); SysPostMessage(6,LED_DLY_ON_CONTROL,2,LED_SEQ_ON_TIME,LED_SEQ_OFF_TIME,200); SysPostMessage(6,LED_DLY_ON_CONTROL,1,LED_SEQ_ON_TIME,LED_SEQ_OFF_TIME,100); SysPostMessage(6,LED_DLY_ON_CONTROL,0,LED_SEQ_ON_TIME,LED_SEQ_OFF_TIME,0); Wait(6000); } }
int main(void) { WatchDogDisable(); NutDelay(100); SysInitIO(); SPIinit(); LedInit(); LcdLowLevelInit(); LcdBackLight(1); PrintStr("Starting System"); Uart0DriverInit(); Uart0DriverStart(); LogInit(); CardInit(); char custom[48] = ALL; LoadCustomChars(custom, 6); X12Init(); if (X12RtcGetClock(&gmt) == 0) { LogMsg_P(LOG_INFO, PSTR("RTC time [%02d:%02d:%02d]"), gmt.tm_hour, gmt.tm_min, gmt.tm_sec ); } if (At45dbInit()==AT45DB041B) { // ...... } RcInit(); KbInit(); SysControlMainBeat(ON); // enable 4.4 msecs hartbeat interrupt ClearLcdScreen(); //Nieuwe threads aanmaken NutThreadCreate("t01", Thread1, NULL, 512); NutThreadCreate("time", TimeUpdater, NULL, 512); //Start netwerk int i = initNetworkDHCP(); LogMsg_P(LOG_INFO, PSTR("Ethernet Startup Message: [%d]"),i); //Haal Internet tijd op pgmt = getNTPTime(); X12RtcSetClock(&pgmt); //LogMsg_P(LOG_INFO, PSTR("New RTC time [%02d:%02d:%02d]"), gmt.tm_hour, gmt.tm_min, gmt.tm_sec ); /* * Increase our priority so we can feed the watchdog. */ NutThreadSetPriority(1); /* Enable global interrupts */ sei(); /******************NETWERK**TEST*****************************************************/ //Maak nieuwe socket TCPSOCKET *sock; sock = NutTcpCreateSocket(); //Connect met google.nl LogMsg_P(LOG_INFO, PSTR("Connecting client")); clientConnect(sock); //Zend http req clientSend(sock,buffer,sizeof(buffer)); //Ontvang response in buffer --> grotere buffer (1500)= crash-->heapsize??(8k ram) char rcvbuffer [500]; int rec; rec = clientReceive(sock,rcvbuffer,sizeof(rcvbuffer)); LogMsg_P(LOG_INFO, PSTR("received [%d]"),rec); //0 terminate buffer(string) //rcvbuffer[499] = 0; //Print buffer(http response enz) LogMsg_P(LOG_INFO, PSTR("received [%s]"),rcvbuffer); //Sluit connectie clientClose(sock); /***********************************************************************************/ //Main gui besturing?? for (;;) { NutSleep(100); WatchDogRestart(); } return(0); }