void Button28OnClick() {
    unsigned char l,cnt[4];
    if(i==6) {
        if(a==0) {  
            a=1; 
            i=0; 
            InitMCU();
            SF_Start();
            SF_mem();
            Write_Log("Security armed");             
        }
        else {  
            i=0;
            InitMCU();            
            SF_Start();
            SF_rem();
            Write_Log("Security disarmed");   
        }
        DrawScreen(&System_Log_Screen);
        Delay_ms(2000);
        strcpy(Label24.Caption," ");
        hom=1;
        DrawScreen(&Home);
    }
}
Example #2
0
void main()
{
	FATFS fs;
	FIL file;

	InitMCU();
	//VS_SinTest(0x74);
	VS_Init();

	if(disk_initialize(0))
		ConsoleWrite("Disk Initialization FAILED. :(\n");
	else
		ConsoleWrite("Disk Initialization Complete.\n");

	if(f_mount(0,&fs))
		ConsoleWrite("Mount FieSystem Failed\n");
	else
		ConsoleWrite("Mount FileSystem Success!\n");

	ConsoleWrite("Scaning Music Files...\n\n");
	if(scan_files("/",&(Player.TotalSongNum)))
		ConsoleWrite("Scan Files Failed\n");
	else{
		ConsoleWrite("\nScan Files Accomplished.\ntotal files: ");
		ConsolePutUInt (Player.TotalSongNum);
		ConsoleWrite ("\n\n");}

	if(scan_files_open (&file,"/",1))       // Start node to be scanned and opened
		ConsoleWrite("Open File Error\n");  //Playing mp3/track001.mp3 ... will apear in function		

	
	Player.currFile	= &file;
	Player.SongNum	= 1;
	Player.Status	= PS_PLAYING;
	Player.Mode		= SM_SONG;
	Player.Volume	= 170;
	Player.Bass		= 7;
	Player.Treble	= 0;

	VS_SetBassTreble(Player.Bass,Player.Treble);

	BufCnt = 0;
//	GenerateEvent(EV_BUFEMPTY);

	//Main loop
	while(1)
	{
		//Get system event
		Player.Event = GetEvent();
		//Handle Events
		HandleEvent();
	}
}
Example #3
0
//-----------------------------------------------------------------------------
// Main function
//-----------------------------------------------------------------------------
int main(void) {

	WDT_INIT();
	InitMCU();
	initRotary();
	InitUART();
	timer_init();
	rotary__GetValue();
	nRF24L01_Initial();

	// initialize dmx driver
	MDP_SendDimmingReqToMDP(0xff, 0xFF);

	//DMX512Send();
	PORTC = 0x00;

	TCCR1A = 0x00;
	TCCR1B = 0x06;
	TCNT1H = 0xFF;
	TCNT1L = 0xFF;

	TIMSK |= 0x04;

	ZRMSendSetPreconfig(0x15);
	MSLEEP(100);
	ZRMSendReset();
	MSLEEP(1000);

	timer_set(ON_WTD_TIMER_ID, 500);
	timer_set(ON_TEST_TIMER_ID, 3000);

	timer_set(ON_ZIGBEE_PING_TIMER_ID, 3000);
	timer_set(ON_ONTIME_TIMER_ID, 100);
	timer_set(NCP_TIMER_ID, 2000);

	tmp_zrmp.zrm_State = ZRM_INIT;

	xcps_init_zigbee(USART0_Receive, USART0_Transmit);
	xcps_init_rs485(USART1_Receive, USART1_Transmit);
//	FILE mystdout =
	TX_Mode(0);
//			FDEV_SETUP_STREAM((void *)USART0_Transmit, NULL, _FDEV_SETUP_WRITE);
//	stdout = &mystdout;
//
//	DEBUG("\n\r=========START PROGRAM ===========\n\r");
	while (1) {
		ledTask();
		ZigbeeUsartTask();
		NCP_Task();
	}

	return 0;
}
Example #4
0
//-----------------------------------------------------------------------------
int main(void)
{
    // Protect code from being overwritten
    MPU_createTwoSegments(__MSP430_BASEADDRESS_MPU__,0x0DC0,MPU_EXEC|MPU_READ,MPU_EXEC|MPU_READ|MPU_WRITE);
    MPU_start(__MSP430_BASEADDRESS_MPU__);


    // Check if a wakeup from LPMx.5 was detected and use a dedicated device-init flow and continue
    // previous program execution in that case.
    if (SYSRSTIV == SYSRSTIV_LPM5WU) {
        mode = APP_MAIN_MENU;
        select = 0;
    }
    else {              // Start up normally
        SystemInit();   // Initialize board

        // Display TI Logo
        LCD_drawPicture(1);
        TA1_sleep(8192);         // 2s
        TA1_sleep(8192);         // 2s
        // Write Title Screen on LCD
        LCD_introWrite();
        TA1_sleep(8192);         // 2s
        TA1_sleep(8192);         // 2s
    }

    // Init CapTouch Sliders
    TI_CAPT_Init_Baseline(&slider0);             //slider0 is the left capacitive touch slider (note right slider is not used)
 //   TI_CAPT_Init_Baseline(&slider1);

    TI_CAPT_Update_Baseline(&slider0, 10);
 //   TI_CAPT_Update_Baseline(&slider1, 10);


    InitMCU(); //initialize MCU for BMS
    BMSstart(); //start the BMS by searching for BQ76PL536 chips and addressing them

    while (1) {
        // Choose which app to enter based on mode variable
        switch (mode) {
        case APP_MAIN_MENU:
            mode = MainMenu();                                      //start main menu
            break;
        case APP_CELL_VOLTAGE:
        	CellVoltApp();                                          //run the cell voltage app
            break;
        case APP_PACK_VOLTAGE:
        	LCD_displayPackVoltage();                               //displays pack voltage
            break;
        case APP_STATE_OF_CHARGE:                                   //run state of charge app
        	StateOfChargeApp();
            break;
        case APP_TEMPERATURE:                                       //display pack temperatures
        	LCD_displayTemperature();
            break;
        case APP_CELL_BALANCE:                                      //run cell balance app
            //CellBalanceApp();
        	LCD_displayCellsImbalanced();
            break;
        default: break;
        }
    }
}
Example #5
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
	}