1602 liquid crystal display experiment

Experimental example using 1602 liquid crystal display

This article refers to the address: http://

SMC1602A (16*2) analog port wiring connection cable diagram:

|LCM-----51 | LCM-----51 | LCM------51 |
|
|DB0-----P1.0 | DB4-----P1.4 | RW-------P2.0 |
|DB1-----P1.1 | DB5-----P1.5 | RS-------P2.1 |
|DB2-----P1.2 | DB6-----P1.6 | E--------P2.2 |
|DB3-----P1.3 | DB7-----P1.7 | VLCD connected to 1K resistor to GND|


//Read status
Unsigned char ReadStatusLCM(void)
{
LCM_Data = 0xFF;
LCM_RS = 0;
LCM_RW = 1;
LCM_E = 0;
LCM_E = 0;
LCM_E = 1;
While (LCM_Data & Busy); //Detect busy signal
Return(LCM_Data);
}

Void LCMInit(void) //LCM initialization
{
LCM_Data = 0;
WriteCommandLCM (0x38, 0); / / three display mode settings, do not detect busy signals
Delay5Ms();
WriteCommandLCM(0x38,0);
Delay5Ms();
WriteCommandLCM(0x38,0);
Delay5Ms();

WriteCommandLCM (0x38, 1); / / display mode settings, start requiring each time to detect busy signals
WriteCommandLCM (0x08, 1); / / close the display
WriteCommandLCM (0x01, 1); / / display clear screen
WriteCommandLCM(0x06,1); // Display cursor movement settings
WriteCommandLCM(0x0C,1); // Display on and cursor settings
}

/ / Display a character by the specified position
Void DisplayOneChar(unsigned char X, unsigned char Y, unsigned char DData)
{
Y &= 0x1;
X &= 0xF; //Restrict X cannot be greater than 15, Y cannot be greater than 1
If (Y) X |= 0x40; //When the second line is to be displayed, the address code is +0x40;
X |= 0x80; //calculate the instruction code
WriteCommandLCM (X, 0); / / here does not detect the busy signal, send the address code
WriteDataLCM(DData);
}

/ / Display a string of characters by the specified position
Void DisplayListChar(unsigned char X, unsigned char Y, unsigned char code *DData)
{
Unsigned char ListLength;

ListLength = 0;
Y &= 0x1;
X &= 0xF; //Restrict X cannot be greater than 15, Y cannot be greater than 1
While (DData[ListLength]>0x20) // quit if the end of the string is reached
{
If (X <= 0xF) //X coordinate should be less than 0xF
{
DisplayOneChar(X, Y, DData[ListLength]); //Show a single character
ListLength++;
X++;
}
}
}

//5ms delay
Void Delay5Ms(void)
{
Unsigned int TempCyc = 5552;
While(TempCyc--);
}

//400ms delay
Void Delay400Ms(void)
{
Unsigned char TempCycA = 5;
Unsigned int TempCycB;
While(TempCycA--)
{
TempCycB=7269;
While(TempCycB--);
};
}

[Note: AT89S51 uses 12M crystal oscillator]

#define LCM_RW P2_0 //Define the pin
#define LCM_RS P2_1
#define LCM_E P2_2
#define LCM_Data P1
#define Busy 0x80 //Used to detect the Busy flag in the LCM status word

#include

Void WriteDataLCM(unsigned char WDLCM);
Void WriteCommandLCM(unsigned char WCLCM,BuysC);
Unsigned char ReadDataLCM(void);
Unsigned char ReadStatusLCM(void);
Void LCMInit(void);
Void DisplayOneChar(unsigned char X, unsigned char Y, unsigned char DData);
Void DisplayListChar(unsigned char X, unsigned char Y, unsigned char code *DData);
Void Delay5Ms(void);
Void Delay400Ms(void);

Unsigned char code cdle_net[] = {""};
Unsigned char code email[] = {""};

Void main(void)
{
Delay400Ms(); //Start waiting, wait for LCM to talk to working status
LCMInit(); //LCM initialization
Delay5Ms(); //Time delay (may not)

DisplayListChar(0, 0, cdle_net);
DisplayListChar(0, 1, email);
ReadDataLCM (); / / test sentence meaningless
While(1);
}

/ / Write data
Void WriteDataLCM(unsigned char WDLCM)
{
ReadStatusLCM(); //Detect busy
LCM_Data = WDLCM;
LCM_RS = 1;
LCM_RW = 0;
LCM_E = 0; //If the crystal oscillator speed is too high, you can add a small delay after this.
LCM_E = 0; //delay
LCM_E = 1;
}

/ / write instructions
Void WriteCommandLCM(unsigned char WCLCM,BuysC) //Buy busy detection when BuysC is 0
{
If (BuysC) ReadStatusLCM (); / / detect busy as needed
LCM_Data = WCLCM;
LCM_RS = 0;
LCM_RW = 0;
LCM_E = 0;
LCM_E = 0;
LCM_E = 1;
}

/ / Read the data
Unsigned char ReadDataLCM(void)
{
LCM_RS = 1;
LCM_RW = 1;
LCM_E = 0;
LCM_E = 0;
LCM_E = 1;
Return(LCM_Data);
}

VECSEL Module

Vecsel Module,Laser Module Violet,10 Watt Laser Module,Laser Module Fritzing

AcePhotonics Co.,Ltd. , https://www.cgphotonics.com