Olá Isadora!
Bem vou tentar explicar mais sucintamente o meu projeto.
Estou tentar criar um modulo de monitorização de estado de alguns equipamentos auxiliares de produção, por exemplo bombas de agua, nivel de deposito, estado de variadores de frequencia. Sendo estes indicativos por sinais digitais.
Também apliquei sonda de temperatura para monitorizar a temperatura, fazendo ligar um ventilador, e se necessario uma bomba aspressora de agua no ventilador.
Já peguei no codigo de aquisição de temperatura na porta analógica, no canal A0, minha intenção é usar mais canais analógicos.
Utilizo a PORTB para o LCD, e a PORTD para a entrada dos meus sinais digitais.
De momento o meu problema está na indicação do texto no display, quando ativo as entradas D1; ou D2; ou D3, não aparece o texto que pretendo, ou aparece parte do texto ou aparece outro texto que não aquele que devia.
Não entendo a razão dessa anomalia, pois quando acionada outras entradas o texto é o correto.
Utilizo a port E para os botões para ajustar o set de temperatura que guardo na eeprom, ainda está em desenvolvimento.
sbit LCD_RS at RB0_bit;
sbit LCD_EN at RB1_bit;
sbit LCD_D4 at RB2_bit;
sbit LCD_D5 at RB3_bit;
sbit LCD_D6 at RB4_bit;
sbit LCD_D7 at RB5_bit;
sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB4_bit;
sbit LCD_D7_Direction at TRISB5_bit;
int fg;
int num=5;
const char character[] = {0,14,10,14,0,0,0,0,0,0,0};
void graus(char pos_row, char pos_char) {
char i;
Lcd_Cmd(64);
for (i = 0; i<=10; i++) Lcd_Chr_CP(character[i]);
Lcd_Cmd(_LCD_RETURN_HOME);
Lcd_Chr(pos_row, pos_char, 0);
}
void rearm(int fg)
{
while(PORTC!=0b00000001)
{
if (PORTE==0b001)
{
PORTC=0b00000001;
}
}
return;
}
void printLCDtemp(char linha,char coluna, unsigned int valortemp)
{
char txt_temp[6];
txt_temp[0] = (valortemp/1000) + 48;
txt_temp[1] = (valortemp/100)%10 + 48;
txt_temp[2] = (valortemp/10)%10 + 48;
txt_temp[3] = (valortemp%10) + 48;
Lcd_Chr(linha,coluna,txt_temp[0]);
Lcd_Chr(linha,coluna+1,txt_temp[1]);
Lcd_Chr(linha,coluna+2,txt_temp[2]);
graus(linha,coluna+3);
Lcd_Chr_CP('C');
delay_ms(200);
}
void adquir()
{
unsigned int valorAD1 = ADC_Get_Sample(0);
Lcd_Out(1,4,"Company");
Lcd_Out(2,2,"Central Monitor");
Lcd_Out(4,1,"Temp:");
valorAD1 = valorAD1 * 4.887;
printLCDtemp(4,6,valorAD1);
}
void teste_alarm()
{
Lcd_Cmd(_LCD_CLEAR);
fg=0;
while(PORTD!=0)
{
PORTB.f6=0;
if (PORTD.f0==1)
{
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,4,"ALARME");
Lcd_Out(2,2,"DEPOSITO VAZIO");
delay_ms(1000);
}
if (PORTD.f1==1)
{
Lcd_Cmd(_LCD_CLEAR);
PORTC.f1=0;
Lcd_Out(1,4,"ALARME");
Lcd_Out(2,5,"pouco A");
delay_ms(1000);
}
if (PORTD.f2==1)
{
Lcd_Cmd(_LCD_CLEAR);
PORTC.f1=0;
Lcd_Out(1,4,"ALARME");
Lcd_Out(2,5,"pouco B");
delay_ms(1000);
}
if (PORTD.f3==1)
{
Lcd_Cmd(_LCD_CLEAR);
PORTC.f1=0;
Lcd_Out(1,4,"ALARME");
Lcd_Out(2,5,"pouco C");
delay_ms(1000);
}
if (PORTD.f4==1)
{
fg=1;
Lcd_Cmd(_LCD_CLEAR);
//delay_ms(150);
Lcd_Out(1,4,"ALARME");
Lcd_Out(2,2,"CENTRAL HIDRAUL");
delay_ms(1000);
}
if (PORTD.f5==1)
{
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,4,"ALARME");
Lcd_Out(2,5,"BOMBA FAB1");
delay_ms(1000);
}
if (PORTD.f6==1)
{
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,4,"ALARME");
Lcd_Out(2,2,"BOMBA FAB2 E9");
delay_ms(1000);
}
if (PORTD.f7==1)
{
Lcd_Cmd(_LCD_CLEAR);
PORTC.f0=0;
Lcd_Out(1,4,"ALARME");
Lcd_Out(2,5,"TORRE 3");
delay_ms(1000);
}
//rearm(fg);
}
PORTB.f6=1;
return;
}
void menu()
{
int y, x=0;
char text[10];
Lcd_Cmd(_LCD_CLEAR);
num=EEPROM_Read(0);
while(x==0)
{
if (PORTE==0x02)
{
delay_ms(100);
num=num++;
}
if (PORTE==0x04)
{
delay_ms(100);
num=num--;
}
IntToStr(num,text);
Lcd_Out(1,7,text);
Lcd_Out(1,1,"SET TEMP:");
delay_ms(100);
if (PORTE==0x01)
{
x==1;
EEPROM_Write(0,num);
Lcd_Cmd(_LCD_CLEAR);
return;
}
}
}
void comand()
{
num=EEPROM_Read(0);
}
void main()
{
Lcd_Init();
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_CLEAR);
ADCON0 = 0b10100001;
ADCON1 = 0b11001110;
TRISA5_bit = 1;
TRISB6_bit=0;
TRISB7_bit=0;
TRISC =0x00;
TRISE0_bit=1;
TRISD=0xff;
PORTD=0x00;
PORTB.f6=0;
while(1)
{//inicio LOOP
teste_alarm();
adquir();
if (PORTE==0x01)
{
menu();
}
comand();
}//Final LOOP
}
Obrigado pela atenção.
Cumprimentos,
JorgeTuga