Hago un programa para leer datos de EEPROM en el microcontrolador PIC16F887 Pic. Cuando almaceno estos datos en variables, esas se muestran en la pantalla LCD en una mezcla.
Este es mi código:
// LCD module connections
sbit LCD_RS at RD0_bit;
sbit LCD_EN at RD1_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;
sbit LCD_RS_Direction at TRISD0_bit;
sbit LCD_EN_Direction at TRISD1_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
// End LCD module connections
char txt1[] = "Welcome !";
int i=0;
unsigned short a;
char txt[4];
unsigned counter=0;
char count[7];
char shed[5];
char shedfn[10];
unsigned short int shedno;
unsigned short valuw1;
unsigned valuw3;
char valuw2[6];
unsigned int valreg=0;
unsigned int stv=0;
unsigned int lsv=0;
unsigned int valuc = 0;
unsigned char rel1[6],rel2[6],rel3[6],rel4[6],rel5[6],rel6[6];
unsigned char ntrel1[5],ntrel2[5],ntrel3[5],ntrel4[5],ntrel5[5],ntrel6[5];
void dis(){ /// Y - POINT
Lcd_Out(1,1,"Shd:");
Lcd_Out(2,1,"Temp: ");
Lcd_Out(3,1,"Count: ");
Lcd_Out(4,1,"Steps: ");
Lcd_Out(1,6,shedfn);
WordToStr(counter, count);
Lcd_Out(3,7,count);
Delay_ms(100);
}
void nextshed(int nshno){
IntToStr(nshno, ntrel1);
strcpy(ntrel2, ntrel1);
}
void main(){
ANSEL = 0;
ANSELH = 0;
C1ON_bit = 0;
C2ON_bit = 0;
TRISC = 0b00000000;
TRISB = 0b11111111;
PORTC = 0b00000000;
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1,6,txt1);
Delay_ms(2000);
Lcd_Cmd(_LCD_CLEAR);
shedno = EEPROM_Read(0x00);
shedno = 256 - shedno;
delay_ms(50);
valreg = shedno;
WordToStr(shedno, shed);
strcpy(shedfn, "S");
strcat(shedfn, shed);
stv = 6*valreg + 4;
lsv = stv + 6;
for(stv; stv<lsv; stv++){
valuw1 = EEPROM_Read(stv); //decimal value auto convert to hex ex. 20 value = 14 hex
delay_ms(50);
valuw3 = valuw1+200; //start time 200
WordToStr(valuw3, valuw2);
delay_ms(50);
if( valuc == 0) {
strcpy(rel1, valuw2);
} else if (valuc == 1){
strcpy(rel2, valuw2);
}else if (valuc == 2){
strcpy(rel3, valuw2);
}else if (valuc == 3){
strcpy(rel4, valuw2);
}else if (valuc == 4){
strcpy(rel5, valuw2);
}else if (valuc == 5){
strcpy(rel6, valuw2);
}
delay_ms(100);
valuc ++;
}
Lcd_Out(4,1,rel4); //// X - POINT
Lcd_Out(1,1,rel1);
Lcd_Out(2,1,rel2);
Lcd_Out(3,1,rel3);
Delay_ms(4000);
Lcd_Cmd(_LCD_CLEAR);
while(1) {
dis(); /// Y - POINT
PORTC = 0b00000010;
Lcd_Out(2,7,"60 C");
Delay_ms(100);
if(PORTB.B7 = 1){
counter ++;
Delay_ms(200);
Lcd_Cmd(_LCD_CLEAR);
}
if(PORTB.B5 = 1){
Delay_ms(200);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,"Do You Want Reset Count?");
i = 1;
while(i){
if(PORTB.B4 = 1){
counter = 0;
i = 0;
Delay_ms(100);
}else if(PORTB.B5 = 1){
i = 0;
Delay_ms(100);
}
}
Lcd_Cmd(_LCD_CLEAR);
Delay_ms(100);
}
if(PORTB.B0 = 1){ //auto mode
if((PORTB.B3 = 1) || (PORTB.B2 = 1)){
Delay_ms(200);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,"Shd:");
Lcd_Out(1,5,shed);
Lcd_Out(2,1,"Next Shedule:(in ms)");
while(1){
nextshed(5);
Lcd_Out(3,1,ntrel2);
}
}
}else{ //manual mode
}
}
}
Teniendo en cuenta que X-Point
en la visualización de código se muestra así. El valor FISrt NO se muestra en 455.
Alcontinuar,elprogramaY-Point
encódigosemuestraasíenlapantallaLCD.Todomezcladoconvariables.
CreoqueestoesunproblemadetamañosdevariablesounproblemadebibliotecaLCD.Porqueutilicébibliotecade4bits.
Cuandoeditolasiguientelíneadevariables,
unsignedcharrel1[6],rel2[6],rel3[6],rel4[6],rel5[6],rel6[6];
A,
unsignedcharrel1,rel2,rel3,rel4,rel5,rel6;
Muestraelsiguienteerror.LapantallaLCDnomuestralosdatosdeX-Point
,peromuestralosdatosdeY-Point
alaperfección.
El error debería estar con strcpy
¿Cómo puedo resolverlo?