Пример #1
0
void  PB_Init (void)
{
    PB_Config();                                                        /* Configure the port pins                                  */
    PB_IntInit();                                                       /* Configure interrupt settings                             */
}    
Пример #2
0
int main(void){
	
	//configure push-button interrupts
	PB_Config();
	
	 /* LCD initiatization */
  LCD_Init();
  
  /* LCD Layer initiatization */
  LCD_LayerInit();
    
  /* Enable the LTDC */
  LTDC_Cmd(ENABLE);
  
  /* Set LCD foreground layer */
  LCD_SetLayer(LCD_FOREGROUND_LAYER);

	
	
	//======You need to develop the following functions======
	//Note: these are just placeholders; function definitions are at bottom of this file
	//configure real-time clock
	RTC_Config();
	
	//configure external push-buttons and interrupts
	ExtPB_Config();
	ExtPBNum2();
	
	
	//main program
	
	LCD_Clear(LCD_COLOR_WHITE);
		
	//line=0;
	//Display a string in one line, on the first line (line=0)
	//LCD_DisplayStringLine(LINE(line),  (uint8_t *) "Init EEPROM...");
	//line++;
	
	//i2c_init(); //initialize the i2c chip
	sEE_Init();  

	
	//LCD_DisplayStringLine(LINE(line),  (uint8_t *) "done..."); 
	//line++;
	
	//LCD_DisplayStringLine(LINE(line),  (uint8_t *) "Writing...");
	//line++;
	
	
	/* First write in the memory followed by a read of the written data --------*/
  /* Write on I2C EEPROM from memLocation */
  //sEE_WriteBuffer(&Tx1_Buffer, memLocation,1); 

  /* Wait for EEPROM standby state */
  //sEE_WaitEepromStandbyState();  
 
  
	//LCD_DisplayStringLine(LINE(line),  (uint8_t *) "Reading...");
  /* Read from I2C EEPROM from memLocation */
  //sEE_ReadBuffer(&Rx1_Buffer, memLocation, (uint16_t *)(&NumDataRead)); 
	//line++;
	
	//LCD_DisplayStringLine(LINE(line),  (uint8_t *) "Comparing...");  
	//line++;
	
	
	//if(Tx1_Buffer== Rx1_Buffer){
		//LCD_DisplayStringLine(LINE(line),  (uint8_t *) "Success!");  
	//}else{
		//LCD_DisplayStringLine(LINE(line),  (uint8_t *) "Mismatch!"); 
	//}
	
	//main loop
	while(1){
		RTC_GetTime(RTC_Format_BIN,&RTC_TimeStructure);
		hours = RTC_TimeStructure.RTC_Hours;
		minutes = RTC_TimeStructure.RTC_Minutes;
		seconds = RTC_TimeStructure.RTC_Seconds;

		sprintf(time,"%0.2d:%0.2d:%0.2d",hours,minutes,seconds);
		LCD_DisplayStringLine(LINE(6),  (uint8_t *) time); 
		
		if(UBPressed == 1){
			
			toBeSaved = time[7];
			sEE_WriteBuffer(&toBeSaved, memLocation+1,1); 
			sEE_WaitEepromStandbyState();  
			
			sEE_ReadBuffer(&Rx1_Buffer, memLocation+1, (uint16_t *)(&NumDataRead)); 
			saved[0] = Rx1_Buffer;

			
			
			LCD_DisplayStringLine(LINE(7),  (uint8_t *) saved);
			
			UBPressed = 0;
			PB_Config();
			
		}
		if(EB1Pressed == 1 && state == 0){
			state = 1;
			EB1Pressed = 0;
			ExtPB_Config();
		}
		if(EB1Pressed == 1 && state == 1){
			state = 2;
			EB1Pressed = 0;
			ExtPB_Config();
			
		}
		if(EB1Pressed == 1 && state == 2){
			state = 3;
			EB1Pressed = 0;
			ExtPB_Config();
			
		}
		if(EB1Pressed == 1 && state == 3){
			state = 0;
			EB1Pressed = 0;
			ExtPB_Config();
			
		}
		if(EB2Pressed == 1 && state == 1){
			
			RTC_TimeStructure.RTC_Hours = hours + 1;
			RTC_SetTime(RTC_Format_BCD, &RTC_TimeStructure);
			EB2Pressed = 0;
			ExtPBNum2();
		}
		if(EB2Pressed == 1 && state == 2){
			
			RTC_TimeStructure.RTC_Minutes = minutes + 1;
			RTC_SetTime(RTC_Format_BCD, &RTC_TimeStructure);
			EB2Pressed = 0;
			ExtPBNum2();
		}
		if(EB2Pressed == 1 && state == 3){
			
			RTC_TimeStructure.RTC_Seconds = seconds + 1;
			RTC_SetTime(RTC_Format_BCD, &RTC_TimeStructure);
			EB2Pressed = 0;
			ExtPBNum2();
		}
		
	}
}
Пример #3
0
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f4xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f4xx.c file
     */
	
