Exemplo n.º 1
0
int main(void)
{

	POWEROFF();
	delayU(100);
	POWERUP();

	lcd.setLineOne("Welcome to");
	lcd.setLineTwo("TowerBuilder");
	sei();        //Enable global interrupt

	while(1)
	{
		//Send 1 character to LCD if LCD is ready
		if(lcd.ready())
		lcd.print();

		//Task scheduler
		if(taskDone == FALSE) {

			switch(taskNumber++) {

				case 0:
				button.readButtons();
				menu();
				break;

				case 1:
				adc.convertPOT();
				break;

				case 2:
				sensor.readSensors();
				break;

				case 3:
				first();
				break;

				case 4:

				break;

				case 5:

				break;

				case 6:

				break;

				default:
				taskNumber = 0;
				break;
			}

			taskDone = TRUE;

			//Update servo's channel after each task finished
			while(updateChannel == FALSE);
			servo.servoPWM();
			updateChannel = FALSE;

		}
	}
}
Exemplo n.º 2
0
void menu() {

	//Add your code here
	//You may add more functions or volatile variables
	//But DO NOT modify anything else

	//Press S1 to display the first group member's student id
	//Press S1 again to display the second group member's student id
	//Debouncing need to be done for S1 to work properly
	//16 char for each row LCD
	char row1[]= "F12  M67  B12   ";
	char row2[]= "                ";


	char MidS= sensor.middle_sensor;
	char MidL= MidS & 0xF0;
	MidL= MidL>>4;
	char MidR= MidS & 0x0F;

	char FrontS= sensor.front_sensor;
	char FrontL= FrontS & 0xF0;
	FrontL= FrontL>>4;
	char FrontR= FrontS & 0x0F;

	char BackS= sensor.back_sensor;
	char BackL= BackS & 0xF0;
	BackL= BackL>>4;
	char BackR= BackS & 0x0F;


	//////////////////////////////////convert to ascii number
	if ( MidL <10 )
	{
		MidL += 0x30;
	}
	else
	{
		MidL +=55;
	}

	if (MidR <10)
	{
		MidR += 0x30;
	}
	else
	{
		MidR +=55;
	}

	row1[6]= MidL;
	row1[7]= MidR;

	////////////////////////// c TO d, 3 TO b/f
	if ( FrontL <10 )
	{
		FrontL += 0x30;
	}
	else
	{
		FrontL +=55;
	}

	if (FrontR <10)
	{
		FrontR += 0x30;
	}
	else
	{
		FrontR +=55;
	}

	row1[1]= FrontL;
	row1[2]= FrontR;
	//////////////////////////
	if ( BackL <10 )
	{
		BackL += 0x30;
	}
	else
	{
		BackL +=55;
	}

	if (BackR <10)
	{
		BackR += 0x30;
	}
	else
	{
		BackR +=55;
	}

	row1[11]= BackL;
	row1[12]= BackR;



	lcd.setLineOne(row1);
	row2[0] = condition + 48;
	row2[2] = nextCondition + 48;

	char check1L = check1 & 0xF0;
	char check1R = check1 & 0x0F;
	check1L = check1L >> 4;
	if(check1L < 10) check1L += 0x30;
	else check1L += 55;
	if(check1R < 10) check1R += 0x30;
	else check1R += 55;

	char check2L = check2 & 0xF0;
	char check2R = check2 & 0x0F;
	check2L = check2L >> 4;
	if(check2L < 10) check2L += 0x30;
	else check2L += 55;
	if(check2R < 10) check2R += 0x30;
	else check2R += 55;

	char check3L = check3 & 0xF0;
	char check3R = check3 & 0x0F;
	check3L = check3L >> 4;
	if(check3L < 10) check3L += 0x30;
	else check3L += 55;
	if(check3R < 10) check3R += 0x30;
	else check3R += 55;

	row2[4] = check1L;
	row2[5] = check1R;

	row2[7] = check2L;
	row2[8] = check2R;

	row2[10] = check3L;
	row2[11] = check3R;

	lcd.setLineTwo(row2);



}