Example #1
0
/**
 * \brief Configure one or more pin(s) of a PIO controller as outputs, with
 * the given default value. 
 * 
 * \param p_pio Pointer to a PIO instance.
 * \param ul_mask Bitmask indicating which pin(s) to configure.
 * \param ul_default_level Default level on the pin(s).
 * \param ul_pull_up_enable Indicates if the pin shall have its pull-up
 * activated.
 */
void _pio_set_output(Pio *p_pio, const uint32_t ul_mask, const uint32_t ul_default_level, const uint32_t ul_pull_up_enable){
	p_pio->PIO_WPMR = 0;
	p_pio->PIO_PER = ul_mask;
	p_pio->PIO_OER = ul_mask;
	if(ul_default_level){
		_pio_set(p_pio,ul_mask);
	}else{
		_pio_clear(p_pio,ul_mask);
	}
	_pio_pull_up(p_pio,ul_mask,ul_pull_up_enable);
}
Example #2
0
void _pio_set_output( Pio *p_pio, const uint32_t ul_mask, const uint32_t ul_default_level, const uint32_t ul_pull_up_enable){
	//31.6.1 PIO Enable Register
	// 1: Enables the PIO to control the corresponding pin (disables peripheral control of the pin).
	p_pio->PIO_PER |= ul_mask;
	
	// 31.6.46 PIO Write Protection Mode Register
	// 0: Disables the write protection if WPKEY corresponds to 0x50494F (PIO in ASCII).
	p_pio->PIO_WPMR = 0;
	
	if (ul_pull_up_enable)
		_pio_pull_up(p_pio,ul_mask, ul_pull_up_enable);
	
	if (ul_default_level)
		_pio_set(p_pio, ul_mask);
	else
		_pio_clear(p_pio, ul_mask);
	
	// 31.6.4 PIO Output Enable Register
	// 1: Enables the output on the I/O line.
	p_pio->PIO_OER |= ul_mask;

}
Example #3
0
int main (void)
{

	/**
	* Inicializando o clock do uP
	*/
	sysclk_init();
	
	/** 
	*  Desabilitando o WathDog do uP
	*/
	WDT->WDT_MR = WDT_MR_WDDIS;
		
	// 29.17.4 PMC Peripheral Clock Enable Register 0
	// 1: Enables the corresponding peripheral clock.
	// ID_PIOA = 11 - TAB 11-1
	//PMC->PMC_PCER0 |= (1<<ID_PIOA) | (1<<ID_PIOB);
	_pmc_enable_clock_periferico(ID_PIOA);
	_pmc_enable_clock_periferico(ID_PIOB);
	
	//PMC->PMC_PCER0 |= ID_PIOC;
	 //31.6.1 PIO Enable Register
	// 1: Enables the PIO to control the corresponding pin (disables peripheral control of the pin).	
	//PIOA->PIO_PER = (1 << PIN_LED_BLUE );
	//PIOB->PIO_PER = (1 << PIN_PUSHBUTTON_2 );
	
	//PIOA->PIO_PER |= (1 << PIN_LED_GREEN );
	//PIOC->PIO_PER |= (1 << PIN_LED_RED );
	// 31.6.46 PIO Write Protection Mode Register
	// 0: Disables the write protection if WPKEY corresponds to 0x50494F (PIO in ASCII).
	//PIOA->PIO_WPMR = 0;
	//PIOB->PIO_WPMR = 0;
	
	//PIOB->PIO_ODR  = (1 << PIN_PUSHBUTTON_2 );
	//PIOB->PIO_PUER = (1 << PIN_PUSHBUTTON_2 );

	
	// 31.6.4 PIO Output Enable Register
	// 1: Enables the output on the I/O line.
	//PIOA->PIO_OER |=  (1 << PIN_LED_BLUE );
	//PIOA->PIO_OER |=  (1 << PIN_LED_GREEN );
	//PIOC->PIO_OER |=  (1 << PIN_LED_RED );

	// 31.6.10 PIO Set Output Data Register
	// 1: Sets the data to be driven on the I/O line.
	
	_pio_set_output(PIOA,(1 << PIN_LED_BLUE ), 1, 0);
	_pio_set_input(PIOB, 1<<PIN_PUSHBUTTON_2,1);

	/**
	*	Loop infinito
	*/
		while(1){
		
            /*
             * Utilize a função delay_ms para fazer o led piscar na frequência
             * escolhida por você.
             */
			
		if(((PIOB->PIO_PDSR >> PIN_PUSHBUTTON_2) & 1) == 1)
		{
			_pio_set(PIOA,1<<PIN_LED_BLUE);
			//PIOA->PIO_SODR =  (1 << PIN_LED_BLUE );
		}
		else
		{
			_pio_clear(PIOA,1<<PIN_LED_BLUE);
			
			//PIOA->PIO_CODR =  (1 << PIN_LED_BLUE );
			
		}	
		
		
	}
Example #4
0
int main (void)
{

	/**
	* Inicializando o clock do uP
	*/
	sysclk_init();
	
	/** 
	*  Desabilitando o WathDog do uP
	*/
	WDT->WDT_MR = WDT_MR_WDDIS;
		
	// 29.17.4 PMC Peripheral Clock Enable Register 0
	// 1: Enables the corresponding peripheral clock.
	// ID_PIOA = 11 - TAB 11-1
	_pmc_enable_clock_periferico(ID_PIOA);
	_pmc_enable_clock_periferico(ID_PIOB);
	_pmc_enable_clock_periferico(ID_PIOC);
	
	_pio_set_output(PIOC, (1 << PIN_LED_RED),1,0);
	
	// 31.6.46 PIO Write Protection Mode Register
	// 0: Disables the write protection if WPKEY corresponds to 0x50494F (PIO in ASCII).
	PIOA->PIO_WPMR = 0;
//	PIOC->PIO_WPMR = 0;
	PIOB->PIO_WPMR = 0;

	 //31.6.1 PIO Enable Register
	// 1: Enables the PIO to control the corresponding pin (disables peripheral control of the pin).	
	PIOA->PIO_PER = (1 << PIN_LED_BLUE );
	PIOA->PIO_PER = (1 << PIN_LED_GREEN );
//	PIOC->PIO_PER = (1 << PIN_LED_RED );
	PIOB->PIO_PER = (1 << PIN_PUSHBUTTON_1);

	
	// 31.5.6: PIO disable buffer
	// Enables the input on the I/O line.
	PIOB->PIO_ODR = (1 << PIN_PUSHBUTTON_1);

	
	//31.5.6: Pull up enable
	//PIOB->PIO_PUER = (1 << PIN_PUSHBUTTON_1);	
	_pio_pull_up(PIOB, (1 << PIN_PUSHBUTTON_1), 1);
	
	//PIOB->PIO_IFDR = (1 << PIN_PUSHBUTTON_1);
	PIOB->PIO_IFSCER = (1 << PIN_PUSHBUTTON_1);
	

	// 31.6.4 PIO Output Enable Register
	// 1: Enables the output on the I/O line.
	PIOA->PIO_OER =  (1 << PIN_LED_BLUE );
	PIOA->PIO_OER =  (1 << PIN_LED_GREEN );
//	PIOC->PIO_OER =  (1 << PIN_LED_RED );

	// 31.6.10 PIO Set Output Data Register
	// 1: Sets the data to be driven on the I/O line.
	
	
	/* Biblioteca dos LED's
	
	//Manual do SAM4S-EK2 sessão 4.3.15 
	*Para acender os LED's verde(PA19) e azul(PA20), é necessário um baixo nivel.
	*Para acender o LED vermelho(PC20), é necessário um alto nível
	
	//Apagar os LED's
	PIOA->PIO_SODR = (1 << PIN_LED_BLUE );
	PIOA->PIO_SODR = (1 << PIN_LED_GREEN );
	PIOC->PIO_CODR = (1 << PIN_LED_RED );
	
	//Acender os LED's
	PIOA->PIO_CODR = (1 << PIN_LED_BLUE );
	PIOA->PIO_CODR = (1 << PIN_LED_GREEN );
	PIOC->PIO_SODR = (1 << PIN_LED_RED );
	
	
	*/

	/**
	*	Loop infinito
	*/
		while(1){
			
			/* WHile para verificar se o botão USRPB1 foi pressionado */
			
	//		if ( ((PIOB->PIO_PDSR >> PIN_PUSHBUTTON_1) & 1)  == 0){
			if (_pio_get_output_data_status(PIOB,1 << PIN_PUSHBUTTON_1 ) == BOTAO_1_APERTADO){
				_pio_clear(PIOA, MASK_LED_BLUE);
				_pio_set(PIOC, 1 << PIN_LED_RED );			
				delay_ms(200);
			}
			else {
				_pio_set(PIOA, MASK_LED_BLUE);
				_pio_clear(PIOC,1 << PIN_LED_RED);
				delay_ms(200);
			} 
						
			

            /*
             * Utilize a função delay_ms para fazer o led piscar na frequência
             * escolhida por você.
             */
            //delay_ms();
			
			//LED's dançando
			
			/* 
			
			for(int i = 0; i<4;i++){
			
			PIOC->PIO_SODR = (1 << PIN_LED_RED );
			PIOA->PIO_SODR = (1 << PIN_LED_BLUE );
			PIOA->PIO_SODR = (1 << PIN_LED_GREEN );
			delay_ms(TEMPO);
			
			PIOC->PIO_CODR = (1 << PIN_LED_RED );
			PIOA->PIO_CODR = (1 << PIN_LED_BLUE );
			delay_ms(TEMPO);
			
			PIOA->PIO_SODR = (1 << PIN_LED_BLUE );
			PIOA->PIO_CODR = (1 << PIN_LED_GREEN );
			delay_ms(TEMPO);
			
			}
			
			for(int i = 0; i<2;i++){
				PIOA->PIO_CODR = (1 << PIN_LED_BLUE );
				PIOA->PIO_CODR = (1 << PIN_LED_GREEN );
				PIOC->PIO_SODR = (1 << PIN_LED_RED );
				delay_ms(TEMPO*2);
				
				PIOA->PIO_SODR = (1 << PIN_LED_BLUE );
				PIOA->PIO_SODR = (1 << PIN_LED_GREEN );
				PIOC->PIO_CODR = (1 << PIN_LED_RED );
				delay_ms(TEMPO*2);
			}
			*/
	
	}
}