Hands-on teaching of 51 single chip microcomputer | 1602 LCD

Publisher:HarmoniousVibesLatest update time:2022-04-18 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

For components like this that contain chips, the most important thing is to learn how to understand the pin functions of the chip, rather than to memorize the statements of the chip. The same components from different manufacturers have slight differences, so when purchasing such things, ask the manufacturer for a chip manual and design the program or circuit according to the manual.


1602 LCD

1602: 16 means that 16 characters can be displayed in one line, and 02 means there are two lines in total

Only numbers and characters can be displayed


Write data timing diagram

insert image description here
insert image description here

RS low level selects data, high level selects instruction

RW High level means read, low level means write

E is the enable signal, which sends high and low pulses


According to the timing diagram, write the instruction (data) first, delay, and give the pulse


Write command (data)

First select the write instruction, then assign the value to port P0, and then write the program according to the instructions of the timing diagram. Writing data is the same, so I won't go into details.


void write_com(uchar com) //

{

lcdrs=0; // set write com

P0=com; // give value data

delay(5);

lcden=1;// Âö³å

delay(5);

lcden=0;

}


Initialization Procedure

insert image description here
insert image description here
insert image description here

What is displayed here is the RAM address of each bit of the matrix, only 00-0F, 40-4F are displayed. Although there are addresses on the right side of these two rows, they are not displayed. They can be used to shift the full screen to the left to achieve a dynamic effect.


void init()

{

dula=0; //Because the digital tube will divide the voltage, turn it off to prevent insufficient voltage

wela=0;

lcden=0;

write_com(0x38); //Initialize 5*7 matrix

//0000 1DCB D displays C cursor B flashes 

write_com(0x0f);

//0000 01NS  

write_com(0x06); //The cursor moves, but the data does not move

write_com(0x80); //Initialize pointer position, 80H is the first position

}


Character Manual

We can write data using matrices, according to the following table

insert image description here

If you want to write directly, separate them with '

write_data('A');


If you want to write a string of characters

Just use the matrix


uchar code table[]=" I Love U";


But here the matrix is ​​no longer surrounded by {} curly braces, but double quotes.


move

insert image description here

According to the chip manual, assigning P0 = 0x18 means moving left once, and the cursor will also move left.


other settings

insert image description here

0x01 is to clear the screen 0x02 is to enter


Code Sample

Does not include movement, includes clearing the screen, and code examples on a new page


#include

#define uchar unsigned char

#define uint unsigned int 


sbit lcden=P3^4;

sbit lcdrs=P3^5;

sbit dula=P2^6;

sbit wela=P2^7;

uchar code table[]=" I Love U";

uchar code table1[]=" FOREVER";

uchar code table2[]="Just a joking";


void delay(uint z)

{

uint x,y;

for(x=z;x>0;x--)

for(y=110;y>0;y--);

}

void write_com(uchar com) //write instruction

{

lcdrs=0; // set writing com

P0=com; // input value data

delay(5);

lcden=1; // give pulse

delay(5);

lcden=0;

}


void write_data(uchar date) //write data

{

lcdrs=1; //Select data

P0=date; 

delay(5);

lcden=1;

delay(5);

lcden=0;

}

void init()

{

dula=0;

wela=0;

lcden=0;

write_com(0x38);

write_com(0x0f);

write_com(0x06);

write_com(0x80);

}


void main()

{

uint time;

init();

for(time=0;time<12;time++)

{

write_data(table[time]);

delay(300);

}

write_com(0x80+0x40);

for(time=0;time<11;time++)

{

write_data(table1[time]);

delay(300);

}

delay(300);

write_com(1);

delay(300);

delay(300);

delay(300);

write_com(0x80+0x00);

for(time=0;time<13;time++)

{

write_data(table2[time]);

delay(300);

}

while(1);

}


Full screen mobile code

#include

#define uchar unsigned char

#define uint unsigned int 


sbit lcden=P3^4;

sbit lcdrs=P3^5;

sbit dula=P2^6;

sbit wela=P2^7;

uchar code table[]="I Love U";

uchar code table1[]="FOREVER";

uchar code table2[]="Just a joking";


void delay(uint z)

{

uint x,y;

for(x=z;x>0;x--)

for(y=110;y>0;y--);

}

void write_com(uchar com) //дÃüÁî

{

lcdrs=0; // set write com

P0=com; // give value data

delay(5);

lcden=1;// Âö³å

delay(5);

lcden=0;

}


void write_data(uchar date) //

{

lcdrs=1; // set write com

P0=date; // give value data

delay(5);

lcden=1;// Âö³å

delay(5);

lcden=0;

}

void init()

{

dula=0;

wela=0;

lcden=0;

write_com(0x38);

write_com(0x0f);

write_com(0x06);

write_com(0x80+0x10);


void main()

{

uint time;

init();

for(time=0;time<8;time++)

{

write_data(table[time]);

delay(20);

}


write_com(0x80+0x50);//»»ÐÐ


for(time=0;time<7;time++)

{

write_data(table1[time]);

delay(20);

}



for(time=0;time<16;time++)

{

write_com(0x18);

delay(200);

}

while(1);

}

Reference address:Hands-on teaching of 51 single chip microcomputer | 1602 LCD

Previous article:Step-by-step teaching of 51 MCU Lesson 7 | AT24C02 I²C bus data transmission
Next article:Hands-on teaching of 51 single-chip microcomputer | Section 4 Dynamic digital tube, use 6-bit digital tube to make a clock

Recommended posts

Millimeter wave radar IWR1443
IhaveanES3.0versionofIWR1443radarboard.TItechnicianssaidthatitcanonlybeusedforvitalsignexperiments.Iwanttodoagesturerecognitionexperiment,whichcanonlybedonewiththeES2.0version.HowcanIbuyanES2.0version
ifif RF/Wirelessly
In a battery-powered microcontroller product, when a pin is used for falling edge interrupt, how should this pin be set to achieve the most energy-efficient
Inabattery-poweredSTM32microcontrollerproduct,whenapinisusedforfallingedgeinterrupt,howshouldthispinbesettoachievethemostenergy-efficient Readthemanualandapplicationnotes TheinterruptisusedtoindicatethattheS
一沙一世 stm32/stm8
[Digi-Key Follow Me Issue 1] + Task 1: Familiarize yourself with the basic syntax of MicroPython
RaspberryPiPicoWisanewproductlaunchedbytheRaspberryPiFoundationin2022.Itaddsacertified2.4GHz802.11nwirelessmoduletotheRaspberryPiPico,makingitanidealsolutionforprojectsrequiringwirelesscommunication. Featur
ID.LODA DigiKey Technology Zone
[Renesas RA8D1 development board, graphics MCU based on M85 core] USB development environment construction takes CDC as an example
Preface ThisvideosharestheconstructionofUSBdevelopmentenvironment,takingCDCasanexample. Createaproject Opene2studio Menubarclick File-New-RenesasC/C++Project-RenesasRA SelectC/C++-RenesasRAC/C++Project
qinyunti Renesas Electronics MCUs
How to ensure that DA has no output when downloading the program
Projectrequirements:DAhasnooutputwhendownloadingtheprogram,howtoensurethis?WhatshouldIconsider?
sudongpo2018 Motor Drive Control(Motor Control)
Looking for a book host computer to develop a pass
Lookingforabookhostcomputertodevelopapass Isthereabookcover?Ithinktherearemanyhostcomputerlanguages,soitismoreappropriatetochooseagoodone. Iguessit'snotpossibletopassitthroughthisbook. Youcantakea
spwongks Download Centre
Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号