Пример #1
0
int main(int argc, const char *argv[])
{
	unsigned char i;
	LCDInit(LS_NONE);
	LCDClear();

	// Initialize usart
	init_usart(BAUDRATE, TRANSMIT_RATE, DATA_BITS, STOP_BITS, PARITY_BITS);

	char recipe_name[RECIPE_NAME_LENGTH];

    eeprom_read_block((void*)&recipe_name, (const void*)0x00, RECIPE_NAME_LENGTH);
    
	LCDWriteString("Recipe Name:");
	LCDWriteStringXY(0,1,recipe_name);

	for(i=0;i<25;i++) _delay_loop_2(0);
	
	// Clear second row
	LCDWriteStringXY(0,1,"                ");
    eeprom_read_block((void*)&recipe_name, (const void*)0x76, RECIPE_NAME_LENGTH);

	LCDWriteString("Recipe Name:");
	LCDWriteStringXY(0,1,recipe_name);

	return 0;
}
Пример #2
0
void main(void)
{
    //Initialize the LCD module
    LCDInit(LS_NONE);

    //Initialize the ADC module
    ADCInit();

    //Clear the LCD
    LCDClear();

    LCDWriteString("Thermometer");

    while(1)
    {
        //Read the temperature using LM35
        float t = LM35ReadTemp();

        //Print it on the LCD
        LCDWriteIntXY(0,1,t,3);

        //Print the degree symbol and C
        LCDWriteString("%0C");

        //Wait 200ms before taking next reading
        __delay_ms(200);
    }

}
Пример #3
0
void displayAntShort(uint8_t id, const char* name, const char* decor)
{
	uint8_t x = (id * 8);
	uint8_t len = strLen(name);
	x += (6 - len) / 2;
	LCDGotoXY(x,1);
	LCDWriteString(decor);
 	LCDWriteString(name);
	LCDWriteString(decor);
}
Пример #4
0
void main()
{
     unsigned char i;

   //Initialize LCD module
   LCDInit(LS_BLINK|LS_ULINE);

   //Clear the screen
   LCDClear();

   //Simple string printing
   LCDWriteString("Congrats ");

   //A string on line 2
   LCDWriteStringXY(0,1,"Loading ");

   //Print some numbers
   for (i=0;i<99;i+=1)
   {
      LCDWriteIntXY(9,1,i,3);
      LCDWriteStringXY(12,1,"% ");
      _delay_loop_2(0);
      _delay_loop_2(0);
      _delay_loop_2(0);
      _delay_loop_2(0);

   }

   //Clear the screen
   LCDClear();

   //Some more text

   LCDWriteString("Hello world");
   LCDWriteStringXY(0,1,"By YourName Here");    // <--- Write ur NAME HERE !!!!!!!!!!!

   //Wait
   for(i=0;i<100;i++) _delay_loop_2(0);

   //Some More ......
   LCDClear();
   LCDWriteString("    eXtreme");
   LCDWriteStringXY(0,1,"  Electronics");

	//Wait
   for(i=0;i<100;i++) _delay_loop_2(0);

   //Custom Chars ......
   LCDClear();
   LCDWriteString("Custom Char !!!");
   LCDWriteStringXY(0,1,"%0%1%2%3%4%5%6%7");

}
void main()
{
    unsigned char i;
   for(i=0;i<10;i++) _delay_loop_2(0);
   
    while(1)
   {

   //Initialize LCD module
   LCDInit(LS_BLINK|LS_ULINE);
  
   for(i=0;i<10;i++) _delay_loop_2(0);
   //Clear the screen
   LCDClear();

   //Simple string printing
   LCDWriteStringXY(0,0,"Welcome to CELAB");
   //LCDWriteString("Congrats ");

   //A string on line 2
   LCDWriteStringXY(0,1,"Loading ");

   //Print some numbers
   for (i=0;i<99;i+=1)
   {
      LCDWriteIntXY(9,1,i,3);
      LCDWriteStringXY(12,1,"%");
      _delay_loop_2(0);

   }

   //Clear the screen
   LCDClear();

   //Some more text

   LCDWriteString("Hello world");
   LCDWriteStringXY(0,1,"ComputronicsLab");    // <--- Write ur NAME HERE !!!!!!!!!!!

   //Wait
  for(i=0;i<50;i++) _delay_loop_2(0);

   //Some More ......
   LCDClear();
   LCDWriteString("Computronics");
   LCDWriteStringXY(0,1,"Lab");
   for(i=0;i<50;i++) _delay_loop_2(0);
   }

}
Пример #6
0
void clearPrompt()
{
  next_menu_clear = 0 ;
  menuFunction = MENU_NONE ;
  LCDGotoXY(9,0);
  LCDWriteString("       ");              
}
Пример #7
0
int main(int argc, const char *argv[])
{
	LCDInit(LS_NONE);
	LCDClear();

	// while(1)
	// {
		//Clear the screen
		// LCDClear();


		//Simple string printing
		LCDWriteString("GET A STRING!");

		//A string on line 2
		// LCDWriteStringXY(0,1," Senior Project");
		// int i;
		//Wait
		// for(i=0;i<100;i++) _delay_loop_2(0);

		//Clear the screen
		// LCDClear();
	// }

	return 0;
}
Пример #8
0
void init_lcd(void)
{
	LCDInit(LS_NONE);
	LCDClear();

	LCDWriteString("    Mr. Pour    ");
	LCDWriteStringXY(0,1," Senior Project");
}
Пример #9
0
/* FUNCTIILE DE OUTPUT PE LED,BUZZER*/
void view_MORSE(char* msg, char* msg2)
{
	int i;
	LCDClear();
	LCDWriteString(msg2);
	for (i=0;i<strlen(msg);i++) {
		if (msg[i]=='s') S();
		else if (msg[i]=='o') O();
	}
}
Пример #10
0
void update_LCD_screen(int view)
{
	/* Switch view on LCD */
	if (view == LCD_CURRENT_TEMP) {
		/* Create string to display on LCD */
		sprintf(lcd_string, "     %1.1f F", (double)g_current_temp);

		/* Print update to LCD */
		LCDClear();
		LCDWriteString(" Internal Temp  ");
		LCDWriteStringXY(0, 1, lcd_string);
	} 
	if (view == LCD_DEFINED_TEMP) {
		/* Create string to display on LCD */
		sprintf(lcd_string, "     %1.1f F", (double)g_defined_temp);

		/* Print update to LCD */
		LCDClear();
		LCDWriteString("  Desired Temp");
		LCDWriteStringXY(0, 1, lcd_string);
	}
}
Пример #11
0
void main()
{
	uint8_t cmd=0;


	RemoteInit();

	LCDInit(LS_BLINK);

	LCDClear();

	LCDWriteString("IR RemoteDecoder");
	LCDWriteStringXY(0,1,"Key Code:");

	while(1)
	{
		cmd=GetRemoteCmd(1);
		LCDWriteIntXY(10,1,cmd,3);
	}
}
Пример #12
0
int main(void)
{
	stdin = stdout = &usart0_str;

	perform_inits();

	/* Local variables */
	char c;
	char *ing1;
	char *ing2;
	char *ing3;
	char *ing4;
	char *sensor_temp;
	char *defined_temp;
	TempData *temps;
	Recipe *recipe;

	/* Allocate space for temp struct */
	temps = malloc(sizeof(TempData));

	/* Allocate space for recipe struct */
	recipe = malloc(sizeof(Recipe));

	/* Allocate space for holding each ingredient */
	ing1 = malloc(3 * sizeof(char));
	ing2 = malloc(3 * sizeof(char));
	ing3 = malloc(3 * sizeof(char));
	ing4 = malloc(3 * sizeof(char));

	/* Allocate space for temp data */
	sensor_temp = malloc(4 * sizeof(char));
	defined_temp = malloc(2 * sizeof(char));

	/* Check for memory allocation errors */
	if ((temps == NULL) || (recipe == NULL) || (ing1 == NULL) || (ing2 == NULL) || (ing3 == NULL) || (ing4 == NULL) || (sensor_temp == NULL) || (defined_temp == NULL)) {
		LCDClear();
		LCDWriteString("Error while alloc");
		LCDWriteStringXY(0,1,"ating memory :(");
		while(1);
	}

	/* Initialize structure values */
	init_temps_struct(temps);
	init_recipe_struct(recipe);

	/* Enable Timer3 overflow interrupt - used for changing display of LCD */
	enable_temp_sensor_timer_interrupt();

	while(1) {
		// Wait for signal from website
		scanf(" %1c", &c);

		switch(c) {
			case 'c':
			// get value from temp sensor
			// compare with set temp
			// decide whether cooler is on/off
				disable_temp_sensor_timer_interrupt();
				scanf(" %4s", sensor_temp);
				convert_temp_to_float(temps, sensor_temp, 0);
				g_current_temp = temps->sensor_temp;
				if (temps->sensor_temp >= 20 || temps->sensor_temp <= 90) {
					update_LCD_screen(LCD_CURRENT_TEMP);
					compare_temps(temps);
				}
				enable_temp_sensor_timer_interrupt();
				break;
			case 'p':
			// read the four ingredient amounts
			// turn each motor on to pour the ingredients
				disable_temp_sensor_timer_interrupt();
				isPouring = true;
				scanf(" %s", ing1);
				scanf(" %s", ing2);
				scanf(" %s", ing3);
				scanf(" %s", ing4);
				convert_recipe_to_float(recipe, ing1, ing2, ing3, ing4);

				if ((recipe->ing1 >= 0. || recipe->ing1 <= 8.) && (recipe->ing2 >= 0. || recipe->ing2 <= 8.)  && (recipe->ing3 >= 0. || recipe->ing3 <= 8.)  && (recipe->ing4 >= 0. || recipe->ing4 <= 8.)) {
					LCDClear();
					LCDWriteString("Pouring recipe..");
					
					/* Go pour the recipe */
					pour_recipe(recipe);

					update_LCD_screen(LCD_CURRENT_TEMP);
				}
				enable_temp_sensor_timer_interrupt();
				break;
			case 't':
				/* Grab updated internal temp from site */
				disable_temp_sensor_timer_interrupt();
				scanf(" %2s", defined_temp);
				convert_temp_to_float(temps, defined_temp, 1);

				/* Create string to display on LCD */
				g_defined_temp = temps->defined_temp;
				sprintf(lcd_string, "     %1.1f F", (double)g_defined_temp);
				LCDClear();
				LCDWriteString("  Temp updated");
				LCDWriteStringXY(0, 1, lcd_string);

				_delay_ms(1000);
				update_LCD_screen(LCD_CURRENT_TEMP);
				enable_temp_sensor_timer_interrupt();
				break;
		}
	}
	if (ing1) free(ing1);
	if (ing2) free(ing2);
	if (ing3) free(ing3);
	if (ing4) free(ing4);
	if (sensor_temp) free(sensor_temp);
	if (defined_temp) free(defined_temp);
	if (temps) free(temps);
	if (recipe) free(recipe);
	return 0;
}
Пример #13
0
void sMCIfaceLCD_writeString(const sc_string chr) {
	LCDWriteString(chr);
}
Пример #14
0
int main(void)
{
	
	Port_Init();
	DDRE |= (1<<3);
	DDRA |= (1<<6);
	LCDInit(LS_NONE);
	
	DDRC |= (1<<3);
	PORTC |= (1<<3);
	cal_point_1 = eeprom_read_dword(0);
	cal_point_2 = eeprom_read_dword((uint32_t*)5);
	target_feedback = (cal_point_1 + cal_point_2)/2;
	cli();
	TIMSK |= ((1 << TICIE1)| (1 << TOIE1));   //Set capture interrupt
	TCCR1B |= ((1 << ICES1) | (1<<CS10));
	TCCR3A = ((1<<COM3A1));
	TCCR3B = ((1<<CS30) | (1<<WGM33));
	ICR3 = 1000;
	OCR3A = 0;
	sei(); 
	LCDClear();
	//LCDWriteString("Powering On...");
	red_light();
	WDT_Init();
	OCR3A = (int)pwm_duty_cycle;
	_delay_ms(100);
	/*int warm_up_timer = 10;
	while(warm_up_timer > 0)
	{
		if (feedback_speed < (target_feedback - 7))
		{
			if (feedback_speed > (target_feedback - 100))
			{
				pwm_duty_cycle += 1;
			}
		}
		if (feedback_speed > (target_feedback + 7))
		{
			if(feedback_speed < (target_feedback + 100))
			{
				pwm_duty_cycle -= 1;
			}
			
		}
		if (feedback_speed < (target_feedback - 100) )
		{
			pwm_duty_cycle += 3;
		}
		if (feedback_speed > (target_feedback + 100))
		{
			pwm_duty_cycle -= 3;
		}
		if(pwm_duty_cycle > 499){pwm_duty_cycle = 499;}
		if(pwm_duty_cycle < 0 ){pwm_duty_cycle = 0;}
		
		wdt_reset();
		_delay_ms(100);
		LCDClear();
		char feedback_speed_string[4];
		snprintf(feedback_speed_string,4,"%d",feedback_speed);
		LCDWriteString(feedback_speed_string);
		warm_up_timer -= 1;
	}
	*/
	
	
	
	
    while(1)
    {
		feedback_speed = (new_feedback_speed);
        if (page == 0)
		{
			wdt_reset();
			real_speed = ((double) feedback_speed / (double) target_feedback)*4.5f;
			average_speed = (real_speed+average_speed*4.0f)/5.0f;
			int avg_speed_int = (int)average_speed;
			float avg_speed_float = average_speed - avg_speed_int;
			int avg_speed_dec = avg_speed_float*10;
			snprintf(avg_speed_string,4,"%01d.%01d",avg_speed_int,avg_speed_dec);
			LCDClear();
			LCDWriteString("Airflow: ");
			LCDWriteString(avg_speed_string);
			LCDWriteString(" m/s");
			LCDWriteStringXY(0,1,"Target: 4.5 m/s");
			wdt_reset();
			_delay_ms(100);
			wdt_reset();
			
			// speed control section
			if (feedback_speed < (target_feedback - 10))
			{
				if (feedback_speed > (target_feedback - 200))
				{
					pwm_duty_cycle += 0.25;
				}
			}
			if (feedback_speed > (target_feedback + 10))
			{
				if(feedback_speed < (target_feedback + 200))
				{
					pwm_duty_cycle -= 0.25;
				}
				
			}
			if (feedback_speed < (target_feedback - 200) )
			{
				pwm_duty_cycle += 4;
			}
			if (feedback_speed > (target_feedback + 200))
			{
				pwm_duty_cycle -= 4;
			}
			if (feedback_speed < (target_feedback - 60))
			{
				errors += 20;
			}
			if (feedback_speed > (target_feedback + 60))
			{
				errors += 20;
			}
			if (feedback_speed < (target_feedback + 40))
			{
				if (feedback_speed > (target_feedback - 40))
				{
					errors = 0;
				}
			}
			if (errors > 250) 
			{
				errors = 250;
				
			}
			if (pwm_duty_cycle > 999) {pwm_duty_cycle = 999;}
			if (pwm_duty_cycle < 0){pwm_duty_cycle = 0;}
				
		
			
			OCR3A = (int)pwm_duty_cycle;
			wdt_reset();
		}
		
		
		
		
		
		if (page == 1)
		{
			LCDClear();
			LCDWriteString("Calibration Mode");
			if(cal_number == 0)
			{
				LCDWriteStringXY(0,1,"Cal. Point 1");
			}
			if(cal_number == 1)
			{
				LCDWriteStringXY(0,1,"Cal. Point 2");
			}
			if(cal_number == 2)
			{
				LCDWriteStringXY(0,1,"Press %1 To Save");
			    _delay_ms(50);
				LCDWriteStringXY(0,1,"Press %2 To Save");
				_delay_ms(50);
				wdt_reset();
			}
			wdt_reset();
			_delay_ms(150);
			wdt_reset();
			
		}
		
		
		
		
		if (!(PINA & (1<<3)))
		{
			page++;
			while(!(PINA & (1<<3)))
			{
				wdt_reset();
			} //right
			_delay_ms(25);
			if (page > 1)
			{
				page = 0;
			}
		}
		
		
		
		if (!(PINA & (1<<0))) //up
		{
			if (page == 1)
			{
				cal_speed += 5;
				if (cal_speed > 1000)
				{
					cal_speed = 1000;
				}
				OCR3A = cal_speed;
				wdt_reset();
			}	
			_delay_ms(25);	
		}
		
		
		
		
		if (!(PINA & (1<<4))) //down
		{
			if (page == 1)
			{
				cal_speed -= 5 ;
				if (cal_speed < 0)
				{
					cal_speed = 0;
				}
				OCR3A = cal_speed;
				wdt_reset();
			}
			_delay_ms(25);
		}
		
		
		
		
		if (!(PINA & (1<<2))) //center
		{
			wdt_reset();
			if (page == 1)
			{			
				switch (cal_number)
				{
					case 0:
					cal_point_1 = feedback_speed;
					cal_number = 1;
					break;
					
					case 1:
					cal_point_2 = feedback_speed;
					cal_number = 2;
					break;
					
					case 2:
					wdt_reset();
					eeprom_write_dword(0,cal_point_1);
					eeprom_write_dword((uint32_t*)5,cal_point_2);
					wdt_reset();
					page = 0;
					cal_number = 0;
					break;
					
				}
			}
			
			
			while(!(PINA & (1<<2)))
			{
				wdt_reset();
			}
			_delay_ms(25);
		}
		if (!(PINA & (1<<1))) //left
		{
			page--;
			while(!(PINA & (1<<3)))
			{
				wdt_reset();
			}
			_delay_ms(25);
			if (page < 0)
			{
				page = 1;
			}
		}
		if (errors == 0)
		{
			green_light();
		}
		if(errors >= 250)
		{
			red_light();
		}
		
		
    }
}
Пример #15
0
void LCDWriteStringXY(uint8_t x, uint8_t y, const char *msg) {
    LCDGotoXY(x, y);
    LCDWriteString(msg);
}
Пример #16
0
void doMenu()
{   
    while(bButton)
        readInputs();
    
    // set the new time
    if (menuFunction == MENU_NONE | menuFunction == MENU_TIME)
    {
        int h,m,s ;
        
        h = hour ;
        m = minute ;
        s = seconds ;
        
        LCDClear();
        LCDWriteString(setText);
        LCDWriteString("Hours");
        
        LCDGotoXY(0,1) ;
        showTime();

        while(!bButton)
        {
            readInputs();
            
            if (state & DIR_CW)
            {
                hour++;
                if (hour > 23)
                    hour = 0 ;
            }
            else if (state & DIR_CCW)
            {
                hour--;
                if (hour < 0)
                    hour = 0 ;
            }
            
            if (state & 0x30)
            {
                LCDGotoXY(0,1) ;
                showTime();
            }
        }
        
        while(bButton)
            readInputs();
    
        LCDGotoXY(0,0) ;
        LCDWriteString(setText);
        LCDWriteString("Minutes");

        while(!bButton)
        {
            readInputs();
            
            if (state & DIR_CW)
            {
                minute++;
                if (minute > 59)
                    minute = 0 ;
            }
            else if (state & DIR_CCW)
            {
                minute--;
                if (minute < 0)
                    minute = 0 ;
            }
            
            if (state & 0x30)
            {
                LCDGotoXY(0,1) ;
                showTime();
            }
        }
        
        while(bButton)
            readInputs();

        LCDGotoXY(0,0) ;
        LCDWriteString(setText);
        LCDWriteString("Seconds");

        while(!bButton)
        {
            readInputs();
            
            if (state & DIR_CW)
            {
                seconds++;
                if (seconds > 59)
                    seconds = 0 ;
            }
            else if (state & DIR_CCW)
            {
                seconds--;
                if (seconds < 0)
                    seconds = 0 ;
            }
            
            if (state & 0x30)
            {
                LCDGotoXY(0,1) ;
                showTime();
            }
        }
        
        // save changes
        if (h != hour || m != minute || s != seconds)
        { // we only update the RTC if changes have been made
            h = ((hour / 10) << 4) + hour % 10 ;
            m = ((minute / 10) << 4) + minute % 10 ;
            s = ((seconds / 10) << 4) + seconds % 10 ;

            DS1307_SetTime(h,m,s) ;
            
            runningMinute = minute ;
        }
        
        while(bButton)
            readInputs();
    }
    
    // set the new date
    if (menuFunction == MENU_NONE | menuFunction == MENU_DATE)
    {
        int n,d,m,y ;
        
        n = day ;
        d = date ;
        m = month ;
        y = year ;
        
        LCDClear();
        LCDWriteString(setText);
        LCDWriteString("Year");
        
        LCDGotoXY(0,1) ;
        showDate();

        while(!bButton)
        {
            readInputs();
            
            if (state & DIR_CW)
            {
                year++;
                if (year > 99)
                    year = 0 ;
            }
            else if (state & DIR_CCW)
            {
                year--;
                if (year < 0)
                    date = 99 ;
            }
            
            if (state & 0x30)
            {
                LCDGotoXY(0,1) ;
                showDate();
            }
        }
        
        while(bButton)
            readInputs();
    
        LCDGotoXY(0,0) ;
        LCDWriteString(setText);
        LCDWriteString("Month");

        while(!bButton)
        {
            readInputs();
            
            if (state & DIR_CW)
            {
                month++;
                if (month > 12)
                    month = 1 ;
            }
            else if (state & DIR_CCW)
            {
                month--;
                if (!month)
                    month = 12 ;
            }
            
            if (state & 0x30)
            {
                LCDGotoXY(0,1) ;
                showDate();
            }
        }
        
        while(bButton)
            readInputs();

        LCDGotoXY(0,0) ;
        LCDWriteString(setText);
        LCDWriteString("Date ");

        while(!bButton)
        {
            readInputs();
            
            if (state & DIR_CW)
            {
                date++;
                if (date > monthDays[month-1])
                    date = 1 ;
            }
            else if (state & DIR_CCW)
            {
                date--;
                if (date < 0)
                    date = monthDays[month-1] ;
            }
            
            if (state & 0x30)
            {
                LCDGotoXY(0,1) ;
                showDate();
            }
        }
        
        while(bButton)
            readInputs();

        LCDGotoXY(0,0) ;
        LCDWriteString(setText);
        LCDWriteString("Day  ");

        while(!bButton)
        {
            readInputs();
            
            if (state & DIR_CW)
            {
                day++;
                if (day > 7)
                    day = 1 ;
            }
            else if (state & DIR_CCW)
            {
                day--;
                if (day < 0)
                    day = 7 ;
            }
            
            if (state & 0x30)
            {
                LCDGotoXY(0,1) ;
                showDate();
            }
        }

        if (n != day || d != date || m != month || y != year)
        { // again, we only update the RTC if changes have been made
            n = ((day / 10) << 4) + day % 10 ;
            d = ((date / 10) << 4) + date % 10 ;
            m = ((month / 10) << 4) + month % 10 ;
            y = ((year / 10) << 4) + year % 10 ;

            DS1307_SetDate(n,d,m,y) ;
        }

        
        while(bButton)
            readInputs();
    }
}
Пример #17
0
void testLCD(void)
{
    LCDGotoXY(3,1);
    LCDWriteString("Hello");
    taskExit();
}
Пример #18
0
void main()
{
	//Wait Util Other device startup
	_delay_loop_2(0);
	_delay_loop_2(0);

	//Initialize the LCD Module
	LCDInit(LS_BLINK);

	//Initialize I2C Bus
	I2CInit();

	//Enable Pull ups on keys
	PORTB|=((1<<PB2)|(1<<PB1)|(1<<PB0));

	//Clear CH bit of RTC
	#define CH 7

	uint8_t temp;
	DS1307Read(0x00,&temp);

	//Clear CH Bit
	temp&=(~(1<<CH));

	DS1307Write(0x00,temp);

	//Set 12 Hour Mode
	DS1307Read(0x02,&temp);

	//Set 12Hour BIT
	temp|=(0b01000000);

	//Write Back to DS1307
	DS1307Write(0x02,temp);

	
	LCDClear();
	
	LCDWriteString("DS1307 RTC Exmple");
	
	char Time[12];	//hh:mm:ss AM/PM
	
	//Now Read and format time
	uint8_t data;
	
	while(1)
	{
		
		DS1307Read(0x00,&data);
		Time[8]='\0';
		Time[7]=48+(data & 0b00001111);
		Time[6]=48+((data & 0b01110000)>>4);
		Time[5]=':';
	
		DS1307Read(0x01,&data);
	
		Time[4]=48+(data & 0b00001111);
		Time[3]=48+((data & 0b01110000)>>4);
		Time[2]=':';
	
		DS1307Read(0x02,&data);
	
		Time[1]=48+(data & 0b00001111);
		Time[0]=48+((data & 0b00010000)>>4);

		LCDClear();
	
		LCDWriteString("DS1307 RTC Exmple");
	
		LCDWriteStringXY(2,1,Time);

		//AM/PM
		if(data & 0b00100000)
		{
			LCDWriteStringXY(11,1,"PM");
		}
		else
		{
			LCDWriteStringXY(11,1,"AM");
		}

		//Wait Some time and keep testing key input
		uint8_t i;
		for(i=0;i<20;i++)
		{
		
			if(GetKeyStatus(2))
			{
				//Go To Main Menu
				ShowMainMenu();

				_delay_loop_2(0);
				_delay_loop_2(0);
				_delay_loop_2(0);

			}
			_delay_loop_2(5000);
		}
	}
	

	
}
Пример #19
0
void SetTime()
{
	

	uint8_t hr,min,sec,am_pm,temp;

	//Read the Second Register
	DS1307Read(0x00,&temp);
	sec=(((temp & 0b01110000)>>4)*10)+(temp & 0b00001111);

	//Read the Minute Register
	DS1307Read(0x01,&temp);
	min=(((temp & 0b01110000)>>4)*10)+(temp & 0b00001111);

	//Read the Hour Register
	DS1307Read(0x02,&temp);
	hr=(((temp & 0b00010000)>>4)*10)+(temp & 0b00001111);

	am_pm=(temp & 0b00100000)>>4;

	//If Hour Register is 0 make it 12, as 00:00:00 invalid time
	if(hr==0) hr=12;

	uint8_t sel=0;

	while(1)
	{
		LCDClear();

		LCDWriteString("00:00:00    <OK>");
		
		LCDWriteIntXY(0,0,hr,2);
		LCDWriteIntXY(3,0,min,2);
		LCDWriteIntXY(6,0,sec,2);

		if(am_pm)
		{
			LCDWriteStringXY(9,0,"PM");
		}
		else
		{
			LCDWriteStringXY(9,0,"AM");
		}

		//Draw Pointer
		LCDWriteStringXY(sel*3,1,"^^");

		//Input Up key
		if(GetKeyStatus(1))
		{
			if(!GetPrevKeyStatus(1))
			{
				if(sel==0)
				{	
					//Hour
					if(hr==12)
					{
						hr=1;
					}
					else
					{
						hr++;
					}
				}

				if(sel==1)
				{	
					//Min
					if(min==59)
					{
						min=0;
					}
					else
					{
						min++;
					}
				}

				if(sel==2)
				{	
					//Sec
					if(sec==59)
					{
						sec=0;
					}
					else
					{
						sec++;
					}
				}

				if(sel==3)
				{	
					//AM-PM
					if(am_pm==0)
					{
						am_pm=1;
					}
					else
					{
						am_pm=0;
					}
				}
				if(sel == 4)
				{
					//OK
					break;
				}
			}
		}

		//Input Down
		if(GetKeyStatus(0))
		{
			if(!GetPrevKeyStatus(0))
			{
				if(sel==0)
				{	
					//Hour
					if(hr==1)
					{
						hr=12;
					}
					else
					{
						hr--;
					}
				}

				if(sel==1)
				{	
					//Min
					if(min==0)
					{
						min=59;
					}
					else
					{
						min--;
					}
				}

				if(sel==2)
				{	
					//Sec
					if(sec==0)
					{
						sec=59;
					}
					else
					{
						sec--;
					}
				}

				if(sel==3)
				{	
					//AM-PM
					if(am_pm==0)
					{
						am_pm=1;
					}
					else
					{
						am_pm=0;
					}
				}
				if(sel == 4)
				{
					//OK
					break;
				}
			}
		}

		if(GetKeyStatus(2))
		{
			if(!GetPrevKeyStatus(2))
			{
				//Change Selection
				if(sel==4)
					sel=0;
				else
					sel++;
			}
		}

		PREV_PINB=PINB;

		_delay_loop_2(30000);

	}

	//Now write time back to RTC Module
	temp=((sec/10)<<4)|(sec%10);
	DS1307Write(0x00,temp);

	temp=((min/10)<<4)|(min%10);
	DS1307Write(0x01,temp);

	temp=((hr/10)<<4)|(hr%10);
	temp|=0b01000000; //12 Hr Mode
	if(am_pm)
	{
		temp|=0b00100000;
	}
	DS1307Write(0x02,temp);

	LCDClear();
	LCDWriteString("Message !");
	LCDWriteStringXY(0,1,"Main Time Set");

	uint8_t i;
	for(i=0;i<10;i++)
		_delay_loop_2(0);




}
Пример #20
0
void ShowMainMenu()
{
	//The Main Menu
	char *menu_items[]={ 	"Set Time",
							"Set On Time",
							"Set Off Time",
							"Quit"
						};
	uint8_t menu_count=4;
	uint8_t selected=0;

	_delay_loop_2(0);
	_delay_loop_2(0);

	while(1)
	{
		LCDClear();
		LCDWriteString("    Main Menu  ");

		LCDWriteStringXY(2,1,menu_items[selected]);

		LCDWriteStringXY(0,1,"<");
		LCDWriteStringXY(15,1,">");

		if(GetKeyStatus(1))
		{
			//Left Key(No 1) is pressed
			//Check that it was not pressed previously
			if(!GetPrevKeyStatus(1))
			{
				if(selected !=0)
					selected--;
			}
		}

		if(GetKeyStatus(0))
		{
			//Right Key(No 0) is pressed
			//Check that it was not pressed previously
			if(!GetPrevKeyStatus(0))
			{
				if(selected !=(menu_count-1))
					selected++;
			}
		}

		if(GetKeyStatus(2))
		{
			//Enter Key Pressed
			//Check that it was not pressed previously
			if(!GetPrevKeyStatus(2))
			{
				//Call Appropriate Function
				switch (selected)
				{
					case 0:
						SetTime();
						break;
					case 1:
						//SetOnTime();
						break;

					case 2:
						//SetOffTime();
						break;

					case 3:
						return;//Quit
				}
				
			}
		}

		PREV_PINB=PINB;

		_delay_loop_2(5000);
	}
}
Пример #21
0
void main(void) 
{
    // initialise the RTC communication line
    I2C_Init() ;
    // initialise the LCD display
    LCDInit(LS_NONE);
    // initialise the actual RTC
    DS1307_Init() ;

    //clear the display
    LCDClear();
    
    // read back our running time
    DS1307_readRam(&runningMinutes,0,2) ;
    DS1307_readRam(&runningHours,2,2) ;
    
    LCDWriteString("Starting counter");
    LCDGotoXY(0,1) ;
    LCDWriteString("at ");
    LCDWriteInt(runningHours,1);
    LCDWriteString(":");
    LCDWriteInt(runningMinutes,1);
    __delay_ms(750) ;
    __delay_ms(750) ;
    __delay_ms(750) ;
    __delay_ms(750) ;

    // compensate for our handling on the first run of the readClock routine
    runningMinutes-- ;

    LCDClear();
    // infinite loop, read the clock, display on the LCD, check for the button, and if needed, process the menus
   while(1)
  {       
      readClock();
      
      showClock() ;           
      
      readInputs() ;
      
      if (bButton)
        doMenu();
      else if (state & 0x30)
      {
          // rotate the encoder to select a menu function, well, that was the aim, but encoder reading
          // seems a tad slow or inaccurate.
          //
          // there is a timeout if the button isn't pressed after selecting the menu option
          
          if (state & DIR_CW)
          {
              menuFunction++ ;
              if (menuFunction == MENU_LAST)
                  menuFunction = MENU_NONE ;
          }
          else if (state & DIR_CCW)
          {
              menuFunction-- ;
              if (menuFunction < MENU_NONE)
                  menuFunction = MENU_LAST-1 ;
          }
          
          if (menuFunction != MENU_NONE)
          {
              next_menu_clear = minute * 60 + seconds + 20 ;
              LCDGotoXY(9,0);
              if (menuFunction == MENU_TIME)
                LCDWriteString("Time ?");
              if (menuFunction == MENU_DATE)
                LCDWriteString("Date ?");
          }
          else
              clearPrompt();
      }
      else if (next_menu_clear && ((minute * 60 + seconds) > next_menu_clear))
      {
          clearPrompt();
      }
  }
}
Пример #22
0
int main(void)
{
	//int flag;
	
	TWI_init_master();
	_delay_ms(100);
	//sei();
	//_delay_ms(1000);
	InitLCD(0);
	_delay_ms(50);
	LCDClear();
	_delay_ms(10);
    uart_0_ini();
	uart_1_ini();
        Init_LED();
		sei();
		_delay_ms(50);
		
		LCD(0,0,"VIT");
		_delay_ms(500);
		LCDClear();
		_delay_ms(10);
		LCD(0,0,"SURACSHA");
		_delay_ms(100);
		LCDClear();
		_delay_ms(100);
	
	
		while (1)
		{
LCDvar(0,0,Y_Data,5);
 		if (Y_Data > 2000 || Y_Data < -2000 ||X_Data > 2000 || X_Data < -2000||Z_Data > 2000 || Z_Data < -2000)
 		{
				_delay_ms(50);
 					LCDClear();
 					_delay_ms(70);
 				LCD(0,1,"accident Happned");
 				//flag=1;
 				glow3();
 				glow4();

 				 LCDGotoXY(0,0);
			LCDWriteString("Waiting for GPS");
 			while(valid!='A');
 			 LCDClear();
				 _delay_ms(100);
			 LCDGotoXY(0,0);
 			LCDWriteString("Fix Available");
 				_delay_ms(2000);
				 LCDClear();
				 _delay_ms(100);
 				 sendlocation("9503139115");
 				//break;
 		}		
 		else
 		{_delay_ms(70);
 		 LCDGotoXY(0,1);
	LCDWriteString("Normal");
 		glow2();
 		glow3();
 		_delay_ms(50);
 		off2();
 		off3();
 
	}

			
		 }}