ReyDemonio
Newbie level 3
Hello, I'm trying to use a LCD Display (LM016L) with Hitachi processor, controlling it with an AT89C5131 and a 4 bits interface, but I'm only getting black rectangles and nothing else in the real kit and nothing at all in the protheus simulation.
Could anyone help me with the code please? Thanks
Could anyone help me with the code please? Thanks
Code:
#include<at89c5131.h>
sbit EN = P3^6;
sbit RS = P3^4;
sbit RW = P3^5;
unsigned char dato = 0;
unsigned char code tex1[16] = {' ','L','C','D',' ','d','e',' ','2',' ','f','i','l','a','s',' '};
unsigned char i = 0, j = 0, k = 0, z = 0;
bit BU = 0;
void ini();
void trans (unsigned char i);
void wait (unsigned char z);
void main (void)
{
ini();
for(;;)
{
dato = 0x80;
trans(0);
for(k=0;k<17;k++)
{
dato = tex1[k];
trans(1);
}
}
}
void ini()
{
wait(0);
dato = 0x30;
BU = 0; //Normal delay
trans(0); //Function set 1 + wait
trans(0); //Function set 2 + wait
trans(0); //Functino set 3 + wait
BU = 1; //Wait for BF flag
dato = 0x20;
trans(0);
BU = 1;
dato = 0x80;
trans(0);
BU = 1;
dato = 0x01;
trans(0);
BU = 1;
dato = 0x06;
trans(0);
BU = 1;
dato = 0x14;
trans(0);
BU = 1;
dato = 0x02;
trans(0);
BU = 1;
dato = 0x0C;
trans(0);
}
void trans (unsigned char i)
{
if (i == 0)
{
RS = 0;
}
else
{
RS = 1;
}
RW = 0;
P2 = dato;
EN = 1;
while (EN == 0);
EN = 0;
dato = dato << 4;
P2 = dato;
EN = 1;
while (EN == 0);
EN = 0;
wait(BU);
}
void wait (unsigned char z)
{
if (z == 0)
{
for(i=0;i<255;i++)
{
for(j=0;j<80;j++);
}
}
else
{
P2 = 0xFF;
RS = 0;
RW = 1;
EN = 1;
while (P2_7 == 1); //Wait for BF to fall
EN = 0;
RW = 0;
P2 = 0x00;
}
}