示例#1
0
void main()
{
	unsigned int i,j,k,l,m,n;
	PINSEL0=0X00000000;
	PINSEL1=0X00000000;
	IO0DIR=0XFFFFFFFF;
	lcd_init();
	init_rtc();
	lcd_str("CLOCK:- 24");
	cmd(0xc0);
	lcd_str("00:00:00");
	while(1)
	{ 
	        if(flag)
	        {
			flag=0;
			lcd_pos(2,0);
			lcd_display(HOUR/10 + '0');
			lcd_display(HOUR%10 + '0'); 
			lcd_display(':') ;
			lcd_display(MIN/10 + '0');
			lcd_display(MIN%10 + '0');
			lcd_display(':') ;
			lcd_display(SEC/10 + '0');
		        lcd_display(SEC%10 + '0');
	        }
	}

}
示例#2
0
文件: main.c 项目: lysy1033/sfp
void lcd_start_screen()
{
	lcd_cls();
	lcd_locate(0,0);
	lcd_str(" SFP PROGRAMMER ");
	lcd_locate(1,0);
	lcd_str(" ALPHA 0.1 2014 ");
}
/* wyœwietlanie temperatury na pozycji X w pierwszej linii LCD */
void display_temp(uint8_t x) {
	lcd_locate(0,x);
	if(subzero) lcd_str("-");	/* jeœli subzero==1 wyœwietla znak minus (temp. ujemna) */
	else lcd_str(" ");	/* jeœli subzero==0 wyœwietl spacjê zamiast znaku minus (temp. dodatnia) */
	lcd_int(cel);	/* wyœwietl dziesiêtne czêœci temperatury  */
	lcd_str(".");	/* wyœwietl kropkê */
	lcd_int(cel_fract_bits); /* wyœwietl dziesiêtne czêœci stopnia */
	lcd_str(" C"); /* wyœwietl znak jednostek (C - stopnie Celsiusza) */
	lcd_char(0xDF);
}
示例#4
0
void DisplayRefresh(uint8_t Refresh) {
	if ( (Refresh == 1) && (_FLAG.LCDExist == _Set) ) {

		lcd_locate(0,0);
		lcd_str(FirstLine);

		//lcd_locate(1,0);
		lcd_locate( 1, (8-(length(SecondLine)/2)) );
		lcd_str(SecondLine);
	}
}
void M1_func_ustawienia(char *str)
{
	if(Flagi.flaga_lcd)
	{
		lcd_locate(0, 0);
		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;
	}
}
示例#6
0
文件: menu.c 项目: j-a-r-i/stm32
void menu_select(menu_t *menu)
{
	uint8_t i = menu->current;
	//menuItems_t *mi = menu->items;

	lcd_str(menu->items[i].label);
}
示例#7
0
// displays a formated string, similar to printf
void lcd_string_format(char *szFormat, ...)
{
	char szBuffer[256]; //in this buffer we form the message
	int NUMCHARS = sizeof(szBuffer) / sizeof(szBuffer[0]);
	int LASTCHAR = NUMCHARS - 1;
	va_list pArgs;
	va_start(pArgs, szFormat);
	vsnprintf(szBuffer, LASTCHAR, szFormat, pArgs);
	va_end(pArgs);
	
	lcd_str(szBuffer);
}
示例#8
0
文件: menu.c 项目: j-a-r-i/stm32
void menu_display(menu_t *menu)
{
	menuItems_t *mi = menu->items;
	uint8_t i;

	for (i=0; i<menu->size; i++) {
		if (i == menu->current)
			lcd_str("<");
		else
			lcd_str(" ");

		lcd_str(mi->label);

		if (i == menu->current)
			lcd_str(">");
		else
			lcd_str(" ");

		mi++;
	}	
}
示例#9
0
文件: LCD.c 项目: raghav1296/LPC2148
int main()
{
int x,y,z,w,val;
IODIR0=0x00000007;
IODIR1=0xffffffff;
PINSEL0=0x00000000;
PINSEL1=0x00000000;
lcd_init();
while(1)
     {
     lcd_cmd(0x01);  delay();//Clear Display Screen       
	/* lcd_cmd(0x02);	  delay();//Return Home
	 lcd_cmd(0x04);   delay();//decrement curser(shift to left)
	 lcd_cmd(0x06);   delay();//Increment curser(shift to right)
	 lcd_cmd(0x05);   delay();//Shift display right
	 lcd_cmd(0x07);	  delay();//shift display left
	 lcd_cmd(0x08);   delay();//Display Off,Cursor Off
	 lcd_cmd(0x0C);	  delay();//Display On,Cursor Off
	 lcd_cmd(0x0A);   delay();//Display Off,Cursor On
	 lcd_cmd(0x0E);   delay();//Display On,cursor No blink
	 lcd_cmd(0x0F);   delay();//Display On cursor blink
	 lcd_cmd(0x10);   delay();//Shift cursor to left
	 lcd_cmd(0x14);  delay(); //Shift cursor to right
	 lcd_cmd(0x18);   delay();//Shift entire display to left
	 lcd_cmd(0x1C);   delay();//Shift entire display to right
	 lcd_cmd(0x80);   delay();//Force Cursor to begining of First Line
	 lcd_cmd(0xC0);   delay();//Force Cursor to begining of Second Line
	 lcd_cmd(0x38);	  delay();//2lines and 5X7 matrix 
	 IODIR0=0x000000f7; //ABCD as output and 1234 as input
	 x=IOSET0=0x000000f0; //ABCD to high and 1234 to low;
	 while(IOPIN0==x);
     w=IOPIN0&0xff0;
	 w=w>>4;
	 lcd_int(w);
	 lcd_str(" ");
	 IOCLR0=0x000000f0;

	 IODIR0=0x00000f07; //ABCD as input and 1234 as output
	 y=IOSET0=0x00000f00; //ABCD to low and 1234 to high
	 while(IOPIN0==y);
	 z=IOPIN0&0xff0;
	 z=z>>4;
	 lcd_int(z);
	 lcd_str(" ");
	 IOCLR0=0x00000f00;

	 val=w&z;
	 //val=~val;
	 lcd_int(val); */
	 lcd_str("RAGHAV");
	  wait();
	  }
}
void stopWatchReload(void) {
    char min[4];
    char sec[4];
    char down[4];
    if(swMode==1) {
        if(sw_down==99) {
            if(sw_sec==59) {
                if(sw_min==59) {
                } else {
                    sw_down=0;
                    sw_sec=0;
                    sw_min++;
                }
            } else {
                sw_down=0;
                sw_sec++;
            }
        } else {
            sw_down++;
        }
    }
    lcdCmd(0x80);///カーソルを先頭に移動
    ByteToStr(sw_min,min);
    if(sw_min<10) {
        min[1]='0';
    }
    lcd_str(1,min);
    ByteToStr(sw_sec,sec);
    if(sw_sec<10) {
        sec[1]='0';
    }
    sec[0]=':';
    lcd_str(0,sec);
    ByteToStr(sw_down,down);
    if(sw_down<10) {
        down[1]='0';
    }
    down[0]='.';
    lcd_str(0,down);
}
示例#11
0
int main(void)
{
	lcd_init();
	init_adc();
	while(1)
	{
		if(czujnik_dymu_ON)
		{
			lcd_locate(0,0);
			lcd_str("WYKRYTO DYM");
		}
		else
		{
			lcd_locate(0,0);
			lcd_str("BRAK DYMU  ");
		}
		wartosc_pomiaru = pomiar(czujnik_dymu_ktory);
		lcd_locate(1,0);
		lcd_int(wartosc_pomiaru);
		lcd_str("   ");
		_delay_ms(500);
	}
}
示例#12
0
文件: main.c 项目: lysy1033/sfp
int main(void) {


	// LCD INIT
	lcd_init();
	lcd_start_screen();

	_delay_ms(500);

	while(1)
	{
		lcd_backlight(1);
		//sfp_read_vendor_name(sfp_vendor_name);
		EI2C_read_buf(0xa0,0x14,15,sfp_vendor_name);
		EI2C_read_buf(0xa0,56,4,sfp_vendor_rev);
		lcd_cls();
		lcd_locate(0,0);
		lcd_str((char*)sfp_vendor_name);
		lcd_locate(1,0);
		lcd_str((char*)sfp_vendor_rev);
		_delay_ms(1000);

	}
}
void clockReload(void) {
    if(lcdIsOn==1) {
        char hour[4];
        char minute[4];
        char second[4];
        lcdCmd(0x80);///カーソルを先頭に移動
        ByteToStr(h,hour);
        if(h<10) {
            hour[1]='0';
        }
        lcd_str(1,hour);
        ByteToStr(m,minute);
        if(m<10) {
            minute[1]='0';
        }
        minute[0]=':';
        lcd_str(0,minute);
        ByteToStr(s,second);
        if(s<10) {
            second[1]='0';
        }
        second[0]=':';
        lcd_str(0,second);

        if(mode==1) { ///lcd_str_byCode(0x5E);0x5E 上向き矢印
            lcdCmd(0xC0);///カーソルを2行目の先頭に移動
            if(mode1At==0) {
                lcd_str(0,"       ");
                lcd_str_byCode(0x5E);
            } else if(mode1At==1) {
                lcd_str(0,"    ");
                lcd_str_byCode(0x5E);
                lcd_str(0,"   ");
            } else if(mode1At==2) {
                lcd_str(0," ");
                lcd_str_byCode(0x5E);
                lcd_str(0,"      ");
            }
        }
    }
}
示例#14
0
void main()
{
    char X[]= {"sumit"},b;
    IODIR1=0XFFFFFFFf;
    PINSEL0=0X50;			 //PIN SET
    I2CONSET=0x44;						//SCL Duty Cycle Register Low Half Word
    I2ADR=0X02;							 // slave add.
    lcd_ini();
    while(1)
    {
//lcd_cmd(0x01);
        while((I2CONSET&0X08)==0X00); 		//ADD. POLLING
        for(b=0; b<5; b++)
        {
            I2DAT=X[b];
            I2CONCLR=0X08;	   			//	   SLAVE ADD & data.
            while((I2CONSET&0X08)==0X00);					  //DATA POLLING
        }

        lcd_str("123");

    }

}
示例#15
0
//----------------------------------------------------------------------------------------
//
//		 Wy�wietla liczb� szestnastkow� HEX na wy�wietlaczu LCD
//
//----------------------------------------------------------------------------------------
void lcd_hex(int val)
{
	char bufor[17];
	lcd_str( itoa(val, bufor, 16) );
}
示例#16
0
void main() 
{
  unsigned char i;
  unsigned char tmp;
  unsigned int tmpi;

  char str[6];

  ADCON1=0x06;
  TRISA=0xFF;
  TRISB=0x00;
  TRISC=0x01;
  TRISD=0x00;
  TRISE=0x00;

  lcd_init();
  i2c_init();
  serial_init();
  adc_init();

//testa caracter especial
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str(rom2ram("   Teste LCD"));

  lcd_cmd(0x40);//endereço

  lcd_dat(0x11);
  lcd_dat(0x19);
  lcd_dat(0x15);
  lcd_dat(0x13);
  lcd_dat(0x13);
  lcd_dat(0x15);
  lcd_dat(0x19);
  lcd_dat(0x11);

  lcd_dat(0x0E);
  lcd_dat(0x11);
  lcd_dat(0x0E);
  lcd_dat(0x05);
  lcd_dat(0x0E);
  lcd_dat(0x14);
  lcd_dat(0x0A);
  lcd_dat(0x11);


  lcd_cmd(L_L2);

  for(i=0;i<16;i++)
  {
    lcd_dat(i%2);
    atraso_ms(100);
  }

//teste lcd
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str(rom2ram("   Teste LCD"));
  
  for(i=32;i<128;i++)
  {
    if((i%16) == 0)lcd_cmd(L_L2);
    lcd_dat(i);
    atraso_ms(50);
  }

  atraso_ms(100);
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str(rom2ram("   Teste LCD"));
  lcd_cmd(L_L2);
  lcd_str(rom2ram("       Ok"));
  atraso_ms(500);




//testa display 7s

  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str(rom2ram("   Teste 7 Seg"));


    PORTBbits.RB7=1;
    for(i=0;i<4;i++)
    {
      PORTB=0x10<<i;  
      for(tmp=0;tmp<16;tmp++)
      {
        PORTD=display7s(tmp);	 
        atraso_ms(200);	
      }
    }

  PORTD=0;

//testa LEDs

  lcd_cmd(L_CLR);
  lcd_cmd(L_L1+3);
  lcd_str(rom2ram("Teste LEDs"));

  for(tmp=0;tmp<3;tmp++)
    {
      for(i=1;i < 16;i=i*2)
      { 
        PORTB=i;
        atraso_ms(200);  
      }
    }
  PORTB=0;
  for(i=0;i<4;i++)
  {
    PORTB^=0x0F;
    atraso_ms(200);
  }  

//testa chaves


  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str(rom2ram("  Teste Chaves"));

  tmp=0;

  while((tmp & 0x0F) != 0x0F)
  {
    TRISB=0x0F;

    if(PORTBbits.RB0 == 0)
    {
      tmp|=0x01;
    }
    if(PORTBbits.RB1 == 0)
    {
      tmp|=0x02;
    }
    if(PORTBbits.RB2 == 0)
    {
      tmp|=0x04;
    }
    if(PORTBbits.RB3 == 0)
    {
      tmp|=0x08;
    }
    
    TRISB=0x00;
    PORTB=tmp;
    atraso_ms(10);
  }
  PORTB=0; 


//teste EEPROM INT
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str(rom2ram("Teste EEPROM INT"));
// testar ? 
  lcd_cmd(L_L2);
  lcd_str(rom2ram(" (s=S1 n=S2) ?"));

  TRISB=0x03;

  while(PORTBbits.RB0 && PORTBbits.RB1);

  if(PORTBbits.RB0 == 0)
  {
    tmp=e2prom_r(10);
    lcd_dat(tmp);

    e2prom_w(10,0xA5);
    e2prom_w(10,0x5A);
    i=e2prom_r(10);

    e2prom_w(10,tmp);

    lcd_cmd(L_CLR);
    lcd_cmd(L_L1);
    lcd_str(rom2ram("Teste EEPROM INT"));
    lcd_cmd(L_L2);
    if(i == 0x5A) 
      lcd_str(rom2ram("       OK"));
    else
      lcd_str(rom2ram("      ERRO"));

    atraso_ms(1000);
  }
  else
  {
    while(PORTBbits.RB1 == 0);
  }

  TRISB=0x00;
  PORTB=0;

//teste EEPROM EXT
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str(rom2ram("Teste EEPROM EXT"));
// testar ? 
  lcd_cmd(L_L2);
  lcd_str(rom2ram(" (s=S1 n=S2) ?"));

  TRISB=0x03;

  while(PORTBbits.RB0 && PORTBbits.RB1);

  if(PORTBbits.RB0 == 0)
  {
    tmp=e2pext_r(10);
    lcd_dat(tmp);

    e2pext_w(10,0xA5);
    e2pext_w(10,0x5A);
    i=e2pext_r(10);

    e2pext_w(10,tmp);

    lcd_cmd(L_CLR);
    lcd_cmd(L_L1);
    lcd_str(rom2ram("Teste EEPROM EXT"));
    lcd_cmd(L_L2);
    if(i == 0x5A) 
      lcd_str(rom2ram("       OK"));
    else
      lcd_str(rom2ram("      ERRO"));

    atraso_ms(1000);
  }
  else
  {
    while(PORTBbits.RB1 == 0);
  }

  TRISB=0x00;
  PORTB=0;

//teste serial
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str(rom2ram("Teste Serial TX"));
  lcd_cmd(L_L2+4);
  lcd_str(rom2ram("9600 8N1"));

  serial_tx_str(rom2ram("\r\n Picsimlab\r\n Teste Serial TX\r\n"));

  for(i=0;i<4;i++)
  {
    serial_tx(i+0x30);
    serial_tx_str(rom2ram(" PicsimLab\r\n"));
  }
  atraso_ms(1000);

  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str(rom2ram("Teste Serial RX"));
  serial_tx_str(rom2ram(" Digite!\r\n"));
  for(i=0;i<32;i++)
  {
    if(!(i%16))
    {
       lcd_cmd(L_L2);
       serial_tx_str(rom2ram("\r\n"));
    }
    tmp=serial_rx(2000);
    lcd_dat(tmp);
    serial_tx(tmp);
  }
  atraso_ms(100);


//teste ADC
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str(rom2ram(" Teste ADC (P2)"));

  for(i=0; i< 200; i++)
  {
    tmp=((unsigned int)adc_amostra(1)*10)/204;
    lcd_cmd(L_L2+6);
    itoa(tmp,str); 
    lcd_dat(str[3]);
    lcd_dat(',');
    lcd_dat(str[4]);
    lcd_dat('V');
    atraso_ms(10);
  }



//teste TEMP
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str(rom2ram("   Teste TEMP"));

  for(i=0; i< 100; i++)
  {
    tmpi=((unsigned int) adc_amostra(0)*81)/100;
    lcd_cmd(L_L2+5);
    itoa(tmpi,str);
    lcd_dat(str[2]);
    lcd_dat(str[3]);
    lcd_dat(',');
    lcd_dat(str[4]);
    lcd_dat('C');
    atraso_ms(10);
  }


//teste Aquecimento
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str(rom2ram("   Teste AQUEC"));
  PORTCbits.RC2=1;
  for(i=0; i< 100; i++)
  {
    tmpi=((unsigned int) adc_amostra(0)*81)/100;
    lcd_cmd(L_L2+5);
    itoa(tmpi,str);
    lcd_dat(str[2]);
    lcd_dat(str[3]);
    lcd_dat(',');
    lcd_dat(str[4]);
    lcd_dat('C');
    atraso_ms(10);
  }
  PORTCbits.RC2=0;


//teste Resfriamento
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str(rom2ram("   Teste RESFR"));

//timer0 temporizador

 T0CONbits.T0CS=0;
 T0CONbits.PSA=0;
 T0CONbits.T08BIT=1;
 T0CONbits.T0PS0=0; // divide por 32
 T0CONbits.T0PS1=0;
 T0CONbits.T0PS2=1;
 T0CONbits.TMR0ON=1;

 INTCONbits.T0IE=1;

//T = 32x250x125 = 1segundo;

//timer1 contador
 T1CONbits.TMR1CS=1;
 T1CONbits.T1CKPS1=0;
 T1CONbits.T1CKPS0=0;


 INTCONbits.T0IF=0;
 TMR0H=0;
 TMR0L=6; //250
 cnt=125; 
 INTCONbits.GIE=1;

 TMR1H=0;
 TMR1L=0;
 T1CONbits.TMR1ON=1;

  PORTCbits.RC1=1;
  for(i=0; i< 150; i++)
  {
    tmpi=((unsigned int) adc_amostra(0)*81)/100;
    lcd_cmd(L_L2+2);
    itoa(tmpi,str);
    lcd_dat(str[2]);
    lcd_dat(str[3]);
    lcd_dat(',');
    lcd_dat(str[4]);
    lcd_dat('C');

    lcd_cmd(L_L2+8);
    itoa(t1cont,str);
    lcd_dat(str[1]);
    lcd_dat(str[2]);
    lcd_dat(str[3]);
    lcd_dat(str[4]);
    lcd_dat('R');
    lcd_dat('P');
    lcd_dat('S');

    atraso_ms(10);
  }

  INTCONbits.GIE=0;
  PORTCbits.RC1=0;

//fim teste 
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str(rom2ram("      Fim"));
  lcd_cmd(L_L2);
  lcd_str(rom2ram(" Pressione RST"));

  serial_tx_str(rom2ram("\r\n FIM!\r\n"));


   while(1);

}
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;
	}

}
示例#18
0
int main(void) {

	DDRA |= (1<<PA7);
	PORTA |= (1<<PA7); // podœwietlenie wyœwietlacza LCD

	// Przerwanie INT0
	MCUCR |= (1<<ISC01);	// wyzwalanie zboczem opadaj¹cym
	GICR |= (1<<INT0);		// odblokowanie przerwania
	PORTD |= (1<<PD2);		// podci¹gniêcie pinu INT0 do VCC


	// definiujemy sobie dla polepszenia czytelnoœci programu typ wyliczeniowy
	// wskazuj¹cy nam póŸniej na odpowiednie indeksy w tablicy (buforze)
	enum {ss=1, mm, hh};
	uint8_t bufor[4];		// rezerwacja bufora 4 bajty
	uint8_t sekundy, minuty, godziny;


	i2c_init();
	lcd_init();

	sei();

	lcd_str_P(PSTR("start..."));

	// Ustawianie czasu na godzinê: 18:34:27
	/*
	bufor[0] = 0;			// setne czêœci sekundy
	bufor[1] = dec2bcd(27);	// sekundy
	bufor[2] = dec2bcd(34);	// minuty
	bufor[3] = dec2bcd(18);	// godziny
	// zapis 4 bajtów z bufora pod adres 0x01 w pamiêci RAM naszego RTC
	I2C_write_buf( PCF8583_ADDR, 0x01, 4, bufor );
	*/

	// zapis tekstu do pamiêci EEPROM od adresu 253, dlatego aby tekst
	// zosta³ zapisany w jednym i drugim banku pamiêci
	EI2C_write_buf( _24C04_ADDR, 253, sizeof(tekst), tekst );

	while(1) {

		if ( int0_flag ) {
			//odczyt 4 bajtów do bufora od adresu 0x01 z pamiêci RAM naszego RTC
			I2C_read_buf( PCF8583_ADDR, 0x01, 4, bufor );

			sekundy = bcd2dec( bufor[ss] );
			minuty = bcd2dec( bufor[mm] );
			godziny = bcd2dec( bufor[hh] );

			// wyœwietlenie czasu na LCD
			lcd_locate(1,0);
			if( godziny < 10 ) lcd_str("0");
			lcd_int(godziny);
			lcd_str(":");
			if( minuty < 10 ) lcd_str("0");
			lcd_int(minuty);
			lcd_str(":");
			if( sekundy < 10 ) lcd_str("0");
			lcd_int(sekundy);

			// odczyt z EEPROM
			EI2C_read_buf( _24C04_ADDR, 253, sizeof(tekst), bo );

			// wyœwietlenie napisu z EEPROM na LCD
			lcd_locate(0, 9);
			lcd_str( (char*)bo );

			int0_flag=0;
		}

	}
}
示例#19
0
void main() {
  unsigned char i,tmp;

  CMCON=0x07; 
  TRISA=0x30;
  TRISB=0xE7;
  
  PORTA=0xFE;
  PORTB=0x00;

  lcd_init();

  i2c_init();
  
  serial_init();

//teste lcd
  lcd_cmd(L_CLR); 
  lcd_cmd(L_L1);
  for(i=0;i<16;i++)
  {
    lcd_dat('A'+i);
  }
  lcd_cmd(L_L2);
  for(i=0;i<16;i++)
  {
    lcd_dat('a'+i);
  }

  atraso_ms(200);
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1+3);
  lcd_str("Teste LCD");
  
  for(i=32;i<128;i++)
  {
    if((i%16) == 0)lcd_cmd(L_L2);
    lcd_dat(i);
    atraso_ms(50);
  }

  atraso_ms(100);
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1+3);
  lcd_str("Teste LCD");
  lcd_cmd(L_L2+7);
  lcd_str("Ok");
  atraso_ms(500);

