int main(void) { //Initialize new interrupt fix SYSTEMConfigPerformance(40000000); #ifdef part1 initSW(); initLED(RUN_LED); initLED(STOP_LED); initTimer2(); enableInterrupts(); // initialize the lights state = runToggle; turnOffLED(STOP_LED); turnOnLED(RUN_LED); while(1){ switch(state){ // the state that toggles the LEDs case runToggle: // switch the led's toggleAllLEDs(); prevState = runToggle; state = waitForPress; //Go to debounce press state break; // wait for user input i.e. button press case waitForPress: while (state == waitForPress); break; // once the button has been pressed case dbPress: delayUs(DBdelayTime); // Delay for 5ms while(state == dbPress ); break; // once the button has been released case dbRelease: delayUs(DBdelayTime); //Delay for 5ms state = runToggle; break; } } #endif return 0; }
//Main function int main(void){ //State state = INITIAL; TaskBlock LED1_tb; initTaskBlock(&LED1_tb); initLED(LED1); initLED(LED2); initButton(); while(1){ yield_LED1(&LED1_tb); } }
void vLedTask (void *pvParameters) { uint8_t state=0; initLED(); while(1) { if (state == 0) { GPIO_ResetBits(GPIOC,GREEN); GPIO_SetBits(GPIOC,BLUE); state = 1; } else { GPIO_SetBits(GPIOC,GREEN); GPIO_ResetBits(GPIOC,BLUE); state = 0; } vTaskDelay(500 / portTICK_PERIOD_MS); } }
// You do not need to modify this function void initSystem() { sleep_status = 0; // Make it so that we don't start asleep initLED(); // Turn on our LED initButton(); // Turn on button interrupts sei(); // Nothing's gonna interrupt until we turn on global interrupts }
int main (void) { uint8_t no = 0; // wait(10); setMU2PutFunc(uart0Put); setMU2GetFunc(uart0Get); initUART( UART0, StopBitIs1Bit|NonParity, ReceiverEnable|TransmiterEnable|ReceiveCompleteInteruptEnable, UARTBAUD(19200) ); initLED(); initSwitch(); initRCRx(); no = Switch() & 0x03; mu2Command("EI",EI[no]); mu2Command("DI",DI[no]); mu2Command("GI",GI[no]); mu2Command("CH",CH[no]); sei(); userMain(); return 0; }
int main() { initLED(); while(1) //infinite loop { Blink(); } return 0; }
int main(void){ State state4 = INITIAL; initLED(); initButton(); while(1){ runningLight(&state4, ONE_HUNDRED_MILI_SEC); } }
void initALL() { int flag; /*initialize the clocks and basic peripherals*/ RCC_SYSCLKConfig(RCC_SYSCLKSource_HSE); //set the SYSCLOCK RCC_HCLKConfig(RCC_SYSCLK_Div1); //set the SYSCLOCK initUSART(USART1); //Initialize USART1 //initUSART(USART3); //Initialize USART3 ADC_Initialize(); //Initialize ADCs I2C_LowLevel_Init(I2C1, 100000, 0); //Initialize I2C1 bus @ 100Khz speed I2C_LowLevel_Init(I2C2, 100000, 0); //Initialize I2C1 bus @ 100Khz speed initLED(); //Initialize LEDs D3 D4 initGPIO(); //initialize PB2 and PB12 used as external GPIO //InitTimer(); //Initialize Timer /* Initialize and configure RF related functions */ initRFconfpin(); // Init the GPIO PB15 used as CONFIG PIN with the RADIOCRAFT module //Configure the RF BOARD to standard value (configfile.c): NETID 2.2.2.2 Channel 2 if (readintvalue(FLAG_EEPROM)!=0xf0f0f0f0){ //flag eeprom = f0f0f0f0 only when already initialized flag= ConfigureRF(); close_RFconfig(); if (flag==ERROR) printf("Configuration Failed"); else printf("Configuration RF ok"); } else close_RFconfig(); /* Initialize EEPROM VALUES*/ if (readintvalue(FLAG_EEPROM)!=0xf0f0f0f0){ //flag eeprom = f0f0f0f0 only when already initialized init_eeprom(); //Initialize eeprom Receivedpackage.bytes[0]='$'; Receivedpackage.bytes[1]='V'; Receivedpackage.bytes[2]='x'; Receivedpackage.bytes[3]='x'; } /*Initialize Sensors*/ init_acceler(); //initialize accelerometer /* Initialize interrupts sources*/ EnRtcInter(); //Initialize RTC Interrupt Source EnUsartInter(); //Enable the USART Interrupts //EnPVDInter(); //Enable the power PVD //EnExtInter(); //Initialize External Interrupt Source //EnTimInterr(); //Initialize Timer Interrupt Source }
void BAMClass::begin() { memset((void*)frames, 0, sizeof(frames)); initLED(); tickpos = 0; TCCR1A = 0; TCCR1B = 0; TCCR1B |= (1 << WGM12); // CTC TCCR1B |= (1 << CS12) | (1 << CS10); // 1024 prescaler TIMSK1 |= (1 << OCIE1A); // enable timer compare interrupt TCNT1 = 0; }
int main(void) { initLED(); initDOTS(); /* insert your hardware initialization here */ PORTD |= RESETPIN; for(;;){ for (uint8_t i=0; i<100; i++) { writeCol(i); } _delay_ms(1); for (uint8_t i=0; i<100; i++) { writeCol(0xFF-i); } _delay_ms(1); } return 0; /* never reached */ }
int main(void) { initLED(); initDOTS(); uart_init(UART_BAUD_SELECT(38400, F_CPU)); sei(); uart_flush(); _delay_ms(100); uint8_t i=0; char c; memset(to_write, 0x00, sizeof(to_write)); PORTD &=~RESETPIN; _delay_ms(1); PORTD |= RESETPIN; for (uint8_t i=0; i<200; i++) { writeCol(0xFF); } for (;;) { while(uart_available() == 0) { PORTB|=(1<<PB5); _delay_ms(100); PORTB&=~(1<<PB5); _delay_ms(100); } c = uart_getc(); char c_lo = c; uart_putc(c); if (c_lo >= 0x20) { to_write[i++] = c_lo; } if ((c_lo < 0x20) || (i >= 12)) { writeArray(to_write); i=0; } } return 0; /* never reached */ }
int main(void){ initSysTick(); initTcb(); //taskSwitch(); //testFunc(); TaskBlock tb_LED1; TaskBlock tb_LED2; TaskBlock tb_LED5; initLED(); initLED2(); initLED5(); initPushButton1(); initTaskBlock(&tb_LED1); initTaskBlock(&tb_LED2); initTaskBlock(&tb_LED5); while(1){ SD1(&tb_LED1); SD2(&tb_LED2); SD5(&tb_LED5); } }
int main(void) { int pwm; int adc_on; int adc_off; uint16_t i; element elem; robot.rotation_target = 0; robot.right_motor_pos =0; robot.left_motor_pos =0; robot.right_motor_target =0; robot.left_motor_target =0; SysTick_Config(168000000/8/1000000); // interrupr 1000000 per secound initTimer3(1); initMotors(); initEncoders(); initUsart3(); // enableUSART3RXNEInterrupt(); initADC(); initIRSensors(); initLED(); initSPI2(); LED_OFF; waitMs(1000); LED_ON; initPIDStructures(); stopMotors(); resetEncoders(); updateRobotState(); robot.left_ir_sensor_target = measures.left_ir_sensor; robot.right_ir_sensor_target = measures.right_ir_sensor; initQueue(&robot_queue); //addMove(&robot_queue,FORWARD,2000); addMove(&robot_queue,ROTATE,20000); // addMove(&robot_queue,FORWARD,9000); // addMove(&robot_queue,ROTATE,0); // addMove(&robot_queue,ROTATE,6000); // addMove(&robot_queue,FORWARD,9000); // addMove(&robot_queue,ROTATE,6000); // addMove(&robot_queue,ROTATE,12000); // addMove(&robot_queue,FORWARD,9000); // addMove(&robot_queue,ROTATE,12000); // addMove(&robot_queue,ROTATE,3000); // nextMove(); LED_ON; while(1) { if ( isBatteryWeak() ){ stopMotors(); blinkLed(); } if (flags.update_robot == 1){ moveRobot(); updateRobotState(); flags.update_robot =0; } if (flags.usart_custom == 1){ USART3_transmitString(itoa((int) robot.rotation, buf,10)); USART3_transmitString(" "); USART3_transmitString(itoa((int) robot.rotation_target, buf,10)); USART3_transmitString("\n"); } } // flags.usart_custom == 0; // USART3_transmitString("lewe_kolo_diff "); // USART3_transmitString(itoa((int) robot.left_motor_target - robot.left_motor_pos , buf,10)); // USART3_transmitByte('\n'); // USART3_transmitString("lewe kolo pwm "); // USART3_transmitString(itoa((int) getTranslation(LEFT_MOTOR) , buf,10)); // USART3_transmitByte('\n'); // // USART3_transmitString("prawe kolo diff "); // USART3_transmitString(itoa((int) robot.right_motor_target - robot.right_motor_pos , buf,10)); // USART3_transmitByte('\n'); // USART3_transmitString("prawe kolo pwm "); // USART3_transmitString(itoa((int) getTranslation(RIGHT_MOTOR) , buf,10)); // USART3_transmitByte('\n'); // } // // if (flags.usart_graph == 1){ // static uint8_t usart_start = 1; // if (usart_start ){ // usart_start=0; // USART3_transmitString("\n"); // USART3_transmitString("\n"); // USART3_transmitString("\n"); // USART3_transmitString("__start__\n"); // USART3_transmitString("lewe_kolo_pozycja "); // USART3_transmitString("lewe_kolo_cel "); // USART3_transmitString("lewe_kolo_diff "); // USART3_transmitString("lewe_kolo_pwm_T "); // USART3_transmitString("prawe_kolo_pozycja "); // USART3_transmitString("prawe_kolo_cel "); // USART3_transmitString("prawe_kolo_diff "); // USART3_transmitString("prawe_kolo_pwm_T \n"); // USART3_transmitString(" \n"); // } // // USART3_transmitString(itoa((int) robot.right_motor_pos , buf,10)); // USART3_transmitString(" "); // USART3_transmitString(itoa((int) robot.right_motor_target , buf,10)); // USART3_transmitString(" "); // USART3_transmitString(itoa((int) robot.right_motor_target - robot.right_motor_pos , buf,10)); // USART3_transmitString(" "); // USART3_transmitString(itoa((int) getTranslation(RIGHT_MOTOR) , buf,10)); // USART3_transmitString(" "); // USART3_transmitString(itoa((int) robot.left_motor_pos , buf,10)); // USART3_transmitString(" "); // USART3_transmitString(itoa((int) robot.left_motor_target , buf,10)); // USART3_transmitString(" "); // USART3_transmitString(itoa((int) robot.left_motor_target - robot.left_motor_pos , buf,10)); // USART3_transmitString(" "); // USART3_transmitString(itoa((int) getTranslation(LEFT_MOTOR) , buf,10)); // USART3_transmitByte('\n'); // flags.usart_graph = 0; // } // } // return 0; }
void main (void) { vuint32_t i = 0; initModesAndClock(); /* Initialize mode entries and system clock */ disableWatchdog(); /* Disable watchdog */ initPeriClkGen(); /* Initialize peripheral clock generation for DSPIs */ initADC(); initLED(); //can stuff initDSPI_1(); /* Initialize DSPI_1 as Slave SPI and init CTAR0 */ canSetup(); initEnergizeButton(); energizePacket.ID = ENERGIZE_ID; energizePacket.DATA.W[0] = 0xFFFFFFFF; energizePacket.DATA.W[1] = 0xFFFFFFFF; deenergizePacket.ID = DEENERGIZE_ID; deenergizePacket.DATA.W[0] = 0x00000000; deenergizePacket.DATA.W[1] = 0x00000000; torquePacket.ID = TORQUE_ID; speedPacket.ID = SPEED_ID; shutdownPacket.ID = SHUTDOWN_ID; shutdownPacket.DATA.W[0] = 0xDEADBEEF; shutdownPacket.DATA.W[1] = 0xDEADBEEF; /* Loop forever */ while (1) { prevEnergizeButton = energizeButton; getEnergizeButton(); switch (currentState) { case NOT_ENERGIZED: if (!energizeButton && prevEnergizeButton) { currentState = ENERGIZED; canSend(energizePacket); } break; case ENERGIZED: if (!energizeButton && prevEnergizeButton) { currentState = NOT_ENERGIZED; canSend(deenergizePacket); } else { getADC(); processAnalog(); if (imp_count < 2 || torque0 < 20) { convertSpeed(); convertTorque(); if (MODE == 0) { canSend(speedPacket); } else { canSend(torquePacket); } } else { currentState = SHUTDOWN; canSend(deenergizePacket); } } break; case SHUTDOWN: canSend(shutdownPacket); SHUTDOWN_CIRCUIT = TRUE; break; } toLED(currentState); //canReceive(); delay(); i++; } }
int main(void) { int i; unsigned char add[5]={110,110,8,110,110}; /*!< At this stage the microcontroller clock setting is already configured to 120 MHz, this is done through SystemInit() function which is called from startup file (startup_stm32f2xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f2xx.c file */ #ifdef SERIAL_DEBUG DebugComPort_Init(); #endif initLED(); init_Timer(); //while(1); /*Initialize LCD and Leds */ //LCD_LED_Init(); delay_ms(500); for(i=0;i<100;i++) { setNumber(i); delay_ms(10); } beep(40); offSegment(3); delay_ms(100); setNumber(0); delay_ms(100); beep(40); offSegment(3); delay_ms(100); setNumber(0); delay_ms(100); beep(40); //USART2_Init(); //USART3_Init(); init_NRF1_IO(); init_NRF2_IO(); SPI1_Config(); SPI3_Config(); SPI_Cmd(SPI1, ENABLE); SPI_Cmd(SPI3, ENABLE); nrf24l01_initialize_debug(false, TX_PAYLOAD_SIZE, false); nrf24l01_clear_flush(); add[2]=8; nrf24l01_set_tx_addr(add , 5); add[2]=30; nrf24l01_set_rx_addr(add,5,0); nrf24l01_set_rf_ch(tx_channel); nrf24l02_initialize_debug(false, RX_PAYLOAD_SIZE, false); nrf24l02_clear_flush(); add[2]=8; nrf24l02_set_tx_addr(add , 5); add[2]=30; nrf24l02_set_rx_addr(add,5,0); nrf24l02_set_rf_ch(rx_channel); nrf24l02_set_as_rx(true); /* configure ethernet */ ETH_BSP_Config(); /* Initilaize the LwIP stack */ LwIP_Init(); /* UDP echoserver */ udp_echoserver_init(); /* Infinite loop */ while (1) { /* check if any packet received */ if (ETH_CheckFrameReceived()) { /* process received ethernet packet */ LwIP_Pkt_Handle(); } /* handle periodic timers for LwIP */ LwIP_Periodic_Handle(LocalTime); process_incoming_rf(); if(firstPacketRecieved==0) { demo(); setNumber(22); } } }
int main(void) { //Set clock so it runs directly on the crystal ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); volatile unsigned long ulLoop; // Initialisation des ports ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH); //Enable les GPIO pour les timings des interrupts et autres GPIOPadConfigSet(GPIO_PORTA_BASE, GPIO_PIN_2, GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD_WPD); GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_2); //Mettre les interrupts du port E en haute prorités: évite collisions avec QEI logiciel IntPrioritySet(INT_GPIOE,0); //Activer les interruptions IntMasterEnable(); //Initialisation des variables globales ulLoop = 0; receive_buffer.read=0; receive_buffer.write=0; send_buffer.read=0; send_buffer.write=0; send_buffer2.read=0; send_buffer2.write=0; buffer_commande.read = 0; buffer_commande.write = 0; //QEI position=0; speed=0; state=0; state_m2=0; state_m3=0; position_m2=0; position_m3=0; //Asservissement previous_error0=0; previous_error1=0; previous_error2=0; previous_error3=0; I0=0; I1=0; I2=0; I3=0; consigne0=0; consigne1=0; consigne2=0; consigne3=0; //Pour les déplacements rapides @6400 Kd0 = 0.1; Ki0 = 7; Kp0 = 1.75; Kd1 = 0.1; Ki1 = 7; Kp1 = 1.75; Kd2 = 0.1; Ki2 = 7; Kp2 = 1.75; Kd3 = 0.1; Ki3 = 7; Kp3 = 1.75; Tf0 = 0.1; Tf1 = 0.1; Tf2 = 0.1; Tf3 = 0.1; //Pour les déplacements moyens @3200 Kd0_m = 0.05; Ki0_m = 10; Kp0_m = 1.6; Kd1_m = 0.05; Ki1_m = 10; Kp1_m = 1.5; Kd2_m = 0.05; Ki2_m = 10; Kp2_m = 1.5; Kd3_m = 0.05; Ki3_m = 10; Kp3_m = 1.6; //Pour les mouvements lents @1600 Kd0_s = 0.05; Ki0_s = 12; Kp0_s = 1.2; Kd1_s = 0.05; Ki1_s = 12; Kp1_s = 1.2; Kd2_s = 0.05; Ki2_s = 12; Kp2_s = 1.2; Kd3_s = 0.2; Ki3_s = 12; Kp3_s = 1.2; //Pour les mouvements de dessin @800 Kd0_d = 0.2; Ki0_d = 10; Kp0_d = 1.2; Kd1_d = 0.05; Ki1_d = 10; Kp1_d = 1.2; Kd2_d = 0.05; Ki2_d = 10; Kp2_d = 1.2; Kd3_d = 0.2; Ki3_d = 10; Kp3_d = 1.2; /*Kd0_s = 0.05; Ki0_s = 12;//5.64; Kp0_s = 1.2; Kd1_s = 0.05; Ki1_s = 12;//5.64; Kp1_s = 1.2; Kd2_s = 0.05; Ki2_s = 12;//5.64; Kp2_s = 1.2; Kd3_s = 0.05; Ki3_s = 12;//5.64; Kp3_s = 1.2;*/ dt = 0.1; tolerancePos = 0; posqei1 = 0; speedqei1=0; initCommande(); initMotorCommand(); initLED(); initPrehenseur(); initPWM(); initUART(); initQEI(); //init_lcd(); initTimer(); while(1) { EncoderHandler(); // Traitement des encodeurs en quadrature pour les moteurs 2 et 3 //si un charactère dans la Receive FIFO /*if(!(UART0_FR_R & UART_FR_RXFE)) //&& (send_buffer.read > send_buffer.write-256)) { receive_buffer.buffer[receive_buffer.write%BUFFER_LEN] = UART0_DR_R; receive_buffer.write++; }*/ /* if(!(UART0_FR_R & UART_FR_TXFF) && (send_buffer.read < send_buffer.write)) { UART0_DR_R = send_buffer.buffer[send_buffer.read%BUFFER_LEN]; send_buffer.read++; }*/ /*if(receive_buffer.write - receive_buffer.read > 7){ long i; short commande[8]; for(i=0; i < 8; i++){ commande[i] = receive_buffer.buffer[receive_buffer.read%BUFFER_LEN]; receive_buffer.read++; } traiterNouvelleCommande(commande); //Traitement des commandes } if(buffer_commande.write - buffer_commande.read >= 8){ CommandHandler(); }*/ } }
void pathManagerInit(void) { initTimer4(); initLED(0); //Communication with GPS initGPS(); initBatterySensor(); initAirspeedSensor(); initSPI(IC_DMA_PORT, DMA_CLOCK_KHZ, SPI_MODE1, SPI_BYTE, SPI_MASTER); initInterchip(DMA_CHIP_ID_PATH_MANAGER); //Communication with Altimeter if (initAltimeter()){ float initialValue = 0; while (initialValue == 0) initialValue = getAltitude(); calibrateAltimeter(initialValue); } //Initialize Home Location home.altitude = 400; home.latitude = RELATIVE_LATITUDE; home.longitude = RELATIVE_LONGITUDE; home.radius = 1; home.id = -1; //Initialize first path nodes // PathData* node = initializePathNode(); // node->altitude = 10; // node->latitude = 43.473662; // node->longitude = -80.540019; // node->radius = 5; // appendPathNode(node); // node = initializePathNode(); // node->altitude = 10; // node->latitude = 43.473479; // node->longitude = -80.540601; // node->radius = 5; // appendPathNode(node); // node = initializePathNode(); // node->altitude = 10; // node->latitude = 43.473718; // node->longitude = -80.540837; // node->radius = 5; // appendPathNode(node); // node = initializePathNode(); // node->altitude = 10; // node->latitude = 43.473946; // node->longitude = -80.540261; // node->radius = 5; // appendPathNode(node); // node = initializePathNode(); // node->altitude = 10; // node->latitude = 43.473685; // node->longitude = -80.540073; // node->radius = 5; // appendPathNode(node); #if DEBUG char str[20]; sprintf(str, "PM:%d, AM:%d", sizeof(PMData),sizeof(AMData)); debug(str); #endif }