Experimental example using 1602 LCD

Experimental example using 1602 LCD

SMC1602A (16 * 2) analog port wiring wiring connection 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 | Connect VLCD with 1K resistor to GND |

[Note: AT89S51 uses 12M crystal]

#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 logo 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 speak into working state
LCMInit (); // LCM initialization
Delay5Ms (); // Delay for a moment (not necessary)

DisplayListChar (0, 0, cdle_net);
DisplayListChar (0, 1, email);
ReadDataLCM (); // The test sentence is meaningless
while (1);
}

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

// write instruction
void WriteCommandLCM (unsigned char WCLCM, BuysC) // BuyC ignores busy detection when it is 0
{
if (BuysC) ReadStatusLCM (); // Check busy as needed
LCM_Data = WCLCM;
LCM_RS = 0;
LCM_RW = 0;
LCM_E = 0;
LCM_E = 0;
LCM_E = 1;
}

// Read data
unsigned char ReadDataLCM (void)
{
LCM_RS = 1;
LCM_RW = 1;
LCM_E = 0;
LCM_E = 0;
LCM_E = 1;
return (LCM_Data);
}

// 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 times display mode setting, do not detect busy signal
Delay5Ms ();
WriteCommandLCM (0x38,0);
Delay5Ms ();
WriteCommandLCM (0x38,0);
Delay5Ms ();

WriteCommandLCM (0x38,1); // Display mode setting, start to request to detect busy signal every time
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 setting
}

// Display a character at the specified position
void DisplayOneChar (unsigned char X, unsigned char Y, unsigned char DData)
{
Y & = 0x1;
X & = 0xF; // Limit X cannot be greater than 15, Y cannot be greater than 1
if (Y) X | = 0x40; // Address code + 0x40 when the second line is to be displayed;
X | = 0x80; // Calculate the instruction code
WriteCommandLCM (X, 0); // Do not detect busy signal here, send address code
WriteDataLCM (DData);
}

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

ListLength = 0;
Y & = 0x1;
X & = 0xF; // Limit X cannot be greater than 15, Y cannot be greater than 1
while (DData [ListLength]> 0x20) // Exit if the end of the string is reached
{
if (X <= 0xF) // X coordinate should be less than 0xF
{
DisplayOneChar (X, Y, DData [ListLength]); // Display 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--);
};
}

Desktop Air Purifier For Bedroom

Desktop Air Purifier For Bedroom,Small Desktop Air Purifier,Intellgent Desktop Air Purifier,Desktop Air Purifier For Dust

Ningbo Zhe Kai Electric Appliance Co.,Ltd , https://www.cnairpurifiers.com