//initiate user button
  PB_Config();

	//initiate LEDs and turn them on
  LED_Config();	
	
 

  /* -----------------------------------------------------------------------
    TIM3 Configuration: Output Compare Timing Mode:
    
    In this example TIM3 input clock (TIM3CLK) is set to 2 * APB1 clock (PCLK1), 
    since APB1 prescaler is different from 1.   
      TIM3CLK = 2 * PCLK1  
      PCLK1 = HCLK / 4 
      => TIM3CLK = HCLK / 2 = SystemCoreClock /2
          
    To get TIM3 counter clock at 50 MHz, the prescaler is computed as follows:
       Prescaler = (TIM3CLK / TIM3 counter clock) - 1
       Prescaler = ((SystemCoreClock /2) /0.5 MHz) - 1
                                              
    CC1 update rate = TIM3 counter clock / CCR1_Val = 10.0 Hz
    ==> Toggling frequency = 5 Hz

    Note: 
     SystemCoreClock variable holds HCLK frequency and is defined in system_stm32f4xx.c file.
     Each time the core clock (HCLK) changes, user had to call SystemCoreClockUpdate()
     function to update SystemCoreClock variable value. Otherwise, any configuration
     based on this variable will be incorrect.    
		 ----------------------------------------------------------------------- */ 	
	
	//=======================Configure and init Timer======================
  /* Compute the prescaler value */
  PrescalerValue = (uint16_t) ((SystemCoreClock / 2) / 500000) - 1;

 /* TIM Configuration */
  TIM3_Config();

	// configure the output compare
	TIM3_OCConfig();

  /* TIM Interrupts enable */
  TIM_ITConfig(TIM3, TIM_IT_CC1, ENABLE);

  /* TIM3 enable counter */
  TIM_Cmd(TIM3, ENABLE);
	
//======================================configure and init LCD  ======================	
	 /* LCD initiatization */
  LCD_Init();
  
  /* LCD Layer initiatization */
  LCD_LayerInit();
    
  /* Enable the LTDC */
  LTDC_Cmd(ENABLE);
  
  /* Set LCD foreground layer */
  LCD_SetLayer(LCD_FOREGROUND_LAYER);
	
//================EEPROM init====================================

/* Unlock the Flash Program Erase controller */
		FLASH_Unlock();
		/* EEPROM Init */
		EE_Init();
		

