/* Initializes the controller */ void controller_init( void ) { /* initialize variables */ flag_check_delay = 0; flag_new_request = 0; /* clear data structures */ memset( &javiator_data, 0, sizeof( javiator_data ) ); /* initialize hardware */ ports_init( ); wdog_init( ); //adc_init( ); parallel_init( ); bmu09a_init( ); lsm215_init( ); //minia_init( ); leds_init( ); /* register watchdog event and start timer */ wdog_register_flag( (uint8_t *) &flag_check_delay, NOTIFY_PERIOD ); wdog_start( ); #if 0 /* register ADC channels */ adc_add_channel( ADC_CH_SONAR ); adc_add_channel( ADC_CH_BATT ); #endif /* set Robostix signal LEDs */ LED_ON( RED ); LED_ON( BLUE ); LED_ON( YELLOW ); /* enable interrupts */ sei( ); }
/** * MCU: Atmega328 * Fuses: Oscilador interno a 8 Mhz (sin dividir por 8) * -U lfuse:w:0xe2:m -U hfuse:w:0xd1:m -U efuse:w:0x07:m */ int main(void) { adc_init(); timer0_init(timer0_callback); i2c_init(); rtc_init(rtc); rtc_sqw_rate(rtc, 1); rtc_sqw_enable(rtc); rtc_clock_start(rtc); eMBInit(MB_RTU, 0x03, 0, 9600, MB_PAR_NONE); eMBSetSlaveID(0x3, TRUE, (UCHAR*) "demeter", 8); eMBEnable(); blinkenlight(5, 100); parameters_init(); ports_init(); f_mount(&fs, "", 0); update_log_filename(); while (1) { eMBPoll(); update_state(); _delay_ms(100); } return (0); }
int main(void) { // init uart_init(UART_BAUD_SELECT(UART_BAUD_RATE, F_CPU)); // enable interrupts after resetting the kicker sei(); uart_puts_P("* Interrupts enabled. - "); ports_init(); uart_puts_P("Ports initialized. - "); kicker_init(); uart_puts_P("Kicker initialized. - "); //kicker_uext(500); uart_puts_P("Device initialized. Enter main loop\n"); for (;;) { parser_process_uart(); } return 0; }
/* Initializes the controller */ void controller_init( void ) { /* initialize variables */ flag_shut_down = 1; flag_check_delay = 0; flag_new_signals = 0; flag_new_sensors = 0; /* clear data structures */ memset( &javiator_data, 0, sizeof( javiator_data ) ); memset( &motor_signals, 0, sizeof( motor_signals ) ); /* initialize hardware */ ports_init( ); wdog_init( ); adc_init( ); serial_init( ); //parallel_init( ); dm3gx1_init( ); minia_init( ); pwm_init( ); leds_init( ); /* register watchdog event and start timer */ wdog_register_flag( (uint8_t *) &flag_check_delay, NOTIFY_PERIOD ); wdog_start( ); /* set Robostix signal LEDs */ LED_ON( RED ); LED_ON( BLUE ); LED_ON( YELLOW ); /* enable interrupts */ sei( ); }
int main(int argc, const char **argv) { int opt; #if 0 if (argc != 2) { fprintf(stderr, "Usage: motlle `smottle`\n"); exit(2); } sscanf(argv[1], "%p", &load_address); #endif for (;;) switch (getopt(argc, argv, "+d")) { case 'd': debug_lvl = 2; break; case '?': break; case -1: goto done; } done: signal(SIGALRM, silly_sig); garbage_init(); interpret_init(); stack_init(); runtime_init(); call_init(); parser_init(); compile_init(); mcompile_init(); context_init(); ports_init(); if (optind < argc) make_global_state(argc - optind, argv + optind); else make_global_state(0, NULL); mudio_init(); print_init(); if (optind < argc) mload(argv[optind]); else push_repl(); for (;;) motlle_run1(); }
void main() { di(); OSCCON = 0x78; ports_init(); usart_init(); timer_init(); ei(); usart_pkt_send('I', 1); while (1) { usart_check(); } }
void mudlle_init(void) { garbage_init(); global_init(); strbuf_init(); print_init(); stack_init(); module_init(); runtime_init(); compile_init(); mcompile_init(); interpret_init(); error_init(); ports_init(); context_init(); }
int main(void) { struct adc adc; struct adc_event adc_e; ports_init(); adc_init(); adc_ctor(&adc); while(1) { adc_e.sample = adc_read(0); adc_e.super_.signal = ADC_NEW_SAMPLE_SIG; FSM_DISPATCH_((struct fsm*)&adc, (struct fsm_event*)&adc_e); _delay_loop_2(10); /* using 16 bit counter, 10 loops, each of them takes 4 CPU cycles, so if F_CPU is 1MHz this does busy waiting for 40 microseconds */ } }
void init_devices(void) { //1. Stop errant interrupts until set up _BIC_SR(GIE); // Disable interrupts during initialization process //2. Init System Clock // By defaut the FLL stabilizes MCLK and SMCLK to 1.048576 MHz and fDCO = 2.097152 MHz. //3. Init Peripherals //RTC_Clock_init(); ports_init(); timer1_A3_init(); timer1_A3_Stop_Mode; //P3DIR |= BIT7; // Show SMCLK to P3.7 //P3SEL |= BIT7; _BIS_SR(GIE); // Global Interrupt enabled. Do this at the END of the initialization!!!!!!!! //all peripherals are now initialized }
void main_init(){ dashboard_state=DASHBOARD_STATE_STARTING; ports_init(); Timer0_init(TMR0_PRESCALER); CANInit(); #if HAS_50HZ|HAS_200HZ|HAS_50HZ Timer1_init(TMR1_PRESCALER,FALSE); #endif #if HAS_10HZ|HAS_5HZ|HAS_4HZ Timer3_init(TMR3_PRESCALER,FALSE); #endif #if HAS_50HZ TIMER_Timer1_OCR1A_on(); #endif #if HAS_25HZ TIMER_Timer1_OCR1B_on(); #endif #if HAS_200HZ TIMER_Timer1_OCR1C_on(); #endif #if HAS_10HZ TIMER_Timer3_OCR3A_on(); #endif #if HAS_BUZZER buzzer_init(); TIMER_Timer3_OCR3C_on(); #endif #if HAS_LEDS led_init(); #endif #if HAS_BUTTONS button_init(); #endif #if HAS_DISPLAY display_init(); #endif #if HAS_RADIO radio_init(); #endif InitWDT(); EventAddEvent(EVENT_INIT); }
void main(void) { unsigned char n; #pragma optsize- #asm("cli") n=(PMIC.CTRL & (~(PMIC_RREN_bm | PMIC_IVSEL_bm | PMIC_HILVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_LOLVLEN_bm))) | PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm; CCP=CCP_IOREG_gc; PMIC.CTRL=n; PMIC.INTPRI=0x00; #pragma optsize_default system_clocks_init(); ports_init(); usartc0_init(); usartd1_init(); rtc32_init_my(); delay_ms(50); tcd0_init(); twie_init(); sprintf(info,"start i2c"); monitor(); delay_ms(50); #asm("sei") delay_ms(1); PORTE.OUT=PORTE.OUT|0b00010000; init_buferU1(); delay_ms(50); PORTE.OUT=PORTE.OUT&0b11101111; delay_ms(50); PORTE.OUT=PORTE.OUT|0b00010000; init_buferU2(); delay_ms(50); PORTE.OUT=PORTE.OUT&0b11101111; delay_ms(50); PORTE.OUT=PORTE.OUT|0b00010000; init_buferU3(); delay_ms(50); PORTE.OUT=PORTE.OUT&0b11101111; delay_ms(50); sprintf(info,"buf i2c start ok"); monitor(); delay_ms(50); PORTE.OUT=PORTE.OUT|0b00010000; bmp_reg_init(); delay_ms(50); sprintf(info,"bmp i2c start ok"); PORTE.OUT=PORTE.OUT&0b11101111; delay_ms(50); monitor(); delay_ms(100); spic_init(); sprintf(info,"SPI START"); monitor(); #asm("sei") delay_ms(200); check_sd_card(); spic_init(); PORTA.DIRSET=0b00000001; PORTA.OUTSET = 0b00000001; delay_ms(10); PORTA.OUTCLR = 0b00000001; delay_ms(100); PORTA.OUTSET = 0b00000001; delay_ms(10); ad7705_init(can1cl,mclk4,can1set,set1); delay_ms(10); PORTE.OUT=PORTE.OUT&0b11101111; delay_ms(10); PORTE.OUT=PORTE.OUT|0b00010000; sprintf(info,"ad7705 start ok"); monitor(); RESULT=ad7705(1); S0[7]=RESULT;// Сигнал усилителя младший S0[8]=(RESULT>>8); //Сигнал усилителя старший // ADCA initialization adca_init(); // ADCB initialization adcb_init(); // Timer/Counter tcc0_init(); tcc1_init(); tcf0_init(); delay_ms(10); sprintf(info,"start device"); monitor(); delay_ms(50); if(Xsave==0xFFFFFFFF)Xsave=0; sprintf(info,"START WHILE"); monitor(); delay_ms(50); if(RTC32.CNT<1454622753) RTC32.CNT=1454622753; PORTE.OUT=PORTE.OUT&0b11101111; //прописываем заводской ответ //!!!! важно смертельно initzavod(); reginit(); while (1) { PORTR.OUTTGL=0b00000010; //////////////////////////////////////************************************* //поиск ошибки буфера //buferU1_error(); //включаю подсветку //if(error_buf!=0) PORTE.OUT=PORTE.OUT|0b00010000; init_buferU1(); ///////////////////////////////////////////////////////////////////////////// read_bmp(); /////////////////////////////////////////////////////////////// if((0.0<Tempf&&Tempf<60.0)&&(300.0<p1&&p1<825.0)) { Tempf_K=Tempf*10.0+2730.0; S0[11]=Tempf_K;// температура бмп младший S0[12]=(Tempf_K>>8); //температура бмп старший /////////////////////////////////////////////////////////////// S0[15]=p/10;//ДАВЛЕНИЕ бмп младший S0[16]=(p/10>>8);//ДАВЛЕНИЕ бмп старший } init_buferU2(); if(SD_IN) { get_CNTRTC(&X); calcDateTime(X, 0, &date1,&time1); bufform(); GETFILNAME(); } init_buferU3(); buferU1_opros(); buferU2_opros(); buferU3_opros(); //обработочка //21.1 b2 io7 + if((U2in.input&0b10000000)==0b10000000) S0[21]=S0[21]|0b00000010; else if((U2in.input&0b10000000)==0b00000000) S0[21]=S0[21]&0b11111101; //21.2 b1 io4 + if((U1in.input&0b00010000)==0b00010000) S0[21]=S0[21]|0b00000100; else if((U1in.input&0b00010000)==0b00000000) S0[21]=S0[21]&0b11111011; //21.3 b1 io5 + if((U1in.input&0b00100000)==0b00100000) S0[21]=S0[21]|0b00001000; else if((U1in.input&0b00100000)==0b00000000) S0[21]=S0[21]&0b11110111; //21.4 b1 io1 ---- if((U1in.input&0b00000010)==0b00000010) S0[21]=S0[21]|0b00010000; else if((U1in.input&0b00000010)==0b00000000) S0[21]=S0[21]&0b11101111; //21.5 b2 io3 if((U2in.input&0b00001000)==0b00001000) S0[21]=S0[21]|0b00100000; else if((U2in.input&0b00001000)==0b00000000) S0[21]=S0[21]&0b11011111; //21.6 b2 io4 if((U2in.input&0b00010000)==0b00010000) S0[21]=S0[21]|0b01000000; else if((U2in.input&0b00010000)==0b00000000) S0[21]=S0[21]&0b10111111; //21.6 b3 io6 if((U3in.input&0b01000000)==0b01000000) S0[21]=S0[21]|0b10000000; else if((U3in.input&0b01000000)==0b00000000) S0[21]=S0[21]&0b01111111; //пождиг if( (B5upr&0b00000010)==0b00000010 ) { U3out.output=U3out.output|0b00000010; } else if( (B5upr&0b00000010)==0b00000000 ) {U3out.output=U3out.output&0b11111101;} //клапан1 if( (B5upr&0b00000100)==0b00000100 ) {U3out.output=U3out.output|0b00000100;} else if( (B5upr&0b00000100)==0b00000000 ) {U3out.output=U3out.output&0b11111011;} //контрольная кювета if( (B5upr&0b00001000)==0b00001000) {U1out.output=U1out.output&0b00111111; U1out.output=U1out.output|0b01000000;} else if((B5upr&0b00001000)==0b00000000) {U1out.output=U1out.output&0b00111111; U1out.output=U1out.output|0b10000000;} //клапан 2 if( (B5upr&0b00010000)==0b00010000 ) {U3out.output=U3out.output|0b00001000;} else if( (B5upr&0b00010000)==0b00000000 ) {U3out.output=U3out.output&0b11110111;} //клапан 3 if( (B5upr&0b00100000)==0b00100000 ) {U3out.output=U3out.output|0b00010000;} else if( (B5upr&0b00100000)==0b00000000 ) {U3out.output=U3out.output&0b11101111;} //реле 1 инверсно if( (B5upr&0b01000000)==0b01000000 ) {U1out.output=U1out.output&0b11111110;} else if( (B5upr&0b01000000)==0b00000000 ) {U1out.output=U1out.output|0b00000001;} //реле 2 инверсно if( (B5upr&0b10000000)==0b10000000 ) {U2out.output=U2out.output&0b11111110;} else if( (B5upr&0b10000000)==0b00000000 ) {U2out.output=U2out.output|0b00000001;} buferU1_set(); buferU2_set(); buferU3_set(); //////////////////////////////////////************************************* //установка даты времени if ((newtime==1)||(newdate==1)) { calcSeconds(date1,time1,0,&X); Xsave=X;//последняя установка set_CNTRTC(); newdate=0; newtime=0; } }
void main(void) { // Declare your local variables here unsigned char n; // Interrupt system initialization // Optimize for speed #pragma optsize- // Make sure the interrupts are disabled #asm("cli") // Low level interrupt: Off // Round-robin scheduling for low level interrupt: Off // Medium level interrupt: Off // High level interrupt: On // The interrupt vectors will be placed at the start of the Application FLASH section n=(PMIC.CTRL & (~(PMIC_RREN_bm | PMIC_IVSEL_bm | PMIC_HILVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_LOLVLEN_bm))) | PMIC_HILVLEN_bm; CCP=CCP_IOREG_gc; PMIC.CTRL=n; // Set the default priority for round-robin scheduling PMIC.INTPRI=0x00; // Restore optimization for size if needed #pragma optsize_default // System clocks initialization system_clocks_init(); // Ports initialization ports_init(); // Virtual Ports initialization vports_init(); // USARTE0 initialization usarte0_init(); // USARTE1 initialization usarte1_init(); // USARTF0 initialization usartf0_init(); // Alphanumeric LCD initialization // Connections specified in the // Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu: // RS - PORTD Bit 0 // RD - PORTD Bit 1 // EN - PORTD Bit 2 // D4 - PORTD Bit 4 // D5 - PORTD Bit 5 // D6 - PORTD Bit 6 // D7 - PORTD Bit 7 // Characters/line: 16 lcd_init(16); // Globally enable interrupts #asm("sei") a1=255; PORTB.OUT = a1 ; lcd_putsf("START"); delay_ms(2000); lcd_clear(); printf("START\n"); PORTB.OUT = 0 ; delay_ms(1000); /* PORTF.OUTCLR = 0b00010000; PORTB.OUTCLR = 0b10000000; delay_ms(100); PORTF.OUTSET = 0b00010000; PORTB.OUTSET = 0b10000000; delay_ms(100); PORTF.OUTCLR = 0b00010000; PORTB.OUTCLR = 0b10000000; delay_ms(500); */ PORTF.OUTSET = 0b00010000; PORTB.OUTSET = 0b10000000; delay_ms(1000); PORTF.OUTCLR = 0b00010000; PORTB.OUTCLR = 0b10000000; delay_ms(1000); putchar_usarte1('A'); putchar_usarte1('T'); //putchar_usarte1('I'); putchar_usarte1('\r'); //putchar_usartf0('A'); //putchar_usartf0('T'); //putchar_usartf0('I'); //putchar_usartf0('\r'); while (1) { // Place your code here PORTB.OUTTGL = 1; PORTB.OUTSET = (PORTF.IN & 0b00100000) << 1; PORTB.OUTCLR =!(PORTF.IN & 0b00100000) << 1; delay_ms(100); } }
void app_init() { ports_init(); ACTOR1_init(); ACTOR2_init(); ISR_init(); }
/** * function to initialise the inshift registers. * Here, all inshift registers are prepared for their use * and the input filter is set to a correct state. * To set the input filters correct, the input is reading the * values three times and is making a majority decision on the * value */ void inshiftInit(void) { struct sRegister * ptr = m_pInshiftReg; unsigned short i, j, k; LOG_INF("started"); assert(NULL != ptr); if(!ptr) { LOG_ERR("not existing pointer"); return; } /* Schritt 1: Initialisiere alle Filterwerte */ ptr = m_pInshiftReg; for(j = 0; j < m_inshiftRegLen; j++) { /* wiederhole fuer jeden vorhandenen EP16-Print */ for(k = 0; k < 16; k++) { /* wiederhole fuer jedes Bit des EP16 */ ptr->filterValue[k] = 0; } ptr++; } /* Schritt 2: Lies alle Werte 3 mal */ for(i = 0; i < 3; i++) { ptr = m_pInshiftReg; /* Initialisiere Einlesen */ ports_init(); /* Bereite Einschieben vor */ /* Pn/S high, clock high and low */ port_set_in_clk_1(); port_set_in_ps(false); waitALittle(); port_set_in_clk_0(); waitALittle(); port_set_in_ps(true); /* Nun ist das Schieberegister bereit zum Einlesen */ waitALittle(); port_set_in_clk_1(); for(j = 0; j < m_inshiftRegLen; j++) { /* wiederhole fuer jeden vorhandenen EP16-Print */ for(k = 0; k < 16; k++) { /* wiederhole fuer jedes Bit des EP16 */ waitALittle(); port_set_in_clk_0(); waitALittle(); if(port_get_in_in()) { /* wenn der Eingang gesetzt ist */ ptr->filterValue[k] += (unsigned char) 1; } port_set_in_clk_1(); } /* Ende fuer alle Bits */ ptr++; } /* Ende fuer alle EP16 */ } /* Ende fuer 3 mal lesen */ /* Nun rechne fuer jedes Bit * 2 oder 3 mal 1 --> filter >= 2 --> set * 0 oder 1 mal 1 --> filter < 2 --> clear */ ptr = m_pInshiftReg; for(j = 0; j < m_inshiftRegLen; j++) { /* wiederhole fuer jeden vorhandenen EP16-Print */ ptr->value = 0; for(k = 0; k < 16; k++) { /* wiederhole fuer jedes Bit des EP16 */ ptr->value <<= 1; if(((unsigned char) 2) <= ptr->filterValue[k]) { ptr->filterValue[k] = 0x0080; ptr->value |= 0x0001; } else { ptr->filterValue[k] = 0; } } ptr++; } LOG_INF("ended"); }