#include <reg52.h> #define UCHAR unsigned char#define uint unsigned intsbit rs=p3^5;sbit lcden=p3^4;sbit dula=p2^6; Sbit Wela=p2^7;uchar table1[]= "Tx-51star MCU"; Uchar table2[]= "WWW. Txmcu.com "; void delay (uint x) {uint a,b;for (a=x;a>0;a--) for (b=10;b>0;b--);} void write_com (Uchar com)//some commands, Rs=0{p0=com;rs=0;lcden=0;delay (ten); Lcden=1;delay (ten); lcden=0;} void Write_data (Uchar dat)//write data, Rs=1{p0=dat;rs=1;lcden=0;delay (ten); Lcden=1;delay (ten); lcden=0;} void Init () {dula=0;wela=0;write_com (0x38); Display Mode settings: 16x2 display, 5x7 lattice, 8-bit Data interface delay (write_com); 0x0f; Display Mode setting delay ((); write_com (0x06); Display Mode settings: The cursor moves right, the character does not move delay ((); write_com (0x01); Clear the screen instruction, clears the previous display content delay (20);} void Main () {Uchar a;init (); 1602 Initialize write_com (0x80); Set the position of the character you want to display as the first row of the first column a=0;while (table1[a]!= ' s)//As long as you do not write to the end flag, continue to write {//This is the first method of the write character, using the while loop. Write_data (Table1[a]); a++;} Write_com (0x80+0x40); Sets the position of the second line character display, for the second row, the first column a=0;for (a=0;a<13;a++)//To display a total of 13 characters, so Loop 13 times. {//This is the second method of the write character, with a For loop Write_data (Table2[a]);d Elay (10);} while (1);}
1602 LCD Display