Ejemplo n.º 1
0
/*----------------------------------------------------------------------------
  MAIN function
 *----------------------------------------------------------------------------*/
int main (void) {
	//initiliaze RGB LED
	Init_RGB_LEDs();

if (init_mma() == 0)
{ 
  Control_RGB_LEDs(1,0,0);
  while (1); //stay in the infinite loop to indicate the error with the RED LED
}	
	
//Add Delay (1000); here	
	Delay(1000);
	
	while (1) {
		//Read the data on x, y, and z axis; // Use function call to read the axes data
		//Convert x, y, and z axis to roll and pitch as described in the class 
		// use function call to convert the data
		
		// Light green LED if pitch > 10 ; pick a pitch angle between 10 and 15 degrees
		// Light blue LED if roll > 10 ; pick a roll angle between 10 to 15 degrees
		
		// use LED function call "Control_RGB_LEDs" from previous labs and display  
		// roll and pitch angles using the tri-color LED; you may
		//ignore the yaw angle; for details, see lab manual for roll, pitch, and yaw
		//definitions
		
	}
}
/*----------------------------------------------------------------------------
  MAIN function
 *----------------------------------------------------------------------------*/
int main (void) {

	Init_Debug_Signals();
	Init_RGB_LEDs();
	Sound_Init();	
	// Sound_Disable_Amp();
	Play_Tone();
	
	TFT_Init();
	TFT_Text_Init(1);
	TFT_Erase();
	TFT_Text_PrintStr_RC(0,0, "Test Code");

/*
	Graphics_Test();
	while (1) 
		;
*/
	
//	TFT_TS_Calibrate();
//	TFT_TS_Test();

	TFT_Text_PrintStr_RC(1,0, "Accel...");

	i2c_init();											// init I2C peripheral
	if (!init_mma()) {							// init accelerometer
		Control_RGB_LEDs(1,0,0);			// accel initialization failed, so turn on red error light
		while (1)
			;
	}
	TFT_Text_PrintStr_RC(1,9, "Done");

	Play_Waveform_with_DMA();

	Delay(70);

	os_sys_init(&Task_Init);

	while (1)
		;
}
/*----------------------------------------------------------------------------
  MAIN function
 *----------------------------------------------------------------------------*/
int main (void) {
	#if USE_VLPR == 1
		// enter low power run
		SIM->CLKDIV1 = (0x1 << SIM_CLKDIV1_OUTDIV1_SHIFT) | (0x5 << SIM_CLKDIV1_OUTDIV4_SHIFT);		// reduce core clock < 4 MHz and flash < 1 MHz
		MCG->C6 &= ~MCG_C6_CME0_MASK;			// disable MCG clock monitor
		MCG->C2 |= MCG_C2_IRCS_MASK;			// don't use slow internal reference clock
		MCG->C1 |= MCG_C1_CLKS(2);				// enter BLPE mode
		MCG->C1 &= ~MCG_C1_IREFS_MASK;
		MCG->C6 &= ~MCG_C6_PLLS_MASK;
		while(!(MCG->S & MCG_S_IREFST_MASK >> MCG_S_IREFST_SHIFT));		// wait to ensure clock change
		MCG->C2 |= MCG_C2_LP_MASK;
	#endif
	
	Init_RGB_LEDs();
	
	#if DEBUG_SIGNALS == 1
		Init_Debug_Signals();
	#endif
	
	// I2C and MMA
	i2c_init();																/* init i2c	*/
	if (!init_mma()) {												/* init mma peripheral */
		Control_RGB_LEDs(1, 0, 0);							/* Light red error LED */
		while (1)																/* not able to initialize mma */
			;
	}
	
	#if RUN_I2C_FAST == 1
		// increase i2c baud rate
		I2C_DISABLE;
		I2C0->F = (I2C_F_ICR(0x00) | I2C_F_MULT(0));
		I2C_ENABLE;
	#endif
	
	// configure low power modes
	SMC->PMPROT = SMC_PMPROT_ALLS_MASK | SMC_PMPROT_AVLP_MASK;				// allow low leakage stop mode
	SMC->PMCTRL = SMC_PMCTRL_RUNM(2) | SMC_PMCTRL_STOPM(3);	// enable low power run mode (10) and low leakage stop mode (011)
	SMC->STOPCTRL = SMC_STOPCTRL_PSTOPO(0) | SMC_STOPCTRL_VLLSM(3);	// normal stop mode and VLL stop3 (not needed?)
	
	// configure low leakage wakeup unit (LLWU)
	LLWU->ME |= LLWU_ME_WUME0_MASK;						// internal module 0 is wakeup source which is apparently the LPTMR
	
	// enable stop mode (deep sleep)
	SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
	
	// LPTMR
	Init_LPTMR();
	Start_LPTMR();

	__enable_irq();
	
	while (1) {				
		// read acceleration every 100 ms
		if (run_Read_Accel){
			run_Read_Accel = 0;
			Read_Accel();
		}
		
		// update LEDs every 500 ms; keep them on for 10 ms
		if (run_Update_LEDs){
			run_Update_LEDs = 0;
			Update_LEDs();
			
			#if USE_PWM == 1
				#if PWM_SLEEP == 1
					SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk;		// switch to regular sleep mode
					#if USE_SLEEP_MODES == 1
						#if DEBUG_SIGNALS == 1
							PTE->PSOR |= MASK(30);
						#endif
						__wfi();															// PWM does not work in LLS mode
					#endif
					SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;		// switch back to LLS mode
				#else
					while(led_on_period);									// poll -> bad solution
				#endif
			#endif
		}
				
		#if USE_SLEEP_MODES == 1
			#if DEBUG_SIGNALS == 1
					PTE->PSOR |= MASK(30);
			#endif
			__wfi();			// go to sleep
		#endif
	}
}