Esempio n. 1
0
void bluetooth_init(void)
{
	ioport_set_pin_dir(BT_TX,IOPORT_DIR_OUTPUT);
	
	static usart_serial_options_t usart_options = {
		.baudrate = 115200,
		.charlength = USART_CHSIZE_8BIT_gc,
		.paritytype = USART_PMODE_DISABLED_gc,
		.stopbits = false
	};
	usart_serial_init(BLUETOOTH, &usart_options);
	
	#ifdef PRINTF_BLUETOOTH
	// setup our stdio stream
	stdout = &mystdout;
	stdin = &mystdout;
#endif
	
}

void bluetooth_init_interrupt(void)
{
	pmic_init();
	pmic_set_scheduling(PMIC_SCH_ROUND_ROBIN);
	USARTD0.CTRLA = USART_RXCINTLVL_HI_gc;
	cpu_irq_enable();
}
Esempio n. 2
0
// setup the board instead of board_init() as recommended by ASF.. because christmas lights, that's why.
void init (void) {
	static usart_serial_options_t usart_options = {
		.baudrate = USART_SERIAL_BAUDRATE,
		.charlength = USART_SERIAL_CHAR_LENGTH,
		.paritytype = USART_SERIAL_PARITY,
		.stopbits = USART_SERIAL_STOP_BIT
	};
	
	// initialize ASF stuff
	board_init();
	sysclk_init();
	ioport_init();
	pmic_init();
	pmic_set_scheduling(PMIC_SCH_FIXED_PRIORITY);
	
	// remap, enable TX, and configure USART on PORT C
	PORTC.REMAP |= PR_USART0_bm;
	PORTC.DIR |= (1 << PIN7_bp);
		
	sysclk_enable_module(SYSCLK_PORT_C, PR_USART0_bm);
	usart_init_rs232(USART_SERIAL, &usart_options);
	
	// setup timer for PWM
	tc45_enable(&TCC4);
	tc45_set_overflow_interrupt_callback(&TCC4, pwm_callback);
	tc45_set_wgm(&TCC4, TC45_WG_NORMAL);
	tc45_write_period(&TCC4, 256);
	tc45_set_overflow_interrupt_level(&TCC4, TC45_INT_LVL_MED);
		
	// enable all channels and turn off (high)
	ioport_set_port_dir(IOPORT_PORTA, PORTA_MASK, IOPORT_DIR_OUTPUT);
	ioport_set_port_dir(IOPORT_PORTD, PORTD_MASK, IOPORT_DIR_OUTPUT);
	ioport_set_port_dir(IOPORT_PORTR, PORTR_MASK, IOPORT_DIR_OUTPUT);
	ioport_set_port_level(IOPORT_PORTA, PORTA_MASK, 0xFF);
	ioport_set_port_level(IOPORT_PORTD, PORTD_MASK, 0xFF);
	ioport_set_port_level(IOPORT_PORTR, PORTR_MASK, 0xFF);
	for (uint8_t i=0; i<NUM_CHANNELS; i++) {
		compare[i] = 0;
		compbuff[i] = 0;
	}
	
	// enable status LEDs and turn off
	ioport_set_pin_dir(LED_STATUS, IOPORT_DIR_OUTPUT);
	ioport_set_pin_dir(LED_DATA, IOPORT_DIR_OUTPUT);
	ioport_set_pin_level(LED_STATUS, 1);
	ioport_set_pin_level(LED_DATA, 1);
	
	// enable interrupts and start timer for PWM
	cpu_irq_enable();
	tc45_write_clock_source(&TCC4, TC45_CLKSEL_DIV2_gc);	
}
Esempio n. 3
0
int main (void)
{

	ioport_set_pin_dir(IO_1,IOPORT_DIR_OUTPUT);
	ioport_set_pin_dir(IO_2,IOPORT_DIR_OUTPUT);
	ioport_set_pin_dir(IO_3,IOPORT_DIR_OUTPUT);
	ioport_set_pin_dir(IO_4,IOPORT_DIR_OUTPUT);
	ioport_set_pin_dir(IO_5,IOPORT_DIR_OUTPUT);
	ioport_set_pin_dir(IO_6,IOPORT_DIR_OUTPUT);
	ioport_set_pin_dir(IO_7,IOPORT_DIR_OUTPUT);
	ioport_set_pin_dir(IO_8,IOPORT_DIR_INPUT);
	init_octopus();
 	animation();
	 
	//Activate button interrupt
	pmic_init();
	pmic_set_scheduling(PMIC_SCH_ROUND_ROBIN);
	PORTC.INTCTRL = 0x03;
	PORTC.INT0MASK = (1<<3);
	PORTC.PIN3CTRL |= (1<<1);
	cpu_irq_enable();
	
	
	//Activate ZCD signal interruption 
	 cpu_irq_disable();
	 PORTD.INTCTRL = 0x03;
	 PORTD.INT0MASK = (1<<5);
	 PORTD.PIN5CTRL |= 0x01;
	 cpu_irq_enable();
	 
	//Activate RTC
	rtc_init();
	 
// 	pwm_ini(SERVO_0);
// 	pwm_update(SERVO_0,0);
// 	delay_ms(1000);
// 	pwm_update(SERVO_0,500);
// 	delay_ms(1000);
// 	pwm_update(SERVO_0,1000);
	 
	char aux;
	char aux2;
	for(;;)
	{
		printf("hello");
		if(bluetooth_is_rx_complete())
		{
			scanf("%1c",&aux);
			switch (aux)
			{
				case 'C':
					scanf("%1c",&aux);
					if (aux=='1')
					{
						led1(ON);
						ioport_set_pin_level(IO_1,ON);
					}
					else
					{
						led1(OFF);
						ioport_set_pin_level(IO_1,OFF);
					}
				break;
				case 'T':
					scanf("%1c",&aux);
					if (aux=='1')
					{
						led2(ON);
						ioport_set_pin_level(IO_2,ON);
					}
					else
					{
						led2(OFF);
						ioport_set_pin_level(IO_2,OFF);
					}
				break;
				case 'D':
					scanf("%i",&dimmer);
					RTC.COMP=dimmer;
										
				break;
				case 'O':
					scanf("%1c",&aux);
					scanf("%1c",&aux);
					scanf("%1c",&aux2);
					if(aux == '1')
					{
						if(aux2=='1')
						{
							led3(ON);
							ioport_set_pin_level(IO_3,ON);
						}
						else
						{
							led3(OFF);
							ioport_set_pin_level(IO_3,OFF);
						}
					}
					else
					{
						if(aux2=='1')
						{
							led4(ON);
							ioport_set_pin_level(IO_4,ON);
						}
						else
						{
							led4(OFF);
							ioport_set_pin_level(IO_4,OFF);
						}
					}
				break;
				
			}
		}
		
	}
}