Estoy intentando conectar una pantalla LCD de 16x4 a una MCU PIC16F877. El proyecto es solo un reloj digital que muestra la fecha y la hora de un DS1307 RTC.
La pantalla funciona correctamente cuando uso una pantalla LCD de 16x2. Pero si trato de imprimir lo mismo, el mismo código en la 3ª y 4ª fila de la pantalla LCD de 16x4, la pantalla lo imprime en la 4ª columna en lugar de 1. He mostrado las capturas de pantalla que funcionan y las que no funcionan a continuación.
Tal vez sea por el uso de una interfaz de 4 bits en lugar de 8. O tal vez algún otro problema. ¿Puedes por favor guiarme?
Estoy usando MikroC Pro para la pantalla LCD de la biblioteca del compilador PIC. Es una biblioteca de interfaz de 4 bits.
Esquema:
1ªfila2:
3ª4ªfila:
Código:
//LCDmoduleconnectionssbitLCD_RSatRB2_bit;sbitLCD_ENatRB3_bit;sbitLCD_D4atRB4_bit;sbitLCD_D5atRB5_bit;sbitLCD_D6atRB6_bit;sbitLCD_D7atRB7_bit;sbitLCD_RS_DirectionatTRISB2_bit;sbitLCD_EN_DirectionatTRISB3_bit;sbitLCD_D4_DirectionatTRISB4_bit;sbitLCD_D5_DirectionatTRISB5_bit;sbitLCD_D6_DirectionatTRISB6_bit;sbitLCD_D7_DirectionatTRISB7_bit;//EndLCDmoduleconnectionsunsignedshortread_ds1307(unsignedshortaddress){unsignedshortr_data;I2C1_Start();I2C1_Wr(0xD0);//address0x68followedbydirectionbit(0forwrite,1forread)0x68followedby0-->0xD0I2C1_Wr(address);I2C1_Repeated_Start();I2C1_Wr(0xD1);//0x68followedby1-->0xD1r_data=I2C1_Rd(0);I2C1_Stop();return(r_data);}voidwrite_ds1307(unsignedshortaddress,unsignedshortw_data){I2C1_Start();//issueI2Cstartsignal//address0x68followedbydirectionbit(0forwrite,1forread)0x68followedby0-->0xD0I2C1_Wr(0xD0);//sendbyteviaI2C(deviceaddress+W)I2C1_Wr(address);//sendbyte(addressofDS1307location)I2C1_Wr(w_data);//senddata(datatobewritten)I2C1_Stop();//issueI2Cstopsignal}unsignedcharBCD2UpperCh(unsignedcharbcd){return((bcd>>4)+'0');}unsignedcharBCD2LowerCh(unsignedcharbcd){return((bcd&0x0F)+'0');}intBinary2BCD(inta){intt1,t2;t1=a%10;t1=t1&0x0F;a=a/10;t2=a%10;t2=0x0F&t2;t2=t2<<4;t2=0xF0&t2;t1=t1|t2;returnt1;}intBCD2Binary(inta){intr,t;t=a&0x0F;r=t;a=0xF0&a;t=a>>4;t=0x0F&t;r=t*10+r;returnr;}intsecond;intminute;inthour;inthr;intday;intdday;intmonth;intyear;intap;unsignedshortset_count=0;shortset;chartime[]="00:00:00 PM";
char date[] = "00-00-00";
void main()
{
I2C1_Init(100000); //DS1307 I2C is running at 100KHz
CMCON = 0x07; // To turn off comparators
ADCON1 = 0x06; // To turn off analog to digital converters
TRISA = 0x07;
PORTA = 0x00;
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_out(3,1,"Time:");
Lcd_out(4,1,"Date:");
do
{
second = read_ds1307(0);
minute = read_ds1307(1);
hour = read_ds1307(2);
hr = hour & 0b00111111;
ap = hour & 0b00100000;
dday = read_ds1307(3);
day = read_ds1307(4);
month = read_ds1307(5);
year = read_ds1307(6);
time[0] = BCD2UpperCh(hr);
time[1] = BCD2LowerCh(hr);
time[3] = BCD2UpperCh(minute);
time[4] = BCD2LowerCh(minute);
time[6] = BCD2UpperCh(second);
time[7] = BCD2LowerCh(second);
date[0] = BCD2UpperCh(day);
date[1] = BCD2LowerCh(day);
date[3] = BCD2UpperCh(month);
date[4] = BCD2LowerCh(month);
date[6] = BCD2UpperCh(year);
date[7] = BCD2LowerCh(year);
if(ap)
{
time[9] = 'P';
time[10] = 'M';
}
else
{
time[9] = 'A';
time[10] = 'M';
}
Lcd_out(3, 6, time);
Lcd_out(4, 6, date);
Delay_ms(100);
}while(1);
}