Ejemplo n.º 1
0
void toggleADC()
{
	
	if(state==1)
	{
	startADC(0);
	state=0;
	}
	else
	{
	startADC(1);
	state=1;
	}
}
Ejemplo n.º 2
0
int main(void) //main body calls all other functions to initialize the proper values of the Transmission protocol, timer and ADC module, then starts them
{
	InitialzeLCD(); //initializes LCD
	SetADCChannel(5); // sets ADC channel for temperature sensor 
	InitADC(); // Initializes ADC and timer below to 1 second 
	InitTimer();
	startTimer();
	startADC();
	while(1)
	{
		// Main loop
	}
}
Ejemplo n.º 3
0
int main(void)
{
	sysInfo = 0;
	
	SCS |= 0x01;
	FIODIR0 |= ((1<<21) | (1<<4) | (1<<11) | (1<<6) | (1<<23) | (1<<19) | (1<<17));
	FIODIR0 |= (1<<12);
	FIOSET0 |= (1<<12);
	xx = 0x00;

	setSpeed(SPEED_30);

	lcd_init(0);
	serial_init();

	startTimerIRQ();
	startADC();

	initKeys();

	initSound();
	startSoundIRQ();

	initIR();
	startIrIRQ();

    RF_init();
    startcc1100IRQ();
	enableWOR();
	
	initRTC();
	startRtcIRQ();
	
	enableIRQ();

	testmenu_init();
	init_menu();
	
	initBacklight();

	oldkeys[0] = keys[0];
	oldkeys[1] = keys[0];

	key_state = KEY_IDLE;

	set_font(BOLDFONT);
	
	BFS_Mount();
	load_RC_setting();
	load_RF_setting();
	load_setting();
	
	{
		struct RAWset_ RAWset;
        unsigned char x;
        unsigned long RAWcmdbase;
        
        RAWcmdbase = FLASH1_BASE +(secaddr[0]<<1);
        x=memcmp((void*)RAWcmdbase,"RC01",4);
		
        if(!x) {
               
				memcpy(&RAWset,(void *)RAWcmdbase,sizeof(struct RAWset_));
				RAWset.name[7] = 0;
				BFS_SaveFile(BFS_ID_RAWslot0, sizeof(struct RAWset_), (unsigned char*) &RAWset);
				eraseSector(1,0);
        }
	}
	
	if (EncIsValid(irDevTab.device[irDevTab.active].encoder, irDevTab.device[irDevTab.active].set)) {
		setEncoder(irDevTab.device[irDevTab.active].encoder, irDevTab.device[irDevTab.active].set);
	}	
	
	drawMainscreen();
	ask_for_time(0);
	
						
/*
	playSound((unsigned char*)sound1_data, sound1_len);
	waitSound();
	playSound((unsigned char*)sound2_data, sound2_len);
*/

	while (1)
	{
		if(keys[0] != oldkeys[0] || keys[1] != oldkeys[1])
		{
			oldkeys[0] = keys[0];
			oldkeys[1] = keys[1];
			sysInfo |= 0x40;
		}

		switch(key_state)
		{
			case KEY_IDLE:
				if(sysInfo & 0x40)
				{
					sysInfo &= 0xBF;
					if(KEY_Betty)
					{
						setBacklight(BL_AUTO);
						menu_exec(&mainMenu);
						if (EncIsValid(irDevTab.device[irDevTab.active].encoder, irDevTab.device[irDevTab.active].set)) {
							setEncoder(irDevTab.device[irDevTab.active].encoder, irDevTab.device[irDevTab.active].set);
						}
						drawMainscreen();
					}
					else if(KEY_2)
					{
						//setSpeed(SPEED_30);
					}
					else if(KEY_3)
					{
						//setSpeed(SPEED_60);
					}
					else  if(KEY_A || KEY_B || KEY_C || KEY_D)
					{
						unsigned char x;
						//playSound((unsigned char*)sound3_data, sound3_len);
						x=0;
						if (KEY_B) x=1;
						if (KEY_C) x=2;
						if (KEY_D) x=3;
						
						if (EncIsValid(irDevTab.device[x].encoder, irDevTab.device[x].set)) {
							setBacklight(BL_AUTO);
							irDevTab.active = x;
							setEncoder(irDevTab.device[x].encoder, irDevTab.device[x].set);
							drawMainscreen();
						}	
					}
/*					else if(KEY_B)
					{
					
					}
					else if(KEY_C)
					{	
//						playSound((unsigned char*)sound1_data, sound1_len);
					}
					else if(KEY_D)
					{	
//						playSound((unsigned char*)sound2_data, sound2_len);
					}*/
					if((keys[0] != 0) || (keys[1] != 0))
						key_state = KEY_PRESS;
				}
				break;
			case KEY_PRESS:
				irSend(getCode());
				key_state = KEY_HOLD;
//				autorepeat = 0;
				break;
			case KEY_HOLD:
//				if(autorepeat >= AUTO_TIMEOUT)
					irRepeat();

				if(keys[0] == 0 && keys[1] == 0)
					key_state = KEY_RELEASE;

				break;
			case KEY_RELEASE:
				irStop();
				key_state = KEY_IDLE;
				break;
		}

		if(serial_tstc() > 0)
		{
			i = serial_getc();
			if(i=='.')
			{
				serial_puts("HELO");
			}
			else if(i=='0')
			{
				setBacklight(0x00);	// pwm value
			}
			else if(i=='1')
			{
				setBacklight(0x1F);	// pwm value
			}
			else if(i=='2')
			{
				setBacklight(0x3F);	// pwm value
			}
			else
				serial_putc(i);
		}
		
		if ((bl_val == 0) && (key_state == KEY_IDLE) && !((FIOPIN0 & (1<<30)) == 0) && (((RFstatus & (WORrxon | RXenabled)) == 0))) {
			EXTINT = 0x08;
			PCON = 0x02;
			PLLFEED = 0xAA;
			PLLFEED = 0x55;
		}
		
		if (timeInfo & timechanged) {
			printTime(86,152,(struct time_ *)&time);
			printDate(0,152,(struct date_ *)&date,0);
			
			timeInfo &= ~timechanged;
		}
		
	}
	return 0;
}