void initialize(bool verbose) { CPU_PRESCALE(0); USART_init(BAUD_RATE); USART_transmit('\f'); // Send form feed to clear the terminal. if (verbose) USART_send_string("WunderBoard initializing...\r\n"); if (verbose) USART_send_string("\tSetting ADC prescaler and disabling free running " "mode...\r\n"); setup_ADC(ADC_PRESCALER_32, FALSE); if (verbose) USART_send_string("\tEnabling ADC...\r\n"); ADC_enable(); if (verbose) USART_send_string("\tSetting ADC reference to Vcc...\r\n"); ADC_set_reference(ADC_REF_VCC); // Configure IO // if (verbose) USART_send_string("\tConfiguring IO...\r\n"); //DDRx corresponds to PORTx/PINx, dependng on direction of data flow -- //PORT for output, PIN for input DDRA = 0x00; // Buttons and switches DDRB = 0b11100111; // Red enable, green enable and audio out DDRC = 0b11111111; // Discrete LEDs DDRE = 0b01000111; // LED Column DDRF = 0x00; // Accelerometer // Disable pullups and set outputs low // PORTA = 0x00; PORTB = 0b00000001; PORTC = 0x00; PORTE = 0x00; PORTF = 0x00; if (verbose) USART_send_string("\tSetting SPI\r\n"); //Set the SPI bus appropriately to use the LED array SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0); }
void Setup_initializeBoard(void) { INTDisableInterrupts(); Setup_ports(); setup_ADC(); INTEnableSystemMultiVectoredInt(); Setup_timers(); RcRx_setupInputCaptures(); MotorCtrl_setupOutputCompares(); Setup_configInterrupts(); }
int main(void) { reset(); setup_ADC(); setup_UART(); println("Welcome to the read-out of the ADC"); for (;;) { ADC10CTL0 &= ~ENC; while (ADC10CTL1 & BUSY); // Wait if ADC10 core is active ADC10SA = (int)res; // Data buffer start P1OUT |= 0x01; // Set P1.0 LED on ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start __bis_SR_register(CPUOFF + GIE); // LPM0, ADC10_ISR will force exit P1OUT &= ~0x01; // Clear P1.0 LED off } }
/** \brief main loop to run tests. * * The tests being run are described in the documentation of this file. * * \return never returns, test loop runs ad infinitum. */ int main(void) { uint8_t switch_mask = 0x00; // Input switches. Read hi when pressed uint16_t result = 0; SR_t shift_reg; /* call all of the setup_* functions */ cli(); setup_clocks(); setup_LEDs(); setup_switches(switch_mask); setup_SR(&shift_reg, &SR_PORT, &SR_SPI_MODULE, false); setup_ADC(&ADC_PORT, &ADC_SPI_MODULE, ADC_CONVST_bm, ADC_EOC_bm, ADC_callback); setup_USART_BC(); sei(); set_channel(MPx, 15, &shift_reg); set_channel(MPy, 15, &shift_reg); /* signal debugging */ PORTD.DIRCLR |= PIN4_bm; PORTD.PIN4CTRL = PORT_OPC_PULLDOWN_gc; while (1) { if (ADC_ready(&adc)) { // get a new conversion result result = ADC_sample_once(&adc); } if (PORTD.IN & PIN4_bm) { LED_PORT.OUT = 0xFF; } else { LED_PORT.OUT = (uint8_t)(result >> 4); printf("%u ", result); } } }
void gen_setup(void){ usb_conn_test = Matlab_pos_tracking || go_to_location_test || debug_com || debug_goto || debug_find_puck; if (usb_conn_test ){ m_usb_init(); m_green(ON); while (!m_usb_isconnected()); m_green(OFF); } m_bus_init(); m_wii_open(); // m_port_init(PORT_ADD); setup_pins(); setup_puckfinding(); //Puck Finding Intialization setup_timer_1(); setup_timer_3(); setup_ADC(); }
//programa principal void main() { set_tris_A(0x00);/* 0000 0000 RA0 LED1 PIN 02 RA1 LED2 PIN 03 RA2 LED3 PIN 04 RA3 LED4 PIN 05 RA4 LED5 PIN 06 RA5 LED6 PIN 07 */ set_tris_B(0x00);/* (0000 0000) RB0 LED7 PIN 40 RB1 LED8 PIN 39 RB2 LED9 PIN 38 RB3 LED10 PIN 37 RB4 LED11 PIN 36 RB5 LED12 PIN 35 RB6 LED13 PIN 34 RB7 LED14 PIN 33 */ set_tris_C(0X00);/* RC0 ----- PIN 15 RC1 ----- PIN 16 RC2 ----- PIN 17 RC6 LED15 PIN 25 RC7 LED16 PIN 26 */ // Configuración de Leds 17 hasta 20 y Pulsadores 1 y 2 set_tris_D(0X00);/* RD0 SW01 PIN 19 --->Pulsador 1 RD1 SW02 PIN 20 --->Pulsador 2 RD2 ----- PIN 21 RD3 ----- PIN 22 RD4 LED17 PIN 27 RD5 LED18 PIN 28 RD6 LED19 PIN 29 RD7 LED20 PIN 30 */ set_tris_E(0x00);/* bits(**** 0000) RE0 ----- PIN 08 RE1 ----- PIN 09 RE2 ----- PIN 10 RE3 ----- PIN 01 */ //Habilitando y deshabilitando modulos... setup_timer_1(T1_disabled); setup_timer_2(T2_disabled,0,1); setup_timer_3(T3_disabled); setup_ccp1(CCP_OFF); setup_ADC(ADC_OFF); setup_VREF(FALSE);//no voltaje de referencia setup_COMPARATOR(NO_ANALOGS);// //limpie los puertos OUTPUT_A(0x00); OUTPUT_B(0x00); OUTPUT_C(0X00); OUTPUT_D(0X00); //limpiar registros, probar limpiar todos los registros en assembler con =0 //#ZERO_RAM limpiarRegistros(); /*condicional para lanzar secuencia cuando el pulsador esté presionado. */ output_float(SW01); output_float(SW02); while(TRUE) { if (input_state(SW01) == 1 && input_state(SW02) == 1) { secuencia1(); }else if (input_state(SW01) == 0 && input_state(SW02) == 1) { secuencia2(); }else if (input_state(SW01) == 1 && input_state(SW02) == 0) { secuencia4(); }else { } } //vuelva a inicio y vuelva y arranque reset_cpu(); }