//teste LEDS
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1+1);
  lcd_str("Teste LEDs");
 
for(i=0;i<4;i++)
  {
    atraso_ms(100);
    RA1^=1;
    atraso_ms(100);
    RA2^=1;
    atraso_ms(100);
    PORTA^=0x40; //RA6=1;
    atraso_ms(100);
    PORTA^=0x80; //RA7=1;
    atraso_ms(100);
  }


//teste Teclado
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1+2);
  lcd_str("Teste Teclado");

  lcd_cmd(L_L2+1);

  i=0;
  while(i<14)
  {
    lcd_dat(tc_tecla(3000)+0x30);
    i++;
  }

//teste EEPROM EXT
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("Teste EEPROM EXT");
// testar ? 
  lcd_cmd(L_L2);
  lcd_str("Testar (1/0) ?");
 
  if(tc_tecla(0) == 1)
  {
    tmp=e2pext_r(10);
    lcd_dat(tmp);

    e2pext_w(10,0xA5);
    e2pext_w(10,0x5A);
    i=e2pext_r(10);

    e2pext_w(10,tmp);

    lcd_cmd(L_CLR);
    lcd_cmd(L_L1);
    lcd_str("Teste EEPROM EXT");
    lcd_cmd(L_L2);
    if(i == 0x5A) 
      lcd_str("     OK");
    else
      lcd_str("     ERRO");

    atraso_ms(1000);
  }


