44780 16x2 character LCD screen drive demo program bus mode

44780 16x2 character LCD screen drive demo program bus mode
Connection diagram: LCM ------- 51 LCM ------- 51 LCM -------- 51
DB0 ----- P0.0 DB4 ----- P0.4 RW ------- P2.0
DB1 ----- P0.1 DB5 ----- P0.5 RC ------- P2.1
DB2 ----- P0.2 DB6 ----- P0.6 E -------- P2.7 => 74ls00 + wr + rd
DB3 ----- P0.3 DB7 ----- P0.7 VLCD connect 1K2 resistor to GND

[Note]: The crystal frequency of AT89C51 is 12MHz
// # pragma src // Generate assembly file
#include
#include

Macro definition of variable type identification
#define Uchar unsigned char
#define Uint unsigned int

LCM1602A port address definition

char xdata Lcd1602CmdPort _at_ 0x7cff; // E = 1 RS = 0 RW = 0
char xdata Lcd1602WdataPort _at_ 0x7eff; // E = 1 RS = 1 RW = 0
char xdata Lcd1602StatusPort _at_ 0x7dff; // CS = 1 RS = 0 RW = 1

#define Busy 0x80 // Busy discrimination bit


code char exampl [] = "For an example.-By xiaoqi";

void Delay400Ms (void);
void Delay5Ms (void);
void LcdWriteData (char dataW);
void LcdWriteCommand (Uchar CMD, Uchar AttribC);
void LcdReset (void);
void Display (Uchar dd);
void DispOneChar (Uchar x, Uchar y, Uchar Wdata);
void ePutstr (Uchar x, Uchar y, Uchar code * ptr);

Test the main program

void main (void)
{
Uchar temp;

Delay400Ms (); // Delay necessary at startup, waiting for lcm to enter working state

LcdReset (); // This is also required ... Initialize temp = 32;
ePutstr (0,0, exampl); // The upper line displays a predetermined string

Delay400Ms (); // Keep display content Delay400Ms ();
Delay400Ms ();
Delay400Ms ();
Delay400Ms ();
Delay400Ms ();
Delay400Ms ();
Delay400Ms ();

while (1)
{
temp & = 0x7f; // Only display ASCII characters

if (temp <32) temp = 32; // mask control characters, not display Display (temp ++);

Delay400Ms ();
}
}
Display string
void ePutstr (Uchar x, Uchar y, Uchar code * ptr) {
Uchar i, l = 0;
while (ptr [l]> 31) {l ++;};
for (i = 0; i DispOneChar (x ++, y, ptr [i]);
if (x == 16) {
x = 0; y ^ = 1;
}
}
}

Demonstrate a line of continuous character strings, demonstrate mobile character strings with the upper program
void Display (Uchar dd) {

Uchar i;

for (i = 0; i <16; i ++) {

DispOneChar (i, 1, dd ++);

dd & = 0x7f;
if (dd <32) dd = 32;
}
}

Show cursor positioning
void LocateXY (char posx, char posy) {

Uchar temp;

temp = posx & 0xf;
posy & = 0x1;
if (posy) temp | = 0x40;
temp | = 0x80;
LcdWriteCommand (temp, 0);
}

Display a character at the specified position
void DispOneChar (Uchar x, Uchar y, Uchar Wdata) {

LocateXY (x, y); // Positioning display address LcdWriteData (Wdata); // Write character
}
The initialization procedure must be carried out in accordance with the initialization process described in the product information
void LcdReset (void) {

LcdWriteCommand (0x38, 0); // Display mode setting (do not detect busy signal)
Delay5Ms ();
LcdWriteCommand (0x38, 0); // Delay5Ms () three times in total;
LcdWriteCommand (0x38, 0);
Delay5Ms ();

LcdWriteCommand (0x38, 1); // Display mode setting (detect busy signal in the future)
LcdWriteCommand (0x08, 1); // Display off LcdWriteCommand (0x01, 1); // Display clear screen LcdWriteCommand (0x06, 1); // Display cursor movement setting LcdWriteCommand (0x0c, 1); // Display on and cursor setting
}


Write control character subroutine: E = 1 RS = 0 RW = 0
void LcdWriteCommand (Uchar CMD, Uchar AttribC) {

if (AttribC) while (Lcd1602StatusPort & Busy); // Detect busy signal?
Lcd1602CmdPort = CMD;
}

Write character subroutine at current position: E = 1 RS = 1 RW = 0
void LcdWriteData (char dataW) {

while (Lcd1602StatusPort & Busy); // Detect busy signal Lcd1602WdataPort = dataW;
}

// short delay
void Delay5Ms (void)
{
Uint i = 5552;
while (i--);
}

// Long delay
void Delay400Ms (void)
{
Uchar i = 5;
Uint j;
while (i--)
{
j = 7269;
while (j--);
};
}

Electronic motors specilized for zebra blinds.

Zebra Blinds Motor

Zebra Blinds Motor,Multiple Limits Zebra Blind Motor,Radio Receiver Zebra Blind Motor,Zigbee Tubular Zebra Blind Motor

GUANGDONG A-OK TECHNOLOGY GRAND DEVELOPMENT CO.,LTD. , https://www.a-okmotor.com