Example #1
0
/** Configures the board hardware and chip peripherals for the demo's functionality. */
void SetupHardware(void)
{
	/* Disable watchdog if enabled by bootloader/fuses */
	MCUSR &= ~(1 << WDRF);
	wdt_disable();

	/* Disable clock division */
	clock_prescale_set(clock_div_1);

	/* Hardware Initialization */
	SerialStream_Init(9600, false);
	LEDs_Init();
	Joystick_Init();
	Buttons_Init();
	USB_Init(USB_MODE_UID);
}
Example #2
0
/** Configures the board hardware and chip peripherals for the demo's functionality. */
void SetupHardware(void)
{
#if (ARCH == ARCH_AVR8)
	/* Disable watchdog if enabled by bootloader/fuses */
	MCUSR &= ~(1 << WDRF);
	wdt_disable();

	/* Disable clock division */
	clock_prescale_set(clock_div_1);
#endif

	/* Hardware Initialization */
	LEDs_Init();
	USB_Init();
	Joystick_Init();
	Buttons_Init();
}
Example #3
0
/** Configures the board hardware and chip peripherals for the demo's functionality. */
void SetupHardware(void)
{
	/* Disable watchdog if enabled by bootloader/fuses */
	MCUSR &= ~(1 << WDRF);
	wdt_disable();

	/* Disable clock division */
	clock_prescale_set(clock_div_1);

	/* Hardware Initialization */
	LEDs_Init();
	Buttons_Init();
	ADC_Init(ADC_FREE_RUNNING | ADC_PRESCALE_32);
	ADC_SetupChannel(MIC_IN_ADC_CHANNEL);
	USB_Init();

	/* Start the ADC conversion in free running mode */
	ADC_StartReading(ADC_REFERENCE_AVCC | ADC_RIGHT_ADJUSTED | MIC_IN_ADC_MUX_MASK);
}
Example #4
0
/** Configures the board hardware and chip peripherals for the demo's functionality. */
void SetupHardware(void)
{
	/* Disable watchdog if enabled by bootloader/fuses */
	MCUSR &= ~(1 << WDRF);
	wdt_disable();

	/* Disable clock division */
	clock_prescale_set(clock_div_1);

	/* Hardware Initialization */
	Serial_Init(9600, false);
	LEDs_Init();
	Joystick_Init();
	Buttons_Init();
	USB_Init(USB_MODE_UID);

	/* Create a stdio stream for the serial port for stdin and stdout */
	Serial_CreateStream(NULL);
}
Example #5
0
/** Configures the board hardware and chip peripherals for the demo's functionality. */
void SetupHardware(void)
{
	/* Disable watchdog if enabled by bootloader/fuses */
	MCUSR &= ~(1 << WDRF);
	wdt_disable();

	/* Disable clock division */
	clock_prescale_set(clock_div_1);

	/* Hardware Initialization */
	Serial_Init(9600, false);
	LEDs_Init();
	Buttons_Init();
	ADC_Init(ADC_FREE_RUNNING | ADC_PRESCALE_32);
	ADC_SetupChannel(MIC_IN_ADC_CHANNEL);
	USB_Init();

	/* Create a stdio stream for the serial port for stdin and stdout */
	Serial_CreateStream(NULL);
}
/** Configures the board hardware and chip peripherals for the demo's functionality. */
void SetupHardware(void)
{
	/* Disable watchdog if enabled by bootloader/fuses */
	MCUSR &= ~(1 << WDRF);
	wdt_disable();

	/* Disable clock division */
	clock_prescale_set(clock_div_1);

	/* Hardware Initialization */
	LEDs_Init();
	Joystick_Init();
	Buttons_Init();
	SPI_Init(SPI_SPEED_FCPU_DIV_2 | SPI_SCK_LEAD_FALLING | SPI_SAMPLE_TRAILING | SPI_MODE_MASTER);
	Dataflash_Init();
	USB_Init();

	/* Clear Dataflash sector protections, if enabled */
	DataflashManager_ResetDataflashProtections();
}
Example #7
0
//debug code
int main(void){ 
	DisableInterrupts();
  PLL_Init(Bus80MHz);								// bus clock at 50 MHz
	PortF_Init();
  LEDS = 0;													// turn all LEDs off
	DAC_Init(0);
	Buttons_Init();
	SysTick_Init();
	//Timer0A_Init(&Song_PlayHandler, F20KHZ);	// initialize timer0A (20,000 Hz)
  Timer0A_Init(&Song_PlayHandler, F16HZ);		// initialize timer0A (16 Hz)
  EnableInterrupts();
	
	Song_PlayInit(Prelude);
	Pause();

  while(1){
		LEDS ^= RED;
		for(int i = 0; i < 1000000; i += 1);
  }
}
Example #8
0
int main(void){
	HeartBeat_Init();
	DAC_Init(1024);							// initialize with command: Vout = Vref
	Timer0A_Init(dt[0]);
	LCD_Init();  
    // Initialize RNG
  Random_Init(121213);
    // Initialize touchscreen GPIO
  Touch_Init();
	//lenPush = 1;
  //for(i=0; i<50; i=i+1){
	InitializeBars();
  for(i=0; i<400; i=i+1){
	MovingColorBars();
	}
	for(i=0; i<400; i=i+1){
		DestabilizeBars();
	}
	for(i=0; i<350; i=i+1){
		FinishBars();
	}
	for(i=0; i<1000; i=i+1){
     Random4BPPTestSprite();
  }
	LCD_ColorFill(convertColor(0, 0, 0));
	Buttons_Init();
	play = 0;
	while(1){
			if (instrument == 0){
				Music_Play(Wave[0], 64, strobePtr, 35);		
			}
			if (instrument == 1){
				Music_Play(Trumpet[0], 32, strobePtr, 35);
			}
			if (instrument == 2){
				Music_Play(Flute[0], 32, strobePtr, 35);
			}
	}
}
int main(void)
{
	uint_reg_t Dummy;
	
	/* Buttons Compile Check */
	Buttons_Init();
	Dummy = Buttons_GetStatus();
	Buttons_Disable();
	
	/* Dataflash Compile Check */
	Dataflash_Init();
	Dataflash_TransferByte(0);
	Dataflash_SendByte(0);
	Dummy = Dataflash_ReceiveByte();
	Dummy = Dataflash_GetSelectedChip();
	Dataflash_SelectChip(0);
	Dataflash_DeselectChip();
	Dataflash_SelectChipFromPage(0);
	Dataflash_ToggleSelectedChipCS();
	Dataflash_WaitWhileBusy();
	Dataflash_SendAddressBytes(0, 0);

	/* LEDs Compile Check */
	LEDs_Init();
	LEDs_TurnOnLEDs(LEDS_ALL_LEDS);
	LEDs_TurnOffLEDs(LEDS_ALL_LEDS);
	LEDs_SetAllLEDs(LEDS_ALL_LEDS);
	LEDs_ChangeLEDs(LEDS_ALL_LEDS, LEDS_NO_LEDS);
	LEDs_ToggleLEDs(LEDS_ALL_LEDS);
	Dummy = LEDs_GetLEDs();
	LEDs_Disable();
	
	/* Joystick Compile Check */
	Joystick_Init();
	Dummy = Joystick_GetStatus();
	Joystick_Disable();
	
	(void)Dummy;
}
Example #10
0
/** Configures the board hardware and chip peripherals for the demo's functionality. */
void SetupHardware(void)
{
#if (ARCH == ARCH_AVR8)
	/* Disable watchdog if enabled by bootloader/fuses */
	MCUSR &= ~(1 << WDRF);
	wdt_disable();

	/* Disable clock division */
	clock_prescale_set(clock_div_1);
#elif (ARCH == ARCH_XMEGA)
	/* Start the PLL to multiply the 2MHz RC oscillator to 32MHz and switch the CPU core to run from it */
	XMEGACLK_StartPLL(CLOCK_SRC_INT_RC2MHZ, 2000000, F_CPU);
	XMEGACLK_SetCPUClockSource(CLOCK_SRC_PLL);

	/* Start the 32MHz internal RC oscillator and start the DFLL to increase it to 48MHz using the USB SOF as a reference */
	XMEGACLK_StartInternalOscillator(CLOCK_SRC_INT_RC32MHZ);
	XMEGACLK_StartDFLL(CLOCK_SRC_INT_RC32MHZ, DFLL_REF_INT_USBSOF, F_USB);

	PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm;
#endif

	/* Hardware Initialization */
	LEDs_Init();
	Joystick_Init();
	Buttons_Init();
	Dataflash_Init();
	USB_Init();

	/* Check if the Dataflash is working, abort if not */
	if (!(DataflashManager_CheckDataflashOperation()))
	{
		LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
		for(;;);
	}

	/* Clear Dataflash sector protections, if enabled */
	DataflashManager_ResetDataflashProtections();
}
/** Configures the board hardware and chip peripherals for the demo's functionality. */
void SetupHardware(void)
{
	/* Disable watchdog if enabled by bootloader/fuses */
	MCUSR &= ~(1 << WDRF);
	wdt_disable();

	/* Disable clock division */
	clock_prescale_set(clock_div_1);

	/* Hardware Initialization */
	Serial_Init(9600, false);
	Buttons_Init();
	ADC_Init(ADC_FREE_RUNNING | ADC_PRESCALE_32);
	ADC_SetupChannel(MIC_IN_ADC_CHANNEL);
	LEDs_Init();
	USB_Init();

	/* Create a stdio stream for the serial port for stdin and stdout */
	Serial_CreateStream(NULL);

	/* Start the ADC conversion in free running mode */
	ADC_StartReading(ADC_REFERENCE_AVCC | ADC_RIGHT_ADJUSTED | ADC_GET_CHANNEL_MASK(MIC_IN_ADC_CHANNEL));	
}
Example #12
0
/** Configures the board hardware and chip peripherals for the demo's functionality. */
void SetupHardware(void)
{
	/* Disable watchdog if enabled by bootloader/fuses */
	MCUSR &= ~(1 << WDRF);
	wdt_disable();

	/* Disable clock division */
	clock_prescale_set(clock_div_1);

	/* Hardware Initialization */
	#if defined(USB_CAN_BE_BOTH)
	USB_Init(USB_MODE_UID);
	#else
	USB_Init();
	#endif

	LEDs_Init();
	SPI_Init(SPI_SPEED_FCPU_DIV_2 | SPI_SCK_LEAD_FALLING | SPI_SAMPLE_TRAILING | SPI_MODE_MASTER);
	Dataflash_Init();
	Buttons_Init();
	Serial_Init(9600, true);

	/* Create a stdio stream for the serial port for stdin and stdout */
	Serial_CreateStream(NULL);

	#if defined(USB_CAN_BE_DEVICE)
	/* Check if the Dataflash is working, abort if not */
	if (!(DataflashManager_CheckDataflashOperation()))
	{
		LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
		for(;;);
	}

	/* Clear Dataflash sector protections, if enabled */
	DataflashManager_ResetDataflashProtections();
	#endif
}
Example #13
0
/** Configures the board hardware and chip peripherals for the demo's functionality. */
inline static void SetupHardware(void)
{
	/* Disable watchdog if enabled by bootloader/fuses */
	MCUSR &= ~(1 << WDRF);
	wdt_disable();

	/* Disable clock division */
	clock_prescale_set(clock_div_1);

	/* Hardware Initialization */
	LEDs_Init();
	Buttons_Init();	//button HWB
	Joystick_Init();

	//gate driving output - PORTC.6 / PWM-A Timer3
	DDRC |= (1<<PC6);
	PORTC &= ~(1<<PC6);
	Init_PWM_timer();
	
	/* conversion mode (free running or single) and prescaler masks 
	 * ACDSRA: start ADC, clock prescaler, interrupt, trigger enable, start single conv */
	ADC_Init( ADC_SINGLE_CONVERSION | ADC_PRESCALE_128);	
	/* Must setup the ADC channel to read beforehand */
	ADC_SetupChannel(3);
	ADC_SetupChannel(4);
	
	/* Start the ADC conversion in free running mode 
	 * ADMUX and Vref, adjust, sel mux channel with gain
	 * 
	*/
	//ADC_StartReading(ADC_REFERENCE_INT2560MV | ADC_RIGHT_ADJUSTED | ADC_1100MV_BANDGAP);
	
	//Temperature_Init();
	//Dataflash_Init();
	SerialStream_Init(9600, false);

}
Example #14
0
int main(void)
{

	unsigned char tmp;
	
	wdt_disable();		/* Disable watchdog if enabled by bootloader/fuses */
	power_usb_disable() ;
	power_usart1_disable();
	power_spi_disable();
	
	Buttons_Init();
	LEDs_Init();
	clock_prescale_set(clock_div_1);	// run at x-tal frequency 16Mhz
	
	
	eeprom_read_block( &EE_data,0,sizeof(EE_data));
		
	if (EE_data.bright_level == 0xff && EE_data.dim_level == 0xff)
	{
		EE_data.bright_level = LED_BRIGHT;
		EE_data.dim_level = LED_DIMM;
		eeprom_write_block(&EE_data,0,sizeof(EE_data));
		eeprom_busy_wait();
	}
	
	OCR0A = EE_data.bright_level;
	OCR0B = EE_data.dim_level;

	// Timer 0 setup for simple count mode, used as timebase LED PWM
	TCCR0A = 0;		// simple count more 		
	TCCR0B = 4;		// system Clock 16Mhz/256 = 16us per counter tick 
	//TCCR0B = 3;		// system Clock 16Mhz/64 = 4us per counter tick 
	//TCCR0B = 5;		// system Clock 16Mhz/1024 = 64us per counter tick 
	//TCCR0B = 2;		// system Clock 1Mhz/8 = 8us per counter tick 
	TIMSK0 = 0x7;	// Enable OverFLow , OCR0A and OCR0B interrupt enables
	
	MCUSR =0; //MCU status register clear 
	
	// Timer 1 setup for  fast PWM mode for servo pulse generation 1 to 2ms 

	TIMSK1 = 0x2;		// Enable OCR1A interrupt 
	TCCR1A = 0x00;		// No pin toggles on compare -- CTC (normal) mode
	TCCR1B = 0x0D;		// CTC mode, F_CPU 16mhz/1024 clock ( 64us)
	//TCCR1B = 0x0B;		// CTC mode, F_CPU 1Mhz/64 clock ( 64us)
	OCR1A = 15625-1;	// counting 15625 counts of 64 us == 1 second

	sei();
		
    while(1)	// for ever
    {
		
		if (IsButtonPressed(BUTTON1) )
		{

			// de-bounce -- 10 consecutive reads of switch open 
			for (tmp =0; tmp<=10; tmp++)
			{
				_delay_ms(2);
				if (IsButtonPressed(BUTTON1))
					tmp = 0;
			}
			
			if ( mode < 3)
				mode++;
			else
			{
				eeprom_write_block(&EE_data,0,sizeof(EE_data));
				eeprom_busy_wait();
				mode = 0; // enter running mode
			}				
		
		}			
				
		if (IsButtonPressed(BUTTON2) ) // increases Minutes and decrease brightness 
		{

			// de-bounce -- 10 consecutive reads of switch open
			for (tmp =0; tmp<=10; tmp++)
			{
				_delay_ms(2);
				if (IsButtonPressed(BUTTON2))
				tmp = 0;
			}
			
			switch (mode) 
			{
				case 1:
					Minutes++;
					ripple();
					break;
					
				case 2:
					if (OCR0B < 0xff )		// dim level
					{
						OCR0B++;
						EE_data.dim_level = OCR0B;
					}						
					break;
					
				case 3:						// bright level
					if (OCR0A < OCR0B-10  )		// make sure that bright is at least 10 counts brighter than dim
					{
						OCR0A +=10;				// step in increments of 10
						EE_data.bright_level =OCR0A;
					}						
					break;
			}			
			
		}	
		
		if (IsButtonPressed(BUTTON3) )	// Increases Hours and increase brightness
		{

			// de-bounce -- 10 consecutive reads of switch open
			for (tmp =0; tmp<=10; tmp++)
			{
				_delay_ms(2);
				if (IsButtonPressed(BUTTON3))
				tmp = 0;
			}
						
			switch (mode)
			{
				case 1:
					Hours++;
					ripple();
					break;
					
				case 2:
					if (OCR0B > OCR0A+10)		// dim level
					{	

						OCR0B--;
						EE_data.dim_level = OCR0B;
					}						
					break;
					
				case 3:						// bright level
					if (OCR0A > 20)	
					{
						OCR0A -=10;		//step in increments of 10
						EE_data.bright_level =OCR0A;
					}						
					break;
			}
		}
				
    } // end of for-ever
}
Example #15
0
int main(void){ 
	
	DisableInterrupts();
	PLL_Init(Bus10MHz);								// bus clock at 10 MHz
	Buttons_Init();
	SysTick_Init();
	ST7735_InitR(INITR_REDTAB);
	TEC_Init();
	ADC0_InitSWTriggerSeq3_Ch0();
		
	printf("Critical Can Cooler\nV1.0\n\nCurrent Temp: \nDesired Temp: \nTEC Status: ");
	
	EnableInterrupts();
	while(1) {

		/*
		convert ADC_sample to Current_Temp
		Get TEC_Temp
		Compare TEC_Temp with Current_Temp
		Turn off if less than/equal to
		
		Display "Critical Can Cooler V1.0"
		Display Current_Temp
		Display TEC_temp
		Display TEC_Status
		*/
	
		/*
		Temp scale:
		MAX 1740 mV or 2160 ADC measure = 25 C
		MIN 960  mV or 1192 ADC measure = 0 C
		
		2160* .806mV/adctic = temp in mV
		vo -480/15.6
		
		adc tics * .806mV/tic = sample in mV
		(mV - 960) /31.2 = T
		
		((adc *806) - 960000) / 31200 = T
		
		*/
		
		Current_Temp = (((int32_t)ADC_Sample * 806) - 960000) / 31200;
		
		//if(TEC_Get() > Current_Temp) {
		//	TEC_Stop();
		//}
		ST7735_SetCursor(14,3);
		printf("%-3d",Current_Temp);
		ST7735_SetCursor(14,4);
		printf("%d",TEC_Get());
		ST7735_SetCursor(14,5);
		if(TEC_Status()) {
			printf("ON \n");
		}
		else {
			printf("OFF\n");
		}
		
		WaitForInterrupt();
	}
}
Example #16
0
/*******************************************************************************//**
 * @implements InitComponents
 **********************************************************************************/