//teste RTC
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("Teste RTC");
  
//ajuste  rtc_w();

//  rtc_w();
 
  rtc_r();
  lcd_cmd(L_L2);
  lcd_str((char *)date);
   atraso_ms(1500);
  for(i=0;i<16;i++)
  {
    rtc_r();
    lcd_cmd(L_L2);;
    lcd_str((char *)time);
    atraso_ms(500); 
  }

   
   //teste serial
   
 //teste EEPROM EXT
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("Teste Serial");
// testar ? 
  lcd_cmd(L_L2);
  lcd_str("Testar (1/0) ?");
  if(tc_tecla(0) == 1)
  {  
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("Teste Serial TX");
  lcd_cmd(L_L2+2);
  lcd_str("9600 8N1");

  serial_tx_str("\r\n Picsimlab\r\n Teste Serial TX\r\n");

  for(i=0;i<4;i++)
  {
    serial_tx(i+0x30);
    serial_tx_str(" PicsimLab\r\n");
  }
  atraso_ms(1000);

  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("Teste Serial RX");
  serial_tx_str(" Digite!\r\n");
  for(i=0;i<32;i++)
  {
    if(!(i%16))
    {
       lcd_cmd(L_L2);
       serial_tx_str("\r\n");
    }
    tmp=serial_rx(3000);
    lcd_dat(tmp);
    serial_tx(tmp);
  }
  atraso_ms(100);
  
  
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("Teste Teclado TX");
  serial_tx_str("\r\n Aguarde!\r\n");
  for(i=0;i<32;i++)
  {
    if(!(i%16))
    {
      lcd_cmd(L_L2);
      serial_tx_str("\r\n");
    }
    tmp=tc_tecla(2000)+0x30;
    lcd_dat(tmp);
    serial_tx(tmp);
  }
  atraso_ms(100);
  }

