MCU Lesson 14th: LCD

Source: Internet
Author: User
Tags clear screen

Below is the LCD circuit, where RD is connected to P2 ^ 6; lcde is connected to P2 ^ 7; WR is connected to P2 ^ 5.

# Include <reg51.h> # define uint unsigned int # define uchar unsigned charsbit LCD _e = P2 ^ 7; sbit LCD _rs = P2 ^ 6; sbit LCD _wr = P2 ^ 5; uchar code table_show1 [] = "Hello! "; Uchar code table_show2 [] =" I am chenlu! "; Void delay (uint time); void init_ LCD (); void write_ LCD _command (uchar comm); void write_ LCD _data (uchar lcddata); void main () {int flag1, flag2, flag3; init_ LCD (); // write to the cache zone write_ LCD _command (0x80 + 0x10); For (flag1 = 0; flag1 <6; flag1 ++) {write_ LCD _data (table_show1 [flag1]);} // write to the cache zone write_ LCD _command (0x80 + 0x50); For (flag2 = 0; flag2 <12; flag2 + +) {write_ LCD _data (table_show2 [flag2]);} // move the entire screen to the left to for (flag3 = 0; flag3 <16; flag3 ++) {write_ LCD _command (0x18);} // stop here to avoid refresh while (1);} // initialize lcdvoid init_ LCD () {// initialize the LCD attributes // display mode write_ LCD _command (0x38); // The cursor write_ LCD _command (0x0f); write_ LCD _command (0x06 ); // clear screen write_ LCD _command (0x01); // Data Pointer write_ LCD _command (0x80);} // LCD write command void write_ LCD _command (uchar comm) {delay (5 ); // rs = l rw = l e = hlcd_rs = 0; delay (5); LCD _wr = 0; // write command p0 = comm; delay (5); LCD _e = 1; delay (5); LCD _e = 0;} // void write_ LCD _data (uchar lcddata) {delay (5 ); // rs = h rw = l e = hlcd_rs = 1; delay (5); LCD _wr = 0; // write data p0 = lcddata; delay (5); LCD _e = 1; delay (5); LCD _e = 0 ;}// delay function void delay (uint time) {uint I, j; for (I = 100; I> time; I --) for (j = 0; j <100; j ++ );}
The use of LCD is mainly referred to the LCD Data Manual. The basic usage is the above procedure. The key is to pay attention to timing issues.

Readers can download 1602 LCD data online, and then ponder over this program.

Note: write commands can be understood as setting display properties; write data can be understood as the data you want to display on the display.

MCU Lesson 14th: LCD

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.