void main(){
	SET_BIT(DDRB, 0);
	ini_lcd();
	clr_lcd();
	for(;;){
	pos_lcd(0,0);
	put_str_lcd("Press 1. Saria's...");
	pos_lcd(1,0);
	put_str_lcd("Press 2. Mary...");
		if (get_key() == 16)
		{
			clr_lcd();
			pos_lcd(0,2);
			put_str_lcd("Saria's Song");
			pos_lcd(1, 0);
			put_str_lcd("Press B to stop.");
			play_song(saria, 85);
			clr_lcd();
		}
		else if (get_key() == 15)
		{
			clr_lcd();
			pos_lcd(0,2);
			put_str_lcd("Mary Had A");
			pos_lcd(1, 2);
			put_str_lcd("Little Lamb");
			play_song(mary, 26);
			clr_lcd();
		}	
		wait_avr(50);
	}
}
Пример #2
0
void LCD(void)
{
	ini_lcd();
	clr_lcd();
	put_str_lcd("hi");
	wait_avr(3000);
	clr_lcd();	
	
	resetLCD();
	setDateTime();	
}
void setDate()
{
	unsigned int pre_m = month;
	unsigned int pre_d = day;
	unsigned int pre_y = year;
	month = date[0] * 10 + date[1];
	day = date[2] * 10 + date[3];
	year = date[4] * 1000 + date[5] * 100 + date[6] * 10 + date[7];
	
	if ((year%4 == 0 && year%100 != 0) || year%400 == 0)
	{
		if (month > 12 || day > leapyear[month-1])
		{
			clr_lcd();
			pos_lcd(0,0);
			put_str_lcd("MMDDYYYY");
			pos_lcd(0,0);
			col = 0;
			index = 0;
			month = pre_m;
			day = pre_d;
			year = pre_y;
		}
	}
	else
	{
		if (month > 12 || day > normal[month-1])
		{
			clr_lcd();
			pos_lcd(0,0);
			put_str_lcd("MMDDYYYY");
			pos_lcd(0,0);
			col = 0;
			index = 0;
			month = pre_m;
			day = pre_d;
			year = pre_y;
		}
	}
	set_date = 0;
}
Пример #4
0
void resetLCD(void)
{
	clr_lcd();
	// print the first date line
	char buf[10];
	pos_lcd(0, 2);
	sprintf(buf, "%02s/%02s/%04s", "MM", "DD", "YYYY");
	put_str_lcd(buf);
	
	// print time line
	pos_lcd(1, 2);
	sprintf(buf, "%02s:%02s:%02s", "HH", "MM", "SS");
	put_str_lcd(buf);
}
Пример #5
0
void update_lcd(void) {
	if (mode == 1) { // Show first 32 supported Service 1 PIDs 
		sprintf(buf0, "%02X %02X %02X %02X %02X", (unsigned int)(s1pid00[0] & 0xFF), (unsigned int)(s1pid00[1] & 0xFF), (unsigned int)(s1pid00[2] & 0xFF),
				(unsigned int)(s1pid00[3] & 0xFF), (unsigned int)(s1pid00[4] & 0xFF));
		sprintf(buf1, "%02X %02X %02X %02X %02X", (unsigned int)(s1pid00[5] & 0xFF), (unsigned int)(s1pid00[6] & 0xFF), (unsigned int)(s1pid00[7] & 0xFF),
				(unsigned int)(s1pid00[8] & 0xFF), (unsigned int)(s1pid00[9] & 0xFF));
	}
	else if (page == 0) { // Show first page: RPM and speed
		sprintf(buf0, "RPM: %i", rpm);
		sprintf(buf1, "KM/H: %i", speed);
	}
	else { // Show second page: Engine load and engine coolant temperature
		sprintf(buf0, "Load: %i", load);
		sprintf(buf1, "Temp: %i", temperature);
	}
	
	clr_lcd();
	pos_lcd(0, 0);
	puts_lcd2(buf0);
	pos_lcd(1, 0);
	puts_lcd2(buf1);
}
void setTime()
{
	unsigned int pre_hr = hr;
	unsigned int pre_min = min;
	unsigned int pre_sec = sec;
	hr = time[0] * 10 + time[1];
	min = time[2] * 10 + time[3];
	sec = time[4] * 10 + time[5];

	if(hr >= 24 || min > 59 || sec > 59){
		clr_lcd();
		pos_lcd(1,0);
		put_str_lcd("HHMMSS");
		pos_lcd(1,0);
		col = 0;
		index = 0;
		hr = pre_hr;
		min = pre_min;
		sec = pre_sec;
	}
	
	set_time = 0;
}
int main(void){
	ini_lcd();
	ini_avr();

	for(;;)
	{
		if(get_key() == 13) // SET DATE
			{
				//put_lcd('A');
				row = 0;
				col = 0;
				clr_lcd();
				pos_lcd(0,0);
				put_str_lcd("MMDDYYYY");
				start = 0;
				pos_lcd(0,0);
				set_date = 1;
				set_time = 0;
				index = 0;
			}
			
			else if(get_key() == 9) // SET TIME
			{
				//put_lcd('B');
				row = 1;
				col = 0;
				clr_lcd();
				pos_lcd(1,0);
				put_str_lcd("HHMMSS");
				start = 0;
				pos_lcd(1,0);
				set_time = 1;
				set_date = 0;
				index = 0;
			}
		if (start == 1)
		{
			increment();
			print();
		}
		else 
		{
			if(get_key() == 2)
			{
				//put_lcd('#');
				if (set_date)	{setDate();}
				if (set_time)	{setTime();}
				start = 1;
			}
			else if(get_key() == 3){
				put_lcd('0');
				if(set_date){
					date[index] = 0;
				}
				else if(set_time){
					time[index] = 0;
				}
				index++;
				col++;
			}
			else if(get_key() == 4){
				//put_lcd('*');
				clr_lcd();
				col = 0;
				row = 0;
				set_time = 0;
				set_date = 0;
				start = 1;
				index = 0;
			}
			else if(get_key() == 6){
				put_lcd('9');
				if(set_date){
					date[index] = 9;
				}
				else if(set_time){
					time[index] = 9;
				}
				index++;
				col++;
			}
			else if(get_key() == 7){
				put_lcd('8');
				if(set_date){
					date[index] = 8;
				}
				else if(set_time){
					time[index] = 8;
				}
				index++;
				col++;
			}
			else if(get_key() == 8){
				put_lcd('7');
				if(set_date){
					date[index] = 7;
				}
				else if(set_time){
					time[index] = 7;
				}
				index++;
				col++;
			}
			else if(get_key() == 10){
				put_lcd('6');
				if(set_date){
					date[index] = 6;
				}
				else if(set_time){
					time[index] = 6;
				}
				index++;
				col++;
			}
			else if(get_key() == 11){
				put_lcd('5');
				if(set_date){
					date[index] = 5;
				}
				else if(set_time){
					time[index] = 5;
				}
				index++;
				col++;
			}
			else if(get_key() == 12){
				put_lcd('4');
				if(set_date){
					date[index] = 4;
				}
				else if(set_time){
					time[index] = 4;
				}
				index++;
				col++;
			}
			else if(get_key() == 14){
				put_lcd('3');
				if(set_date){
					date[index] = 3;
				}
				else if(set_time){
					time[index] = 3;
				}
				index++;
				col++;
			}
			else if(get_key() == 15){
				put_lcd('2');
				if(set_date){
					date[index] = 2;
				}
				else if(set_time){
					time[index] = 2;
				}
				index++;
				col++;
			}
			else if(get_key() == 16){
				put_lcd('1');
				if(set_date){
					date[index] = 1;
				}
				else if(set_time){
					time[index] = 1;
				}
				index++;
				col++;
			}
			if (set_time)
			{
				if (col > 5)
				{
					col = 0;
					pos_lcd(row, col);
				}
			}
			else if (set_date)
			{
				if (col > 7)
				{
					col = 0;
					pos_lcd(row, col);
				}
			}
		}
		wait_avr(25);
	}
	return 0;
}
Пример #8
0
void setDateTime(void)
{
	// keep track of LCD pos
	int row, col;
	row = 0;
	col = 2;
	// number is the number entered
	int number;
	// counter to keep track of how many digits entered
	int counter = 0;
	// number to keep track of the number so far
	int userInput = 0;
	char buf[1]; 
	do 
	{
		while(col < 10 || row != 1)
		{
			pos_lcd(row, col);
			number = get_key();
			if(isValidKey(number))
			{
				sprintf(buf, "%i", number);
				put_str_lcd(buf);
				wait_avr(400);

				if(col >= 11 && row == 0)
				{
					row++;
					col = 2;
				}
				else if(col <= 11)
				{
					col++;
					if(col == 4 || col == 7)
						col++;
				}
					
				counter++;
				if(counter%2 == 0 && counter != 6)
					userInput += number;
				else if(counter == 5)
					userInput = 1000*number;
				else if(counter == 6)
					userInput += 100*number;
				else if(counter == 7)
					userInput += 10*number;
				else 
					userInput = 10*number;
			
			}
			if(counter == 2)
				Month = userInput;
			else if(counter == 4)
				Day = userInput;
			else if(counter == 8)
				Year = userInput;
			else if(counter == 10)
				Hour = userInput;
			else if(counter == 12)
				Minutes = userInput;
			else if(counter == 14)
				Seconds = userInput;
		}
		if(!isValidDate(Day, Month, Year))
		{
			clr_lcd();
			sprintf(buf, "%s", "invalid date");
			put_str_lcd(buf);
			wait_avr(2000);
			row = 0;
			col = 2;

			// counter to keep track of how many digits entered
			counter = 0;
			// number to keep track of the number so far
			userInput = 0;
			resetLCD();
		}
	}while(!isValidDate(Day, Month, Year));


	while(1)
	{
		wait_avr(1000);
		incrementTime();
		pos_lcd(0, 2);
		sprintf(buf, "%02i/%02i/%02i", Month, Day, Year);
		put_str_lcd(buf);
		pos_lcd(1, 2);
		sprintf(buf, "%02i:%02i:%02i", Hour, Minutes, Seconds);
		put_str_lcd(buf);
	}	
}
Пример #9
0
int main(void)
{
	ini_lcd();
	clr_lcd();
	int ca = 0;
	int cb = 0;
	int aa=0;
	int ab=0;
	int ma=0;
	int mb=0;
	int mina=0;
	int minb=0;
	//ADMUX |= 71;
	//SET_BIT(ADMUX,6);
	//ADCSRA|=135;
	//SET_BIT(ADCSRA)
	//ADMUX=(1<<REFS0); // For Aref=AVcc;
	SET_BIT(ADMUX,6);
	//ADCSRA=(1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0); //Prescalar div factor =128
	ADCSRA|=135;
	
	//wait_avr(50000);
	//uint8_t ch=ch&0b00000111;
	
	//ADMUX|=ch;
	//ADCSRA|=(1<<ADSC);

	//ADCSRA|=(1<<ADEN);
	
	
    while(1)
    {
        //TODO:: Please write your application code 
		pos_lcd(0,0);
		sprintf(beg,"A:Start Sampling");
		puts_lcd2(beg);
		pos_lcd(1, 0);
		sprintf(beg,"B:reset");
		puts_lcd2(beg);
		if(key_pressed(0, 7))
		{
			while(1)
			{
				if(key_pressed(1, 7))
				{
					result = 1;
					max=0;
					min=9999;
					average=0;
					total=0;
					count=0;
					clr_lcd();
					break;
				}
				get_adc();
				clr_lcd();
				pos_lcd(0, 0);
				//int a,b;
				ca = result / 100;
				cb = result % 100;
				aa=average/100;
				ab=average%100;
				ma=max/100;
				mb=max%100;
				mina=min/100;
				minb=min%100;
				sprintf(beg,"Cr:%01d.%02d Mx:%01d.%02d",ca,cb,ma,mb);//(adc/1023)*5
				puts_lcd2(beg);
				pos_lcd(1, 0);
				sprintf(beg,"Avg:%01d.%02d Mn:%01d.%02d",aa,ab,mina,minb);
				puts_lcd2(beg);
				wait_avr(500);
			}
		}
		

			
    }
}
Пример #10
0
/////////////////////////
// Simple application.
void main (void)
{
	unsigned char cdata[4]={0,0,0,0};
	unsigned char status;
	unsigned long conv = 0;
	unsigned char buf[14];
	unsigned char na = 0;

	float reads = 0;
	float avr = 0;

	/////////////////////////////////////////////////////////////////////

	// Initialize lcd 
	init_lcd();
	// Initialize LTC2440
	init_ad();

	// Turn off blinking cursor
	control (BLINK_OFF_CURSOR_OFF);

	// Clean lcd screen
	clr_lcd();

	// Display first message
 	wrstr_lcd ("    LTC2440 TEST");
	locate_lcd(1, 0);
  	wrstr_lcd (" DIGITAL VOLTMETER ");
	delay (30000);
 	clr_lcd();

 	// Screen template 
	locate_lcd(0, 0);
	wrstr_lcd ("INPUT: ");

 	while (1) 
	{
		if (LTC2440_eoc() == IDLE) { 
			delay(300);
		}			
		else {
			// Get status and raw conversion from ADC
			status = LTC2440_rd(&cdata) ; 					
			conv = LTC2440_get_value (&cdata); 

			// Test if Over or Under flow 
			if (status == ADOVF)			
				sprintf (buf, "%s    ", "+++ OVL +++ ");			
			else if (status == ADUNF)
				sprintf (buf, "%s    ", "--- UNF --- ");			
			else {
				// If readings are valid convert in signed floating number
				if (status == (ADRDY | ADOVF))  
					reads = (float) (conv * VREF) / RANGE ; 		
				else if (status == (ADRDY | ADUNF)) 
					reads = (float) (conv * VREF) / RANGE - VREF ; 		
				// Add averages
				if (na++ < MAXAVR) 
					avr += reads; 
				else {
				// Display averaged value
					sprintf (buf, "%+1.7f V", avr/(na-1));			
					na = 0;
					avr = 0;
				}
			}
		}	
		// display value in the right position.
		locate_lcd(0, 7);
		wrstr_lcd (buf);						
	}
}