RESULT InitComponents(void)
{
	// init guard
	if(Guard_Init()==FAIL)
		return FAIL;
	
	// init utils
	if(Utils_Init()==FAIL)
		return FAIL;
	
	// init MCU
	if(MCU_Init()==FAIL)
		return FAIL;
	
	// init scheduler
	if(Scheduler_Init()==FAIL)
		return FAIL;
	
	// init power management system
	#ifdef USE_PWR
	if(PWR_Init()==FAIL)
		return FAIL;
	#endif
	
	// init timers
	#ifdef USE_TIMERS
	if(Timers_Init()==FAIL)
		return FAIL;
	#endif
	
	// init LEDs
	#ifdef USE_LEDS
	if(LEDs_Init()==FAIL)
		return FAIL;
	#endif
	
	// init buttons
	#ifdef USE_BUTTONS
	if(Buttons_Init()==FAIL)
		return FAIL;
	#endif
	
	// init UART
	#ifdef USE_UART
	if(UART_Init()==FAIL)
		return FAIL;
	#endif
	
	// init SPI
	#ifdef USE_SPI
	if(SPI_Init()==FAIL)
		return FAIL;
	#endif
	
	// init TWI
	#ifdef USE_TWI
	if(TWI_Init()==FAIL)
		return FAIL;
	#endif
	
	// init OWI
	#ifdef USE_OWI
	if(OWI_Init()==FAIL)
		return FAIL;
	#endif
	
	// init other components
	if(InitOther()==FAIL)
		return FAIL;
	
	// init sensors
	#ifdef USE_SENSORS
	if(Sensors_Init()==FAIL)
		return FAIL;
	#endif
	
	// init NWK
	#ifdef USE_NWK
	if(NWKLayer_Init()==FAIL)
		return FAIL;
	#endif
	
	// return success
	return SUCCESS;
}