예제 #1
0
파일: main.c 프로젝트: coocox/Mplib
int main()
{
    Read_EEPROM();
    while(1);

    return 0;
}
//========================================================================//
//                          Leer EEPROM                                  //
//======================================================================//
void leer_EEPROM(void)
{
uint8_t dat;
 if(RD_Mer_L==0xff)
   {
     RD_Mer_H++;}

 _delay_ms(3);
  I2c_start();
  WR_EEPROM(DIR_WR);//Dirrecion de la memoria para escuribir en la memoria
  WR_EEPROM(RD_Mer_H);//Dirrecion Alta de la EEPROM
  WR_EEPROM(RD_Mer_L);//Dirrecion baja de la EEPROM

  I2c_start();

  dat=Read_EEPROM();

Lcd_pixel(p_x,p_y,dat);
Lcd_pixel(p_x,p_y,dat);
Lcd_pixel(p_x,p_y,dat);

PORTB=dat;
    if(p_y==132)
   {
     p_x++;
     p_y=0;
   }
  if(p_x==132)
  {
     p_x=0;
  }
p_y++;
RD_Mer_L++;


TWCR=_BV(TWINT)|_BV(TWEN)|_BV(TWSTO);

}
예제 #3
0
/** Main loop */
void main()
{
	unsigned char actionCounter=0xFF;

	InitMCU();

	LCD_Init3V();
	LCD_SetContrast(Read_EEPROM(EEAddr_LCDContrast));
	LCD_SendString("LCD ok ");

	SetupRTC();
	RefreshTime=1;
	LCD_SendString("RTC ok ");

	//load RAM values from EEPROM
	Brightness_start[0]=Read_EEPROM(EEAddr_DispBrightness);
	ReceiverMode=Read_EEPROM(EEAddr_ReceiverMode);
	SenderMode=Read_EEPROM(EEAddr_SenderMode);
	RC5Addr=Read_EEPROM(EEAddr_RC5Addr);
	Update_PWM_Offset(1);
	Update_PWM_Offset(2);

	// Infinite loop
	while(1) {
		if (TimerFlag)
			{
			PWM_StepDim();			// do next dimming step
			TimerFlag=0;
			++actionCounter;

			// check keys here since we can have only new input if timerflag was set by the keys interrupt program
			// Select key is pressed, show preview of action
			// need to check each time to generate single events directly from KeyPressDuration counter
			if (KeySelect == KeyState)
				{
				SwBackLightOn(fadetime);	//switch on or stay on
				if (Minutes2Signal)
					{
					if(0 == KeyPressDuration)
						{
						LCD_SendStringFill2ndLine("Set Snooze End");
						}
					else if (KeyPressLong == KeyPressDuration)
						{
						LCD_SendStringFill2ndLine("End Alarm");
						Beep();
						}
					}
				else if (KeyPressShort == KeyPressDuration)
					if (LightOn)
						{
						LCD_SendStringFill2ndLine("Enter Standby");
						Beep();
						}
					else
						{
						LCD_SendStringFill2ndLine("Switch All On");
						Beep();
						}
				else if (KeyPressLong == KeyPressDuration)
					{
					LCD_SendStringFill2ndLine("Enter Options");
					Beep();
					}
				else if (KeyPressLonger == KeyPressDuration)
					{
					LCD_SendStringFill2ndLine(&Canceltext[0]);
					Beep();
					}
				}

			switch (actionCounter)
				{
				case 0:
					DecodeRemote();
					Alarm_StepDim_all();
					if (1 < DisplayDimCnt)		// LCD backlight fadout count down
						{
						--DisplayDimCnt;
						}
					else if (1 == DisplayDimCnt)	// switch display backlight off?
						{
						SwLightOff(0);
						DisplayDimCnt=0;
						//set lsb, so we can use the encode to switch on again without changing alarm settings
						skipAlarmCnt = (skipAlarmCnt & skipAlarmMask) | skipAlarmhalfStep;
						}
					else				// do not measure intensity with backlight on
						{
						MeasureExtBrightness();
						}
					break;
				case 1:
					if (RefreshTime || RefreshTimeRTC)
						{
						GetTimeDateRTC();
						LCD_SendTime();
						if (RefreshTimeRTC)		//execute only once(!) every minute or we can not leave the alarm during its first minute
							{
							CheckAlarm();
							}
						if (0==LightOn)
							{
							LCD_NextAlarm();
							}
						if (1 < Minutes2Signal)
							{
							LCD_SnoozeTime();
							if (RefreshTimeRTC)
								{
								--Minutes2Signal;
								}
							}
						else if (1 == Minutes2Signal)
							{
							SwBackLightOn(1);					//switch on now
							LCD_SendStringFill2ndLine(&Alarmtext[0]);
							if (AcousticDDSAlarm())
								{
								Minutes2Signal=Read_EEPROM(EEAddr_AlarmTimeSnooze);	//button was pressed, start snooze
								}
							else
								{
								AlarmEnd();					//timeout occured, terminate alarm and switch off
								SwAllLightOff();
								LCD_SendStringFill2ndLine("Alarm Time Out");
								}
							}
						RefreshTime=0;
						RefreshTimeRTC=0;
						}
					break;
				case 2:
					// A Key was pressed if OldKeyState != 0 and Keystate = 0
					// OldKeyState = 0 must be set by receiving program after decoding as a flag
					if ((KeySelect == OldKeyState) && (0 == KeyState))
						{
						OldKeyState=0;		//Ack any key anyway
						if (Minutes2Signal)
							{
							if (KeyPressLong > KeyPressDuration)
								{
								AlarmSnoozeEnd();
								}
							else
								{
								AlarmEnd();
								LCD_SendBrightness(FocusBacklight+1);
								}
							}
						else if (KeyPressShort > KeyPressDuration)
							{
							if (LightOn) 
								{
								FocusBacklight=!FocusBacklight;
								LCD_SendBrightness(FocusBacklight+1);
								}
							else
								{
								SendRC5(RC5Addr_com, RC5Cmd_On, 1, ComModeAll, RC5Cmd_Repeats);
								SwAllLightOn();
								}
							}
						else if (KeyPressLong > KeyPressDuration)
							{
							if (LightOn)
								{
								SendRC5(RC5Addr_com, RC5Cmd_Off, 1, ComModeAll, RC5Cmd_Repeats);
								SwAllLightOff();
								}
							else
								{
								if (ComModeConditional<=SenderMode)		//reset to eeprom value in swalllightoff()
									{
									SenderMode=ComModeAll;
									}
								SendRC5(RC5Addr_com, RC5Cmd_On, 1, ComModeAll, RC5Cmd_Repeats);
								SwAllLightOn();
								}
							}
						else if (KeyPressLonger > KeyPressDuration)
							{
							Alarmflag=0;
							Options();
							}
						else
							{
							if (LightOn)	// Cancel key pressing, refresh display
								{
								LCD_SendBrightness(FocusBacklight+1);
								}
							RefreshTime=1;
							}
						}
					break;
				case 3:
					// A Rotation occured if EncoderSteps!= 0
					// EncoderSteps = 0 must be set by receiving program after decoding
					if (EncoderSteps)
						{
						Alarmflag=0;
						SwBackLightOn(fadetime);
						if (LightOn)
							{
							PWM_SetupDim(FocusBacklight+1, Brightness_steps, EncoderSteps);
							EncoderSteps = 0;								//ack any steps
							LCD_SendBrightness(FocusBacklight+1);
							SendRC5(RC5Addr_front+FocusBacklight, (Brightness[FocusBacklight+1]>>1) & 0x3F, Brightness[FocusBacklight+1] & 0x01, ComModeAll, RC5Value_Repeats);
							}
						else 
							{
							EncoderSetupValue(&skipAlarmCnt, maxskipAlarmCnt, 0);
							RefreshTime=1;
							}
						}
					actionCounter=0xFF;	//last time slot, do reset counter with increment to 0
					break;
				}
			}
		PCON=MCUIdle;				//go idel, wake up by any int
	}