//============ Set up for random number generation==============
	RNG_Config();


	//with the default font, LCD can display  12 lines of chars, they are LINE(0), LINE(1)...LINE(11) 
	//with the default font, LCD can display  15 columns, they are COLUMN(0)....COLUMN(14)


		LCD_Clear(LCD_COLOR_WHITE);
			
	

		
		LCD_DisplayStringLine(LINE(0),  (uint8_t *) "Attempt");
		LCD_DisplayStringLine(LINE(2),  (uint8_t *) "Record");
		
		EE_WriteVariable(VirtAddVarTab[0],VarValue);
		EE_ReadVariable(VirtAddVarTab[0], &VarDataTab[0]);
		sprintf(str, "%d", VarDataTab[0]);
		//LCD_DisplayStringLine(LINE(3),  (uint8_t *) str);
		//randomNumber = RNG_GetRandomNumber()/100000;

		//sprintf(str, "%d", randomNumber());
		//LCD_DisplayStringLine(LINE(5),  (uint8_t *) str);
		
		resetTimer();
		
		/*the following while loop is where the main part of the code is
		* it currently uses the userbutton on board since Mario forgot to bring along his
		* jumper cables to test out the push button part
		*/
		
		//if toggle = 0 lights are  blinking
		//if toggle = 1 2 second wait
		//if toggle = 2 LED toggle off, the lights stay on
		
		//@TODO add external push button to code
		externalButton();
  while (1){ 
			int num = TIM_GetCounter(TIM3);
		//This is for the start of the procedure 
		if(toggle==0){
			if(num == 3000){
					STM_EVAL_LEDOn(LED3);
				  STM_EVAL_LEDOn(LED4);
			}
			else if(num == 6000){
					STM_EVAL_LEDOff(LED3);
					STM_EVAL_LEDOff(LED4);
					resetTimer();
			}
		}
			//if the user button has been pressed and the lights are blinking
			if (UBPressed==1 && toggle==0) {
				STM_EVAL_LEDOff(LED3);
				STM_EVAL_LEDOff(LED4);
				UBPressed=0;
				PB_Config();
				resetTimerLong();
				toggle = 1;
				rand = randomNumber();//generate a random number 
			}

			//this is the to get the wait time for the reaction test.
			if(toggle==1){
					if(num == rand){ //if num is equal to the ramdom gened number turn on the LEDs and reset the timer
							STM_EVAL_LEDOn(LED3);
							STM_EVAL_LEDOn(LED4);
							resetTimerLong();
					}
			}
			//this is the code for when the reaction timer has gone off
			if (UBPressed==1 && toggle==1) {
				 
				//this if statement is to prevent cheating
				//if the number = 0 it means that the user cheated as someone should not be able to get 0
				if(num == 0){
					ExtButtonPressed=0;
					PB_Config();
					externalButton();
					resetTimer();
					toggle = 0;
				}else{
				sprintf(str, "%d", num);
				//this block of code writes to the LCD the lastest user reaction time.
				LCD_DisplayStringLine(LINE(1),  (uint8_t *) "          ");
				LCD_DisplayStringLine(LINE(1),  (uint8_t *) str);
				EE_ReadVariable(VirtAddVarTab[0], &VarDataTab[0]);
				//this if statement determines wheter the user has beat their best reaction time
				if(num < VarDataTab[0]){
						VarValue = num;
						EE_WriteVariable(VirtAddVarTab[0],VarValue);
				}
				/*the following block of code writes to the LCD the record reaction time*/
				EE_ReadVariable(VirtAddVarTab[0], &VarDataTab[0]);
				sprintf(str, "%d", VarDataTab[0]);
				LCD_DisplayStringLine(LINE(3),  (uint8_t *) "          ");
				LCD_DisplayStringLine(LINE(3),  (uint8_t *) str);
				UBPressed=0;
				PB_Config();
				resetTimerLong();
				toggle = 2; 
			}
			}
			//the user needs to press the button to get the reaction time game going again. 
			//to reset the reaction timer
			if (ExtButtonPressed==1) {
				ExtButtonPressed=0;
				PB_Config();
				externalButton();
				resetTimer();
				toggle = 0;
			}
			
	}
	
}
Пример #4
0
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f4xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f4xx.c file
     */
	
//initiate user button
  PB_Config();

	//initiate LEDs and turn them on
  LED_Config();	
	
 

  /* -----------------------------------------------------------------------
    TIM3 Configuration: Output Compare Timing Mode:
    
    In this example TIM3 input clock (TIM3CLK) is set to 2 * APB1 clock (PCLK1), 
    since APB1 prescaler is different from 1.   
      TIM3CLK = 2 * PCLK1  
      PCLK1 = HCLK / 4 
      => TIM3CLK = HCLK / 2 = SystemCoreClock /2
          
    To get TIM3 counter clock at 50 MHz, the prescaler is computed as follows:
       Prescaler = (TIM3CLK / TIM3 counter clock) - 1
       Prescaler = ((SystemCoreClock /2) /50 MHz) - 1
                                              
    CC1 update rate = TIM3 counter clock / CCR1_Val = 9.154 Hz
    ==> Toggling frequency = 4.57 Hz

    Note: 
     SystemCoreClock variable holds HCLK frequency and is defined in system_stm32f4xx.c file.
     Each time the core clock (HCLK) changes, user had to call SystemCoreClockUpdate()
     function to update SystemCoreClock variable value. Otherwise, any configuration
     based on this variable will be incorrect.    
		 ----------------------------------------------------------------------- */ 	
	
	//=======================Configure and init Timer======================
  /* Compute the prescaler value */
  PrescalerValue = (uint16_t) ((SystemCoreClock / 2) / 200000) - 1;

 /* TIM Configuration */
  TIM2_Config();

	// configure the output compare
	TIM2_OCConfig();

  /* TIM Interrupts enable */
  TIM_ITConfig(TIM2, TIM_IT_CC1, ENABLE);

  /* TIM3 enable counter */
  TIM_Cmd(TIM2, ENABLE);
  while (1){ 
		
			if (UBPressed==1) { 
				
				STM_EVAL_LEDOff(LED3);
				STM_EVAL_LEDOff(LED4);
				
				hardwareBlinking();
				
				UBPressed=0;				
			}

			
	}
	
}