LCD1602 display numbers, characters, custom characters, strings, cursors

Source: Internet
Author: User
Tags clear screen

LCD1602 display numbers, characters, custom characters, strings, cursors

/******************************************* program name:   1602 LCD Clock program writing time: October 4, 2015 hardware support: LCD1602 LCD screen   &NBSP;STC12C4052AD external 12MHZ crystal oscillator   Wiring definition:  db0_db7 --> p1^0 --p1^7rs    = p3 ^ 2;        rw   = p3  ^ 3; E    = P3 ^ 4;  function: Test LCD1602 display, display time,/HTTP// 990487026.blog.51cto.com/ ,welcome to linux debian vs redhat ************** /#include  <AT89X52.h>      //  include header files  //typedef unsigned char      uint8;   //  Unsigned 8-bit integer variable  //#define   LCD1602_DB0_DB7  P1   //  define LCD1602 data bus sbit  LCD1602_RS   = P3 ^ 2;     //  Defines the RS control line for the LCD1602 SBIT&NBSP;LCD1602_RW&NBsp;  = p3 ^ 3;     //  defines the RW control line for LCD1602 sbit lcd1602_ e    = p3 ^ 4;     //  defines the E control line for LCD1602 Sbit  LCD1602_Busy = P1 ^ 7;     //  define LCD1602 lines (with lcd1602_ DB0_DB7 Association)//  Definition LCM2402 instruction set  //  (see Technical Manual for details) #define           CMD_clear         0x01              //  Clear Screen #define          CMD_back          0x02              // ddram back to 0-bit #define          CMD_dec1          0x04              //  read-in AC (pointer) minus 1, write left #define          CMD_add1          0x06              //  read-in AC (pointer) plus 1, write right #define          CMD_dis_gb1     0x0f              //  Open Cursor _ open cursor blinking #define          CMD_dis_gb2     0x0e              //  on display _ Open cursor _ off cursor blink #define          CMD_dis_gb3     0x0c              //  on show _ Off cursor blink #define          cmd_off_dis     0x08             //  off Display _ off cursor _ Off cursor Blinking #define         cmd_set82        0x38             // 8 Bit Bus _ 2 Line Display #define         cmd_set81        0x30             // 8 bit bus _1 line display (top row) #define          CMD_set42        0x28             // 4 bit bus _2 line display # define         cmd_set41        0x20             // 4 bit bus _1 line display (top row) #define          lin_1           0x80              // 4-bit bus _1 line display (top row) #define           lin_2            0xc0             // 4 Bit Bus _ 1 line display (top row) void delay_ms  (unsigned int a)  {    unsigned int  i;    while  ( --a != 0 )    {  for   (i=0;i<=600;i++)     }}// lcd1602, if LCD1602 is busy, this function will wait until the non-busy state  //void  lcd1602_testbusy (void) {    lcd1602_db0_db7 = 0xff;  //device read state     LCD1602_RS = 0;    LCD1602_RW = 1;     LCD1602_E = 1;    while (lcd1602_busy);   //wait for LCM not busy     lcd1602_e =  0;    }//  Write instruction Program  //void lcd1602_writecmd (Uint8 lcd1602_command)  {    lcd1602_testbusy ();    lcd1602_db0_db7 = lcd1602_ command;   lcd1602_rs = 0;   lcd1602_rw = 0;    lcd1602_e = 1;   delay_ms (5);  //  Modify the delay, change the display speed     lcd1602_e = 0;}   Write Data program  //void lcd1602_writedata (uint8 lcd1602_data) {    lcd1602_ Testbusy ();    lcd1602_db0_db7 = lcd1602_data;   lcd1602_rs =  1;   LCD1602_RW = 0;   LCD1602_E = 1;    delay_ms (5);  //  Modify the delay, change the display speed    lcd1602_e = 0;}  //  Print String Program     (This function calls pointer function) length 48 characters within  void print (UINT8&NBSP;A,UINT8&NBSP;*STR) {  lcd1602_writecmd (a  | 0x80)   while (*str !=  ') {  lcd1602_writedata (*str++);  }  *str = 0;}   Print single character program  // void print2 (uint8 a,uint8 t) {  lcd1602_writecmd (a | &NBSP;0X80);   lcd1602_writedata (t);}   Custom characters   write a total of 16 literal characters, which can be extracted directly from the Cgram code after writing. Uint8 code xword[]={    0x18,0x18,0x07,0x08,0x08,0x08,0x07,0x00,  //℃, Code  0x00    0x00,0x00,0x00,0x00,0xff,0x00,0x00,0x00,  //One, code  0x01     0x00,0x00,0x00,0x0e,0x00,0xff,0x00,0x00,  //Two, Code  0x02     0x00,0x00,0xff,0x00,0x0e,0x00,0xff,0x00,  //Three, code &NBSP;0X03&NBSP;&NBSP;&NBSP;&NBSP;0X00,0X00,0XFF, 0xf5,0xfb,0xf1,0xff,0x00,  //Four, code  0x04    0x00,0xfe,0x08,0xfe,0x0a,0x0a, 0xff,0x00,  //Five, code  0x05    0x00,0x04,0x00,0xff,0x00,0x0a,0x11,0x00,  //six, Code  0x06    0x00,0x1f,0x11,0x1f,0x11,0x11,0x1f,0x00,  //Day, code  0x07};void  cgramwrite (void)  { //  loading cgram //    uint8 i;     lcd1602_writecmd (0x06);    // cgram address Auto plus 1    lcd1602_ Writecmd (0x40)    // cgram address is set at 00     for (i=0;i<64;i++)  {     lcd1602_writedata (Xword[i]);//  writes data by array     }}// lcd1602 initialization  //(user definable, add  *  program line must be retained but modifiable) void lcd1602_init (void) {   lcd1602_writecmd ( CMD_SET82); //*  display mode settings: Display 2 lines, each character is 5*7 pixels, cmd_set81 is a row    lcd1602_writecmd (cmd_clear);  //   Display Clear Screen    lcd1602_writecmd (cmd_back);  //*  data pointer to 1th line 1th character position    lcd1602_writeCMD (CMD_ADD1);  //   display cursor movement settings: text does not move, the cursor moves right    lcd1602_writecmd (CMD_DIS_GB1);   //   display on and cursor settings: Display on, cursor open, flashing open    cgramwrite ();      //    Write custom character}void main  (void) {  lcd1602_init () to Cgram,//lcd1602 initialize       while (1) {   print2 (0x80,1+0x30);   //  show number 1   on 1th row 1th digit Print2 (0x40,5+0x30);   //  shows the number 2  print2 (0x85,0x05);    on line 1th 1th digit   //  Display the custom character   print2 (0x88,0xe4);     //  on line 5th of line 1th 9th bit  ASCII  in the upeer 4bit 1110  lower 4bit 0100 corresponding  μ    Delay_ms (;  // ) Open cursor display, flashing, after μ will show a beating cursor   print2 (0x81, ' D ');      //  shows the custom character   print  (0x42, "www.51cto.com") on line 5th of row 1th, and  //prints from left to right at the first place on line 2nd. Blog.51cto.com "String &NBSP;&NBSP;PRint  (0x8e, "hi");  //prints the "HI" string from left to right in the 15th place on line 1th   } } //LCD1602  displays numbers, characters, custom characters, strings, Cursor

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/74/0E/wKiom1YQ4wKxkIEUAAJ68eTjxSo774.jpg "title=" Lab.png "alt=" Wkiom1yq4wkxkieuaaj68etjxso774.jpg "/>

LCD1602 display numbers, characters, custom characters, strings, cursors

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.