コード例 #1
0
/**
 * \brief initialize pins, watchdog, etc.
 */
static void init_system(void)
{
	/* Disable the watchdog */
	wdt_disable(WDT);

        /* Initialize the system clock */
	sysclk_init();

	/* Configure LED pins */
	gpio_configure_pin(LED0_GPIO, LED0_FLAGS);
	gpio_configure_pin(LED1_GPIO, LED1_FLAGS);

	/* Enable PMC clock for key/slider PIOs  */
	pmc_enable_periph_clk(ID_PIOA);
	pmc_enable_periph_clk(ID_PIOC);

	/* Configure PMC */
	pmc_enable_periph_clk(ID_TC0);

        /* Configure the default TC frequency */
	configure_tc(DEFAULT_LED_FREQ);
}
コード例 #2
0
/**
 * \brief Application entry point for usart_serial example.
 *
 * \return Unused (ANSI-C compatibility).
 */
int main(void)
{
	/* Initialize the SAM system. */
	sysclk_init();
	board_init();

	/* Configure UART for debug message output. */
	configure_console();

	/* Output example information. */
	puts(STRING_HEADER);
	puts("-- Start to echo serial inputs with PDCA -- \r\n\r");

	/* Configure TC. */
	configure_tc();

	/* Enable PDCA module clock */
	pdca_enable(PDCA);
	/* Init PDCA channel with the pdca_options.*/
	pdca_channel_set_config(PDCA_RX_CHANNEL, &pdca_rx_options);
	pdca_channel_set_config(PDCA_TX_CHANNEL, &pdca_tx_options);
	/* Enable PDCA channel, start receiving data. */
	pdca_channel_enable(PDCA_RX_CHANNEL);
	pdca_channel_enable(PDCA_TX_CHANNEL);

	/* Enable USART RXBUFF interrupt */
	usart_enable_interrupt(BOARD_USART, US_IER_RXBUFF);
	/* Configure and enable interrupt of USART. */
	NVIC_EnableIRQ(USART_IRQn);

	/* Start timer. */
	tc_start(TC0, 0);

	while (1) {
	}
}
コード例 #3
0
ファイル: main.c プロジェクト: Cbrazioli/Entregas
/* Main Code	                                                        */
/************************************************************************/
int main(void)
{
	/* Initialize the SAM system */
	sysclk_init();

	/* Disable the watchdog */
	WDT->WDT_MR = WDT_MR_WDDIS;

    /* Configura Leds */
    configure_leds();

	/** Configura o timer */
	configure_tc();
	
	/* Configura os botões */
	configure_buttons();

    
	while (1) {
		/* Entra em modo sleep */
		pmc_sleep(SAM_PM_SMODE_SLEEP_WFI);
		
	}
コード例 #4
0
/**
 *  \brief getting-started Application entry point.
 *
 *  \return Unused (ANSI-C compatibility).
 */
int main(void)
{
	/*Status flags to indicate the re-burst for library */
	uint16_t status_flag = 0u;
	uint16_t burst_flag = 0u;

	/* Initialize the SAM system */
	init_system();

	/* Reset touch sensing */
	qt_reset_sensing();

	/* Configure the Sensors as keys or Keys With Rotor/Sliders in this
	   function */
	config_sensors();

	/* Initialize touch sensing */
	qt_init_sensing();

	/* Set the parameters like recalibration threshold, Max_On_Duration etc
	   in this function by the user */
	qt_set_parameters();

	/* Configure timer ISR to fire regularly */
	init_timer_isr();

	/* Address to pass address of user functions */

	/* This function is called after the library has made capacitive
	   measurements, but before it has processed them. The user can
	   use this hook to apply filter functions to the measured signal
	   values.(Possibly to fix sensor layout faults) */
	qt_filter_callback = 0;

	/* Loop forever */
	for (;;) {
		if (time_to_measure_touch) {
			/* Clear flag: it's time to measure touch */
			time_to_measure_touch = 0u;

			do {
				/*  One time measure touch sensors    */
				status_flag = qt_measure_sensors
							(current_time_ms_touch);

				burst_flag = status_flag & QTLIB_BURST_AGAIN;

				/*Time critical host application code goes here */

			} while (burst_flag);
		}

		/* Get slider value and update the blink frequency */
		if (GET_ROTOR_SLIDER_POSITION(0) != qt_shift_data) {
			qt_shift_data = GET_ROTOR_SLIDER_POSITION(0);
#ifdef QT_DATA_REVERT
			configure_tc((QT_MAX_DATA - qt_shift_data)/LED_FREQ_DIV);
#else
			configure_tc(qt_shift_data/LED_FREQ_DIV);
#endif
		}
	}
}
コード例 #5
0
/**
 * \brief Configures the DAC in event triggered mode.
 *
 * Configures the DAC to use the module's default configuration, with output
 * channel mode configured for event triggered conversions.
 *
 * \param dev_inst  Pointer to the DAC module software instance to initialize
 */
static void configure_dac(struct dac_module *dac_module)
{
    struct dac_config config;
    struct dac_chan_config channel_config;

    /* Get the DAC default configuration */
    dac_get_config_defaults(&config);

    /* Switch to GCLK generator 0 */
    config.clock_source = GCLK_GENERATOR_0;

    dac_init(dac_module, DAC, &config);

    /* Get the default DAC channel config */
    dac_chan_get_config_defaults(&channel_config);

    /* Set the channel configuration, and enable it */
    dac_chan_set_config(dac_module, DAC_CHANNEL_0, &channel_config);
    dac_chan_enable(dac_module, DAC_CHANNEL_0);

    /* Enable event triggered conversions */
    struct dac_events events = { .on_event_start_conversion = true };
    dac_enable_events(dac_module, &events);

    dac_enable(dac_module);
}

/**
 * \brief Configures the TC to generate output events at the sample frequency.
 *
 * Configures the TC in Frequency Generation mode, with an event output once
 * each time the audio sample frequency period expires.
 *
 * \param dev_inst  Pointer to the TC module software instance to initialize
 */
static void configure_tc(struct tc_module *tc_module)
{
    struct tc_config config;
    tc_get_config_defaults(&config);

    config.clock_source    = GCLK_GENERATOR_0;
    config.wave_generation = TC_WAVE_GENERATION_MATCH_FREQ;

    tc_init(tc_module, TC3, &config);

    /* Enable periodic event output generation */
    struct tc_events events = { .generate_event_on_overflow = true };
    tc_enable_events(tc_module, &events);

    /* Set the timer top value to alter the overflow frequency */
    tc_set_top_value(tc_module,
                     system_gclk_gen_get_hz(GCLK_GENERATOR_0) / sample_rate);


    tc_enable(tc_module);
}

/**
 * \brief Configures the event system to link the sample timer to the DAC.
 *
 * Configures the event system, linking the TC module used for the audio sample
 * rate timing to the DAC, so that a new conversion is triggered each time the
 * DAC receives an event from the timer.
 */
static void configure_events(struct events_resource *event)
{
    struct events_config config;

    events_get_config_defaults(&config);

    config.generator    = EVSYS_ID_GEN_TC3_OVF;
    config.path         = EVENTS_PATH_ASYNCHRONOUS;

    events_allocate(event, &config);
    events_attach_user(event, EVSYS_ID_USER_DAC_START);
}

/**
 * \brief Main application routine
 */
int main(void)
{
    struct dac_module dac_module;
    struct tc_module tc_module;
    struct events_resource event;

    /* Initialize all the system clocks, pm, gclk... */
    system_init();

    /* Enable the internal bandgap to use as reference to the DAC */
    system_voltage_reference_enable(SYSTEM_VOLTAGE_REFERENCE_BANDGAP);

    /* Module configuration */
    configure_tc(&tc_module);
    configure_dac(&dac_module);
    configure_events(&event);

    /* Start the sample trigger timer */
    tc_start_counter(&tc_module);

    while (true) {
        while (port_pin_get_input_level(SW0_PIN) == SW0_INACTIVE) {
            /* Wait for the button to be pressed */
        }

        port_pin_toggle_output_level(LED0_PIN);

        for (uint32_t i = 0; i < number_of_samples; i++) {
            dac_chan_write(&dac_module, DAC_CHANNEL_0, wav_samples[i]);

            while (!(DAC->INTFLAG.reg & DAC_INTFLAG_EMPTY)) {
                /* Wait for data buffer to be empty */
            }

        }

        while (port_pin_get_input_level(SW0_PIN) == SW0_ACTIVE) {
            /* Wait for the button to be depressed */
        }
    }
}
コード例 #6
0
int main(void)
{
	sysclk_init();
	board_init();

	/** Initialize debug console */
	configure_console();

	/** Enable peripheral clock */
	pmc_enable_periph_clk(ID_SMC);

	/** Configure SMC interface for Lcd */
	smc_set_setup_timing(SMC, ILI93XX_LCD_CS, SMC_SETUP_NWE_SETUP(2)
			| SMC_SETUP_NCS_WR_SETUP(2)
			| SMC_SETUP_NRD_SETUP(2)
			| SMC_SETUP_NCS_RD_SETUP(2));
	smc_set_pulse_timing(SMC, ILI93XX_LCD_CS, SMC_PULSE_NWE_PULSE(4)
			| SMC_PULSE_NCS_WR_PULSE(4)
			| SMC_PULSE_NRD_PULSE(10)
			| SMC_PULSE_NCS_RD_PULSE(10));
	smc_set_cycle_timing(SMC, ILI93XX_LCD_CS, SMC_CYCLE_NWE_CYCLE(10)
			| SMC_CYCLE_NRD_CYCLE(22));
#if ((!defined(SAM4S)) && (!defined(SAM4E)))
	smc_set_mode(SMC, ILI93XX_LCD_CS, SMC_MODE_READ_MODE
			| SMC_MODE_WRITE_MODE
			| SMC_MODE_DBW_8_BIT);
#else
	smc_set_mode(SMC, ILI93XX_LCD_CS, SMC_MODE_READ_MODE
			| SMC_MODE_WRITE_MODE);
#endif
	/** Initialize display parameter */
	g_ili93xx_display_opt.ul_width = ILI93XX_LCD_WIDTH;
	g_ili93xx_display_opt.ul_height = ILI93XX_LCD_HEIGHT;
	g_ili93xx_display_opt.foreground_color = COLOR_BLACK;
	g_ili93xx_display_opt.background_color = COLOR_WHITE;

	/** Switch off backlight */
	aat31xx_disable_backlight();

	/** Initialize LCD */
	ili93xx_init(&g_ili93xx_display_opt);

	/** Set backlight level */
	aat31xx_set_backlight(AAT31XX_AVG_BACKLIGHT_LEVEL);

	ili93xx_set_foreground_color(COLOR_WHITE);
	ili93xx_draw_filled_rectangle(0, 0, ILI93XX_LCD_WIDTH,
			ILI93XX_LCD_HEIGHT);
	/** Turn on LCD */
	ili93xx_display_on();
	ili93xx_set_cursor_position(0, 0);

	/** Draw text, image and basic shapes on the LCD */
	ili93xx_set_foreground_color(COLOR_RED);
	ili93xx_draw_string(10, 20, (uint8_t *)"     13 - LCD");
	ili93xx_set_foreground_color(COLOR_BLACK);
	ili93xx_draw_string(40, 40, (uint8_t *)"   Renan");
	ili93xx_draw_string(70, 70, (uint8_t *)"Henrique");
	
	ili93xx_set_foreground_color(COLOR_RED);
	ili93xx_draw_filled_rectangle(240,110,0,120);
	ili93xx_set_foreground_color(COLOR_GREEN);
	ili93xx_draw_filled_rectangle(240, 120, 0,130);
	/* Configura os botões */
	configure_buttons();
	configure_tc();
	while (1) {
	}
}
コード例 #7
0
ファイル: main.c プロジェクト: diman2/tetris_samd10
/**
 *  \brief getting-started Application entry point.
 *
 *  \return Unused (ANSI-C compatibility).
*/
int main(void)
{
    struct port_config pin;
    unsigned char c;

    system_init();

    //Configure UART console.
    configure_console();

    configure_usart_callbacks();
    usart_enable_rx_interrupt(&cdc_uart_module,&c);

    usart_enable(&cdc_uart_module);
    //Configures  TC driver
    configure_tc();

    //Configures TC callback
    configure_tc_callbacks();

    //Initialize the delay driver
    delay_init();

    //Enable system interrupt
    system_interrupt_enable_global();

    //Configures PORT for LED0
    port_get_config_defaults(&pin);
    pin.direction = PORT_PIN_DIR_OUTPUT;
    port_pin_set_config(LED0_PIN, &pin);

    port_pin_set_output_level(LED0_PIN, LED0_INACTIVE);
    port_pin_set_output_level(LED0_PIN, LED0_INACTIVE);

    /*main loop*/
    while(1)
    {
        if (is_running)
        {
            //Handle user's input
            //		if (uart_getc(&c))
            //		{
            switch (c)
            {
            case 'w':
            case ' ':
                //ROTATE
                tetris_rotate();
                break;
            case 's':
                //DOWN
                tetris_gravity();
                break;
            case 'd':
                //RIGHT
                tetris_move_right();
                break;
            case 'a':
                //LEFT
                tetris_move_left();
                break;
            default:
                break;
            }
            c=0;
            //		}
            // was here if(!iterate_game)
            if(iterate_game)
            {
                //Update game
                iterate_game = false;
                tetris_gravity();
                tetris_check_lines();
                terminal_cursor_home();
                tetris_print();
                if (tetris_is_game_over())
                {
                    is_running = false;
                }
            }
        }
        else
        {
            //	if (uart_getc(&c))
            //	{
            if (c == 'n')
            {
                c=0;
                //Seed random function so we do not get same start condition
                //for each new game. In essence we will not start a new game
                //exactly at the same time.
                srand(tick);

                //New Game
                is_running = true;
                terminal_cursor_off();
                terminal_clear();
                tetris_init();
                tetris_new_block();
                terminal_cursor_home();
                tetris_print();
            }
            //	}
        }
    }
}
コード例 #8
0
ファイル: main.c プロジェクト: RenanLoyola/Maua-trabalhos
int main(void)
{
	uint8_t vetor[TAMANHO+1];
	uint8_t uc_key;
	uint8_t rtn;

	/* Initialize the system */
	sysclk_init();
	board_init();


	/* Initialize debug console */
	config_uart();

	/* Initialize_tc */
	configure_tc();

	/* Initialize Led */
	config_led();
	
	/* frase de boas vindas */
	puts(" ---------------------------- \n\r"
	 	 " Bem vindo terraquio !		\n\r"
		 " ---------------------------- \n\r");
		 
	/* display main menu */
	display_menu();
	
	/* init var */
	vetor[TAMANHO] = STRING_NULL;
	
	while (1) {

		while(!g_UartStrgOk){ 
			pmc_sleep(SAM_PM_SMODE_SLEEP_WFI);
		};

		//rtn = readvec(&vetor[0]);
	
			if (strcmp(g_UartStrg, "LGON") == 0)
			{
				pio_clear(PORT_LED_GREEN, MASK_LED_GREEN);
				puts("Led ON \n\r");
			}
			else if (strcmp(g_UartStrg, "LBPISCA") == 0)
			{
			flagB = 1;	
			puts("Pisca LED azul \n\r");	
			}
			else if (strcmp(g_UartStrg, "LGPISCA") == 0)
			{
				flagG = 2;
			}
			else if (strcmp(g_UartStrg, "LBON") == 0)
			{
				pio_clear(PORT_LED_BLUE, MASK_LED_BLUE);
				puts("Led ON \n\r");
			}
			else if (strcmp(g_UartStrg, "LRON") == 0)
			{
				pio_set(PORT_LED_RED, MASK_LED_RED);
				puts("Led ON \n\r");
			}
			else if (strcmp(g_UartStrg, "LGOFF") == 0)
			{
			pio_set(PORT_LED_GREEN, MASK_LED_GREEN);
			puts("Led OFF \n\r");	
			flagG = 0 ;
			}
			else if (strcmp(g_UartStrg, "LBOFF") == 0)
			{
				pio_set(PORT_LED_BLUE, MASK_LED_BLUE);
				puts("Led OFF \n\r");
				flagB = 0;
			}
			else if (strcmp(g_UartStrg, "LROFF") == 0)
			{
				pio_clear(PORT_LED_RED, MASK_LED_RED);
				puts("Led OFF \n\r");
			}
			else if (strcmp(g_UartStrg, "FREQ1") == 0)
			{
				tc_write_rc(TC0,0,8000);
				puts("Frequencia 8000 \n\r");
			}
			else if (strcmp(g_UartStrg, "FREQ2") == 0)
			{
				tc_write_rc(TC0,0,4000);
				puts("Frequencia 4000 \n\r");
			}
			else if (strcmp(g_UartStrg, "FREQ3") == 0)
			{
				tc_write_rc(TC0,0,2000);
				puts("Frequencia 2000 \n\r");
			}
			
			/* more else if clauses */
			else 
			{
				printf("[INFO] Opcao nao definida: %s \n\r", g_UartStrg);
			}

			//g_UartStrgAck = 1;
			limparvetor();

	}
}
コード例 #9
0
ファイル: parc_example.c プロジェクト: InSoonPark/asf
/**
 * \brief Application entry point for PARC example.
 *
 * \return Unused (ANSI-C compatibility).
 */
int main(void)
{
	uint32_t uc_key;

	/* Initialize the SAM system. */
	sysclk_init();
	board_init();

	/* Configure UART for debug message output. */
	configure_console();
	parc_port_source_simulation_config();

	//! [parc_variables]	
	struct parc_module module_inst;
	struct parc_config config;
	//! [parc_variables]	

	/* Output example information. */
	puts(STRING_HEADER);

	/* Configure TC. */
	configure_tc();
	/* Start timer. */
	tc_start(TC0, 0);

	//! [parc_get_defaults]	
	// Get default configuration
	parc_get_config_defaults(&config);
	//! [parc_get_defaults]	
	printf("Press y to sample the data when both data enable pins are enabled.\r\n");
	printf("Press n to sample the data, don't care the status of the data enable pins.\r\n");
	uc_key = 0;
	while ((uc_key != 'y') && (uc_key != 'n')) {
		usart_read(CONF_UART, &uc_key);
	}
	if (uc_key == 'y') {
		/* Sample the data when both data enable pins are enabled. */
		config.smode = PARC_SMODE_PCEN1_AND_PCEN2_H;
		ioport_set_pin_level(PIN_PCEN1_INPUT, IOPORT_PIN_LEVEL_HIGH);
		ioport_set_pin_level(PIN_PCEN2_INPUT, IOPORT_PIN_LEVEL_HIGH);
		printf("Receive data when both data enable pins are enabled.\r\n");
	} else {
		/* Sample the data, don't care the status of the data enable pins. */
		config.smode = PARC_SMODE_ALWAYS;
		printf("Receive data, don't care the status of the data enable pins.\r\n");
	}

	printf("Press y to sample all the data.\r\n");
	printf("Press n to sample the data only one out of two.\r\n");
	uc_key = 0;
	while ((uc_key != 'y') && (uc_key != 'n')) {
		usart_read(CONF_UART, &uc_key);
	}
	if (uc_key == 'y') {
			/* Sample all the data. */
		config.capture_mode = PARC_BOTH_CAPTURE;
		printf("All data are sampled.\r\n");
	} else {
		/* Sample the data only one out of two. */
		config.capture_mode = PARC_EVEN_CAPTURE;
		printf("Only one out of two data is sampled, with an even index.\r\n");
	}

	//! [parc_init_enable_and_start]
	//! [parc_init_enable_and_start_1]
	// Initialize PARC.
	parc_init(&module_inst, PARC, &config);
	//! [parc_init_enable_and_start_1]
	
	//! [parc_init_enable_and_start_2]
	// Enable the PARC
	parc_enable(&module_inst);
	
	// Start capture.
	parc_start_capture(&module_inst);
	//! [parc_init_enable_and_start_2]
	//! [parc_init_enable_and_start]

	/* Enable PDCA module clock */
	pdca_enable(PDCA);
	/* Init PDCA channel with the pdca_options.*/
	pdca_channel_set_config(PDCA_PARC_CHANNEL, &PDCA_PARC_OPTIONS);

	/* Set callback for PDCA interrupt. */
	pdca_channel_set_callback(PDCA_PARC_CHANNEL,
			pdca_parc_callback,PDCA_0_IRQn,1,PDCA_IER_RCZ);

	/* Enable PDCA channel, start receiving data. */
	pdca_channel_enable(PDCA_PARC_CHANNEL);
	/* Start read PARC data capture via PDCA. */
	pdca_channel_write_load(PDCA_PARC_CHANNEL,
			(void *)gs_puc_buffer, BUFFER_SIZE);
	/* Main loop. */
	while(1) {
	}
}
コード例 #10
0
ファイル: main.c プロジェクト: AlexShiLucky/freertos
// [main]
int main(void)
{
//! [main_step_sys_init]
	/* Initialize the SAM system */
	sysclk_init();
	board_init();
//! [main_step_sys_init]

#ifndef BOARD_NO_PUSHBUTTON_2
#if (SAMV71 || SAMV70 || SAMS70 || SAME70)
	if (GPIO_PUSH_BUTTON_2 == PIO_PB12_IDX) {
		matrix_set_system_io(matrix_get_system_io() | CCFG_SYSIO_SYSIO12);
	}
	ioport_set_pin_dir(GPIO_PUSH_BUTTON_2, IOPORT_DIR_INPUT);
	ioport_set_pin_mode(GPIO_PUSH_BUTTON_2, GPIO_PUSH_BUTTON_2_FLAGS);
	ioport_set_pin_sense_mode(GPIO_PUSH_BUTTON_2, GPIO_PUSH_BUTTON_2_SENSE);
#endif
#endif
//! [main_step_console_init]
	/* Initialize the console uart */
	configure_console();
//! [main_step_console_init]

	/* Output example information */
	puts(STRING_HEADER);

	/* Configure systick for 1 ms */
	puts("Configure system tick to get 1ms tick period.\r");
//! [main_step_systick_init]
	if (SysTick_Config(sysclk_get_cpu_hz() / 1000)) {
		puts("-F- Systick configuration error\r");
		while (1);
	}
//! [main_step_systick_init]

#ifndef BOARD_NO_LED_1
	puts("Configure TC.\r");
//! [main_step_tc_init]
	configure_tc();
//! [main_step_tc_init]
#endif

	puts("Configure buttons with debouncing.\r");
//! [main_step_btn_init]
	configure_buttons();
//! [main_step_btn_init]

	printf("Press %s to Start/Stop the %s blinking.\r\n",
			PUSHBUTTON_1_NAME, LED_0_NAME);

#ifndef BOARD_NO_PUSHBUTTON_2
	printf("Press %s to Start/Stop the %s blinking.\r\n",
			PUSHBUTTON_2_NAME, LED_1_NAME);
#endif

//! [main_step_loop]
	while (1) {
		/* Wait for LED to be active */
		while (!g_b_led0_active);

		/* Toggle LED state if active */
		if (g_b_led0_active) {
			ioport_toggle_pin_level(LED0_GPIO);
			printf("1 ");
		}

		/* Wait for 500ms */
		mdelay(500);
	}
//! [main_step_loop]
}
コード例 #11
0
ファイル: main.c プロジェクト: EduGalinskas/Entregas
int main(void)
{
	uint8_t uc_key;

	/* Initialize the system */
	sysclk_init();
	board_init();

	/* Configure LED 1 */
	pmc_enable_periph_clk(PIN_LED_BLUE_ID);
	pio_set_output(PIN_LED_BLUE_PIO , PIN_LED_BLUE_MASK, 1, 0, 0);

	/* Initialize debug console */
	config_uart();
	
	/* frase de boas vindas */
	puts(" ---------------------------- \n\r"
	 	 " Bem vindo terraquio !		\n\r"
		 " ---------------------------- \n\r");
	
	/* Enable peripheral clock */
	pmc_enable_periph_clk(ID_SMC);

	/** Configura o LEDs */
	configure_leds();

	/** Configura o timer */
	configure_tc();


	/* Configuração LCD */
	configure_lcd();
	
	desenhaCabecalho();
	
	/* display main menu */
	display_menu();

	while (1) {
		
		
		usart_serial_getchar((Usart *)CONSOLE_UART, &uc_key);	
		switch (uc_key) {
			case '1':
				display_menu();
				break;
			case '2':
				flagLED = 0;
				pio_clear(PIN_LED_BLUE_PIO, PIN_LED_BLUE_MASK);
				puts("Led ON \n\r");
				break;
			case '3' :
				flagLED = 1;
				pio_set(PIN_LED_BLUE_PIO, PIN_LED_BLUE_MASK);
				puts("Led OFF \n\r");
				break;
			case '4' :
				flagLED = 2;
				pio_set(PIN_LED_BLUE_PIO, PIN_LED_BLUE_MASK);
				puts("Led OFF \n\r");
				break;
			case '5' :
				flagLED = 3;
				pio_set(PIN_LED_BLUE_PIO, PIN_LED_BLUE_MASK);
				puts("Defina a o valor da Frequência (0-65356) \n\r");
				usart_serial_getchar((Usart *)CONSOLE_UART, &uc_key);
				//tc_write_rc(uc_key);
				break;
				
			default:
				printf("Opcao nao definida: %d \n\r", uc_key);
		}	
	}
}
コード例 #12
0
ファイル: main.c プロジェクト: zearaujo25/Entregas
int main(void)
{
	uint8_t uc_key;

	/* Initialize the system */
	sysclk_init();
	board_init();

	/* Configure LED 1 */
	pmc_enable_periph_clk(ID_LED_BLUE);
	pio_set_output(PORT_LED_BLUE  , MASK_LED_BLUE	,1,0,0);

	/* Initialize debug console */
	config_uart();
	
	/* frase de boas vindas */
	puts(" ---------------------------- \n\r"
	 	 " Bem vindo Corsi  !		\n\r"
		 " ---------------------------- \n\r");
		 
	/* display main menu */
	display_menu();
	configure_tc();
	TC0_Handler();
	
	pio_clear(PORT_LED_RED, MASK_LED_RED);
	pio_set(PORT_LED_GREEN, MASK_LED_GREEN);
	
	PIOA->PIO_PER = (1 << PIN_LED_BLUE );
	PIOA->PIO_OER |=  (1 << PIN_LED_BLUE );
	
	
	PMC->PMC_PCER0 |= ID_PIOC;
	PIOC->PIO_PER |= (1 << PIN_LED_RED );
	PIOC->PIO_OER |=  (1 << PIN_LED_RED );
	
	
	tc_stop(TC0, 0);
	PIOA->PIO_SODR = (1 << PIN_LED_BLUE );
	PIOC->PIO_CODR = (1 << PIN_LED_RED );
	
	while (1) {
		usart_serial_getchar((Usart *)CONSOLE_UART, &uc_key);	
		switch (uc_key) {
			case '1':
				display_menu();
				break;
			case '2':
				tc_start(TC0,0);
				PIOA->PIO_CODR = (1 << PIN_LED_BLUE );
				
				puts("Led BLUE ON \n\r");
				break;
			case '3' :
				tc_stop(TC0, 0);
				PIOA->PIO_SODR = (1 << PIN_LED_BLUE );
				puts("Led BLUE OFF \n\r");
			
				break;
			case '4':
				tc_start(TC0,0);
				pio_clear(PORT_LED_GREEN, MASK_LED_GREEN);
				puts("Led GREEN ON \n\r");
				break;
			case '5' :
				tc_stop(TC0, 0);

				pio_set(PORT_LED_GREEN, MASK_LED_GREEN);
				puts("Led GREEN OFF \n\r");
				break;
			case '6':
					tc_start(TC0,0);
					PIOC->PIO_SODR = (1 << PIN_LED_RED );
				
				puts("Led RED ON \n\r");
			break;
			case '7' :
				tc_stop(TC0, 0);
				PIOC->PIO_CODR = (1 << PIN_LED_RED );
				puts("Led RED OFF \n\r");
			break;
			case '8' :
				
				tc_write_rc(TC0, 0, tc_read_rc(TC0,0) * 0.5);
				puts("aumentando \n\r");
				break;
			case '9' :
				
				tc_write_rc(TC0, 0, tc_read_rc(TC0,0) * 1.4);
				puts("diminuindo \n\r");
				break;				
			default:
				printf("Opcao nao definida: %d \n\r", uc_key);
		}	
	}
}
コード例 #13
0
/**
 * \brief Application entry point for smc_lcd example.
 *
 * \return Unused (ANSI-C compatibility).
 */
int main(void)
{
	sysclk_init();
	board_init();
	
	/** Configura os botões, o TC e desabilita o Watchdog Timer. */
	configure_buttons();
	WDT->WDT_MR = WDT_MR_WDDIS;
	configure_tc();

	/** Initialize debug console */
	configure_console();

	/** Enable peripheral clock */
	pmc_enable_periph_clk(ID_SMC);

	/** Configure SMC interface for Lcd */
	smc_set_setup_timing(SMC, ILI93XX_LCD_CS, SMC_SETUP_NWE_SETUP(2)
			| SMC_SETUP_NCS_WR_SETUP(2)
			| SMC_SETUP_NRD_SETUP(2)
			| SMC_SETUP_NCS_RD_SETUP(2));
	smc_set_pulse_timing(SMC, ILI93XX_LCD_CS, SMC_PULSE_NWE_PULSE(4)
			| SMC_PULSE_NCS_WR_PULSE(4)
			| SMC_PULSE_NRD_PULSE(10)
			| SMC_PULSE_NCS_RD_PULSE(10));
	smc_set_cycle_timing(SMC, ILI93XX_LCD_CS, SMC_CYCLE_NWE_CYCLE(10)
			| SMC_CYCLE_NRD_CYCLE(22));
#if ((!defined(SAM4S)) && (!defined(SAM4E)))
	smc_set_mode(SMC, ILI93XX_LCD_CS, SMC_MODE_READ_MODE
			| SMC_MODE_WRITE_MODE
			| SMC_MODE_DBW_8_BIT);
#else
	smc_set_mode(SMC, ILI93XX_LCD_CS, SMC_MODE_READ_MODE
			| SMC_MODE_WRITE_MODE);
#endif
	/** Initialize display parameter */
	g_ili93xx_display_opt.ul_width = ILI93XX_LCD_WIDTH;
	g_ili93xx_display_opt.ul_height = ILI93XX_LCD_HEIGHT;
	g_ili93xx_display_opt.foreground_color = COLOR_BLACK;
	g_ili93xx_display_opt.background_color = COLOR_WHITE;

	/** Switch off backlight */
	aat31xx_disable_backlight();

	/** Initialize LCD */
	ili93xx_init(&g_ili93xx_display_opt);

	/** Set backlight level */
	aat31xx_set_backlight(AAT31XX_AVG_BACKLIGHT_LEVEL);

	ili93xx_set_foreground_color(COLOR_WHITE);
	ili93xx_draw_filled_rectangle(0, 0, ILI93XX_LCD_WIDTH,
			ILI93XX_LCD_HEIGHT);
			
	/** Turn on LCD */
	ili93xx_display_on();
	ili93xx_set_cursor_position(0, 0);

	/** Escreve os nomes no display. */
	ili93xx_set_foreground_color(COLOR_BLACK);
	ili93xx_draw_string(10, 20, (uint8_t *)"Bruna Tavares");
	ili93xx_draw_string(10, 40, (uint8_t *)"Bruno Campos");
	ili93xx_draw_string(10, 60, (uint8_t *)"Keneth Yamada");
	
	/** Desenha linha */
	ili93xx_set_foreground_color(COLOR_BLUEVIOLET);
	ili93xx_draw_line(0, 90, 240, 90);
	
	/** Escreve contador e tempo no display. */
	ili93xx_set_foreground_color(COLOR_BLACK);
	ili93xx_draw_string(10, 110, (uint8_t *)"Contador");
	ili93xx_draw_string(10, 300, (uint8_t *)"Tempo ");

	/** Escreve valores iniciais do contador. */
	ili93xx_draw_string(130, 110, (uint8_t *)"000");
	ili93xx_draw_string(140, 300, (uint8_t *)"00:00");	

	while (1) {
		// Coloca o microcontrolador em modo Sleep aguardando interrupções.
		pmc_sleep(SAM_PM_SMODE_SLEEP_WFI);
	}
}
コード例 #14
0
int main(void)
{
	uint8_t ucKey;

	/* Disable watchdog */
	wdt_disable();

	/* Configure console */
	board_cfg_console();

	/* Output example information */
	printf("\r\n\r\n\r\n");
	printf("-- RTC Example " SOFTPACK_VERSION " --\r\n");
	printf("-- " BOARD_NAME "\r\n");
	printf("-- Compiled: " __DATE__ " " __TIME__ " --\n\r");

	// put 25 °C as a default temp, if there is no temprature sensor
	Temperature = 25;

	printf("Configure TC.\r\n");
	configure_tc();

	/* Default RTC configuration */
	rtc_set_hour_mode(0);	/* 24-hour mode */
	struct _time empty_time = {0,0,0};
	if (rtc_set_time_alarm(&empty_time)) {
		printf("\r\n Disable time alarm fail!");
	}
	struct _date empty_date = {0,0,0};
	if (rtc_set_date_alarm(&empty_date)) {
		printf("\r\n Disable date alarm fail!");
	}

	/* Configure RTC interrupts */
	rtc_enable_it(RTC_IER_SECEN | RTC_IER_ALREN);
	aic_set_source_vector(ID_SYSC, sysc_handler);
	aic_enable(ID_SYSC);

	/* Refresh display once */
	_RefreshDisplay();
	new_time.hour = 0;
	new_time.min = 0;
	new_time.sec = 30;
	rtc_set_time_alarm(&new_time);
	bMenuShown = 0;
	alarmTriggered = 0;
	rtc_calibration(Temperature);

	/* Handle keypresses */
	while (1) {
		ucKey = console_get_char();

		/* set time */
		if (ucKey == 't') {
			bState = STATE_SET_TIME;
			aic_disable(ID_TC0);

			do {
				printf("\r\n\r\n Set time(hh:mm:ss): ");
			} while (get_new_time());

			/* if valid input, none of variable for time is 0xff */
			if (new_time.hour != 0xFF) {
				if (rtc_set_time (&new_time)) {
					printf
					    ("\r\n Time not set, invalid input!\n\r");
				}
			}

			bState = STATE_MENU;
			bMenuShown = 0;
			_RefreshDisplay();
			CountDownTimer = 0;
			aic_enable(ID_TC0);
		}

		/* clock calibration */
		else if (ucKey == 'p') {

			rtc_calibration(30);

			bState = STATE_MENU;
			bMenuShown = 0;
			_RefreshDisplay();
		}

		/* set date */
		else if (ucKey == 'd') {
			bState = STATE_SET_DATE;
			aic_disable(ID_TC0);

			do {
				printf("\r\n\r\n Set date(mm/dd/yyyy): ");
			} while (get_new_date());

			/* if valid input, none of variable for date is 0xff(ff) */
			if (new_date.year != 0xFFFF) {
				if (rtc_set_date(&new_date)) {
					printf
					    ("\r\n Date not set, invalid input!\r\n");
				}
			}

			/* only 'mm/dd' inputed */
			if (new_date.month != 0xFF && new_date.year == 0xFFFF) {
				printf("\r\n Not Set for no year field!\r\n");
			}

			bState = STATE_MENU;
			bMenuShown = 0;
			CountDownTimer = 0;
			aic_enable(ID_TC0);
			_RefreshDisplay();
		}

		/* set time alarm */
		else if (ucKey == 'i') {
			bState = STATE_SET_TIME_ALARM;
			aic_disable(ID_TC0);

			do {
				printf("\r\n\r\n Set time alarm(hh:mm:ss): ");
			} while (get_new_time());

			if (new_time.hour != 0xFF) {
				if (rtc_set_time_alarm(&new_time)) {
					printf
					    ("\r\n Time alarm not set, invalid input!\r\n");
				} else {
					printf
					    ("\r\n Time alarm is set at %02d:%02d:%02d!",
					     new_time.hour, new_time.min, new_time.sec);
				}
			}
			bState = STATE_MENU;
			bMenuShown = 0;
			alarmTriggered = 0;
			CountDownTimer = 0;
			aic_enable(ID_TC0);
			_RefreshDisplay();
		}

		/* set date alarm */
		else if (ucKey == 'm') {
			bState = STATE_SET_DATE_ALARM;
			aic_disable(ID_TC0);

			do {
				printf("\r\n\r\n Set date alarm(mm/dd/): ");
			} while (get_new_date());

			if (new_date.year == 0xFFFF && new_date.month != 0xFF) {
				if (rtc_set_date_alarm(&new_date)) {
					printf
					    ("\r\n Date alarm not set, invalid input!\r\n");
				} else {
					printf
					    ("\r\n Date alarm is set on %02d/%02d!",
					     new_date.month, new_date.day);
				}

			}
			bState = STATE_MENU;
			bMenuShown = 0;
			alarmTriggered = 0;
			CountDownTimer = 0;
			aic_enable(ID_TC0);
			_RefreshDisplay();
		}

		/* clear trigger flag */
		else if (ucKey == 'c') {
			alarmTriggered = 0;
			bMenuShown = 0;
			_RefreshDisplay();
		}

		/* quit */
		else if (ucKey == 'q') {
			break;
		}
	}

	return 0;
}
コード例 #15
0
ファイル: lin_mngt_example.c プロジェクト: thegeek82000/asf
/**
 * \brief This is an example demonstrating the LIN mode of USART IP
 * functionalities using a dedicated USART LIN driver.
 */
int main(void)
{
	st_lin_message lin_desc;
	uint8_t uc_key;

	/* Initialize the SAM system. */
	sysclk_init();
	board_init();

	/* Configure UART for debug message output. */
	configure_console();

	/* Output example information. */
	puts(STRING_HEADER);

	/* Enable the peripheral clock in the PMC. */
	pmc_enable_periph_clk(ID_USART0);

	/* Enable LIN transceiver */
	gpio_set_pin_high(PIN_USART0_CTS_IDX);
	gpio_set_pin_high(PIN_USART0_RTS_IDX);

	display_menu();

	while (true) {
		while (uart_read(CONSOLE_UART, &uc_key)) {
		}

		switch (uc_key) {
		case 'm':
		case 'M':
			puts("-- Set LIN to Master mode\n\r");

			/* Node 0:  LIN_MASTER_MODE */
			lin_init(USART0, true, LIN_MASTER_NODE_NUM, 9600,
					sysclk_get_cpu_hz());

			/* Configure lin_descriptor */
			/* Init LIN data Node 0 */
			/* Object 0 */
			lin_desc.uc_id = LIN_FRAME_ID_12;
			lin_desc.uc_dlc = sizeof(lin_data_node);
			lin_desc.lin_cmd = PUBLISH;
			lin_desc.uc_status = 0;
			lin_desc.uc_pt_data = lin_data_node;
			lin_register_descriptor(LIN_MASTER_NODE_NUM, 0, &lin_desc);

			configure_tc();
			/* In case of Master Mode, the timing transmission starts. */
			tc_start(TC0, 0);
			break;

		case 's':
		case 'S':
			puts("-- Set LIN to Slave mode\n\r");
			/* Node 0:  LIN_SLAVE_MODE */
			lin_init(USART0, false, LIN_SLAVE_NODE_NUM, 9600,
					sysclk_get_cpu_hz());

			/* Configure lin_descriptor */
			/* Init LIN data Node 0 */
			/* Object 0 */
			lin_desc.uc_id = LIN_FRAME_ID_12;
			lin_desc.uc_dlc = sizeof(lin_data_node);
			lin_desc.lin_cmd = SUBSCRIBE;
			lin_desc.uc_status = 0;
			lin_desc.uc_pt_data = lin_data_node;
			lin_desc.pt_function = lin_slave_task_ID12;
			lin_register_descriptor(LIN_SLAVE_NODE_NUM, 0, &lin_desc);

			/* Configure and enable interrupt of USART. */
			NVIC_EnableIRQ(USART0_IRQn);
			usart_enable_interrupt(USART0, US_IER_LINID);
			/* In case of Slave Mode, only wait for ID reception. */
			break;

		case 'h':
		case 'H':
			display_menu();
			break;
		}
		puts("Press \'h\' or \'H\' to display the main menu again!!\r");
	}
}