//fim teste 
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1+4);
  lcd_str("Fim");
  lcd_cmd(L_L2+1);
  lcd_str("Pressione RST");

  serial_tx_str("\r\n FIM!\r\n");  

  while(1);


}
	PixelsData StdDataVisualizer::visualize(const std::string &data) const
	{
		Lcd::LcdString lcd_str(data, begin_point_, font_height_, font_type_);
		return Lcd::TextPixelsGenerator::generate_pixels(lcd_str);
	}
void M0(char *str)
{	
	static uint8_t state=0, term_state=0, i=0;
	static uint32_t cnt=0, offset_cnt=0;
	static char buf[41], buf_lcd[9];
	if(Flagi.flaga_lcd)
	{
		lcd_locate(0, 0);
		lcd_str(str);
		lcd_locate(1, 0);
		lcd_str(str);
		Flagi.flaga_lcd=0;
	}
	if (Flagi.flaga_term)
	{
		switch(term_state)
		{
			case 0:
					DS18X20_start_meas( DS18X20_POWER_EXTERN, NULL );
					term_state=1;
					break;
			case 1:
					if( DS18X20_OK == DS18X20_read_meas(gSensorIDs[0], &subzero, &cel, &cel_fract_bits) ) display_temp(0);
					else {
						lcd_locate(0,0);
						lcd_str("term. error ");	/* wyœwietlamy informacjê o b³êdzie jeœli np brak czujnika lub b³¹d odczytu */
					}
					term_state=0;
					break;
		}
		Flagi.flaga_term=0;

	}
	
	if(Flagi.flaga_rtc)
	{
		pobierz_czas(&czas);
		pobierz_date(&data);
		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);
	
	switch(state)
	{
		case 0:
				state=1;
				
				if(i>= 2*strlen(buf))
					i=0;
				
				lcd_wyswietl_date(&data, buf, 0);
				fifo_bufor_lcd(buf, i, strlen(buf));
				lcd_locate(1,8);
				strncpy(buf_lcd,buf,sizeof(buf_lcd)-1);
				lcd_str(buf_lcd);
				
				cli();
				cnt=25000;
				offset_cnt=licznik;
				sei();
				break;
		case 1:
				if(cnt<=licznik-offset_cnt)
				{
					i++;
					state=0;
				}
				break;
	}
}
示例#22
0
void main() {
  unsigned char i,tmp;
  unsigned int tout;

  CMCON=0x07; 
  TRISA=0x30;
  TRISB=0xE7;
  
  PORTA=0;
  PORTB=0;

  lcd_init();

  UART1_Init(9600);

//teste serial
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str(codetxt_to_ramtxt("Teste Serial TX"));
  lcd_cmd(L_L2+2);
  lcd_str(codetxt_to_ramtxt("9600 8N1"));

  UART1_Write_Text(codetxt_to_ramtxt("\r\n Picsimlab\r\n Teste Serial TX\r\n"));

  for(i=0;i<4;i++)
  {
    UART1_Write(i+0x30);
    UART1_Write_Text(codetxt_to_ramtxt(" PicsimLab\r\n"));
  }
  delay_ms(1000);

  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str(codetxt_to_ramtxt("Teste Serial RX"));
  UART1_Write_Text(codetxt_to_ramtxt(" Digite!\r\n"));
  for(i=0;i<32;i++)
  {
    if(!(i%16))
    {
       lcd_cmd(L_L2);
       UART1_Write_Text(codetxt_to_ramtxt("\r\n"));
    }

  tout=0;
  while(!UART1_Data_Ready() && (tout < 2000))
  {
    tout++;
    delay_ms(1);
  }
    
  if (UART1_Data_Ready() == 1) {
   tmp = UART1_Read();
  }
  else
  {
    tmp='-';
  }

    
    lcd_dat(tmp);
    UART1_Write(tmp);
  }
  delay_ms(100);

  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str(codetxt_to_ramtxt("Teste Teclado TX"));
  UART1_Write_Text(codetxt_to_ramtxt("\r\n Aguarde!\r\n"));
  for(i=0;i<32;i++)
  {
    if(!(i%16))
    {
      lcd_cmd(L_L2);
      UART1_Write_Text(codetxt_to_ramtxt("\r\n"));
    }
    tmp=tc_tecla(2000)+0x30;
    lcd_dat(tmp);
    UART1_Write(tmp);
  }
  delay_ms(100);


//fim teste 
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1+4);
  lcd_str(codetxt_to_ramtxt("Fim"));
  lcd_cmd(L_L2+1);
  lcd_str(codetxt_to_ramtxt("Pressione RST"));

  UART1_Write_Text(codetxt_to_ramtxt("\r\n FIM!\r\n"));

  while(1);


}
void M10_func_ustawienia_data(char *str)
{
	static uint8_t state=0, edit=0, i=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;
	}
	
	if (key_code == PRZYCISK_ENTER)
	{
		edit++;
		if (edit>4)
			edit=1;
		Flagi.flaga_klawiatura=0;
	}
	else if (key_code == PRZYCISK_POWROT && Flagi.flaga_klawiatura==0)
	{
		edit=0;
		Flagi.flaga_klawiatura=1;
		ustaw_date(&data);
	}
	
	switch(edit)
	{
		case 1:
			if (key_code == PRZYCISK_GORA && Flagi.flaga_klawiatura==0)
			{
				data.dzien_tygodnia++;
				if (data.dzien_tygodnia>6)
					data.dzien_tygodnia=0;
			}
			else if (key_code == PRZYCISK_DOL && Flagi.flaga_klawiatura==0)
			{
				data.dzien_tygodnia--;
				if ((int8_t)data.dzien_tygodnia<0)
					data.dzien_tygodnia=6;
			}
			break;
		case 2:
			if (key_code == PRZYCISK_GORA && Flagi.flaga_klawiatura==0)
			{
				data.dzien++;
				switch(data.miesiac)
				{
					case PCF_January:
						if (data.dzien>31)
						{	
							data.dzien=1;
						}
						break;
					case PCF_February:
						if(!(data.rok % 4))
						{
							if (data.dzien>29)
							{
								data.dzien=1;
							}	
						}
						else
						{
							if (data.dzien>28)
							{
								data.dzien=1;
							}							
						}

						break;			
					case PCF_March:
						if (data.dzien>31)
						{
							data.dzien=1;
						}
						break;
					case PCF_April:
						if (data.dzien>30)
						{
							data.dzien=1;
						}
						break;
					case PCF_May:
						if (data.dzien>31)
						{
							data.dzien=1;
						}
						break;
					case PCF_June:
						if (data.dzien>30)
						{
							data.dzien=1;
						}
						break;
					case PCF_July:
						if (data.dzien>31)
						{
							data.dzien=1;
						}
						break;
					case PCF_August:
						if (data.dzien>31)
						{
							data.dzien=1;
						}
						break;
					case PCF_September:
						if (data.dzien>30)
						{
							data.dzien=1;
						}
						break;
					case PCF_October:
						if (data.dzien>31)
						{
							data.dzien=1;
						}
						break;
					case PCF_November:
						if (data.dzien>30)
						{
							data.dzien=1;
						}
						break;			
					case PCF_December:
						if (data.dzien>31)
						{
							data.dzien=1;
						}
						break;
				}
			}
			else if (key_code == PRZYCISK_DOL && Flagi.flaga_klawiatura==0)
			{
				data.dzien--;
				switch(data.miesiac)
				{
					case PCF_January:
						if ((int8_t)data.dzien<1)
						{
							data.dzien=31;
						}
						break;
					case PCF_February:
						if(!(data.rok % 4))
						{
							if ((int8_t)data.dzien<1)
							{
								data.dzien=29;
							}
						}
						else
						{
							if ((int8_t)data.dzien<1)
							{
								data.dzien=28;
							}
						}

						break;
					case PCF_March:
						if ((int8_t)data.dzien<1)
						{
							data.dzien=31;
						}
						break;
					case PCF_April:
						if ((int8_t)data.dzien<1)
						{
							data.dzien=30;
						}
						break;
					case PCF_May:
						if ((int8_t)data.dzien<1)
						{
							data.dzien=31;
						}
						break;
					case PCF_June:
						if ((int8_t)data.dzien<1)
						{
							data.dzien=30;
						}
						break;
					case PCF_July:
						if ((int8_t)data.dzien<1)
						{
							data.dzien=31;
						}
						break;
					case PCF_August:
						if ((int8_t)data.dzien<1)
						{
							data.dzien=31;
						}
					break;
					case PCF_September:
						if ((int8_t)data.dzien<1)
						{
							data.dzien=30;
						}
						break;
					case PCF_October:
						if ((int8_t)data.dzien<1)
						{
							data.dzien=31;
						}
						break;
					case PCF_November:
						if ((int8_t)data.dzien<1)
						{
							data.dzien=30;
						}
						break;
					case PCF_December:
						if ((int8_t)data.dzien<1)
						{
							data.dzien=31;
						}
						break;
				}
			}
			break;
		case 3:
			if (key_code == PRZYCISK_GORA && Flagi.flaga_klawiatura==0)
			{
				data.miesiac++;
				if (data.miesiac>12)
					data.miesiac=1;
					
				switch(data.miesiac)
				{
					case PCF_January:
						break;
					case PCF_February:
						if(!(data.rok % 4))
						{
							if (data.dzien>29)
							{
								data.dzien=29;
							}
						}
						else
						{
							if (data.dzien>28)
							{
								data.dzien=28;
							}
						}

						break;
					case PCF_March:

						break;
					case PCF_April:
						if (data.dzien>30)
						{
							data.dzien=30;
						}
						break;
					case PCF_May:
						break;
					case PCF_June:
						if (data.dzien>30)
						{
							data.dzien=30;
						}
						break;
					case PCF_July:
						break;
					case PCF_August:
						break;
					case PCF_September:
						if (data.dzien>30)
						{
							data.dzien=30;
						}
						break;
					case PCF_October:
						break;
					case PCF_November:
						if (data.dzien>30)
						{
							data.dzien=30;
						}
						break;
					case PCF_December:
						break;
				}
			}
			else if (key_code == PRZYCISK_DOL && Flagi.flaga_klawiatura==0)
			{
				data.miesiac--;
				if ((int8_t)data.miesiac<1)
					data.miesiac=12;
			}
			break;
		case 4:
			if (key_code == PRZYCISK_GORA && Flagi.flaga_klawiatura==0)
			{
				data.rok++;
			}
			else if (key_code == PRZYCISK_DOL && Flagi.flaga_klawiatura==0)
			{
				data.rok--;
			}
			break;
		default:
			if(Flagi.flaga_rtc)
			{
				pobierz_date(&data);
				Flagi.flaga_rtc=0;
			}
			break;
	}
	
	switch(state)
	{
		case 0:
			state=1;
			
			if (!i)
			{
			lcd_wyswietl_date(&data, str, edit);
			lcd_locate(1,0);
			lcd_str(str);
			}
			else
			{
				if(edit==3 || edit==4)
					lcd_wyswietl_date(&data, str, 5);
				else
					lcd_wyswietl_date(&data, str, 0);
					lcd_locate(1,0);
					lcd_str(str);
			}
			
			cli();
			cnt=50000;
			offset_cnt=licznik;
			sei();
			break;
		case 1:
			if(cnt<=licznik-offset_cnt)
			{
				i=~i;
				state=0;
			}
			break;
	}
}
示例#24
0
 int main()
 {
 	int x,y,z;
	adc_init();
	uart_init();

	lcd_init();	delay(100);
	
	lcd_char('a');
 	
	while(1) 
	{	cmd(0x01); // Clear LCD
		
		AD0CR = 0x01200600; // ADC Stop, select Channel 0
		//AD0CR |= 0x01000000;  // Start ADC, Channel 0
		x = read_adc();
		cmd(0x80);
		lcd_int(x);
		uart_tx_num(x);
		uart_tx_char(' ');
		
		AD0CR = 0x01200602;
		//AD0CR |= 0x01000000;  // Start ADC, Channel 0
		y = read_adc();
		cmd(0x85); 
		lcd_int(y);
		uart_tx_num(y);
		uart_tx_char(' ');

		
	
		AD0CR = 0x01200604;
		//AD0CR |= 0x01000000;  // Start ADC, Channel 0
		z = read_adc();
		cmd(0x8A); 
		lcd_int(z);
		uart_tx_num(z);
		uart_tx_str("\r");

				  
		if(x>600 )
		{
			cmd(0x01);
			lcd_str("ALERT x = ");
			uart_tx_str("\nAlert x");
			cmd(0xc0);
			lcd_int(x);
			delay(1000);
			cmd(0x01);
		}
		if(y<300 )
		{
			cmd(0x01);
			lcd_str("ALERT y = ");
			uart_tx_str("\nAlert y");
			cmd(0xc0);
			lcd_int(y);
			delay(1000);
			cmd(0x01);
		}
		delay(100);	
		
			

	}
 	
 }
