void M11_func_ustawienia_godzina(char *str)
{
	static uint8_t i=0, edit=0;
	static uint8_t state=0;
	static uint32_t cnt=0, offset_cnt=0;
	
	if(Flagi.flaga_lcd)
	{
		lcd_locate(0, 10);
		lcd_char(0x7E);
		lcd_str(str);
		EI2C_read_buf(ADDR_EEMEM_24C64, offsetof(EXT_EEPROM_var, empty), SIZEOF (EXT_EEPROM_var, empty), (uint8_t *)str);
		lcd_locate(1, 0);
		lcd_str(str);
		Flagi.flaga_lcd=0;
	}

	switch(state)
	{
		case 0:
			state=1;	
			
			if(i>8)
				i=0;
			lcd_locate(0, 10);
			lcd_char(0x7E);
			fifo_bufor_lcd(str,i,strlen(str));
			lcd_str(str);
			
			cli();
			cnt=25000;
			offset_cnt=licznik;
			sei();
			break;
		case 1:
			if(cnt<=licznik-offset_cnt)
			{
				i++;
				state=0;
			}
			break;
	}
	
	if (key_code == PRZYCISK_ENTER)
	{
		edit++;
		if (edit>3)
			edit=1;
		Flagi.flaga_klawiatura=0;
	}
	else if (key_code == PRZYCISK_POWROT && Flagi.flaga_klawiatura==0)
	{
		edit=0;
		Flagi.flaga_klawiatura=1;
		ustaw_czas(&czas);
	}
	
	
	switch(edit)
	{
		case 1:
			if (key_code == PRZYCISK_GORA && Flagi.flaga_klawiatura==0)
			{
				czas.godziny++;
				if(czas.godziny>23)
					czas.godziny=0;
				lcd_locate(1,0);
				if( czas.godziny < 10 ) lcd_char('0');
				lcd_int(czas.godziny);
			}
			else if (key_code == PRZYCISK_DOL && Flagi.flaga_klawiatura==0)
			{
				czas.godziny--;
				if((int8_t)czas.godziny<0)
					czas.godziny=23;	
				lcd_locate(1,0);
				if( czas.godziny < 10 ) lcd_char('0');
				lcd_int(czas.godziny);
			}

			lcd_cursor_on();
			lcd_blink_on();
			lcd_locate(1,1);
			break;
		case 2:
			if (key_code == PRZYCISK_GORA && Flagi.flaga_klawiatura==0)
			{
				czas.minuty++;
				if(czas.minuty>59)
				czas.minuty=0;
				lcd_locate(1,3);
				if( czas.minuty < 10 ) lcd_char('0');
				lcd_int(czas.minuty);
			}
			else if (key_code == PRZYCISK_DOL && Flagi.flaga_klawiatura==0)
			{
				czas.minuty--;
				if((int8_t)czas.minuty<0)
				czas.minuty=59;
				lcd_locate(1,3);
				if( czas.minuty < 10 ) lcd_char('0');
				lcd_int(czas.minuty);
			}
			lcd_cursor_on();
			lcd_blink_on();
			lcd_locate(1,4);
			break;
		case 3:
			if (key_code == PRZYCISK_GORA && Flagi.flaga_klawiatura==0)
			{
				czas.sekundy++;
				if(czas.sekundy>59)
				czas.sekundy=0;
				lcd_locate(1,6);
				if( czas.sekundy < 10 ) lcd_char('0');
				lcd_int(czas.sekundy);
			}
			else if (key_code == PRZYCISK_DOL && Flagi.flaga_klawiatura==0)
			{
				czas.sekundy--;
				if((int8_t)czas.sekundy<0)
				czas.sekundy=59;
				lcd_locate(1,6);
				if( czas.sekundy < 10 ) lcd_char('0');
				lcd_int(czas.sekundy);
			}
			lcd_cursor_on();
			lcd_blink_on();
			lcd_locate(1,7);
			break;
		default:
			lcd_cursor_off();
			lcd_blink_off();
			if(Flagi.flaga_rtc)
			{
				pobierz_czas(&czas);
				Flagi.flaga_rtc=0;
			}
			lcd_locate(1,0);
			if( czas.godziny < 10 ) lcd_char('0');
			lcd_int(czas.godziny);
			lcd_char(':');
			if( czas.minuty < 10 ) lcd_char('0');
			lcd_int(czas.minuty);
			lcd_char(':');
			if( czas.sekundy < 10 ) lcd_char('0');
			lcd_int(czas.sekundy);
		break;
	}

}
Esempio n. 2
0
//----------------------------------------------------------------------------------
// ham thay doi trang thai 
void change_state()
{
    //unsigned long temp;
    //dang o trang thai binh thuong set_flag=0 va nhan duoc nut bam
    if(set_flag==0)
    {
        if(!SET_BTN)              //neu button set duoc bam-->chuyen sang trang thai set thoi gian
        {        
            Speaker = 1;
            delay_ms(100);
            Speaker = 0;
            delay_ms(100);
            put_date_info();
            put_time_info();
            while(!SET_BTN)         //cho den khi set button duoc nha?
            {
                // neu giu nut bam qua lau dua ra canh bao\
                // sau thoi gian 5s
                //error_BTN(temp);                   
            }
            //temp=0;
            set_flag=1;             //bao hieu dang la che do set time
            set_val=1;              //tang bien set_val de move blink den vi tri tuong ung
            lcd_blink_on();         //bat blinking  
            //dua contro den vi tri set gia tri giay
            lcd_blink_move();       //dua con tro toi vi tri tuong ung            
        }
        // neu khong duoc an nut thi chi hien thi thoi gian thuc
       /* else
        {
            //delay_ms(5);
            //if(state_settime)
            //{
                //set_val=0;
                //set_flag=0; 
                delay_ms(100);
                button_menu=0;
                lcd_gotoxy(0,0);
                lcd_puts("Setup thoi gian "); 
                lcd_gotoxy(0,1);
                lcd_puts("                ");
                //Speaker=1;   
            //}
            //state_settime=0;
        }*/
    }
           
    //dang o trang thai set time  set_flag=1
    if(set_flag==1)
    {
        while(!UP_BTN)            //neu bam button add------
        {
            //cho toi khi tha nut bam
            time_change(1);         //goi ham add time
            Speaker = 1;
            delay_ms(150);
            Speaker = 0;
            delay_ms(150);
        }

        while(!DOWN_BTN)          //neu bam nut sub--------
        {
            //cho toi khi tha nut bam
            time_change(-1);        //goi ham tru thoi gian
            Speaker = 1;
            delay_ms(150);
            Speaker = 0;
            delay_ms(150);
        }

        if(SET_BTN==0)              //neu bam nut set---------
        {
            Speaker = 1;
            delay_ms(150);
            Speaker = 0;
            delay_ms(150);
            while(!SET_BTN)        //cho den khi tha nut bam 
            {    
                //error_BTN(temp); 
            }
            //temp=0;
            set_val++;
            if(set_val==9)          
                set_val=1;
            if(set_val!=8)
            {
                lcd_gotoxy(13,0);
                lcd_puts("  "); 
                lcd_blink_on()  ;
                lcd_blink_move();       //dua con tro toi vi tri tiep theo   
            }
            else 
            {
                lcd_blink_off()  ;
                lcd_gotoxy(13,0);
                lcd_puts("OK"); 
            rtc_set_time(hour,minute,second);
                rtc_set_date(day,date,month,year);
            }
         }  
        //else if(ok_BTN==0)         //neu bam nut ok---------
//        if(OK_BTN==0) 
//        {
//            Speaker = 1;
//            delay_ms(150);
//            Speaker = 0;
//            delay_ms(150);
//            while(!OK_BTN)        //cho toi khi tha nut bam  
//            { 
//                //error_BTN(temp);    
//            }
//            //temp=0;
//            lcd_blink_off();
//            set_val=0;
//            set_flag=0;
//            button_menu=1;
//            rtc_set_time(hour,minute,second);
//            rtc_set_date(day,date,month,year);
//        }    
     }

}
Esempio n. 3
0
//------------------------------------------------------------------------------------
// ham su ly che do setup time
void set_time()
{
    if(state_settime)
    {
        lcd_gotoxy(0,0);
        lcd_puts("Setup time      ");
        lcd_gotoxy(0,1);
        lcd_puts("                ");  
        // hien thi gia tri thoi gian ra lcd   
        put_time(hour,5,1);
        lcd_puts(":");
        put_time(minute,8,1);
        lcd_puts(":");
        put_time(second,11,1); 
        // duoc set lai bang 1 khi chuuyen che do setup
        state_settime=0;
    }  
    
    if(!SET_BTN)          //neu bam nut enter(nut set)--------
    {
        //cho toi khi tha nut bam
        Speaker = 1;
        delay_ms(150);
        Speaker = 0;
        delay_ms(150); 
        set_flagtiet++;
        if(set_flagtiet==7)        set_flagtiet=0; 
        if(set_flagtiet!=6)
        {
            lcd_gotoxy(2,1);
            lcd_puts("     ");
        }  
    } 
         
    switch(set_flagtiet)
    {
        case 0:             //set complete
        {    
            lcd_gotoxy(4,0); 
            lcd_blink_on(); 
            delay_ms(10);  
            lcd_gotoxy(0,1);
            if(enable[STT_tiet]==1)  
                lcd_puts("EN ");
            else
                lcd_puts("DIS");
            if(!UP_BTN)            //neu bam button add------
            {
            //cho toi khi tha nut bam
                Speaker = 1;
                delay_ms(150);
                Speaker = 0;
                delay_ms(150);
                STT_tiet++;
                if(STT_tiet==13)        STT_tiet=1; 
                put_time(STT_tiet,4,0);  
                put_time(h_in[STT_tiet],11,0);
                put_time(m_in[STT_tiet],14,0);
                put_time(h_out[STT_tiet],11,1);
                put_time(m_out[STT_tiet],14,1); 
                lcd_gotoxy(0,1);
                if(enable[STT_tiet]==1)  
                    lcd_puts("EN ");
                else
                    lcd_puts("DIS");
            }

        if(!DOWN_BTN)          //neu bam nut sub--------
        {
            //cho toi khi tha nut bam
            Speaker = 1;
            delay_ms(150);
            Speaker = 0;
            delay_ms(150); 
            STT_tiet--;
            if(STT_tiet==0)        STT_tiet=12;   
            //lcd_gotoxy(5,0);
            put_time(STT_tiet,4,0); 
            put_time(h_in[STT_tiet],11,0);
            put_time(h_in[STT_tiet],11,0);
            put_time(m_in[STT_tiet],14,0);
            put_time(h_out[STT_tiet],11,1);
            put_time(m_out[STT_tiet],14,1); 
            lcd_gotoxy(0,1);
                if(enable[STT_tiet]==1)  
                    lcd_puts("EN ");
                else
                    lcd_puts("DIS");
        }   
        } 
        break;
        case 1:             //set second
        {
                lcd_gotoxy(11,0); 
                lcd_blink_on(); 
               if(!UP_BTN)            //neu bam button add------
                {
                    //cho toi khi tha nut bam
                    Speaker = 1;
                    delay_ms(150);
                    Speaker = 0;
                    delay_ms(150);
                    h_in[STT_tiet]++;
                    if(h_in[STT_tiet]==24)    h_in[STT_tiet]=0; 
                    put_time(h_in[STT_tiet],11,0); 
                }

                if(!DOWN_BTN)          //neu bam nut sub--------
                {
                    //cho toi khi tha nut bam
                    Speaker = 1;
                    delay_ms(150);
                    Speaker = 0;
                    delay_ms(150); 
                    if(h_in[STT_tiet]==0)
                        h_in[STT_tiet]=12;
                    else
                        h_in[STT_tiet]--;  
                    put_time(h_in[STT_tiet],11,0);
                }
            //delay_ms(2);
        }
        break;
        case 2:             //set minute
        {    
            lcd_gotoxy(14,0); 
            lcd_blink_on();  
               if(!UP_BTN)            //neu bam button add------
                {
                    //cho toi khi tha nut bam
                    Speaker = 1;
                    delay_ms(150);
                    Speaker = 0;
                    delay_ms(150);
                    m_in[STT_tiet]++;
                    if(m_in[STT_tiet]==60)    m_in[STT_tiet]=0;   
                    //put_tietinfo();
                    put_time(m_in[STT_tiet],14,0); 
                }

                if(!DOWN_BTN)          //neu bam nut sub--------
                {
                    //cho toi khi tha nut bam
                    Speaker = 1;
                    delay_ms(150);
                    Speaker = 0;
                    delay_ms(150); 
                    if(m_in[STT_tiet]==0)
                        m_in[STT_tiet]=59;
                    else
                        m_in[STT_tiet]--; 
                    put_time(m_in[STT_tiet],14,0);
                }
        }
        break;
        case 3:             //set hour
        {
                lcd_gotoxy(11,1);
                //delay_ms(2);
                lcd_blink_on(); 
                if(!UP_BTN)            //neu bam button add------
                {
                    //cho toi khi tha nut bam
                    Speaker = 1;
                    delay_ms(150);
                    Speaker = 0;
                    delay_ms(150);
                    h_out[STT_tiet]++;
                    if(h_out[STT_tiet]==24)    h_out[STT_tiet]=0;  
                    put_time(h_out[STT_tiet],11,1);
                }

                if(!DOWN_BTN)          //neu bam nut sub--------
                {
                    //cho toi khi tha nut bam
                    Speaker = 1;
                    delay_ms(150);
                    Speaker = 0;
                    delay_ms(150); 
                    if(h_out[STT_tiet]==0)
                        h_out[STT_tiet]=12;
                    else
                        h_out[STT_tiet]--; 
                    put_time(h_out[STT_tiet],11,1);
                }
        }
        break;
        case 4:             //set day
        {
            lcd_gotoxy(14,1); 
            lcd_blink_on();    
               if(!UP_BTN)            //neu bam button add------
                {
                    //cho toi khi tha nut bam
                    Speaker = 1;
                    delay_ms(150);
                    Speaker = 0;
                    delay_ms(150);
                    m_in[STT_tiet]++;
                    if(m_out[STT_tiet]==60)    m_out[STT_tiet]=0;  
                    put_time(m_out[STT_tiet],14,1);
                }

                if(!DOWN_BTN)          //neu bam nut sub--------
                {
                    //cho toi khi tha nut bam
                    Speaker = 1;
                    delay_ms(150);
                    Speaker = 0;
                    delay_ms(150); 
                    if(m_out[STT_tiet]==0)
                        m_out[STT_tiet]=59;
                    else
                        m_out[STT_tiet]--; 
                    put_time(m_out[STT_tiet],14,1);
                }
        }
        break;
        case 5:             //set date  
        {    
            lcd_gotoxy(0,1);
            lcd_blink_on();
            if(!UP_BTN)            //neu bam button add------
            {
                //cho toi khi tha nut bam
                Speaker = 1;
                delay_ms(150);
                Speaker = 0;
                delay_ms(150);
                if(enable[STT_tiet]==1) 
                {
                    enable[STT_tiet]=0; 
                    lcd_gotoxy(0,1);
                    lcd_puts("DIS");
                }
                    
                else    
                {
                    enable[STT_tiet]=1;
                    lcd_gotoxy(0,1);
                    lcd_puts("EN ");  
                }
            }

            if(!DOWN_BTN)          //neu bam nut sub--------
            {
                //cho toi khi tha nut bam
                Speaker = 1;
                delay_ms(150);
                Speaker = 0;
                delay_ms(150); 
                if(enable[STT_tiet]==1) 
                {
                    enable[STT_tiet]=0; 
                    lcd_gotoxy(0,1);
                    lcd_puts("DIS");
                }
                    
                else    
                {
                    enable[STT_tiet]=1;
                    lcd_gotoxy(0,1);
                    lcd_puts("EN ");  
                }
            }
        }  
        break;
        case 6:             //set date  
        {
            lcd_blink_off();
            lcd_gotoxy(0,1);
            lcd_puts("Stored");       
            //delay_ms(2); 
        } 
        break;
        default:
        break;
    }
}
// ham chinh trong mode 3
// 
void mode3_main()
{
    //neu bam nut menu
    // lua chon cac che do khac nhau trong setup hoac hien thi
    if(!MENU_BTN)         
    {
        // cho den khi nut duoc nha ra
        while(!MENU_BTN);
        // bat loa len phat hien ra la nut duoc an
        Speaker = 1;
        delay_ms(150);
        Speaker = 0;
        delay_ms(150);
        // tang gia tri bien len de cho cac che do
        mode3_state++;
        if(mode3_state==3)        set_flagtiet=1;  
    }
    switch(mode3_state)
    {
      // che do hien thi gia tri cua nhiet do va do am
      case 1:
      {  
         // hien thi gia tri max va min 
         lcd_gotoxy(1,1);
         // hien thi gia tri cua nhiet do va do am cua moi truong hien tai
         lcd_gotoxy(2,1);
      }
      break;
      // chuong trinh setup cac gia tri nguong cua nhiet do va do am
      case 2:
      {
         lcd_gotoxy(1,1);
         // hien thi che do setup
         lcd_puts("SETUP gia tri nguong");
         // hien thi gia tri nguong
         lcd_gotoxy(4,0); 
         lcd_blink_on(); 
         delay_ms(10);  
         lcd_gotoxy(0,1);
         if(enable[STT_tiet]==1)  
             lcd_puts("EN ");
          else
                lcd_puts("DIS");
         if(!SET_BTN)         
         {
            // cho den khi nut duoc nha ra
            while(!MENU_BTN);
            // bat loa len phat hien ra la nut duoc an
        Speaker = 1;
        delay_ms(150);
        Speaker = 0;
        delay_ms(150);
        // tang gia tri bien len de cho cac che do
        mode3_state++;
        if(mode3_state==3)        set_flagtiet=1;  
    }
            if(!UP_BTN)            //neu bam button add------
            {
            //cho toi khi tha nut bam
                Speaker = 1;
                delay_ms(150);
                Speaker = 0;
                delay_ms(150);
                STT_tiet++;
                if(STT_tiet==13)        STT_tiet=1; 
                put_time(STT_tiet,4,0);  
                put_time(h_in[STT_tiet],11,0);
                put_time(m_in[STT_tiet],14,0);
                put_time(h_out[STT_tiet],11,1);
                put_time(m_out[STT_tiet],14,1); 
                lcd_gotoxy(0,1);
                if(enable[STT_tiet]==1)  
                    lcd_puts("EN ");
                else
                    lcd_puts("DIS");
            }

        if(!DOWN_BTN)          //neu bam nut sub--------
        {
            //cho toi khi tha nut bam
            Speaker = 1;
            delay_ms(150);
            Speaker = 0;
            delay_ms(150); 
            STT_tiet--;
            if(STT_tiet==0)        STT_tiet=12;   
            //lcd_gotoxy(5,0);
            put_time(STT_tiet,4,0); 
            put_time(h_in[STT_tiet],11,0);
            put_time(h_in[STT_tiet],11,0);
            put_time(m_in[STT_tiet],14,0);
            put_time(h_out[STT_tiet],11,1);
            put_time(m_out[STT_tiet],14,1); 
            lcd_gotoxy(0,1);
                if(enable[STT_tiet]==1)  
                    lcd_puts("EN ");
                else
                    lcd_puts("DIS");
        }  
      }
      break;
    }
     
}