void hardware_init(){ init_timer1(); init_timer0(); init_external(); init_int(); LS1=0xFF; }
/** init pwm */ inline void init_pwm(void) /*{{{*/ { uint8_t i; init_timer1(); global_pwm.dim = 255; global_pwm.channel_modifier = 0; for (i=0; i<3; i++) { global_pwm.channels[i].brightness = 0; global_pwm.channels[i].target_brightness = 0; global_pwm.channels[i].speed = 0x0100; global_pwm.channels[i].flags.target_reached = 0; global_pwm.channels[i].remainder = 0; global_pwm.channels[i].mask = _BV(i); } update_pwm_timeslots(); /* set all channels high -> leds off */ #if LED_PORT_INVERT LED_PORT |= 7; #else LED_PORT &= ~7; #endif /* configure Px0-Px2 as outputs */ LED_PORT_DDR |= 7; }
//main code int main(void) { //init stuff //init the ht1632c LED matrix driver chip ht1632c_init(); //init the ADC init_ADC(); //init srand() with a somewhat random number from ADC9's low bits init_srand(); //init button stuff for input and pullup //and setup INT0 for button if you set DO_YOU_WANT_BUTTON_INT0 init_button(); //init timer1 for use in triggering an interrupt //on overflow, which updates the display and calculates new generation. init_timer1(); //init the I/O for the 7 segment display control init_digit_pins(); init_segment_pins(); //reset the display with a "random" array using rand() reset_grid(); //test glider //fb[29] = 0b00100000; //fb[30] = 0b00101000; //fb[31] = 0b00110000; //variable to store generation_count for display on 7 segment displays uint16_t g_count=0; //enable global interrupts sei(); //infinite loop while(1){ //check if the update generation count flag has been set //by within the timer1 overflow interrupt. //if set put the updated value into g_count and reset the flag. if(update_gen_flag){ g_count = generation_count; update_gen_flag=0; } write_number(g_count); //write the g_count to 7 segment displays //write_number(generation_count); //if the seven_seg_error flag is set (output is over 999 for 3 digits) //then reset the grid if(seven_seg_error_flag){ reset_grid(); } } }
void init_all() { init_io(); init_periph(); USART_init(UBBR_VALUE); init_timer1(); set_sleep_mode(SLEEP_MODE_IDLE); }
//Initialize all the timers void InitTimers(void) { init_timer1(); init_timer2(); init_timer3(); init_timer4(); init_timer5(); }
void init(void) { DDRB |= (1<<PB1); DDRB &= ~(1<<PB0); PORTB |= (1<<PB0); init_timer1(); init_timer2(); sei(); dauer = tud[data+1]; }
main() { init_band_to_pin_tables(); init_out_pins(); init_PB5(); init_uart(); init_timer1(); sei(); // выставляем бит общего разрешения прерываний. main_loop(); }
int main(void) { // disable global interrupts cli(); init_pins(); init_timer1(); // reenable global interrupts sei(); // loop forever while interrupts do the real work // TODO: sleep cpu here instead of looping while(1); }
/*! Launch a capture in the \a buf buffer * \param buf The buffer to write to * \sa e_po3030k_config_cam and e_po3030k_is_img_ready */ void e_po3030k_launch_capture(char * buf) { buf_pos = 0; current_col = 0; current_row = 0; img_ready = 0; bpp_current = 0; pbp_current = 0; bbl_current = 0; buffer = buf; init_timer4(); init_timer1(); /* Timer5 must ALWAY be initialized as the last one */ init_timer5(); }
int main(void) { init_port(); init_timer1(); /* enable interrupts */ sei(); #ifdef TMODE_PWM while((PLLCSR & 0x01) == 0) {} // wait for pll is locked PLLCSR = 0x06; // enable pll clock source for timer1, no LSM TCCR1 = 0x07; // start timer1, CKx64 e.g. 1µs period #endif while(1) { } // stop processing here, go idle /* program flow dosn't come here */ return 0; }
int main() { TRISA = 0; TRISB = BIT(0)|BIT(1)|BIT(3)|BIT(7)|BIT(12); TRISC = 0; OUTER_LED = OFF; INNER_LED = OFF; init_pll(); peripheral_pin_config(); init_uart1(); init_spi(); init_adc(); init_timer1(); TX_string("Wait\r\n"); delay(1000); TX_string("Start\r\n"); T1CONbits.TON = 1; //remove first trash reading tiltX = accelRead(XINCL); gRead = gyroRead(GRATE); while(1) { if( newData == TRUE) { TX_snum5(gRead); TX('\t'); TX_snum5(tilt); TX('\t'); TX_snum5(x_00); TX_string("\r\n"); OUTER_LED = OFF; newData = FALSE; } } return 0; };
int main() { stm32_NvicSetup (); Setup_Pll_As_Clock_System(); init_portA(); init_portB(); init_portC(); init_timer2(); init_timer4(); init_timer1(); Setup_Adc(); Adc_On(); init_timer3(); // STM32 setup //GPIOA->ODR |=0x0020; Recule_train_Arriere(); while(1) { } }
void init_mtrn3200(void){ //disable all interrupts cli(); //initialise debugging light DEBUG_DDR |= (1<<DEBUG_PIN0)|(1<<DEBUG_PIN1); //set as ouput pins DEBUG_PORT &= (~((1<<DEBUG_PIN0)|(1<<DEBUG_PIN1))); //turn off check lights //initialise PWM PWM_Init(PRESCALER0); desired_pulse_width = 0; //initialise DAC DAC_Init(); desired_volt = 0; //initialise 7 Segment Led Seg7_Init(); //initialise ADC ADC_Init(ADC_CHANNEL); adc_result = 0; //Interrupt and Timer Setup init_timer1(PRESCALER1); time_step = 0; //enable all interrupts sei(); }
void test_adc12( void ) { uint16_t i; adc_count = 0; for( i = 0; i < 128; i++ ) { adc_in[i] = 0x33; /* For debugging purposes */ } P2DIR = 0x00; /* Input */ P2REN = 0xFF; /* Enable pullups/pulldowns */ P2OUT = 0xFF; /* Pullups */ P2SEL |= BIT5; /* Select ADC12 A5 */ PMAPPWD = PMAPPW; /* Get write access to port mapping registers */ PMAPCTL |= PMAPRECFG; /* Unlock port settings */ P2MAP5 = PM_ANALOG; /* P2.5 is analog pin */ PMAPPWD = 0; /* Disable write access to port mapping registers */ #if 0 /* DEBUG */ if( ( P2IN >> 5 ) & 0x01 ) { LED_ON; } #endif /* S&H time: 192 ADC12CLK cycles; ADC12: on */ ADC12CTL0 = ADC12SHT0_7 | ADC12SHT1_7 | ADC12ON; /* S&H source: ADC12SC bit; Single channel, single conversion; Clock divider: 0; Clock: ADCOSC */ ADC12CTL1 = ADC12SHS_0 | ADC12CONSEQ_0 | ADC12DIV_0 | ADC12SSEL_0; /* Resolution: 8 bits; Data format: binary unsigned */ ADC12CTL2 = ADC12RES_0; /* Referent voltages: AVcc (3.3V) and AVss (0V); Input channel: A5 (P2.5) */ ADC12MCTL0 = ADC12SREF_0 | ADC12INCH_5; ADC12IFG = 0; /* Clear ADC12 interrupt flag register */ ADC12IE |= ADC12IE0; /* Enable interrupt for memory location 0 */ ADC12CTL0 |= ADC12ENC; /* Enable conversion */ /* When using internal reference, wait for it to stabilize here */ init_timer1( ); /* Enable global interrupts and enter LPM0 mode */ _BIS_SR( LPM0_bits | GIE ); /* When ADC12 is finished with sampling, CPU wakes up and execution flow lands here. */ _BIC_SR( GIE ); /* Disable ADC12 conversion */ ADC12CTL0 &= ~( ADC12ENC | ADC12SC | ADC12SHT0_7 | ADC12SHT1_7 ); ADC12CTL0 &= ~ADC12ON; /* Switch off ADC12 */ TA1CTL = 0; /* Disable timer */ LED_ON; }
void init_timer (void){ init_timer2_pid_100Hz(); init_timer0(); init_timer1(); }
int main(void) { /****************INITIALIZATIONS*******************/ //other stuff Im experimenting with for SoR uartInit(); // initialize the UART (serial port) uartSetBaudRate(0, 9600); // set UARTE speed, for Bluetooth uartSetBaudRate(1, 115200); // set UARTD speed, for USB connection, up to 500k, try 115200 if it uartSetBaudRate(2, 57600); // set UARTH speed uartSetBaudRate(3, 57600); // set UARTJ speed, for Blackfin //G=Ground, T=Tx (connect to external Rx), R=Rx (connect to external Tx) // initialize rprintf system and configure uart1 (USB) for rprintf rprintfInit(uart1SendByte); configure_ports(); // configure which ports are analog, digital, etc. LED_on(); rprintf("\r\nSystem Warming Up"); // initialize the timer system (comment out ones you don't want) init_timer0(TIMER_CLK_1024); init_timer1(TIMER_CLK_64); init_timer2(TIMER2_CLK_64); init_timer3(TIMER_CLK_64); init_timer4(TIMER_CLK_64); init_timer5(TIMER_CLK_1024); //timer5Init(); a2dInit(); // initialize analog to digital converter (ADC) a2dSetPrescaler(ADC_PRESCALE_DIV32); // configure ADC scaling a2dSetReference(ADC_REFERENCE_AVCC); // configure ADC reference voltage int i = 0, j = 0; //let system stabelize for X time for(i=0;i<16;i++) { j=a2dConvert8bit(i);//read each ADC once to get it working accurately delay_cycles(5000); //keep LED on long enough to see Axon reseting rprintf("."); } LED_off(); rprintf("Initialization Complete \r\n"); reset_timer0(); reset_timer1(); reset_timer2(); reset_timer3(); reset_timer4(); reset_timer5(); while(1) { control(); delay_cycles(100); //an optional small delay to prevent crazy oscillations } return 0; }
void initialize (void) { init_timer1(); init_queue(); }
void MultiTasking::initTimer(unsigned frequency) { init_timer1(frequency); }
// this is where the program starts int main(void) { //----------------------------------------------------------------- // PORTB //----------------------------------------------------------------- // set individual pin I/O directions set_input(DDRB, p_freq_in); //----------------------------------------------------------------- // PORTA //----------------------------------------------------------------- // set individual pin I/O directions set_output(DDRA, p_debug); set_output(DDRA, p_SR_data); set_output(DDRA, p_SR_SCK); set_output(DDRA, p_SR_RCK); set_output(DDRA, p_UART_Tx); set_input(DDRA, p_UART_trig); // set the initial values of these pins low(PORTA, p_debug); low(PORTA, p_SR_data); low(PORTA, p_SR_SCK); low(PORTA, p_SR_RCK); high(PORTA, p_UART_Tx); // enable pull-up resistor for the UART trigger pin high(PORTA, p_UART_trig); // unused pins set as inputs set_input(DDRA,p_unused_A6); set_input(DDRA,p_unused_A7); // unused pins have pull-up-resistor enabled high(DDRA,p_unused_A6); high(DDRA,p_unused_A7); // set up timers and interrupts sei(); // enable global interrupts init_timer1(); // initialize timer1 init_input_interrupts(); // initialize input interrupts uint8_t sigfig = FIRST_SIGFIG_NOT_FOUND_YET; // records which significant figure of the number we are currently processing uint8_t stopEncoding = 0; // this keeps track of when to stop encoding the number from double into seven-segment format uint16_t digit = 0; // keeps track of which digit is currently being displayed uint16_t s = 0; // keeps track of which segment is being displayed (only used in the startup/debug screen) uint16_t unit = 0; // tells us which unit indicator we should light. // 0 = Megahertz // 1 = Hertz // 2 = Seconds // 3 = Minutes double currentFreqIn = 0; // this keeps track of the current frequency that will be displayed double currentPeriodIn = 0; // this keeps track of the current period that will be displayed double dispNumber = 0; // this keeps track of what number we want to display (frequency/period gets shoved in here and the number gets encoded for the 7-segment display the same way in both cases.) //----------------------------------------------------------------- // the LED displays are handled in this while loop. //----------------------------------------------------------------- while(1) { // if the unit is EVER triggered, it will no longer be in start up mode. if(triggered) { startUp = 0; } // if you need to transmit the frequency measurement over UART, // and if you are not currently transmitting frequency measurements, if(transmitFrequencyMeasurementOverUART) { // then do it. send the last frequency measurement over UART transmit_frequency_measurement_UART(currentFreqIn); // don't keep doing it. transmitFrequencyMeasurementOverUART = 0; } // if you are not in start-up mode (i.e. you are making measurements) if(!startUp) { // check if we are starting a new frame (a new set of six display digits) if(digit >= NUMBER_OF_DIGITS) { digit = 0; double decade; // grab the current frequency and period currentFreqIn = freq_meas_Hz * (double)( (uint32_t)1 << 2*freq_div ); currentPeriodIn = period_meas_s / (double)( (uint32_t)1 << 2*freq_div ); // determine what unit we want to use if (currentFreqIn >= 1e6) { unit = 0; // use units of MHz dispNumber = currentFreqIn/1.0e6; // display MHz } else if(currentFreqIn >= 1) { unit = 1; // use units of Hz dispNumber = currentFreqIn; // display hertz } else if(currentPeriodIn <= 60) { unit = 2; // use units of Seconds dispNumber = currentPeriodIn; // display seconds } else { unit = 3; // use units of Minutes dispNumber = currentPeriodIn/60.0; // display minutes } // default is a bogus value to indicate that the first significant figure has not been found yet sigfig = FIRST_SIGFIG_NOT_FOUND_YET; // make sure the for loop starts encoding stopEncoding = 0; for(decade = DECADE_START; !stopEncoding; decade/=10.0) { // if you have found the first significant digit, if(dispNumber >= decade && sigfig == FIRST_SIGFIG_NOT_FOUND_YET) { // start processing the number into sigfig = 0; } // if you have found at least the first significant digit, if(sigfig < NUMBER_OF_DIGITS) { // record what this digit was by putting it in the disp_data disp_data[sigfig] = (uint8_t)(dispNumber/decade); // subtract the digit that has already been accounted for dispNumber -= (double)disp_data[sigfig]*decade; // replace the digit with the data that will produce a digit on the seven segment display disp_data[sigfig] = sevenseg[disp_data[sigfig]]; // if this is the ones place, if(decade == 1) { // add the decimal place disp_data[sigfig] |= 0x80; } // increment the sigfig sigfig++; } // If you have encoded the necessary number of digits, if(sigfig == NUMBER_OF_DIGITS) { // quit encoding digits stopEncoding = 1; } } } // select the digit you want to display shift_out_24_PORTA(p_SR_SCK, p_SR_data, 8, 1<<digit, 'm'); // select what division factor you want to apply to the input signal before it is applied to the ATtiny84. shift_out_24_PORTA(p_SR_SCK, p_SR_data, 4, freq_div, 'm'); // select the unit LED indicator you want to light shift_out_24_PORTA(p_SR_SCK, p_SR_data, 4, 1<<unit, 'm'); // shift out the data for the current digit of the seven-segment display shift_out_24_PORTA(p_SR_SCK, p_SR_data, 8, disp_data[digit], 'm'); // update the output registers low(PORTA,p_SR_RCK); high(PORTA,p_SR_RCK); // this sets (roughly) the refresh rate of the display. _delay_ms(DIGIT_DISPLAY_PERIOD); // We have just displayed a digit. It is time to digit++; } // if you have just started up and have not seen any transitions, // (this is basically just something to do when the unit first starts up) else { // limit s to the number of segments if(s >= 8){ s = 0; // when the segment overflows, increment the digit digit++; } // limit d to the number of digits if(digit >= 6){ digit = 0; // when the digit overflows, increment the unit unit++; } // limit u to the number of units if(unit >= 4){ unit = 0; } // shift out data that controls everything shift_out_24_PORTA(p_SR_SCK, p_SR_data, 2, 0, 'm'); // shift out two empty bits shift_out_24_PORTA(p_SR_SCK, p_SR_data, 6, (uint16_t)1<<digit, 'm'); // shift out the digit data shift_out_24_PORTA(p_SR_SCK, p_SR_data, 1, 0, 'm'); // shift out one empty bit shift_out_24_PORTA(p_SR_SCK, p_SR_data, 3, (uint16_t)freq_div, 'm'); // shift out the frequency division data shift_out_24_PORTA(p_SR_SCK, p_SR_data, 4, (uint16_t)1<<unit, 'm'); // shift out the unit data shift_out_24_PORTA(p_SR_SCK, p_SR_data, 8, (uint16_t)1<<s, 'm'); // shift out the segment data // update the output registers low(PORTA,p_SR_RCK); high(PORTA,p_SR_RCK); _delay_ms(30); // increment the segment counter s++; } } }
//----- Begin Code ------------------------------------------------------------ int main(void) { static uint8_t f_i2c; static bool f_recieve; static uint8_t rbuf[8], *p, temp; static uint8_t state = S_NORMAL; // TIMER1の設定 init_timer1(); f_i2c = check_I2C(); if (f_i2c) { // I2C スレーブ初期化 usiTwiSlaveInit( TWI_slaveAddress ); } else { // 2313標準UARTの初期化 uart2313_init(); } // LCD初期化 lcd_init(LCD_DISP_ON); lcdMapCustomChar(0, 0); lcdMapCustomChar(1, 1); lcdMapCustomChar(2, 2); lcdMapCustomChar(3, 3); lcdMapCustomChar(4, 4); lcdMapCustomChar(5, 5); lcdMapCustomChar(6, 6); lcdMapCustomChar(7, 7); lcd_gotoxy(0, 0); // any logos? // write something lcd_puts_P("I2CLCD"); if (f_i2c) { //1234567890123456 lcd_puts_P("-I"); } else { //1234567890123456 lcd_puts_P("-S"); } sei(); while (1) { if (f_i2c) { f_recieve = usiTwiDataInReceiveBuffer(); if (f_recieve) { temp = usiTwiReceiveByte(); } } else { f_recieve = xreadOK(); if (f_recieve) { temp = xread(); } } if (f_recieve) { switch (state) { case S_NORMAL: if (temp == ESC) { state = S_SEQUENCE; } else { lcd_putc(temp); } break; case S_SEQUENCE: p = rbuf; *p = temp; switch (temp) { case 'L': // L for Locate (X), (Y) state = S_L1; break; case 'H': // ホームポジションへカーソル移動 lcd_home(); state = S_NORMAL; break; case 'C': // 画面クリア lcd_clrscr(); state = S_NORMAL; break; case 'S': // S for Save Custom Character to EEPROM state = S_S1; break; case 'M': // M for Custom Character Mapping state = S_M1; break; case 'X': // 画面非表示 /* display off */ lcd_command(LCD_DISP_OFF); state = S_NORMAL; break; case 'N': // 画面表示・カーソル消去 /* display on, cursor off */ lcd_command(LCD_DISP_ON); state = S_NORMAL; break; case 'B': // 画面表示・カーソル非表示・ブリンク文字 /* display on, cursor off, blink char */ lcd_command(LCD_DISP_ON_BLINK); state = S_NORMAL; break; case 'D': // 画面表示・カーソル表示 /* display on, cursor on */ lcd_command(LCD_DISP_ON_CURSOR); state = S_NORMAL; break; case 'E': // 画面表示・カーソル表示・ブリンク文字 /* display on, cursor on, blink char */ lcd_command(LCD_DISP_ON_CURSOR_BLINK); state = S_NORMAL; break; case '-': // カーソル左移動 /* move cursor left (decrement) */ lcd_command(LCD_MOVE_CURSOR_LEFT); state = S_NORMAL; break; case '+': // カーソル右移動 /* move cursor right (increment) */ lcd_command(LCD_MOVE_CURSOR_RIGHT); state = S_NORMAL; break; case '<': // 画面左移動 /* shift display left */ lcd_command(LCD_MOVE_DISP_LEFT); state = S_NORMAL; break; case '>': // 画面右移動 /* shift display right */ lcd_command(LCD_MOVE_DISP_RIGHT); state = S_NORMAL; break; } break; case S_L1: *++p = temp; state = S_L2; break; case S_L2: // *++p = temp; lcd_gotoxy(rbuf[1], temp); state = S_NORMAL; break; case S_M1: *++p = temp; state = S_M2; break; case S_M2: // *++p = temp; lcdMapCustomChar(rbuf[1],temp); state = S_NORMAL; break; // ----------------------------- case S_S1: *++p = temp; state = S_S2; break; case S_S2: rCustom[0] = temp; // *++p = temp; state = S_S3; break; case S_S3: rCustom[1] = temp; // *++p = temp; state = S_S4; break; case S_S4: rCustom[2] = temp; // *++p = temp; state = S_S5; break; case S_S5: rCustom[3] = temp; // *++p = temp; state = S_S6; break; case S_S6: rCustom[4] = temp; // *++p = temp; state = S_S7; break; case S_S7: rCustom[5] = temp; // *++p = temp; state = S_S8; break; case S_S8: rCustom[6] = temp; // *++p = temp; state = S_S9; break; case S_S9: rCustom[7] = temp; // *++p = temp; lcdSaveCustomChar(rbuf[1]); state = S_NORMAL; break; } } } return 0; }
/** * void main(void) * * Main program execution function */ void main(void) { /** * General initialization */ init_unused_pins(); init_oscillator(); init_timer0(); init_timer1(); /** * Initialize I/O pins */ // Init CAN termination pin TERM_TRIS = OUTPUT; TERM_LAT = 1; // Terminating // Init RADIO pins #if FRONT RADIO0_TRIS = INPUT; RADIO1_TRIS = INPUT; #endif #if FRONT // Init FRONT ADC pins ADC_SPFL_TRIS = INPUT; ADC_SPFR_TRIS = INPUT; ADC_BPF_TRIS = INPUT; ADC_BPR_TRIS = INPUT; ADC_STRP_TRIS = INPUT; ADC_APPS0_TRIS = INPUT; ADC_APPS1_TRIS = INPUT; ADC_PTDP_TRIS = INPUT; ADC_UAN0_TRIS = OUTPUT; ADC_UAN0_LAT = 0; #elif REAR // Init REAR ADC pins ADC_SPRL_TRIS = INPUT; ADC_SPRR_TRIS = INPUT; ADC_EOS_TRIS = INPUT; ADC_BCD_TRIS = INPUT; ADC_CTRI_TRIS = INPUT; ADC_CTRO_TRIS = INPUT; ADC_CTSP_TRIS = INPUT; ADC_CPSP_TRIS = INPUT; ADC_MCD_TRIS = INPUT; ADC_UAN0_TRIS = OUTPUT; ADC_UAN0_LAT = 0; ADC_UAN1_TRIS = OUTPUT; ADC_UAN1_LAT = 0; #endif /** * Setup Peripherals */ #if FRONT ANCON0 = 0b11100110; // All analog except for AN0, AN3, AN4 ANCON1 = 0b00000111; // All digital except for AN8, AN9, AN10 #elif REAR ANCON0 = 0b11111111; // All analog ANCON1 = 0b00000111; // All digital except for AN8, AN9, AN10 #endif init_ADC(); ECANInitialize(); // Interrupts setup INTCONbits.GIE = 1; // Global Interrupt Enable (1 enables) INTCONbits.PEIE = 1; // Peripheral Interrupt Enable (1 enables) RCONbits.IPEN = 0; // Interrupt Priority Enable (1 enables) // Main loop while(1) { // Sample and send fast speed sensor channels on CAN send_fast_can(); // Sample and send medium speed sensor channels on CAN send_med_can(); // Sample and send slow speed sensor channels on CAN send_slow_can(); // Send diagnostic CAN message send_diag_can(); #if FRONT if (radio_sw) { RADIO0_TRIS = OUTPUT; RADIO1_TRIS = OUTPUT; RADIO0_LAT = 0; RADIO1_LAT = 0; } else { RADIO0_TRIS = INPUT; RADIO1_TRIS = INPUT; } #endif } }