int main(void)
{	
	
#if _EXT_EEPROM_EMPTY==1
	DDRB=0xFF;
	PORTB=0x00;
	
	i2cSetBitrate(100); //Ustaw prêdkoœæ i2c na 100kHz
	EXT_EEPROM_var *struktura_eeprom;
	struktura_eeprom=malloc(sizeof(EXT_EEPROM_var));
	strcpy(struktura_eeprom->empty,  "                ");
	strcpy(struktura_eeprom->temperatura, "Temperatura:    ");
	strcpy(struktura_eeprom->m1,  "Ustawienia      ");
	strcpy(struktura_eeprom->m10, "Data:           ");
	strcpy(struktura_eeprom->m11, "Godzina:        ");
	strcpy(struktura_eeprom->m12, "LCD:            ");
	strcpy(struktura_eeprom->eePCF_Sunday, "Niedziela");
	strcpy(struktura_eeprom->eePCF_Monday, "Poniedzialek");
	strcpy(struktura_eeprom->eePCF_Tuesday, "Wtorek");
	strcpy(struktura_eeprom->eePCF_Wednesday, "Sroda");
	strcpy(struktura_eeprom->eePCF_Thursday, "Czwartek");
	strcpy(struktura_eeprom->eePCF_Friday, "Piatek");
	strcpy(struktura_eeprom->eePCF_Saturday, "Sobota");
	strcpy(struktura_eeprom->eePCF_January, "Styczen");
	strcpy(struktura_eeprom->eePCF_February, "Luty");
	strcpy(struktura_eeprom->eePCF_March, "Marzec");
	strcpy(struktura_eeprom->eePCF_April, "Kwiecien");
	strcpy(struktura_eeprom->eePCF_May, "Maj");
	strcpy(struktura_eeprom->eePCF_June, "Czerwiec");
	strcpy(struktura_eeprom->eePCF_July, "Lipiec");
	strcpy(struktura_eeprom->eePCF_August, "Sierpien");
	strcpy(struktura_eeprom->eePCF_September, "Wrzesien");
	strcpy(struktura_eeprom->eePCF_October, "Pazdziernik");
	strcpy(struktura_eeprom->eePCF_November, "Listopad");
	strcpy(struktura_eeprom->eePCF_December, "Grudzien");
	PORTB=0x0F;
	
	EI2C_write_buf(ADDR_EEMEM_24C64, 0, sizeof(EXT_EEPROM_var), (uint8_t*)struktura_eeprom);
	free(struktura_eeprom);
	PORTB=0xFF;
#endif // _EXT_EEPROM_EMPTY

#if _EXT_EEPROM_EMPTY==0

	char bufor_lcd[41];	//Bufor przechowuj¹cy znaki z pamiêci EEPROM
	
	//Zmienne wykorzystywane w opóŸnieniach:
	uint8_t state=0;
	uint32_t cnt=0, offset_cnt=0;
	uint8_t state_light=0;
	uint32_t cnt_light=0, offset_cnt_light=0;
	
	Ustawienia ustawienia;	//Struktura s³u¿¹ca do odczytania ustawieñ z EEPROM
	ustawienia.ustawienia_poczatkowe=0;
	
	//Ustaw PORTB jak wyjœcie dla LED:
	DDRB=0xFF;
	PORTB=0x00;
	Flagi.flaga_klawiatura=1;
	
	//// ustawienia TIMER0, przerwanie co 10us
	OCR0 = 19;
	TCCR0 |= (1<<WGM01);		//Tryb ctc
	TCCR0 |= (1<<CS01);			// Preskaler 8
	TIMSK |= (1<<OCIE0);

	// Przerwanie INT0
	MCUCR |= (1<<ISC01);	// wyzwalanie zboczem opadaj¹cym
	GICR |= (1<<INT0);		// odblokowanie przerwania
	PORTD |= (1<<PD2);		// podci¹gniêcie pinu INT0 do VCC
	
	i2cSetBitrate(100); //Ustaw prêdkoœæ i2c na 100kHz
	lcd_init();
	pobierz_czas(&czas);
	pobierz_date(&data);

	/* sprawdzamy ile czujników DS18xxx widocznych jest na magistrali */
	czujniki_cnt = search_sensors();

	/* wysy³amy rozkaz wykonania pomiaru temperatury
	 * do wszystkich czujników na magistrali 1Wire
	 * zak³adaj¹c, ¿e zasilane s¹ w trybie NORMAL,
	 * gdyby by³ to tryb Parasite, nale¿a³oby u¿yæ
	 * jako pierwszego prarametru DS18X20_POWER_PARASITE */
	DS18X20_start_meas( DS18X20_POWER_EXTERN, NULL );
	
	/* czekamy 750ms na dokonanie konwersji przez pod³¹czone czujniki */
	_delay_ms(750);

	/* dokonujemy odczytu temperatury z pierwszego czujnika o ile zosta³ wykryty */
	/* wyœwietlamy temperaturê gdy czujnik wykryty */
	if( DS18X20_OK == DS18X20_read_meas(gSensorIDs[0], &subzero, &cel, &cel_fract_bits) ) display_temp(0);
	else {
		lcd_locate(0,0);
		lcd_str("term. error ");	/* wyœwietlamy informacjê o b³êdzie jeœli np brak czujnika lub b³¹d odczytu */
	}
	
#endif	 // _EXT_EEPROM_EMPTY
    while (1) 
    {	
#if _EXT_EEPROM_EMPTY==0
		eeprom_read_block(&ustawienia, &deafult_flags, sizeof(deafult_flags));
		if (ustawienia.ustawienia_poczatkowe)
		{
			eeprom_read_block(&data, &deafult_data, sizeof(data));
			eeprom_read_block(&czas, &deafult_czas, sizeof(czas));
			ustaw_date(&data);
			ustaw_czas(&czas);

			ustawienia.ustawienia_poczatkowe=0;
			eeprom_update_block(&ustawienia, &deafult_flags, sizeof(deafult_flags));
		}

		switch(state_light)
		{
			case 0:
				if (Flagi.light_lcd)
				{

					state_light=1;
					cli();
					cnt_light=200000;
					offset_cnt_light=licznik;
					sei();
					
				}
			break;
			case 1:
			if(cnt_light<=licznik-offset_cnt_light)
			{
				Flagi.light_lcd=0;
				state_light=0;
			}
			break;
		}
		lcd_light(Flagi.light_lcd);
		
		//OpóŸnienie dzia³añ po wciœniêciu przycisku
		switch(state)
		{
			case 0:
					key_code=debouncer(KlawiaturaSkan());
					if(key_code)
					{
						state=1;
						Flagi.light_lcd=1;	//W³¹cz podœwietlanie LCD
						cli();
						cnt=50000;
						offset_cnt=licznik;
						sei();
					}

					break;
			case 1:
					key_code=0;
					if(cnt<=licznik-offset_cnt)
					{
						state=0;
					}
					break;
		}
		
		if (Flagi.flaga_menu_func==1)
		{
			EI2C_read_buf(ADDR_EEMEM_24C64, menu_ptr->addr_ext_eeprom, menu_ptr->size_ext_eeprom, (uint8_t *)bufor_lcd);
			if(Flagi.flaga_lcd)
			{
				lcd_locate(0, 0);
			}

			(*menu_ptr->funkcja)(bufor_lcd);		//WskaŸnik na funkcje dla danej pozycji menu
		}

		if(Flagi.flaga_klawiatura==1)
		{	
			if (key_code == PRZYCISK_PRAWO)
			{
				if(menu_ptr->next!=NULL)
				{
					Flagi.flaga_lcd=1;
					menu_ptr=menu_ptr->next;
				}
			}
			else if (key_code == PRZYCISK_LEWO)
			{
				if(menu_ptr->prev!=NULL)
				{
					Flagi.flaga_lcd=1;
					menu_ptr=menu_ptr->prev;
				}
			}
			else if (key_code == PRZYCISK_DOL)
			{
				if(menu_ptr->down!=NULL)
				{
					Flagi.flaga_lcd=1;
					menu_ptr=menu_ptr->down;
				}
			}
			else if (key_code == PRZYCISK_GORA)
			{
				if(menu_ptr->up!=NULL)
				{
					Flagi.flaga_lcd=1;
					menu_ptr=menu_ptr->up;
				}
			}
		}
		
		if(menu_ptr->funkcja!=NULL)
			Flagi.flaga_menu_func=1;
		else
			Flagi.flaga_menu_func=0;

#endif  // _EXT_EEPROM_EMPTY
    }
}
示例#26
0
文件: main.c 项目: JinhoAndyPark/AVR
int main(void)
{	
	
	S16 cnt; // when operation for x_move_deg(ccw), it makes cnt<0
	U16 ccnt;
	U16 stCNT;
	U08 i;
	Main_Init();

	lcd_iw(0x01);
	lcd_str(str1);	//Welcome to 3D
	lcd_iw(0xc0);	
	lcd_str(str2);	//Scanning world
	
	while(1)	
	{	

		//------------------------------------------------------------------------------ 
		//		=== AUTO MODE ===
		//------------------------------------------------------------------------------
		if( Instruction[0] == 1)
		{	
			Instruction[0] = 0;
			
			Uart_Putch( 0,SIG_To2[0] );	//SIG_To2
			
			lcd_iw(0x01);
			lcd_str(str3);	//<Sensing...>
			lcd_iw(0xc0);	
			lcd_str(str4);	//<Please, Wait^^>"
			
			Lets_Do_FirstStep(); // until start point 
			_delay_ms(1);
			
			for( stCNT=0; stCNT<55000; stCNT++ )
			{
				Y_StepMotor_Move_1step(CCW);
				_delay_us(600);
		
				if( BREAK_NUM1 == 1 )
				{	
					cbi( TIMSK, TOIE0 );
					_delay_ms(10);
					
					Height = (56 * result_op_cnt);
					arr[1] = (Height/1000);
					arr[2] = (Height%1000)/100;
					arr[4] = ((Height%100)/10);
					arr[5] = ((Height%10));

					lcd_iw(0x01); // ALL CLEAR
					lcd_str(str5);	//<The Height is: >				
					lcd_iw(0xc0);
					
					lcd_dw('<');	//1//0
					for(i=1 ;i<3 ;i++)
					{
						lcd_dw(arr[i]+48);	//1//1,2
					}			//4
					lcd_dw('.');	//3//3
					for(i=4 ;i<6 ;i++)
					{
						lcd_dw(arr[i]+48);	//1//4,5
					}			//4//4,5
					lcd_dw('c');	//6		
					lcd_dw('m');	//7
					lcd_dw('>');	//8
					break;
				}
			}
			_delay_ms(10);	//system delay
			
			Y_Move_Startpoint();
			///////////////////////////////measuring op_time until this line
			Uart_Putch(0,SIG_To2[0]);	
			
			lcd_iw(0x01);
			lcd_str(str6);	//<Scanning..>
			lcd_iw(0xc0);	
			lcd_str(str4);	//<Please, Wait^^>"
			
			Lets_Do_FirstStep();
			
			for(ccnt=0; ccnt<25; ccnt++)
			{
				while(1)
				{	
					WRONG_SIG = 0;

					X_Move_Startpoint(CCW);
		
					_delay_ms(10);	//system delay
					
					for(cnt=0; cnt<200; cnt++)
					{
						X_Move_deg(CW);
						SENSING_CW[cnt] = Dis;
					}
					for(cnt=0; cnt<210; cnt++)
					{
						X_Move_deg(CW);
						SENSING_CW[cnt] = Dis;
					}

					_delay_ms(10);
					Filter();
					_delay_ms(10);
					
					X_Move_Startpoint(CCW);
						
					//Compare_Dis();
					
					//if( WRONG_SIG == 0 )
						//{
						Percent[ccnt] = ((5200/Height)*(ccnt+2));
						Percent10[ccnt] = Percent[ccnt]/10;
						Percent1[ccnt] = Percent[ccnt]%10;
						
						lcd_iw(0x01);
						lcd_str(str6);
						lcd_dw(Percent10[ccnt]+48);
						lcd_dw(Percent1[ccnt]+48);
						lcd_dw('%');
						lcd_dw('>');
						
						break;					//wonder the closest repeat sentence ..while(1)? yeap!
					//}
					
				}	
				_delay_ms(10);
				///////////////////////////// X_sensing and return until this line
				Y_Move_Simple(CCW);
				
				if( BREAK_NUM1 == 1 )
				{
					BREAK_NUM1 = 0;
					
					X_Move_Startpoint(CCW);
					
					_delay_ms(10);
					
					for(cnt=0; cnt<200; cnt++)
					{
						X_Move_deg(CW);
						SENSING_CW[cnt] = Dis;
					}
					for(cnt=0; cnt<210; cnt++)
					{
						X_Move_deg(CW);
						SENSING_CW[cnt] = Dis;
					}

					_delay_ms(10);
					Filter();
					_delay_ms(10);
					
					X_Move_Startpoint(CCW);
					
					
					lcd_iw(0x01);
					lcd_str(str8);	//100% Done
					Y_Move_Startpoint();
			
					Uart_Putch(0,SIG_To2[2]);	//sig to2 : laser off

					lcd_iw(0x01), lcd_str(str9), lcd_iw(0xc0), lcd_str(str10);	//laser off complete
					_delay_ms(1000);
					lcd_iw(0x01), lcd_str(str9), lcd_iw(0xc0), lcd_str(str10);
					_delay_ms(1000);
					lcd_iw(0x01), lcd_str(str9), lcd_iw(0xc0), lcd_str(str10);
					_delay_ms(1000);

				 break;
				}
			}
		}

		//------------------------------------------------------------------------------ 
		//		=== FAST MODE ===
		//------------------------------------------------------------------------------		
		else if( Instruction[1] == 1)
		{
			Instruction[1] = 0;
			
			Uart_Putch(0,SIG_To2[0]);	
			
			lcd_iw(0x01), lcd_str(str11), lcd_iw(0xc0), lcd_str(str6);	//< Fast Mode > <Scanning..>
			
			Lets_Do_FirstStep();
			
			for(ccnt=0; ccnt<25; ccnt++)
			{
				while(1)
				{	
					WRONG_SIG = 0;

					X_Move_Startpoint(CCW);
		
					_delay_ms(10);	//system delay
					
					for(cnt=0; cnt<200; cnt++)
					{
						X_Move_deg(CW);
						SENSING_CW[cnt] = Dis;
					}
					for(cnt=0; cnt<210; cnt++)
					{
						X_Move_deg(CW);
						SENSING_CW[cnt] = Dis;
					}

					_delay_ms(10);
					Filter();
					_delay_ms(10);
				
					X_Move_Startpoint(CCW);

					break;
					/*
					Compare_Dis();
					if( WRONG_SIG == 0 )
					{			
						break;					//wonder the closest repeat sentence ..while(1)? yeap!
					}
					*/
				}	
				_delay_ms(10);
				///////////////////////////// X_sensing and return until this line
				Y_Move_Simple(CCW);
				
				if( BREAK_NUM1 == 1 )
				{
					BREAK_NUM1 = 0;
					
					X_Move_Startpoint(CCW);
					_delay_ms(10);
					
					for(cnt=0; cnt<200; cnt++)
					{
						X_Move_deg(CW);
						SENSING_CW[cnt] = Dis;
					}
					for(cnt=0; cnt<210; cnt++)
					{
						X_Move_deg(CW);
						SENSING_CW[cnt] = Dis;
					}
					
					_delay_ms(10);
					Filter();
					_delay_ms(10);
					
					X_Move_Startpoint(CCW);

					//X_Move_Startpoint(CCW);
					
					lcd_iw(0x01);
					lcd_str(str8);	//100% Done
					
					Y_Move_Startpoint();
					_delay_ms(10);
					
					Uart_Putch(0,SIG_To2[2]);	//sig to2 : laser off

					lcd_iw(0x01), lcd_str(str9), lcd_iw(0xc0), lcd_str(str10);	//laser off	Complete
					_delay_ms(1000);
					lcd_iw(0x01), lcd_str(str9), lcd_iw(0xc0), lcd_str(str10);	//laser off	Complete
					_delay_ms(1000);
					lcd_iw(0x01), lcd_str(str9), lcd_iw(0xc0), lcd_str(str10);	//laser off	Complete

					break;
				}
			}
		}
		
		//------------------------------------------------------------------------------ 
		//		=== X_MOVE_LEFT ===
		//------------------------------------------------------------------------------
		else if( Instruction[2] == 1 )
		{
			Instruction[2] = 0;
			
			X_Move_Startpoint(CCW);
			_delay_ms(3);
			//X_Move_Startpoint();
			//_delay_ms(3);
			
		}
		
		//------------------------------------------------------------------------------ 
		//		=== X_MOVE_RIGHT ===
		//------------------------------------------------------------------------------
		else if( Instruction[3] == 1 )
		{	
			Instruction[3] = 0;
			X_Move_Startpoint(CW);
			_delay_ms(3);
		}
		/////////////////////////////////////////////////////////////////////////////
		else if(Instruction[4] == 1)
		{	
			Instruction[4] = 0;
			//Data_to_PC();
			
					/*
					for(i=1 ;i<6 ;i++)
					{
						Uart_Putch(1,arr[i]);
					}		
					*/
					for(ccnt=0;ccnt<10;ccnt++)
					{
						Height = 896;
						Percent[ccnt] = ((Height/80)*(ccnt+1));
					
						Percent10[ccnt] = Percent[ccnt]/10;
						Percent1[ccnt] = Percent[ccnt]%10;
						
						lcd_iw(0x01);
						lcd_str(str6);
						//lcd_iw(0xc0);
						lcd_dw(Percent10[ccnt]+48);
						lcd_dw(Percent1[ccnt]+48);
						lcd_dw('%');
						lcd_dw('>');
						_delay_ms(2000);
					}
		}
		
	}

	return 0;
}
示例#27
0
/*
void isr() interrupt 0 {

}
*/
void main() {
  unsigned char i,tmp;

  CMCON=0x07; 
  TRISA=0x30;
  TRISB=0xE7;
  
  PORTA=0;
  PORTB=0;

  lcd_init();

  i2c_init();

//teste lcd
  lcd_cmd(L_CLR); 
  lcd_cmd(L_L1);
  for(i=0;i<16;i++)
  {
    lcd_dat('A'+i);
  }
  lcd_cmd(L_L2);
  for(i=0;i<16;i++)
  {
    lcd_dat('a'+i);
  }

  atraso_ms(200);
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1+3);
  lcd_str("Teste LCD");
  
  for(i=32;i<128;i++)
  {
    if((i%16) == 0)lcd_cmd(L_L2);
    lcd_dat(i);
    atraso_ms(50);
  }

  atraso_ms(100);
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1+3);
  lcd_str("Teste LCD");
  lcd_cmd(L_L2+7);
  lcd_str("Ok");
  atraso_ms(500);

