void display_row_var (unsigned char p_byRow, unsigned char str[16])
{
	unsigned char k,cpy_str[2];
	unsigned long int i = 0;
	if(p_byRow == 1)			// if row  is same as saying if row is non zero, in our case its row = 1
	{
		lcd_cmd(0xc0);
	}
	else
	{
		lcd_cmd(0x80);
	}
		
	for(k = 0 ; k < 16 ; k ++)
	{

		{
			if (str[k])
				lcd_dat(str[k]) ;
			else
				break ;
		}
	}
	while(k < 16)
	{
		lcd_dat(' ') ;
		k ++ ;
	}

}	
void display_row (unsigned char p_byRow)
{
	unsigned char i,j;
	unsigned char k;
	if(p_byRow == 1)			// if row  is same as saying if row is non zero, in our case its row = 1
	{
	// Set the address to the second line
	lcd_cmd(0xC0);
	Delay10us(5);

	// Output second line
		for(i = 0; i < 16u; i++)
		{
		// Erase the rest of the line if a null char is 
		// encountered (good for printing strings directly)
		if(LCDText[i] == 0u)
		{
			for(j=i; j < 16u; j++)
			{
				LCDText[j] = ' ';
			}
		}
		
		lcd_dat(LCDText[i]);
		Delay10us(5);
		}
	
	}

	else
	{
		lcd_cmd(0x80);
		DelayMs(2);

		// Output first line
		for(i = 0; i < 16u; i++)
		{
		// Erase the rest of the line if a null char is 
		// encountered (good for printing strings directly)
		if(LCDText[i] == 0u)
		{
			for(j=i; j < 16u; j++)
			{
				LCDText[j] = ' ';
			}
		}
		lcd_dat(LCDText[i]);
		Delay10us(5);
		
		}
	}
}
Beispiel #3
0
void lcd_str(char* str)
{
 unsigned char i=0;
  
 while(str[i])
 {
   lcd_dat(str[i]);
   i++;
 }  
}
Beispiel #4
0
//------------------------------------------------------------------------------------
// lcd_puts
//------------------------------------------------------------------------------------
//
// write a string to the LCD screen
//
void lcd_puts(char string[])
{
	int i;
	i=0;
	while(string[i])
	{
		lcd_dat(string[i]);
		i++;
	}
}
Beispiel #5
0
void display_row(unsigned char p_byrow,unsigned char p_byDataArr[16])
{
//row=0;
//row=1;
unsigned char count,ch;
if(p_byrow)
lcd_cmd(0Xc0);
else
lcd_cmd(0X80);
for(count=0;count<16;count++)
{
if(ch=p_byDataArr[count])
lcd_dat(ch);
else
while(count<16)
{
lcd_dat(' ');
count++;
}
}
}
Beispiel #6
0
// Show command by index
void ShowCmd(uint8_t cmd_index) {
	if (state.bits.config==1) return;
	_cmd_type Cmd = CmdArray[cmd_index];
	char buf[6];
	int16_to_str(cmd_index+1, buf, 0x30); // bcd convertion
	lcd_pos(0x10);
	lcd_out(buf+2); lcd_out(": "); 
	lcd_dat(Cmd.cmd_name); lcd_hex(Cmd.cmd_data);
	lcd_pos(0x00); lcd_out(GetTimerName(LastTimerDelay));
//	lcd_hexdigit(LastTimerDelay

}
void only_4_per_row (unsigned int p_byRow,unsigned long int result) {
	int i;
	if(p_byRow == 1)			// if row  is same as saying if row is non zero, in our case its row = 1
	{
		lcd_cmd(0xc0);
	}
	else
	{
		lcd_cmd(0x80);
	}
	for(i=0;i<4;i++) {
	}
	Delay10us(5);
	lcd_dat(inttochar((result/1000)%10));
	lcd_dat(inttochar((result/100)%10));
	lcd_dat(inttochar((result/10)%10));
	lcd_dat(inttochar(result%10));	
	for(i=0;i<12;i++) {
		lcd_dat(' ');
	}
}
Beispiel #8
0
// Show seconds counter value 
void ShowTime(uint16_t data) {
	if (state.bits.config==1) return;

	uint16_t mins = data / 60; if (mins>99) mins=99;
	uint16_t secs = data % 60;

	lcd_pos(0x1b);
	char buf[6];
	int16_to_str(mins, buf, 0x30); 
	lcd_out(buf+3);lcd_dat(':');
	int16_to_str(secs, buf, 0x30); 
	lcd_out(buf+3);
}
Beispiel #9
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);


}
Beispiel #10
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);


}
Beispiel #11
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);


}
Beispiel #12
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);


}
Beispiel #13
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);

}
Beispiel #14
0
void main() 
{
  unsigned char i;
  unsigned char tmp;
  unsigned int tmpi;

  char str[6];


  TRISA=0xC3;
  TRISB=0x01;
  TRISC=0x01;
  TRISD=0x00;
  TRISE=0x00;

#if defined(_16F877A) || defined(_16F777)  
#else  
  INTCON2bits.RBPU=0;
#endif

  lcd_init();
#ifndef _18F4550  
  i2c_init();
#endif  
  serial_init();
  adc_init();
  
#ifdef _18F452
  ADCON1=0x06;
#else
  ADCON1=0x0F;
  CMCON=0x07;
#endif

//dip
  TRISB=0x03;
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("Ligue todos DIP");
  lcd_cmd(L_L2);
  lcd_str("Press. RB1");
  while(PORTBbits.RB1);


//testa caracter especial
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("   Teste LCD");
  
  for(i=0;i<10;i++)
  {
    atraso_ms(200);
    lcd_cmd(0x18);//display shift
  }
  
  for(i=0;i<10;i++)
  {
    atraso_ms(200);
    lcd_cmd(0x1C);//display shift
  }
  
  for(i=0;i<10;i++)
  {
    atraso_ms(200);
    lcd_cmd(0x10);
  }
  for(i=0;i<10;i++)
  {
    atraso_ms(200);
    lcd_cmd(0x14);
  }
  

  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("   Teste LCD");
  
  for(i=32;i>=32;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("   Teste LCD");
  lcd_cmd(L_L2);
  lcd_str("       Ok");
  atraso_ms(500);


  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("   Beep");
  PORTCbits.RC1=1; //beep
  atraso_ms(500);
  PORTCbits.RC1=0;

//testa display 7s

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


#ifdef _18F452
  ADCON1=0x06;
#else
  ADCON1=0x0F;
#endif
    for(i=0;i<4;i++)
    {
      switch(i)
      {
         case 0: 
           PORTA=0x20;
           break;
         case 1: 
           PORTA=0x10;
           break;
         case 2: 
           PORTA=0x08;
           break;
         case 3: 
           PORTA=0x04;
           break;
       }

      for(tmp=0;tmp<16;tmp++)
      {
        PORTD=display7s(tmp);	 
        atraso_ms(200);	
      }
    }

#ifdef _18F452
  ADCON1=0x02;
#else
  ADCON1=0x0B;
#endif
  PORTD=0;


//dip
  TRISB=0x03;
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("Desligue RTC DIP");
  lcd_cmd(L_L2);
  lcd_str("Press. RB1");
  while(PORTBbits.RB1);

//testa LEDs
  TRISB=0x00;
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1+3);
  lcd_str("Teste LEDs");

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

//testa chaves


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

  tmp=0;
#ifdef _18F452
  ADCON1=0x06;
#else
  ADCON1=0x0F;
#endif
  TRISA|=0x20;

  TRISB=0x3F;
  lcd_cmd(L_L2);
  lcd_str(" RB0          ");
  while(PORTBbits.RB0);
  lcd_cmd(L_L2+6);
  lcd_str("Ok");
  atraso_ms(500);
  
  lcd_cmd(L_L2);
  lcd_str(" RB1          ");
  while(PORTBbits.RB1);
  lcd_cmd(L_L2+6);
  lcd_str("Ok");
  atraso_ms(500);
  
  lcd_cmd(L_L2);
  lcd_str(" RB2          ");
  while(PORTBbits.RB2);
  lcd_cmd(L_L2+6);
  lcd_str("Ok");
  atraso_ms(500);
  
  lcd_cmd(L_L2);
  lcd_str(" RB3          ");
  while(PORTBbits.RB3);
  lcd_cmd(L_L2+6);
  lcd_str("Ok");
  atraso_ms(500);
  
  lcd_cmd(L_L2);
  lcd_str(" RB4          ");
  while(PORTBbits.RB4);
  lcd_cmd(L_L2+6);
  lcd_str("Ok");
  atraso_ms(500);
  
  
  lcd_cmd(L_L2);
  lcd_str(" RB5          ");
  while(PORTBbits.RB5);
  lcd_cmd(L_L2+6);
  lcd_str("Ok");
  atraso_ms(500);
  
  lcd_cmd(L_L2);
  lcd_str(" RA5          ");
  while(PORTAbits.RA5);
  lcd_cmd(L_L2+6);
  lcd_str("Ok");
  atraso_ms(500);
  
  
/*
  while((tmp & 0x7F) != 0x7F)
  {
    TRISB=0x3F;

    if(PORTBbits.RB0 == 0)
    {
      tmp|=0x01;
    }
    if(PORTBbits.RB1 == 0)
    {
      tmp|=0x02;
    }
    if(PORTBbits.RB2 == 0)
    {
      tmp|=0x04;
    }
    if(PORTBbits.RB3 == 0)
    {
      tmp|=0x08;
    }
    if(PORTBbits.RB4 == 0)
    {
      tmp|=0x10;
    }
    if(PORTBbits.RB5 == 0)
    {
      tmp|=0x20;
    }
    if(PORTAbits.RA5 == 0)
    {
      tmp|=0x40;
    }

    
    TRISB=0x00;
    PORTB=tmp;
    atraso_ms(10);
  }

    atraso_ms(500);
*/
            
  PORTB=0; 
#ifdef _18F452
  ADCON1=0x02;
#else
  ADCON1=0x0B;
#endif


 
//teste serial
 lcd_cmd(L_CLR);
 lcd_cmd(L_L1);
 lcd_str("Teste Serial TX");
// testar ? 
  lcd_cmd(L_L2);
  lcd_str(" (s=RB0 n=RB1) ?");

  TRISB=0x03;
  while(PORTBbits.RB0 && PORTBbits.RB1);

  if(PORTBbits.RB0 == 0)
  {

  TRISCbits.TRISC7=1; //RX
  TRISCbits.TRISC6=0; //TX


  lcd_cmd(L_L2+4);
  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);
  }

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

  for(i=0; i< 200; i++)
  {
    tmp=(adc_amostra(0)*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);
  }

  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str(" 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 RELE

  TRISCbits.TRISC0=0;
  TRISEbits.TRISE0=0;

  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("Teste RELE 1");

  
  for(i=0;i<5;i++)
  {
    PORTCbits.RC0^=1;
    atraso_ms(500); 
  }
  PORTCbits.RC0=0; 

  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("Teste RELE 2");

  for(i=0;i<5;i++)
  {
    PORTEbits.RE0^=1;
    atraso_ms(500); 
  }
  PORTEbits.RE0=0;
//dip
  TRISB=0x03;
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("Desl. REL1 DIP");
  lcd_cmd(L_L2);
  lcd_str("Press. RB1");
  while(PORTBbits.RB1);


//teste TEMP
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("   Teste TEMP");
  
  TRISA=0x07;

  adc_init();

  for(i=0; i< 100; i++)
  {
    tmpi=(adc_amostra(2)*10)/2;
    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(20);
  }


//teste Aquecimento
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("   Teste AQUEC");
  PORTCbits.RC5=1;
  for(i=0; i< 100; i++)
  {
    tmpi=(adc_amostra(2)*10)/2;
    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(50);
  }
  PORTCbits.RC5=0;


//teste Resfriamento

  TRISCbits.TRISC0=1;
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("   Teste RESFR");

//timer0 temporizador
#if defined(_16F877A) || defined(_16F777)  
 OPTION_REGbits.T0CS=0;
 OPTION_REGbits.PSA=0;
 OPTION_REGbits.PS0=0;
 OPTION_REGbits.PS1=0;
 OPTION_REGbits.PS2=1;
#else
 T0CONbits.T0CS=0;
 T0CONbits.PSA=0;
 T0CONbits.T08BIT=1;
 T0CONbits.T0PS0=0; // divide por 32
 T0CONbits.T0PS1=0;
 T0CONbits.T0PS2=1;
 T0CONbits.TMR0ON=1;
#endif
 
 
 INTCONbits.T0IE=1;

//T = 32x250x125 = 1segundo;

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


 INTCONbits.T0IF=0;
#if defined(_16F877A) || defined(_16F777)  
 TMR0=6;
#else
 TMR0H=0;
 TMR0L=6; //250
#endif
 cnt=125; 
 INTCONbits.GIE=1;

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

  PORTCbits.RC2=1;
  for(i=0; i< 150; i++)
  {
    tmpi=(adc_amostra(2)*10)/2;
    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.RC2=0;


#ifdef _18F452
  ADCON1=0x06;
#else
  ADCON1=0x0F;
#endif

#ifndef _18F4550
//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((const char *)date);
   atraso_ms(2000);
  for(i=0;i<20;i++)
  {
    rtc_r();
    lcd_cmd(L_L2);;
    lcd_str((const char *)time);
    atraso_ms(500); 
  }
#endif

//dip
  TRISB=0x03;
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("Des. DIS* e LED1");
  lcd_cmd(L_L2);
  lcd_str("Press. RB1");
  while(PORTBbits.RB1);



  TRISB=0xF8;
//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)
  {
    TRISD=0x0F;
    tmp=tc_tecla(1500)+0x30;
    TRISD=0x00;
    lcd_dat(tmp);
    i++;
  }


#ifndef _16F777
  TRISB=0x03;
//teste EEPROM INT
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("Teste EEPROM INT");
// testar ? 
  lcd_cmd(L_L2);
  lcd_str(" (s=RB0 n=RB1) ?");


  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("Teste EEPROM INT");
    lcd_cmd(L_L2);
    if(i == 0x5A) 
      lcd_str("       OK");
    else
      lcd_str("      ERRO");

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

#ifndef _18F4550
//teste EEPROM EXT
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("Teste EEPROM EXT");
// testar ? 
  lcd_cmd(L_L2);
  lcd_str(" (s=RB0 n=RB1) ?");

  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("Teste EEPROM EXT");
    lcd_cmd(L_L2);
    if(i == 0x5A) 
      lcd_str("       OK");
    else
      lcd_str("      ERRO");

    atraso_ms(1000);
  }
  else
  {
    while(PORTBbits.RB1 == 0);
  }
#endif
  TRISB=0x00;
  PORTB=0;


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

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


   while(1);

}