16: LCD1602 display

Publisher:心连心意Latest update time:2019-08-13 Source: eefocusKeywords:LCD1602 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

#How to do it




**Schematic**

Code


******************************************************************

* 【Course 17】 ****LCD1602 Experiment***********

* 【illustrate】 ****

* 【Description】 ****Display characters on LCD1602

******************************************************************  

---------------------------------------------------------


Basic operations:

Read status: RS=0,RW=1,EN=1

Output: D0~D7=status word;

Write instruction: RS=0, RW=0, EN=falling edge pulse

D0~D7=instruction code;

Read data: RS=1, RW=1, EN=1

Output: D0~D7=data;

Write data: RS=1, RW=1, EN=falling edge pulse

D0~D7=data;

*********************************************************/


#include //51 header file,


//---------Two commonly used macro definitions-------------- 

#define uint8 unsigned char

#define uint16  unsigned int

//--------1602 control pin definition-------------

sbit RS = P2^5;

sbit RW = P2^6;

sbit EN = P2^7;


//----------Displayed data------------

uint8 Data1[7]="welcom!";

uint8 Data2[13]="www.yxarm.net";


//-----------Function declaration------------------

void DelayMS(uint16 dly);


//----------Declaration of LCD module---------------

bit BUSY(void);

void Write_cmd(uint8 cmd);

void Write_dat(uint8 dat);

void LCD_Init(void);


//---------Main Task---------------------

void main(void)

{

uint8 i;

LCD_Init();

while(1)

{

Write_cmd(0x85); //First line

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

Write_dat(Data1[i]);

Write_cmd(0xc2); //The second line

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

Write_dat(Data2[i]);

}

}


/********************************************************

** Name: void DelayMS(uint16 dly)

** Function: millisecond delay (12M crystal oscillator)

** Entry parameter: dly user's delay parameter   

** Export parameters: None   

*********************************************************/

void DelayMS(uint16 dly)

{

uint16 x,y;

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

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

}

/********************************************************

** Name: bit BUSY(void)

** Function: Check whether LCD1602 is in busy state;

** Input parameters: None   

** Export parameter: bit Bit

Returns 1, then BUSY

Return 0, then OK   

*********************************************************/

bit BUSY(void)

{

bit Bit;

RS = 0;

RW = 1;

EN = 1;

DelayMS(1);

Bit = (bit)(P0 & 0x80); //The highest bit is the busy signal bit

EN = 0;

return Bit;

}


/********************************************************

** Name: void Write_cmd(uint8 cmd)

** Function: Write command

** Input parameter: cmd control command   

** Export parameters: None   

*********************************************************/

void Write_cmd(uint8 cmd)

{

while(BUSY()); //测忙

RS = 0;

RW = 0;

EN = 0;

P0 = cmd;

EN = 1;

DelayMS(1);

EN = 0;

}


/********************************************************

** Required: void Write_dat(uint8 dat)

** Function: write data

** Input parameter: dat data to be displayed  

** Export parameters: None   

*********************************************************/

void Write_dat(uint8 dat)

{

while(BUSY()); //测忙

RS = 1;

RW = 0;

EN = 0;

P0 = that;

EN = 1;

DelayMS(1);

EN = 0;

}

/********************************************************

** Name: void LCD_Init(void)

** Function: LCD initialization

** Input parameters: None 

** Export parameters: None   

*********************************************************/

void LCD_Init(void)

{

Write_cmd(0x38); //Function setting

DelayMS(1);

Write_cmd(0x0c); //Display switch control

DelayMS(1);

Write_cmd(0x06); //Input mode setting

DelayMS(1);

Write_cmd(0x01); //Clear the LCD display content

DelayMS(1);

}



Keywords:LCD1602 Reference address:16: LCD1602 display

Previous article:15: Lighting up the LED matrix
Next article:107: Operation of DS1302

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号