//teste LEDS
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1+1);
  lcd_str("Teste LEDs");
 
for(i=0;i<4;i++)
  {
    atraso_ms(100);
    RA1^=1;
    atraso_ms(100);
    RA2^=1;
    atraso_ms(100);
    PORTA^=0x40; //RA6=1;
    atraso_ms(100);
    PORTA^=0x80; //RA7=1;
    atraso_ms(100);
  }


//teste Teclado
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1+2);
  lcd_str("Teste Teclado");

  lcd_cmd(L_L2+1);

  i=0;
  while(i<14)
  {
    lcd_dat(tc_tecla(1500)+0x30);
    i++;
  }

//teste EEPROM EXT
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("Teste EEPROM EXT");
// testar ? 
  lcd_cmd(L_L2);
  lcd_str("Testar (1/0) ?");
 
  if(tc_tecla(1500) == 1)
  {
    tmp=e2pext_r(10);
    lcd_dat(tmp);

    e2pext_w(10,0xA5);
    e2pext_w(10,0x5A);
    i=e2pext_r(10);

    e2pext_w(10,tmp);

    lcd_cmd(L_CLR);
    lcd_cmd(L_L1);
    lcd_str("Teste EEPROM EXT");
    lcd_cmd(L_L2);
    if(i == 0x5A) 
      lcd_str("     OK");
    else
      lcd_str("     ERRO");

    atraso_ms(1000);
  }


