MCU LCD Operation

Publisher:angelbabyLatest update time:2017-01-09 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

LCD operation:

1602 LCD can only display ASCI. Today, I will drive 1602 LCD. LCD operation is simpler than digital tube.

 Basic operation sequence of LCD:
1.1 Read state: Input: RS = L, RW = H, E = H Output D0~D7

1.2 Write instruction: Input: RS = L, RW = L, D0~D7 instruction code, E = high pulse, output: none;

RS is the data command selection terminal (H/L);

1.3 Read data: input RS= H, RW=H, E=H

1.4 Write instruction: output, RS = L, RW = L, D0~D7 = data, E = high pulse

Note: Before each read and write operation on the controller, a read and write test must be performed to ensure that STA7 is 0. A simple delay can be used instead.

Initial Setup

Display Mode Settings

Instruction code: 00111000 Function 16*2 display, 5*7 dot matrix, 8 is the instruction of data interface 0x38

Display on/off cursor setting

So left and right are set by N and S

Data pointer instruction code

80H+address code (0-27H, 40H to 67H)

other settings

The function of instruction code 01H is to clear the screen: 1 data pointer cleared, 2 all displays cleared

    02H displays carriage return: 1 data pointer cleared

The circuit diagram is shown in the figure:

 Sample code: Dynamic display


#include

#include

#define uchar unsigned char

#define uint unsigned int


sbit lcden = P2^6; //These ports need to be connected to the hardware circuit first  

sbit lcdrw = P2^5;

sbit lcdrs = P2^4;


sbit dula = P3^1;

sbit wela = P3^2;

uchar num;

uchar code table[]="I LIke MCU!";

uchar code table1[]="I LIke HULeiHao";


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 command function

{

    lcdrs = 0; // Enable the terminal to 0. Low pulse writes the instruction, high pulse writes the data   

    _nop_(); // postpone one machine cycle  


    lcdrw = 0; //Low level to write data

    P0=com;


    delay(5);

    lcden = 1; // Enable the terminal to give a high level to read data

    delay(5);

    lcden = 0; // Enable the terminal to return to a low level  


}


void write_date(uchar date) // write data function

{

    lcdrs = 1; // Enable the terminal to 0. Low pulse writes the instruction, high pulse writes the data

    _nop_(); // postpone one machine cycle


    lcdrw = 0;

    P0= date;


    delay(5);

    lcden = 1;

    delay(5);

    lcden = 0;


}


void init()

{

    dula = 0;

    wela = 0; // turn off the digital tube


    lcden = 0;

    write_com(0x38); //Display mode setting

    write_com(0x0e); //Display switch and cursor setting

    write_com(0x06);

    write_com(0x80+0x10);

    

}


void main()

{

    init();

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

    {

        write_date(table[num]);

        delay(20);

    }

// write_com = 1; // clear screen operation

    write_com(0x80+0x53); //Set data pointer

    for(num=0;num<15; num++)

    {

        write_date(table1[num]);

        delay(20);

    }

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

    {

        write_com(0x18); //The entire screen moves left

        delay(20);

    }        

    while(1);

}


Reference address:MCU LCD Operation

Previous article:I2C serial bus composition and working principle
Next article:Application of single chip keyboard

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号