int main(void) { OSCCAL = 0xF2; LEDdrive_on(); LEDdrive_init(); TWI_init(); LED_row_init(); timer_init(); double rand_num; int i,j; while(1) { for(j=0;j<3;j++) { for(i=0;i<81;i++) { rand_num = (double)((uint16_t)rand()) / 65536; update_LED(i,j,rand_num); } } disp_LED(5000); LED_clear(); } }
/** * @brief Function for application main entry. */ int main(void) { nrf_gpio_cfg_output(SENSORS_ON); nrf_gpio_pin_set(SENSORS_ON); ble_stack_init(); // Initialize Bluetooth stack spi_base_addr = (uint32_t)spi_master_init(SPI0, SPI_MODE0, false); CC110L_setupspibaseaddr(spi_base_addr); setup_cc110l(); advertising_init(); // Start execution. PacketData_Update(); advertising_start(); TWI_init(); MPL3115A2_Init(); HDC1008_Init(); HDC1008_TriggerHumidity(); TWI_powerdown(); ble_radio_notification_init(3, NRF_RADIO_NOTIFICATION_DISTANCE_5500US, radio_notification_evt_handler); // Enter main loop. for (;;) { power_manage(); } }
void main (void) { //init LCD LCD_init(); //set TWBR = 32 for 100kHz SCL @ 8MHz TWI_init(32, 0); //write 0x55 @ 513 and print return value on LCD LCD_puthex(EE_write_byte(513, 0x55)); //send stop TWI_stop(); LCD_wait(); LCD_putchar(' '); //wait for the EEPROM to finish the write operation TWI_wait(EE_ADDR); //read the write location again and print return code on LCD LCD_puthex(EE_read_byte(513)); LCD_wait(); LCD_putchar(' '); //print the value read from the EEPROM on the LCD LCD_puthex(TWDR); TWI_stop(); //LCD should now show "0x00 0x00 0x55_" //where the _ is the blinking cursor. }
void SensorsInit() { TWI_init(); MPL3115A2_Init(); HDC1008_Init(); HDC1008_TriggerHumidity(); TWI_powerdown(); }
int main() { UART_init(); TWI_init(); sei(); while (1); return 0; }
int main (void) { TWI_init(); //TWI Bus Initialisieren TWI_59116_reset(); TWI_59116_setup(); if(CORE==Master){ DDRA=0xff; //PORTA als Ausgang DDRD|=(1<<2); // PD2 als Ausgang Interrupt_init(); sei(); SPI_MasterInit(); Ebene_ein=0; while(1) { effect_blinky2(1); //ok effect_planboing(0,AXIS_Z,20); //ok effect_planboing(1,AXIS_X,20); //ok effect_planboing(0,AXIS_Y,20); //ok effect_planboing(1,AXIS_Z,20); //ok for (uint8_t ii=0;ii<8;ii++) effect_box_shrink_grow (0,ii%4, ii & 4, 20); //ok //sendvoxels_rand_z(100,10,20); // ok effect_random_sparkle (1,3,20,10); //ok effect_box_woopwoop(1,40,1); //naja effect_rain(0,300); //ok //effect_wormsqueeze (2, AXIS_Z, 1, 100, 25); //ok for(int i=0;i<8;i++){ // Pixel durchtesten for(int j=0;j<64;j++) { LED[0][i][j/8][j%8]=0xff; _delay_us(500); } for(int j=0;j<64;j++) { LED[0][i][j/8][j%8]=0; _delay_us(500); } } } }else{ DDRA=0x00; //PORTA als Eingang DDRD&=~(1<<2); // PD2 als Eingang SPI_SlaveInit(); Ebene_ein=0; while(1) { I2C_Leds_ein(Ebene_ein%8); //Säulentreiber einschalten für nächste Ebene } } return 0; }
int main() { DDRB = 0xff; PORTB = 0x00; UART_init(); TWI_init(); sei(); while (1); return 0; }
//MAIN int main(void) { interrupts(); setup_motor(); TWI_init(CONTROL_ADDRESS); while(1){ if(x == 0){ manual_control_test(); } else auto_control(); } }
void TaskTWI(void) { OS_WaitTicks(OSALM_TWIWAIT,10); // BMP085 needs 10ms in advance. TWI_init(); bmp085_init(TaskTWIWait1ms); lsm303_config_accel(TaskTWIWait1ms); lsm303_config_magnet(TaskTWIWait1ms); // init ISR INTC_register_interrupt(&int_handler_ACC, AVR32_EIC_IRQ_0, AVR32_INTC_INTLEVEL_INT2); // activate and enable EIC pins: eic_enable_channel(0); // enable rising edge isr. TWI_RegisterReadyHandler(TWIreadyhandler); lsm303_TWI_trig_read_accel(); // restart interrupt TWIstate = etwi_readACC; lastACCSample = OS_GetTicks(); while(1) { if (OS_GetTicks()-lastACCSample > 400) { lsm303_TWI_trig_read_accel(); // restart interrupt TWIstate = etwi_readACC; } uint8_t ret = OS_WaitEventTimeout(OSEVT_TWIRDY,OSALM_TWITIMEOUT,200); if((ret & OSEVT_TWIRDY) == 0) { // timeout //asm("breakpoint"); fixme wtf why and why //emstop(5); // will hang up while flashing, if we stop here! } else { long bar = bmp085_calc_pressure(bmp085raw); // just read stuff from rx buffers out of ISR!!! (large calculation!) int32_t h_mm = bmp085_calcHeight_mm(bar); s_nHeight_mm = h_mm; // update global #if SIMULATION == 1 // do not update z position, this is done in TaskNavi to make it even more complicated. ;) #else NAV_UpdatePosition_z_m((float)h_mm*0.001); #endif } } }
void PacketData_Update() { uint8_t flags = BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED; PACKET_INCR++; //Incrementing the value incr_cnt++; if(incr_cnt==50) { incr_cnt = 0; SensorsInit(); } supercap_measure_start(); TWI_init(); //Initializing TWI and reading values __HUMIDITY = HDC1008_ReadHumidity(); __PRESSURE = MPL3115A2_Read_Baro()>>6; __PRESSURE/=10; //Result in tens of Pascals (9500 equals 95000 Pa etc.) __TEMP = MPL3115A2_Read_Temp(); HDC1008_TriggerHumidity(); TWI_powerdown(); //Power-down of TWI m_beacon_info[6] = __PRESSURE>>8; //Putting data into 2.4 Ghz beacon packet and update advertising data m_beacon_info[7] = (__PRESSURE & 0xFF); m_beacon_info[8] = __TEMP>>8; m_beacon_info[9] = (__TEMP & 0xFF); m_beacon_info[10] = __HUMIDITY; m_beacon_info[4] = PACKET_INCR; m_beacon_info[12] = __SUPERCAP_VOLTAGE>>8; m_beacon_info[13] = __SUPERCAP_VOLTAGE&0xFF; manuf_specific_data.data.p_data = (uint8_t *) m_beacon_info; // Build and set advertising data. memset(&advdata, 0, sizeof(advdata)); advdata.flags.size = sizeof(flags); advdata.flags.p_data = &flags; advdata.p_manuf_specific_data = &manuf_specific_data; ble_advdata_set(&advdata, NULL); CC110L_PACKETCONTENT[2+6] = __PRESSURE>>8; //Putting data into 868 Mhz packet CC110L_PACKETCONTENT[2+7] = (__PRESSURE & 0xFF); CC110L_PACKETCONTENT[2+8] = __TEMP>>8; CC110L_PACKETCONTENT[2+9] = (__TEMP & 0xFF); CC110L_PACKETCONTENT[2+10] = __HUMIDITY; CC110L_PACKETCONTENT[2+4] = PACKET_INCR; CC110L_PACKETCONTENT[2+12] = __SUPERCAP_VOLTAGE>>8; CC110L_PACKETCONTENT[2+13] = __SUPERCAP_VOLTAGE&0xFF; }
int main(void) { TWI_init(); UART_init(); sei(); while(1) { TWI_read(0x50,dat,128); // Czytaj 24c02 EEPROM (A0=A1=A2 = 0) DEBUG_hextable(dat,128); TWI_write(0x50,dat,128); // Zapisz do PCF8583 (A0 = 1) TWI_read(0x51,dat,128); // Czytaj z PCF8583 (A0 = 1) DEBUG_hextable(dat,128); delayms(500); } }
void eeprom_init(){ // Specify startup parameters for the TWI/I2C driver TWI_init( F_CPU, // clock frequency 100000L, // desired TWI/IC2 bitrate TWI_buffer, // pointer to comm buffer sizeof(TWI_buffer), // size of comm buffer &handle_TWI_result // pointer to callback function ); // Enable interrupts sei(); // Set our structure pointers to the TWI/I2C buffer p_write_eeprom = (WRITE_EEPROM *)TWI_buffer; p_set_eeprom_address = (SET_EEPROM_ADDRESS *)TWI_buffer; p_read_eeprom = (READ_EEPROM *)TWI_buffer; }
bool TWI_WR_DAT(const char *Dat, u16 Len, u16 TWI_ADR, void (*TxClbFunc)(void)) { //Falls ein Sendevorgang läuft -> Abbruch if(ReceiveInProcess == true || SendInProcess == true) return false; //Sendevorgang läuft SendInProcess = true; //Überwachung intZ = 0; TWI_init(); //Adresse der Sendedaten sowie Länge speichern Dat2Send = Dat; Len2Send = Len; //Clb-Adresse speichern AktWRClbFunc = TxClbFunc; //Positionszähler zurücksetzen AktPosTx = 0; //Bytes schreiben AT91C_BASE_TWI->TWI_MMR = 0; //Adresse setzen AT91C_BASE_TWI->TWI_MMR = TWI_ADR << 16; //Übertragung starten TWI_WR_BYTE(); return true; }
int main(void) // main function { // setup USART USART_init(); // Set Port pins SETUP_port_init(); // setup PWM timer1 SETUP_pwm_init(); // setup timer0 SETUP_timer0(); // setup TWI TWI_init(); // setup compass SENSOR_HMC5883L_init(); // setup pressure sensor - not needed SENSOR_MS5611_init(); // setup 3-axis tilt sensor - not needed SENSOR_xxxx_init(); // setup GPS // SENSOR_GPS_init(); // error code transmitted - USART_transmit_packet(BASE_ADDRESS, speed); uint8_t waypoint = 0; uint8_t counter = 0; uint8_t current_location = 0; uint8_t target_heading = 0; uint8_t waypoint_distance = 0; uint8_t current_heading = 0; uint8_t target_speed = 0; uint8_t gps_error = 0; uint8_t turning_radius = 0; while(1)// endless loop { counter ++; current_location = SENSOR_GPS_getLocation(); // do not navigate with corrupt data if (!(SENSOR_GPS_locationCheck(current_location))) { // waypoint distance waypoint_distance = NAVIGATION_getDistance(current_location, waypoint); // target_bearing is where we should be heading target_heading = NAVIGATION_getDirection(current_location, waypoint); } // if within error move to next way point if (waypoint_distance<WAYPOINT_ERROR) { waypoint = NAVIGATION_nextWaypoint(waypoint); } // current bearing current_heading = NAVIGATION_getCurrentHeading(); //find steering... might be better to break it out into setsteering and getradius for data logging and fault finding turning_radius = NAVIGATION_getSteering(target_heading, current_heading); //set speed due to way point distance.... not sure if needed. //find speed due to turning radius. need to stop on last waypoint target_speed = NAVIGATION_getSpeed(turning_radius); NAVIGATION_setSpeed(target_speed); NAVIGATION_setSteering(turning_radius); // 1hz loop... 1s = (100 * 0.01) /*if (counter >= 200) { USART_transmit_packet(BASE_ADDRESS, 0x01); counter = 0; } */ // $GPGGA,230600.501,4543.8895,N,02112.7238,E,1,03,3.3,96.7,M,39.0,M,,0000*6A char ReceivedByte; for (;;) // Loop forever { while ((UCSR0A & (1 << RXC0)) == 0) {}; // Do nothing until data have been received and is ready to be read from UDR ReceivedByte = UDR0; // Fetch the received byte value into the variable "ByteReceived" while ((UCSR0A & (1 << UDRE0)) == 0) {}; // Do nothing until UDR is ready for more data to be written to it UDR0 = ReceivedByte; // Echo back the received byte back to the computer } } }
int main (void) { int tmp,i,res; CLKPR = 0x80; CLKPR = 0x00; // Clock prescaler Reset /*-----------------------------------------------------------------* *------------------------- Gear buttoms setup---------------------* *-----------------------------------------------------------------*/ DDRC&=~(1<<PC7); // Neutral PORTC |= (1<<PC7); // Neutral pull-up DDRE&=~(1<<PE6); // Knap1 DDRE&=~(1<<PE7); // Knap2 /* Buttoms interrupt */ EICRB |= (1<<ISC71|1<<ISC70|1<<ISC61|1<<ISC60); /* Rising edge */ EIMSK |= (1<<INT7 | 1<<INT6); uint8_t test_rx[8]; int8_t data; char streng[10]; // Recieve buffer st_cmd_t msg; // Init CAN, UART, I/O init(); uartinit(); sendtekst("UART initialized\n\r"); TWI_init(); sendtekst("TWI initialized\n\r"); sei(); /* Interrupt enable */ sendtekst("Interrupt enabled\n\r"); /*-----------------------------------------------------------------* *----------------------------Display setup -----------------------* *-----------------------------------------------------------------*/ /* Set blink rates */ set_blink_rate(LED0_7_ADDR, LED_BLINK1, 20, 100); set_blink_rate(LED0_7_ADDR, LED_BLINK2, 0, RPM_LED_DUTYCYCLE*2.56); set_blink_rate(LED8_15_ADDR, LED_BLINK1, (1.0/RPM16_RATE)*252, RPM16_DUTYCYCLE*2.56); set_blink_rate(LED8_15_ADDR, LED_BLINK2, 0, RPM_LED_DUTYCYCLE*2.56); set_blink_rate(SEG_ADDR, LED_BLINK1, 20, 100); set_blink_rate(SEG_ADDR, LED_BLINK2, 0, SEG_DUTYCYCLE*2.56); set_blink_rate(LED_BUTTONS_ADDR, LED_BLINK1, 20, 100); set_blink_rate(LED_BUTTONS_ADDR, LED_BLINK2, 0, SEG_DUTYCYCLE*2.56); /*-----------------------------------------------------------------* *----------------------------CAN interrupt setup -----------------* *-----------------------------------------------------------------*/ Can_sei(); /* Enable general can interrupt */ Can_set_tx_int(); /* Enable can tx interrupt */ Can_set_rx_int(); /* Enable can rx interrupt */ /* * Kode til hurtig test af can */ sendtekst("Config 3 mailboxes for rpm_msgid...\n\r"); msg.id.std = rpm_msgid; msg.dlc = 8; res = can_config_rx_mailbox(&msg, 3); if (res == CAN_CMD_ACCEPTED) { sendtekst("SUCCESS\n\r"); } else { sendtekst("FAIL\n\r"); } // --- Init variables /* Init user led 0 & 1 */ DDRB |= (1<<PB6 | 1<<PB5); PORTB |= (1<<PB6 | 1<<PB5); sendtekst("Beep\n\r"); display_test(); params.GearEst = 0; char dataout[] = {gear,0}; while (1) { _delay_ms(20); /* Display selected parameter */ if (mode == RPM_MODE) { set_rpm(params.rpm, LED_ON); } else if (mode == VOLTAGE_MODE) { set_voltage(params.batteryV, LED_ON); } else if (mode == WATER_TEMP_MODE) { set_water_temp(params.waterTemp, LED_ON); } // Geat buttons to CAN dataout[1] = 0; /* Format buttom states for sending */ dataout[1] |= (params.GearButDown*GEARDOWNBUT | GEARUPBUT*params.GearButUp | params.GearButNeutral*GEARNEUBUT); /* Send buttom states */ if(dataout[1] != 0) { // Hack, sender gearskiftesignal et par gange, sådan at det går igennem // Symptombehandling, sygdommen skal kureres... if (dataout[1] & (GEARDOWNBUT) == GEARDOWNBUT) indi_leds_state |= (LED_BLINK2<<LED_BUTTON_1); if (dataout[1] & (GEARUPBUT) == GEARUPBUT) indi_leds_state |= (LED_BLINK2<<LED_BUTTON_1); set_leds(LED_BUTTONS_ADDR, indi_leds_state); for(j=0;j<1;j++){ can_send_non_blocking(gear_msgid, dataout, 2); _delay_ms(5); } indi_leds_state &= ~(LED_BLINK2<<LED_BUTTON_2); indi_leds_state &= ~(LED_BLINK2<<LED_BUTTON_1); set_leds(LED_BUTTONS_ADDR, indi_leds_state); } /* Clear buttom states */ params.GearButDown = 0; params.GearButUp = 0; params.GearButNeutral = 0; /* Display bottons code */ buttons_state = get_buttons(LED_BUTTONS_ADDR) & (BUTTON1 | BUTTON2); if (buttons_state == 2) { indi_leds_state |= (LED_BLINK2<<LED_BUTTON_1); indi_leds_state &= ~(LED_BLINK2<<LED_BUTTON_2); mode = VOLTAGE_MODE; } else if (buttons_state == 1) { indi_leds_state |= (LED_BLINK2<<LED_BUTTON_2); indi_leds_state &= ~(LED_BLINK2<<LED_BUTTON_1); mode = WATER_TEMP_MODE; } else if (buttons_state == 0) { indi_leds_state |= (LED_BLINK2<<LED_BUTTON_1 | LED_BLINK2<<LED_BUTTON_2); } else { indi_leds_state &= ~(LED_BLINK2<<LED_BUTTON_1 | LED_BLINK2<<LED_BUTTON_2); mode = RPM_MODE; } /* Indicator for water temp */ if (params.waterTemp <= WATER_OK) { indi_leds_state |= (LED_BLINK2<<LED_INDI1); indi_leds_state &= ~(LED_BLINK2<<LED_INDI4); } else if (params.waterTemp > WATER_OK) { indi_leds_state |= (LED_BLINK2<<LED_INDI4); indi_leds_state &= ~(LED_BLINK2<<LED_INDI1); } /* Indicator for batt ok */ if (params.batteryV <= VOLTAGE_OK) { indi_leds_state |= (LED_BLINK2<<LED_INDI2); indi_leds_state &= ~(LED_BLINK2<<LED_INDI5); } else if (params.batteryV > VOLTAGE_OK) { indi_leds_state |= (LED_BLINK2<<LED_INDI5); indi_leds_state &= ~(LED_BLINK2<<LED_INDI2); } /* Indicator for oil pressure ok */ if (params.oilPressure <= OILPRESS_OK) { indi_leds_state |= (LED_BLINK2<<LED_INDI3); indi_leds_state &= ~(LED_BLINK2<<LED_INDI6); } else if (params.oilPressure > OILPRESS_OK) { indi_leds_state |= (LED_BLINK2<<LED_INDI6); indi_leds_state &= ~(LED_BLINK2<<LED_INDI3); } /* Indicator for Gear */ if (params.GearNeutral < 0) { SEG_N(LED_ON); } else { if (params.GearEst > 6) { SEG_OFF(); } else { switch (params.GearEst) { case 0: SEG_N(LED_ON); break; case 1: SEG_1(LED_ON); break; case 2: SEG_2(LED_ON); break; case 3: SEG_3(LED_ON); break; case 4: SEG_4(LED_ON); break; case 5: SEG_5(LED_ON); break; case 6: SEG_6(LED_ON); break; default: break; } } } /* if (params.GearNeutral == 0) { SEG_OFF(); } else if (params.GearNeutral > 0) { SEG_N(LED_BLINK2); } */ /* Set indicator leds */ set_leds(LED_BUTTONS_ADDR, indi_leds_state); /* itoa(params.batteryV, streng, 10);*/ /* sendtekst(streng);*/ /* sendtekst("\n\r"); */ PORTB ^= (1<<PB6); } return 0; }