//teste RTC
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("Teste RTC");
  
//ajuste  rtc_w();

//  rtc_w();
 
  rtc_r();
  lcd_cmd(L_L2);
  lcd_str(date);
   atraso_ms(1500);
  for(i=0;i<16;i++)
  {
    rtc_r();
    lcd_cmd(L_L2);;
    lcd_str(time);
    atraso_ms(500); 
  }

//fim teste 
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1+4);
  lcd_str("Fim");
  lcd_cmd(L_L2+1);
  lcd_str("Pressione RST");

  while(1);


}
示例#28
0
文件: main.c 项目: shtomik/AVR
int main(void)
{
lcd_init();
ds1307_init();
adc_init();
timer_init();
asm("sei");
/*
    //test
	lcd_str("Hello, World");
	lcd_gotoxy(1,0);
	lcd_str("by shtomik");
	_delay_ms(1000);
	lcd_clr();
	lcd_str("after clr");*/

start_t();

    //test
    ds1307_setdate(12, 12, 31, 23, 01, 35);

//смонтировать microSD
res = pf_mount(&fs);
if(res == FR_OK)
{
    //диск смонтирован и мы продолжаем работу
    if(pf_open("test.txt") == FR_OK)
    {
        //открыли файл в корне test.txt
        //...
        pf_lseek(0);
            //заполняем буффер, надо набрать 512 байт инфы и писать
			//иначе будет много лишних пробелов
            //sprintf(buff, "%s\n%s", "Hello,World!", "by_sht");
            //записываем его на карту
            pf_write(buff, 512, &br);
			//финализируем запись
       		pf_write(NULL, 0, &br);
			pf_lseek(512);
			pf_write(buff, 512, &br);
        	//финализируем запись
        	pf_write(NULL, 0, &br);

		lcd_clr();
        lcd_str("ok");
    }
    else
    {
        //file not found or ...
        lcd_str("file not found");
    }
    //демонтируем диск передав функции нулевой указатель
    pf_mount(NULL);
	lcd_clr();
	lcd_str("file write");
}
else
{
    //не удалось смонтировать диск
	lcd_clr();
    lcd_str("not flash");
}

    while( 1 )
    {
        ;
    }

return 0;
}
示例#29
0
/*
void isr() interrupt 0 {

}
*/
void main() {
  unsigned char i,tmp;

  CMCON=0x07; 
  TRISA=0x30;
  TRISB=0xE7;
  
  PORTA=0;
  PORTB=0;

  lcd_init();

  serial_init();

//teste serial
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("Teste Serial TX");
  lcd_cmd(L_L2+2);
  lcd_str("9600 8N1");

  serial_tx_str("\r\n Picsimlab\r\n Teste Serial TX\r\n");

  for(i=0;i<4;i++)
  {
    serial_tx(i+0x30);
    serial_tx_str(" PicsimLab\r\n");
  }
  atraso_ms(1000);

  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("Teste Serial RX");
  serial_tx_str(" Digite!\r\n");
  for(i=0;i<32;i++)
  {
    if(!(i%16))
    {
       lcd_cmd(L_L2);
       serial_tx_str("\r\n");
    }
    tmp=serial_rx(2000);
    lcd_dat(tmp);
    serial_tx(tmp);
  }
  atraso_ms(100);

  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("Teste Teclado TX");
  serial_tx_str("\r\n Aguarde!\r\n");
  for(i=0;i<32;i++)
  {
    if(!(i%16))
    {
      lcd_cmd(L_L2);
      serial_tx_str("\r\n");
    }
    tmp=tc_tecla(2000)+0x30;
    lcd_dat(tmp);
    serial_tx(tmp);
  }
  atraso_ms(100);


//fim teste 
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1+4);
  lcd_str("Fim");
  lcd_cmd(L_L2+1);
  lcd_str("Pressione RST");

  serial_tx_str("\r\n FIM!\r\n");

  while(1);


}
示例#30
0
//----------------------------------------------------------------------------------------
//
//		 Wy�wietla liczb� dziesi�tn� na wy�wietlaczu LCD
//
//----------------------------------------------------------------------------------------
void lcd_int(int val)
{
	char bufor[17];
	lcd_str( itoa(val, bufor, 10) );
}