Home > other >  LCD1602 LCD display real time clock returned data errors
LCD1602 LCD display real time clock returned data errors

Time:09-20

Digital tube display the real time clock data is normal, but in 1602 shows that only when the second place, according to data error,

Clock function:
#include

#include

# include "menukey. H"

# include "yanshi. H"

# include "led. H"

# include "LCD. H"

H # include "clock."


Sbit ce=P2 ^ 5;

Sbit SCLK=P2 ^ 3;

Sbit IO=P2 ^ 4;

Sbit we=P2 ^ 7;


Void the write (unsigned char dz, unsigned char sj)

{

Unsigned char I;

Ce=0;

SCLK=0;

Ce=1;

for(i=0; i<8; I++)

{

SCLK=0;

IO=dz& 0 x01;

SCLK=1;

Dz>=1;

}

for(i=0; i<8; I++)

{

SCLK=0;

IO=sj& 0 x01;

SCLK=1;

Sj>=1;

}

}

Char read (unsigned char dz)

{

Unsigned char I, sj.

Ce=0;

SCLK=0;

Ce=1;

for(i=0; i<8; I++)

{

SCLK=0;

IO=dz& 0 x01;

SCLK=1;

Dz>=1;

}

for(i=0; i<8; I++)

{

SCLK=0;

Sj>=1;

If (IO) sj |=0 x80;

SCLK=1;

}

Return sj.

}

Unsigned char BCDZ unsigned char (dat)

{

Unsigned char dat1, dat2;

Dat1=dat/16;

Dat2=16 dat %;

Dat2=dat2 + dat1 * 10;

Return dat2;

}

Unsigned char ZBCD unsigned char (dat)

{

Unsigned char dat1, dat2;

Dat1=dat/10;

Dat2=dat % 10;

Dat2=dat2 + dat1 * 16;

Return dat2;

}

Void clock ()

{

Unsigned char I;

The static char x, y, z;

Unsigned char a1, a2, b1, b2, c1 and c2.

Write (0 x8e, 0);

Write (0 x80, ZBCD (12));

Write (0 x82, ZBCD (00));

Write (0 x84, ZBCD (00));

Write (0 x8e, 0 x80);

While (1)

{

Write (0 x8e, 0);

X=BCDZ (read x81 (0));

Y=BCDZ (read (0 x83));

Z=BCDZ (read (0 x85));

Write (0 x8e, 0 x80);

C1=x/10;

C2=x % 10;

B1=y/10;

B2=y % 10;

A1=z/10;

A2=z % 10;

for(i=0; i<50; i++);

LCD (c1 and c2, a1, a2, b1, b2);

}

}

Function: 1602
#include
# include "menukey. H"
# include "yanshi. H"
# include "LCD. H"
Sbit rs=P3 ^ 5;
Sbit rw=P3 ^ 6;
Sbit en=P3 ^ 4;
Sbit we=P2 ^ 7;
Void busy ()
{
Unsigned char Busy;
P0=0 XFF;
Rs=0;
Rw=1;
Do
{
En=1;
Busy=P0;
En=0;
} while (Busy& 0 x80);
}
Void write_zl (unsigned zl)
{
Busy ();
Rs=0;
Rw=0;
P0=zl;
En=1;
En=0;
}
Void write_sj (unsigned sj)
{
Busy ();
Rs=1;
Rw=0;
P0=sj;
En=1;
En=0;
}
Void LCD (unsigned char unsigned char a1, a2, b1, unsigned char unsigned char b2, unsigned char c1, unsigned char c2)
{
//unsigned char a [9]=,2,3,4,5,6,7,8,9 {1};
Unsigned char I;
We=1;
P0=0 XFF;
We=0;
While (1)
{
We=1;
P0=0 XFF;
We=0;
X38 write_zl (0);
X0c write_zl (0);
Write_zl (0 x01);
Write_zl x06 (0);
Write_zl (0 x80 | 0 x00);
Write_sj (116);
Write_sj (105);
Write_sj (109);
Write_sj (101);
Write_sj (58);
Write_sj (a1 + '0');
Write_sj (a2 + '0');
Delay (3000);
i++;
If (I==10)
i=0;
}
Write_zl (0 x01);
}
  • Related