int main(void) { _delay_ms(1000); char buf[10], a = 0; init_UART_MM(); send_MM_cmd("Hi\r", 0); init_SPI(); Current_state.gps.x = 1; Current_state.gps.y = 2; Current_state.gps.z = 3; while(1) { _delay_ms(2000); a++; sprintf(buf, "sent %d", a); send_MM_cmd(buf, 0); slave_send (HM_DATA, (char *)&Current_state, sizeof (struct state)); } return 0; }
int main() { init_timer(); init_serial(); init_SPI(); init_ATX_power(); sei(); enable_ATX_power(); delay_milliseconds(100); next_update_time = millisecond_time() + FRAME_MS; SPI_write_byte(0x00); while (true) { const uint8_t b1 = MAX_BRIGHTNESS / 4; const uint8_t b2 = MAX_BRIGHTNESS * 3 / 4; const uint8_t b3 = MAX_BRIGHTNESS; ramp(0, b1, set_LEDs_white); ramp(b1, 0, set_LEDs_white); ramp(0, b2, set_LEDs_CMY); ramp(b2, 0, set_LEDs_CMY); ramp(0, b3, set_LEDs_RGB); ramp(b3, 0, set_LEDs_RGB); } }
// main function void main(){ WDTCTL = WDTPW + WDTTMSEL+ WDTCNTCL + 0; // setup using the watchdog timer, using the 8MHz clock, 00 us /32768 BCSCTL1 = CALBC1_8MHZ; // 8Mhz calibration for clock DCOCTL = CALDCO_8MHZ; init_timer(); // initialize timer init_button(); // initialize the button // clear/initialize the global variables xaxis_calibrate=0; yaxis_calibrate=0; x_axis=0; y_axis=0; z_axis=1; count= 100; P1REN = BUTTON_BIT; P1DIR |= LED_center; //(BUTTON_BIT+LED_Xaxis+LED_Yaxis+LED_center); P1OUT &= ~LED_center; init_SPI(); init_accel(); IE1 |= WDTIE; //enable the WDT interrupt _bis_SR_register(GIE+LPM0_bits); // enable general interrupts and power down CPU }
void main(void) { int i; char status; char str[100]; init(); // initialize PIC init_soft_uart(); init_SPI(); GIE = 0; // disable all PIC's interrupts LATB2 = 0; // LED0 off for (i=0;i<100;i++) __delay_ms(10); uart_write_s("init ok !\n\r"); init_RC522(); while (1) { status = MFRC522_Request(PICC_REQIDL, str); // check if card is present if (status == MI_OK) { uart_write_s("ok card ! \n\r"); if (MFRC522_ReadCardSerial(str) == MI_OK) // get UID { uart_write_s("UID = "); // and display it uart_write_hex_c(*(str+0)); uart_write_hex_c(*(str+1)); uart_write_hex_c(*(str+2)); uart_write_hex_c(*(str+3)); uart_write_s("\n\r"); } LATB2 = 1; // blink LED0 for (i=0;i<10;i++) __delay_ms(10); // . LATB2 = 0; // . for (i=0;i<10;i++) __delay_ms(10); // . LATB2 = 1; // . for (i=0;i<10;i++) __delay_ms(10); // . LATB2 = 0; // . for (i=0;i<10;i++) __delay_ms(10); // . LATB2 = 1; // . for (i=0;i<10;i++) __delay_ms(10); // . LATB2 = 0; // . for (i=0;i<10;i++) __delay_ms(10); // . } //for (i=0;i<50;i++) __delay_ms(10); LATB2 = 1; // Blink LED0, visual normal operation works, before watchdog dev __delay_ms(10); LATB2 = 0; __delay_ms(10); } return; }
int main(void) { // ADC Configuration ADMUX = 0x00; // AREF, ADC0 ADCSRB = 0x00; // Free Running Mode ADCSRA |= (1<<ADEN)|(1<<ADIE); // Enable ADC, ADC interrupt ADCSRA |= (1<<ADPS2)|(0<<ADPS1)|(1<<ADPS0); // prescaler 32 DIDR0 |= (1<<ADC0D); // disable digital input // SPI and Display Configuration init_SPI(); send_cmd(SHUTDOWN_ADDR, SHUTDOWN_DISPLAY_ON); send_cmd(DECODE_MODE_ADDR, DECODE_MODE_NO_DECODE); send_cmd(INTENSITY_ADDR, INTENSITY_MAX); send_cmd(SCAN_LIMIT_ADDR, SCAN_LIMIT_MAX); blank_display(); // Test all pixels at startup send_cmd(DISPLAY_TEST_ADDR, DISPLAY_TEST_ON); _delay_ms(500); send_cmd(DISPLAY_TEST_ADDR, DISPLAY_TEST_OFF); _delay_ms(500); sample = 0; sei(); ADCSRA |= (1<<ADSC); // Start ADC while(1); }
int main(void) { uint8_t pressed=0,new_button_state,last_button_state; init_SPI(); init_LED(); init_PB(); #ifdef MASTER STM_EVAL_LEDOn(LED5); xTaskCreate(pb_task, (signed portCHAR *) "Push Button Task", 512 /* stack size */, NULL, tskIDLE_PRIORITY + 2, NULL); #else xTaskCreate(spi_recv_msg_task, (signed portCHAR *) "SPI Recv Task", 512 /* stack size */, NULL, tskIDLE_PRIORITY + 2, NULL); #endif /* Start running the tasks. */ vTaskStartScheduler(); STM_EVAL_LEDOff(LED5); return 0; }
void soc_family_init(void) { init_sysclk(); init_exception_prio(); /* Enable peripheral clocks. */ init_peripheral_clocks(); /* Set up IO pin direction and mode registers. */ init_io(); #ifdef SYSTEM_SOC_CORTEXM3_STM32_GPIO_USED /* Set up GPIO. */ init_GPIO(); #endif #ifdef SYSTEM_SOC_CORTEXM3_STM32_USART_USED /* Set up USART. */ init_USART(); #endif #ifdef SYSTEM_SOC_CORTEXM3_STM32_SPI_USED /* Set up SPI. */ init_SPI(); #endif }
/*---------------------------------------------------------------------------*/ void init(void) { init_PORT(); init_TRIS(); init_ANSEL(); init_UART(); init_SPI(); init_TMR(); init_OSC(); }
// main.c int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer uint8_t eg_Counter = 0; uint8_t eg_Counter2; uint8_t read[1]; // Hub's copy array initialize_Ports(); // Init all non used ports initialize_Clocks(); // Sets up timers (takes care of FRAM issue) uint8_t pin_Setting = 2; // selects the pins used for 6989 uint8_t device_CS = 1; // selects the SYNC/SS pin (5k POT) init_SPI (2, 1); // 2 is slave (changed in header and course file) // clk_Rate -> 8 = 8MHz, 4 = 4MHz, 2 = 2.67MHz, 1 = 1MHz (currently only at 1MHz) //P1.4 - CLK, P1.6 - SIMO, P1.7 - SOMI, 4.1 - GPIO // flash_LED_2(1,10); // make hub wait // P4OUT |= BIT1; // UCB0TXBUF = 0x50; ////////////////////////// Hub //////////////////////////////////////// // for (eg_Counter = 0; eg_Counter < 10; ++eg_Counter) { //loop 10 times // read_SPI (); // device 0 is Hub // read[0] = g_RXData; // saves values read in array // } for (i = 0; i < 10; ++i) { write_uint8_SPI (array[i], device_CS); if (UCB0RXBUF != 0xAA) { write_uint8_SPI (array[i], device_CS); } //++j; } write_uint8_SPI (0xFF, device_CS); /* while (read[0] = 0x00) { read_SPI (); // device 0 is Hub read[1] = g_RXData; ++error_Counter; } if (read[0] == 0x40) { //changed reading to 16 bytes in the SPI_Polling .h .c write_uint8_SPI (0x50, device_CS); // write_uint16_SPI (0xBB, device_CS); // write_uint16_SPI (0xCC, device_CS); LED_1_On(); }else { write_uint8_SPI (0xF0, device_CS); LED_2_On(); } /* for (eg_Counter2 = 0; eg_Counter2 < 10; ++eg_Counter2) { //loop 10 times write_uint16_SPI (read[eg_Counter2], device_CS); // device 0 is Hub } */ while (1) {} }
void LSM_initSPI() { /* Initialize SPI */ init_SPI(); /* CS HIGH */ LSM_CSG_HIGH; LSM_CSXM_HIGH; }
void init(void) { //init_RCC(); /* RCC_Configuration */ RCC_Configuration(); init_GPIO(); init_SPI(); NVIC_Configuration(); USART_Configuration(); init_printf(0,putc); }
int main(void) { unsigned char i, chksum; ioinit(); init_SPI(); sbi(CSPORT,CS); printf("********RFM22 Communication Test********\n"); //====================// //Communications Test printf("Reading DTYPE register, should be 0x08: %d", read(DTYPE)); printf("\n*****************************************\n\n"); init_RFM22(); // Initialize all RFM22 registers printf("Entering RX Mode...\n"); to_rx_mode(); while(1) { if((PIND & (1<<NIRQ)) == 0) //Interrupt will be generated if data is recieved { // Read 18-byte packet into RF_RXBUF[]: for(i=0; i<17; i++) { RF_RXBUF[i] = read(0x7F); } // Check that the checksum matches up: chksum = 0; for(i=0; i<16; i++) chksum += RF_RXBUF[i]; // If checksum is good, print out what was received into the terminal if(chksum == RF_RXBUF[16]) { write(0x07, 0x01); // To ready mode printf("Received: "); for(i=0; i<17; i++) printf("%c", RF_RXBUF[i]); // Print characters if passed the checksum printf("\n"); //printf("To Ready mode\n"); } // otherwise reset and start listening again else { rx_reset(); //printf("Bad checksum RX RESET...Listening again\n"); } delay_ms(50); } } }
bool BoardSupportPackage::init() { bool result = false; SysTick_Config(SystemCoreClock/BSP_TICKS_PER_SECOND); initRCC(); initGPIO_Power(); initGPIO_Fan(); init_DHT11(); init_SPI(); init_TIM(); init_PWM(); screenInit(); result = true; return result; }
int main() { init_timer(); init_SPI(); init_ATX_power(); sei(); enable_ATX_power(); repeat_LEDs_off(); uint32_t d = ROTATION_SECONDS * 1000L / (6 * 127); wait_for_it(d); #if 0 while (true) { for (uint8_t i = 0; i < 6; i++) { for (uint8_t j = 0; j < 127; j++) { wait_for_it(0); uint8_t r, g, b; calc_color(i, j, &r, &g, &b); set_LEDs_color(r, g, b); } } } #else while (true) { for (uint8_t i = 0; i < 6; i++) { for (uint8_t j = 0; j < 127; j++) { wait_for_it(0); begin_LEDs_refresh(); for (uint8_t p = 0; p < PIXEL_COUNT; p++) { uint8_t r=0, g=0, b=0; uint8_t ii = i, jj = j + 4 * p; if (jj >= 127) { jj -= 127; if (++ii == 6) ii = 0; } calc_color(ii, jj, &r, &g, &b); set_pixel_color(r, g, b); } end_LEDs_refresh(); } } } #endif }
int main(void) { //init_USART(); init_SPI(); init_ster(); lcd_init(); LCD_DISPLAY(LCDDISPLAY); lcd_puts("KAROL"); if(GetRegister(STATUS) == 0x0E) { LED_ON; _delay_ms(1000); LED_OFF; _delay_ms(1000); } LCD_CLEAR; NRF24L01_init(); while(1) { reset(); receive_payload(); if(((GetRegister(STATUS) & (1<<RX_DR)) != 0)) { LED_ON; _delay_ms(10); //LCD_CLEAR; receive_buffer=WriteReadToNrf(R,R_RX_PAYLOAD,receive_buffer,5); X_acc=receive_buffer[0]; Y_acc=receive_buffer[1]; Z_acc=receive_buffer[2]; ster(X_acc,Y_acc); LCD_LOCATE(0,0); sprintf(Text_buff,"%3d",X_acc); lcd_puts(Text_buff); LCD_LOCATE(0,1); sprintf(Text_buff,"%3d",Y_acc); lcd_puts(Text_buff); LED_OFF; } } }
int main(void) { uint8_t dest[] = {0x02,0x17,0x31,0x88,0xAF,0x4B}; uint8_t data[100];// = {0x11,0x23,0x58}; uint8_t buffer[100]; uint8_t sendData[100]; uint8_t packetId=0; uint8_t packetSize; uint16_t nextPacket; uint16_t j; //initialize DDRA = 0xFF; //set PORTA to output wdt_disable(); //disable watchdog init_SPI(); //init SPI src_ENC(); //init ENC init_ENC(); rxen_ENC(); //start reading packets //read packets while(1); }
static void system_init(void) { _asm sei; #ifdef FLASH ///// pll_init(); // solo para flash (ver config.h) #endif QueueInit(); Sci_Init(); PORTA = 0x00; DDRA = 0xFF; init_SPI(); atd_init(); rti_start(); speed=DEFAULT_SPEED; // message shift speed Led_intensity=DEFAULT_INTENSITY; // rti_init(); _asm cli; }
int main() { init_timer(); init_SPI(); init_ATX_power(); sei(); enable_ATX_power(); repeat_LEDs_off(); uint16_t refresh_ms = STRIPE_MS / PIXEL_COUNT; while (true) { for (uint8_t i = 0; i < PIXEL_COUNT; i++) { uint8_t j = abs(PIXEL_COUNT / 2 - i); uint8_t k = PIXEL_COUNT - j - 1; uint8_t j1 = (2 * j + PIXEL_COUNT) / 4; uint8_t k1 = (2 * k + PIXEL_COUNT) / 4; begin_LEDs_refresh(); for (uint8_t p = 0; p < PIXEL_COUNT; p++) { uint8_t r = 127, g = 127, b = 127; r = g = b = 63; if ((j <= p && p < j1) || (k1 <= p && p < k)) { r = 127; g = 63; b = 0; } set_pixel_color(r, g, b); } end_LEDs_refresh(); wait_for(refresh_ms); } set_LEDs_level(63); wait_for(IDLE_MS); } }
int main(void) { WDTCTL = WDTPW | WDTHOLD; // 关闭看门狗 __enable_interrupt(); //使能全局中断 init_key(); //初始化按键的管脚设置 init_LCD_hardware(); //初始化LCD液晶显示屏的管脚设置 SetVCore(3); //设VCore为最大,提高Vcore电压到最高级,以满足倍频需求该函数位于HAL_PMM.H中 initClocks(20000000); //初始化时钟20MHz init_SPI(); //初始化SPI ILI9325_CMO24_Initial(); SPILCD_SetWindow(0,480-1,0,320-1); SPILCD_Clear(WHITE); P6DIR |= BIT3+BIT4; Show_splash(); int ai; for(ai=0;ai<200;ai++) { myDelay(); } SPILCD_Clear(WHITE); Show_MenuTheme(); Show_MenuMode(1); Show_Select(); Init_UART2(); UCA0IE |= UCRXIE; int as1=1; buttonsPressed=0; USB_setup(TRUE,TRUE); while (!buttonsPressed) { buttonsPressed = 0; for(ai=0;ai<30;ai++) { myDelay(); } if (buttonsPressed & BUTTON_S3) { Show_ButtonS3(); if(as1==4){ as1=1; Show_MenuMode(as1); }else{ if(as1==1){ as1=2; Show_MenuMode(as1); }else{ if(as1==2){ as1=3; Show_MenuMode(as1); }else{ if(as1==3){ as1=4; Show_MenuMode(as1); } } } } buttonsPressed=0; Show_Select(); } if (buttonsPressed & BUTTON_S2) { Show_ButtonS2(); if(as1==2){ as1=1; Show_MenuMode(as1); }else{ if(as1==3){ as1=2; Show_MenuMode(as1); }else{ if(as1==4){ as1=3; Show_MenuMode(as1); }else{ if(as1==1){ as1=4; Show_MenuMode(as1); } } } } buttonsPressed=0; Show_Select(); } if (buttonsPressed & BUTTON_S1) { Init_UART2(); Show_ButtonS1(); if(as1==1){ menu_select=1; } if(as1==2){ menu_select=2; } if(as1==3){ menu_select=3; } if(as1==4){ menu_select=4; } chanle_menu(); as1=1; buttonsPressed=0; SPILCD_Clear(WHITE); Show_MenuTheme(); Show_MenuMode(1); Show_Select(); } if (buttonsPressed & BUTTON_S4){ Show_ButtonS4(); Show_MenuMode(as1); buttonsPressed=0; Show_Select(); } } }
int main(void) { // Locals General. ----------------------------------------------------- char imu_board_id[9] = {0,0,0,0, 0,0,0,0, 0}; char message[1024]; // Any message to send by UART1 InitOscillator(); // Initialize the PLL (also disables wdt) __delay32(_50MILLISEC); // Init mcu ports ------------------------------------------------------ init_port(); // Initialize ports LED_ORNG =0; LED_RED = 1; // Init UARTS. --------------------------------------------------------- init_UART1(); // Initialize the serial communication (TTL / RS-232) init_UART2(); broadcast_message("RC Testing program\n"); // Init Analog Channels. ----------------------------------------------- analog_initAnalog(); // Init the ADC module // Init SPI. --------------------------------------------------------- init_SPI(); // Init I2C. --------------------------------------------------------- e_i2cp_init(); e_i2cp_enable(); __delay32(_50MILLISEC); e_i2c_write(0x00); // dummy byte to get the START bit on the bus (believe it or not!) // Init RC. ---------------------------------------------------------- initControlVariables(NULL); broadcast_message("Initialising RC\n"); LED_ORNG =1; LED_RED = 1; BuzzerBip(1,1); // Make x bips of the Buzzer (blocking) RCInitReception(); // RCSetType(RC_WK2401); RCSetType(RC_WK2402); broadcast_message("Initialising IMU\n"); // Init BUZZER. ---------------------------------------------------------- __delay32(_200MILLISEC); // Wait for the IMU to boot while (INT_IMU==0) // Wait for the IMU to boot { FlashORNG (); // Flash the LED } read_imu_version(imu_board_id); imu_board_id[8] = 0; broadcast_message("Entering main loop\n"); // Init BUZZER. ---------------------------------------------------------- BuzzerBip(3,1); // Make x bips of the Buzzer, blocking InitLoopTimer(control.params.T_ctrl_ms);// Initialize & Enable control loop timer (20ms; 50Hz) LED_RED = 0; while (1) { __delay32(5*_10MILLISEC); sprintf(message, "RC %+.2f %+.2f %+.2f %.2f %.2f %+.2f %+.2f %+.2f %s CTRL %02X %s %s\n", RC_THROTTLE, RC_YAW, RC_ROLL, RC_PITCH, RC_THROTTLE_TRIM, RC_YAW_TRIM, RC_ROLL_TRIM, RC_PITCH_TRIM, string_of_rc_state(RCSMGetState()), control.flags.CONTROL_MODE, string_of_control_mode(control.flags.CONTROL_MODE), string_of_control_type(control.flags.CONTROL_MODE)); broadcast_message(message); } return 0; } // End of main
int main(void){ //while(1); wdt_disable(); ///Configure the Torquer configure_torquer(); char buf[100]; uint16_t v; int ao; for(ao=0;ao<1;ao++) _delay_ms(1000); /// Initialise Interfaces - UART of Magnetometer and GPS and the SPI bus init_UART_MM(); init_UART_GPS(); init_SPI(); init_TWI(); send_preflight("Master\r", 7); ///Set Preflight pin as input cbi(DDR_PF, PIN_PF); ///* Switch on Global interrupts sei(); ///Check if Preflight Pin is high while(1){ ///* * Reset timer for 2 seconds timer_reset_two_sec(); //get_HM_data(); //send_preflight("Power\r", 6); ///* Preflight Checks if(0){ ///* * Set the mode as preflight Mode = PREFLIGHT; /*slave_send(HM_DATA, "Hello", 5); _delay_ms(10); slave_send (BEGIN_TX_GS, NULL, 0); //power_up_peripheral(PCC); _delay_ms(10); ao = init_CC1020(); if(ao) send_preflight("CC Init\r", 8); else send_preflight("No Init\r", 8); while(1);*/ /*power_up_peripheral(PGPS); while(1) { read_GPS(); while(UCSR0B & _BV(RXCIE0)); copy_gps_reading(); sprintf(buf,"%ld %ld %ld\r", Current_state.gps.x/1000, Current_state.gps.y/1000, Current_state.gps.z/1000); send_preflight(buf, strlen(buf)); sprintf(buf,"%ld %ld %ld\r", Current_state.gps.v_x/1000, Current_state.gps.v_y/1000, Current_state.gps.v_z/1000); send_preflight(buf, strlen(buf)); _delay_ms(1000); }*/ ///* * Magnetometer and Torquer test ///* * Reading with one torquer on at once /*Current_state.pwm.x_dir = 0; Current_state.pwm.x = 10000; Current_state.pwm.y_dir = 0; Current_state.pwm.y = 30000; Current_state.pwm.z_dir = 1; Current_state.pwm.z = 20000; send_preflight("Read\r", 5); set_PWM();*/ while(1) { read_SS(); //send_preflight((char *)&Current_state.ss, sizeof(struct SS_reading)); for(v = 0; v < 6; v++) { sprintf(buf,"%u\r", (uint16_t)(((float)Current_state.ss.reading[v])*1.6*100/4096)); send_preflight(buf, strlen(buf)); sprintf(buf,"%x\r", Current_state.ss.reading[v]); send_preflight(buf, strlen(buf)); } _delay_ms(1000); } ///* * Set Torquer values to zero reset_PWM(); while(1) read_MM(); read_GPS(); send_preflight((char *)&Current_state.gps, sizeof(struct GPS_reading)); ///* * Sunsensor test read_SS(); send_preflight((char *)&Current_state.ss, sizeof(struct SS_reading)); ///* Health Montoring get_HM_data(); send_preflight((char *)&Current_state.hm, sizeof(struct HM_data)); ///Communication Task comm(); ///* * Wait for 2 seconds to get over timer_wait_reset(); } ///Normal Mode else{ ///* Set default mode of Satellite Mode = DETUMBLING; ///* initialise Timer Time = 0; ///Loop begins while(1){ //Fuses Pain, Nominal Mode checking send_preflight("Loop\r", 5); control(); send_preflight("Control\r", 8); //power(); comm(); send_preflight("Comm\r", 5); v = StackCount(); sprintf(buf, "Stack = %d\r", v); send_preflight(buf, strlen(buf)); v = get_free_memory(); sprintf(buf, "Stack(Method 2) = %d\r", v); send_preflight(buf, strlen(buf)); Time += FRAME_TIME; timer_wait_reset(); } } } return 0; }
int main(void){ ///Configure the Torquer configure_torquer(); _delay_ms(1000); /// Initialise Interfaces - UART of Magnetometer and GPS and the SPI bus init_UART_MM(); init_UART_GPS(); init_SPI(); init_TWI(); ///Set Preflight pin as input cbi(DDR_PF, PIN_PF); ///* Switch on Global interrupts sei(); ///Check if Preflight Pin is high while(1){ ///* * Reset timer for 2 seconds timer_reset_two_sec(); ///* Get Health Monitoring data get_HM_data(); ///* Preflight Checks if(PORT_PF & _BV(PIN_PF)){ ///* * Set the mode as preflight Mode = PREFLIGHT; send_preflight("Master\r", 7); ///* * GPS test read_GPS(); while(UCSR0B & _BV(RXCIE0)); send_preflight((char *)&Current_state.gps, sizeof(struct GPS_reading)); ///* * Magnetometer and Torquer test ///* * Reading with no torquers on read_MM (); send_preflight((char *)&Current_state.mm, sizeof(struct MM_reading)); ///* * Reading with one torquer on at once Current_state.pwm.x_dir = 0; Current_state.pwm.x = 32768; Current_state.pwm.y_dir = 0; Current_state.pwm.y = 0; Current_state.pwm.z_dir = 0; Current_state.pwm.z = 0; set_PWM (); read_MM (); send_preflight((char *)&Current_state.mm, sizeof(struct MM_reading)); Current_state.pwm.x_dir = 0; Current_state.pwm.x = 0; Current_state.pwm.y_dir = 0; Current_state.pwm.y = 32768; Current_state.pwm.z_dir = 0; Current_state.pwm.z = 0; set_PWM (); read_MM (); send_preflight((char *)&Current_state.mm, sizeof(struct MM_reading)); Current_state.pwm.x_dir = 0; Current_state.pwm.x = 0; Current_state.pwm.y_dir = 0; Current_state.pwm.y = 0; Current_state.pwm.z_dir = 0; Current_state.pwm.z = 32768; set_PWM (); read_MM (); send_preflight((char *)&Current_state.mm, sizeof(struct MM_reading)); ///* * Reading with one torquer on at once, in other direction Current_state.pwm.x_dir = 1; Current_state.pwm.x = 32768; Current_state.pwm.y_dir = 0; Current_state.pwm.y = 0; Current_state.pwm.z_dir = 0; Current_state.pwm.z = 0; set_PWM (); read_MM (); send_preflight((char *)&Current_state.mm, sizeof(struct MM_reading)); Current_state.pwm.x_dir = 0; Current_state.pwm.x = 0; Current_state.pwm.y_dir = 1; Current_state.pwm.y = 32768; Current_state.pwm.z_dir = 0; Current_state.pwm.z = 0; set_PWM (); read_MM (); send_preflight((char *)&Current_state.mm, sizeof(struct MM_reading)); Current_state.pwm.x_dir = 0; Current_state.pwm.x = 0; Current_state.pwm.y_dir = 0; Current_state.pwm.y = 0; Current_state.pwm.z_dir = 1; Current_state.pwm.z = 32768; set_PWM (); read_MM (); send_preflight((char *)&Current_state.mm, sizeof(struct MM_reading)); ///* * Set Torquer values to zero reset_PWM(); ///* * Sunsensor test read_SS(); send_preflight((char *)&Current_state.ss, sizeof(struct SS_reading)); ///* Health Montoring get_HM_data(); send_preflight((char *)&Current_state.hm, sizeof(struct HM_data)); ///Communication Task comm(); ///* * Wait for 2 seconds to get over timer_wait_reset(); } ///Normal Mode else{ ///* Set default mode of Satellite Mode = DETUMBLING; ///* initialise Timer Time = 0; ///Loop begins while(!(PORT_PF & _BV(PIN_PF))){ /** * * * * Task 2: Control codes * @ref control */ control(); /** * * * * Task 1: Communication with power uC through I2C. @ref power */ power(); /** * * * * Task 3: Communication check routine; * @ref comm */ comm(); wdt_disable(); ///* * Increment the Timer Time += FRAME_TIME; ///* * Wait for 2 seconds to get over timer_wait_reset(); } } } return 0; }
int main(void) { // b. Umleiten der Standardausgabe stdout (Teil 2) //stdout = &mystdout; // Init everything // Init Touch & Potis DDRA = 0x00; // ADWandler-Pins auf Eingang schalten uint16_t ADC_val; ADC_Init(); // Init LED Matrix TLC5940_Init(); // Init SPI init_SPI(); // Init Timer timer_config(); TLC5940_SetAllDC(63); TLC5940_ClockInDC(); TLC5940_SetAllGS(0); // Init all 74hc595 init_74hc595(); // Init all 74hc165 init_74hc165(); // Enable Interrupts globally // TEMP TEMP TEMP DDRC |= 0b01000000; // Kalibriere Touchpanel calibrate(); sei(); // Init UART uart_init(); while (1) { static uint8_t current_potentiometer = 0; // POTENTIOMETER auslesen { /* switch( current_potentiometer ) { // case 1: // PORTC &= ~0b01000000; // break; case 2: PORTC |= 0b01000000; break; } */ // erstes Auslesen immer Fehlerhaft wegen Touchpanel evtl // zweiter Wert beinhaltet richtiges Ergebniss! // POTI_ADC_SAMPLES sollte daher 2 sein damit nach dem zweiten lesen in ADC_val das richtige ergebniss steht ADC_val = 0; for ( uint8_t count = 0 ; count < POTI_ADC_SAMPLES ; count++ ) ADC_val = ADC_Read(potentiometer[current_potentiometer].adc_channel); if( ADC_val > ( potentiometer[current_potentiometer].value + ADC_delta_for_change_poti ) || ( ADC_val < ( potentiometer[current_potentiometer].value - ADC_delta_for_change_poti ) ) ) // +- 8 von 1024 Quantisierungsstufen / 128 Midi Schritte . // if( ADC_val > ( potentiometer[current_potentiometer].value + 10 ) || ( ADC_val < ( potentiometer[current_potentiometer].value - 10 ) ) ) { potentiometer[current_potentiometer].value = ADC_val; controlChange(midi_channel, midi_poti_offset + current_potentiometer,ADC_val/8); //printf("%i. Poti %i\n", current_potentiometer , potentiometer[current_potentiometer].value ); } current_potentiometer++; if ( current_potentiometer == potentiometer_count) current_potentiometer = 0; } //Display_SetCross(4,2); // TOUCHPANEL auslesen read_touchscreen(); if(touchscreen.FLAG_Display_change) { TLC5940_SetAllGS(0); //Display_SetParabel(touchscreen.last_x , touchscreen.last_y ); Display_SetCross(touchscreen.last_LED_x,touchscreen.last_LED_y); touchscreen.FLAG_Display_change = 0; } } }
int main(void) { /* Initialize Interfaces */ if(PINB & (1<<SEL2)){ //SEL2 not installed, modeA init_StepDir(); //init_pwm(); } else { //SEL2 installed, modeB init_SPI(); init_UART(12,1); //For 1MHz testing, change to 14.7456Mhz init_I2C(); } //init_I2C(); //init_SPI(); //init_UART(95,0); /* Run UART at 9600 baud */ //init_StepDir(); init_stepper(); init_chopper(); sei(); int8_t motor_state = 0; motor_enable = WAVE; while(1) { if(motor_enable == FULL){ if(desired_step_cnt < 0){ //backwards if(motor_state == 0) normstep4(); if(motor_state == 2) normstep1(); if(motor_state == 4) normstep2(); if(motor_state == 6) normstep3(); motor_state -= 2; if(motor_state < 0) motor_state = 6; desired_step_cnt++; } else if(desired_step_cnt > 0){ if(motor_state == 0) normstep2(); if(motor_state == 2) normstep3(); if(motor_state == 4) normstep4(); if(motor_state == 6) normstep1(); motor_state += 2; if(motor_state > 6) motor_state = 0; desired_step_cnt--; } } else if(motor_enable == HALF){ if(desired_step_cnt < 0){ if(motor_state == 0) halfstep8(); if(motor_state == 1) halfstep1(); if(motor_state == 2) halfstep2(); if(motor_state == 3) halfstep3(); if(motor_state == 4) halfstep4(); if(motor_state == 5) halfstep5(); if(motor_state == 6) halfstep6(); if(motor_state == 7) halfstep7(); motor_state--; if(motor_state < 0) motor_state = 7; desired_step_cnt++; } else if(desired_step_cnt > 0){ if(motor_state == 0) halfstep2(); if(motor_state == 1) halfstep3(); if(motor_state == 2) halfstep4(); if(motor_state == 3) halfstep5(); if(motor_state == 4) halfstep6(); if(motor_state == 5) halfstep7(); if(motor_state == 6) halfstep8(); if(motor_state == 7) halfstep1(); motor_state++; if(motor_state > 7) motor_state = 0; desired_step_cnt--; } } else if(motor_enable == WAVE){ if(desired_step_cnt < 0){ if(motor_state == 1) wavestep4(); if(motor_state == 3) wavestep1(); if(motor_state == 5) wavestep2(); if(motor_state == 7) wavestep3(); motor_state -= 2; if(motor_state < 1) motor_state = 7; desired_step_cnt++; } else if(desired_step_cnt > 0){ if(motor_state == 1) wavestep2(); if(motor_state == 3) wavestep3(); if(motor_state == 5) wavestep4(); if(motor_state == 7) wavestep1(); motor_state += 2; if(motor_state > 7) motor_state = 1; desired_step_cnt--; } } _delay_ms(100);//Change according to speed input // normstep1(); // _delay_ms(100); // normstep2(); // _delay_ms(100); // normstep3(); // _delay_ms(100); // normstep4(); // _delay_ms(100); // halfstep1(); // _delay_ms(100); // halfstep2(); // _delay_ms(100); // halfstep3(); // _delay_ms(100); // halfstep4(); // _delay_ms(100); // halfstep5(); // _delay_ms(100); // halfstep6(); // _delay_ms(100); // halfstep7(); // _delay_ms(100); // halfstep8(); // _delay_ms(100); // wavestep1(); // _delay_ms(100); // wavestep2(); // _delay_ms(100); // wavestep3(); // _delay_ms(100); // wavestep4(); // _delay_ms(100); } return 0; }