Example #1
0
/*
*------------------------------------------------------------------------------
* void APP_init(void)
*
* Summary	: Initialize application
*
* Input		: None
*
* Output	: None
*------------------------------------------------------------------------------
*/
void APP_init( void )
{
	UINT8 i;

	//Set Date and Time
	//WriteRtcTimeAndDate(writeTimeDateBuffer);

	//Read the value of PRESET TIME from EPROM
	for(i = 0 ; i < NO_OF_DIGITS;i++)
	{
		app.mildstone1[i] = Read_b_eep (EEPROM_MILDSTONE1_ADDRESS  + i);  
		Busy_eep();	
	}

	app.mildstone1Value = (UINT16)(((app.mildstone1[3]- '0' )* 10 )+ ( app.mildstone1[2] - '0') )* 60 +(((app.mildstone1[1]- '0' )* 10 )+ (app.mildstone1[0] - '0'));

	for(i = 0 ; i < NO_OF_DIGITS;i++)
	{
		app.mildstone2[i] = Read_b_eep (EEPROM_MILDSTONE2_ADDRESS  + i);  
		Busy_eep();	
	}

	app.mildstone2Value = (UINT16)(((app.mildstone2[3]- '0' )* 10 )+ ( app.mildstone2[2] - '0') )* 60 +(((app.mildstone2[1]- '0' )* 10 )+ (app.mildstone2[0] - '0'));
	
	APP_resetDisplayBuffer();
	DigitDisplay_updateBufferPartial(app.displayBuffer , 0, 4);

	GREEN_LAMP = RESET;
	RED_LAMP = RESET;

	CLOCK_LED = TRUE;


}
Example #2
0
void APP_task( void )
{
	UINT8 i;


		switch(app.state)
		{
			case HALT_STATE:
			
			//Check the keypress Status of COUNT_PB 
			if ((LinearKeyPad_getKeyState(COUNT_PB) == TRUE) && (app.countFlag == FALSE))
			{
				app.countFlag = TRUE;
				//Reset buffer and RTC
				APP_resetDisplayBuffer();
				DigitDisplay_updateBufferPartial(app.displayBuffer , 0, 4);
				APP_updateRTC();

				//Turn off hooter
				HOOTER = RESET;
				app.hooter_reset = FALSE;
				/*
				//Store the state
				Write_b_eep( EEPROM_STATE_ADDRESS , COUNT_STATE);
				Busy_eep( );
				//ON DOT_CONTROL leds
				CLOCK_LED = 1;
				//Change the state to STOP state
				app.state = COUNT_STATE;
				*/
				
			}
			else if ((LinearKeyPad_getKeyState(COUNT_PB) == FALSE) && (app.countFlag == TRUE))
			{
				app.countFlag = FALSE;	
				//Store the state
				Write_b_eep( EEPROM_STATE_ADDRESS , COUNT_STATE);
				Busy_eep( );
				//ON DOT_CONTROL leds
				CLOCK_LED = 1;
				//Change the state to STOP state
				app.state = COUNT_STATE;
			
			}
			//Check the keypress Status of MODE_CHANGE_PB
			else if (LinearKeyPad_getKeyState(MODE_CHANGE_PB) == TRUE)
			{
				//Reset Target buffer which is used to hold preset data
				APP_resetPresetBuffer();

				//Blink first digit in the display
				app.blinkIndex = 0;
				DigitDisplay_updateBuffer(app.presetBuffer);
				DigitDisplay_blinkOn_ind(500, app.blinkIndex);


				//Change state to setting state
				app.state = SETTING_STATE;
			
			}

			//Check the keypress Status of HOOTER_OFF_PB 
			else if((LinearKeyPad_getKeyState(HOOTER_OFF_PB) == TRUE) && (app.hooter_reset == TRUE))
				{
					HOOTER = RESET;
					Write_b_eep( EEPROM_HOOTER_ADDRESS, HOOTER);
					Busy_eep( );
					app.state = HALT_STATE;	
				}

			
			break;

			case SETTING_STATE:
			
				//ON DOT_CONTROL leds
			CLOCK_LED = ~CLOCK_LED;
			// Code to handle Digit index PB
			if (LinearKeyPad_getKeyState(DIGIT_INDEX_PB ) == TRUE) 
			{
				app.blinkIndex++;

				if(app.blinkIndex > (NO_OF_DIGITS -  1))
					app.blinkIndex = 0 ;

				DigitDisplay_blinkOn_ind(500, app.blinkIndex);

			}

			// Code to handle increment PB
			if (LinearKeyPad_getKeyState(INCREMENT_PB) == 1) 
			{
				app.presetBuffer[app.blinkIndex]++;
				if(app.presetBuffer[app.blinkIndex] > max[app.blinkIndex])
					app.presetBuffer[app.blinkIndex] = '0';			
						
				DigitDisplay_updateBuffer(app.presetBuffer);

			}
			
			if (LinearKeyPad_getKeyState(MODE_CHANGE_PB) == TRUE)
			{
				//Turn of blink
				DigitDisplay_blinkOff();

				//Display the preset value on the display
				DigitDisplay_updateBuffer(app.presetBuffer);


				//Store preset value in the EEPROM
				for(i = 0; i < NO_OF_DIGITS ; i++ )
				{
					Write_b_eep( EEPROM_PRESET_ADDRESS + i ,app.presetBuffer[i] );
					Busy_eep( );
				}

				app.presetValue = (UINT16)(((app.presetBuffer[3]- '0' )* 10 )+ ( app.presetBuffer[2] - '0') )* 60 +(((app.presetBuffer[1]- '0' )* 10 )+ (app.presetBuffer[0] - '0'));
				
				//Store state in the EEPROM
				Write_b_eep( EEPROM_STATE_ADDRESS , HALT_STATE);
				Busy_eep( );
				//Switch state
				CLOCK_LED = 1;
				app.state = HALT_STATE;	
				
			}

				
			break;
			
			case COUNT_STATE:

				app.hooter_set = FALSE;
	
				// On halt PB press change the state into HALT
			if ((LinearKeyPad_getKeyState(HALT_PB) == TRUE) && (app.countFlag == FALSE))
				{
					app.countFlag = TRUE;
				}

			if ((LinearKeyPad_getKeyState(HALT_PB) == FALSE) && (app.countFlag == TRUE))
				{
					app.countFlag = FALSE;				
					Write_b_eep( EEPROM_STATE_ADDRESS ,HALT_STATE);
					Busy_eep( );
	
					app.state = HALT_STATE;
					break;
				}

				// On hooter_off PB press change hooter state by checking condition
/*
				if((LinearKeyPad_getKeyState(HOOTER_OFF_PB) == TRUE) && (app.hooter_reset == TRUE))
				{
					HOOTER = RESET;
					Write_b_eep( EEPROM_HOOTER_ADDRESS, HOOTER);
					Busy_eep( );
				}
*/

				//Read RTC data and store it in buffer
				ReadRtcTimeAndDate(readTimeDateBuffer);  

				//Convert RTC data in to ASCII
				// Separate the higher and lower nibble and store it into the display buffer 
				APP_conversion(); 

				//Store the current RTC data into EEPROM

				for(i = 0 ; i < 6  ; i++)
				{
					if( app.displayBuffer[i] !=	app.prevDisplayBuffer[i] )
					{
						Write_b_eep( (EEPROM_RTC_ADDRESS + i) , app.displayBuffer[i]);
						Busy_eep( );
					}
				}

				//manipulate the MSB_min to display upto 99m:59s 
				if(readTimeDateBuffer[2] > 0)
				{
					app.displayBuffer[3] += '6';
				}
				else 
				{
					app.displayBuffer[3] +=  '0';
				}
				//calculate and store the rtc value in the form of SEC
				app.rtcValue = (UINT16)(((	app.displayBuffer[3]- '0' )* 10 )+ ( app.displayBuffer[2] - '0') )* 60 +((( app.displayBuffer[1]- '0' )* 10 )+ ( app.displayBuffer[0] - '0'));
			
				//check rtcValue and presetValue for turn ON hooter_set
				if((app.hooter_reset == FALSE) && ( app.rtcValue >= app.presetValue ) )
				{
					app.hooter_set = TRUE;

				}

				//check hooter_set for change the HOOTER STATE
				if( app.hooter_set == TRUE) 
				{
					HOOTER = SET;
					app.hooter_reset = TRUE;
					Write_b_eep( EEPROM_HOOTER_ADDRESS, HOOTER);
					Busy_eep( );
					Write_b_eep( (EEPROM_HOOTER_ADDRESS + 1) , app.hooter_reset);
					Busy_eep( );

				}

				//Update digit display buffer with the current data of RTC
				DigitDisplay_updateBufferPartial(app.displayBuffer , 0, 4);

				if(readTimeDateBuffer[2] > 0)
				{
					app.displayBuffer[3] -= '6';
				}
				else 
				{
					app.displayBuffer[3] -=  '0';
				}

				for(	i = 0 ;	i < 6 ;	i++)
				{
					app.prevDisplayBuffer[i] = app.displayBuffer[i];
				}

				if(((readTimeDateBuffer[2] == 0x01) && (readTimeDateBuffer[1] == 0X39) &&
					(readTimeDateBuffer[0] == 0X59)) || (app.hooter_set == TRUE) )
				{
			
					//Change the state
					Write_b_eep( EEPROM_STATE_ADDRESS , HALT_STATE);
					Busy_eep( );
			
					app.state = HALT_STATE;	

					return;
				}

#if defined (RTC_DATA_ON_UART)
				for(i = 0; i < 7; i++)			
				{
					txBuffer[i] = readTimeDateBuffer[i];  //store time and date 
				}
				
				COM_txBuffer(txBuffer, 7);
#endif	

				break;			
		}
			
}		
Example #3
0
void APP_task( void )
{
	UINT8 i;


		switch(app.state)
		{
			case HALT_STATE:
			

			if (LinearKeyPad_getPBState(COUNT_PB) == KEY_PRESSED)
			{
				ResetAppTime();
				app.state = COUNT_STATE;

			
			}
			
			 if (LinearKeyPad_getPBState(MILDSTONE1_PB) == KEY_PRESSED)
			{
				//Reset Target buffer which is used to hold preset data
				APP_resetBuffer1();

				//Blink first digit in the display
				app.blinkIndex = 0;
				DigitDisplay_updateBuffer(app.mildstone1);
				DigitDisplay_blinkOn_ind(500, app.blinkIndex);


				GREEN_LAMP = RESET;
				RED_LAMP = RESET;

				app.mildstone1Flag = TRUE;
				//Change state to setting state
				app.state = SETTING_STATE;
			
			}

			//Check the keypress Status of HOOTER_OFF_PB 
			 if(LinearKeyPad_getPBState(MILDSTONE2_PB) == KEY_PRESSED)
			{
				//Reset Target buffer which is used to hold preset data
				APP_resetBuffer2();

				//Blink first digit in the display
				app.blinkIndex = 0;
				DigitDisplay_updateBuffer(app.mildstone2);
				DigitDisplay_blinkOn_ind(500, app.blinkIndex);

				GREEN_LAMP = RESET;
				RED_LAMP = RESET;

				app.mildstone2Flag = TRUE;
				//Change state to setting state
				app.state = SETTING_STATE;
			}

			
			break;

			case SETTING_STATE:

			// Code to handle Digit index PB
			if (LinearKeyPad_getPBState(DIGIT_INDEX_PB ) == KEY_PRESSED) 
			{
				app.blinkIndex++;

				if(app.blinkIndex > (NO_OF_DIGITS -  1))
					app.blinkIndex = 0 ;

				DigitDisplay_blinkOn_ind(500, app.blinkIndex);

			}

			// Code to handle increment PB
			if (LinearKeyPad_getPBState(INCREMENT_PB) == KEY_PRESSED) 
			{

				if(	app.mildstone1Flag == TRUE )
				{
					app.mildstone1[app.blinkIndex]++;
					if(app.mildstone1[app.blinkIndex] > max[app.blinkIndex])
						app.mildstone1[app.blinkIndex] = '0';			
							
					DigitDisplay_updateBuffer(app.mildstone1);
				}
				if(	app.mildstone2Flag == TRUE)
				{
					app.mildstone2[app.blinkIndex]++;
					if(app.mildstone2[app.blinkIndex] > max[app.blinkIndex])
						app.mildstone2[app.blinkIndex] = '0';			
							
					DigitDisplay_updateBuffer(app.mildstone2);

				}

			}
			
			if ((LinearKeyPad_getPBState(MILDSTONE1_PB) == KEY_PRESSED) && (app.mildstone1Flag == TRUE))
			{
				app.mildstone1Flag = FALSE;
				//Turn of blink
				DigitDisplay_blinkOff();

				//Display the preset value on the display
				DigitDisplay_updateBuffer(app.mildstone1);


				//Store preset value in the EEPROM
				for(i = 0; i < NO_OF_DIGITS ; i++ )
				{
					Write_b_eep( EEPROM_MILDSTONE1_ADDRESS  + i ,app.mildstone1[i] );
					Busy_eep( );
				}

				app.mildstone1Value = (UINT16)(((app.mildstone1[3]- '0' )* 10 )+ ( app.mildstone1[2] - '0') )* 60 +(((app.mildstone1[1]- '0' )* 10 )+ (app.mildstone1[0] - '0'));
				app.state = HALT_STATE;	
				
			}
			if ((LinearKeyPad_getPBState(MILDSTONE2_PB) == KEY_PRESSED) && (app.mildstone2Flag == TRUE))
			{
				app.mildstone2Flag = FALSE;
				//Turn of blink
				DigitDisplay_blinkOff();

				//Display the preset value on the display
				DigitDisplay_updateBuffer(app.mildstone2);


				//Store preset value in the EEPROM
				for(i = 0; i < NO_OF_DIGITS ; i++ )
				{
					Write_b_eep( EEPROM_MILDSTONE2_ADDRESS  + i ,app.mildstone2[i] );
					Busy_eep( );
				}

				app.mildstone2Value = (UINT16)(((app.mildstone2[3]- '0' )* 10 )+ ( app.mildstone2[2] - '0') )* 60 +(((app.mildstone2[1]- '0' )* 10 )+ (app.mildstone2[0] - '0'));
				app.state = HALT_STATE;
				
			}


				
			break;
			
			case COUNT_STATE:

	
				if (LinearKeyPad_getPBState(HALT_PB) == KEY_PRESSED)
				{
					APP_resetDisplayBuffer();
					DigitDisplay_updateBufferPartial(app.displayBuffer , 0, 4);
					GREEN_LAMP = RESET;
					RED_LAMP = RESET;
	
					app.state = HALT_STATE;
					break;
				}


				app.currentTime = GetAppTime();

				if(app.currentTime < 6000)
				{
					APP_conversion();
					DigitDisplay_updateBufferPartial(app.displayBuffer , 0, 4); 
				
				}
				else
				{
					APP_resetDisplayBuffer();
					DigitDisplay_updateBufferPartial(app.displayBuffer , 0, 4);
					app.state = HALT_STATE;	
					break;					
				}

				if( (app.currentTime >= app.mildstone1Value ) && (app.currentTime < app.mildstone2Value) )
				{
					GREEN_LAMP = SET;
				}
				else if (app.currentTime >= app.mildstone2Value)
				{
					GREEN_LAMP = RESET;
					RED_LAMP = SET;					
				}

				break;			
		}
			
}