详细内容下载网址:http://download.csdn.net/detail/chenqiai0/4484389 C语言版本 http://download.csdn.net/detail/chenqiai0/4485053汇编语言版本
#include<reg52.h>typedef unsigned char uint8;sbit RS=P1^0;sbit RW=P1^1;sbit E=P1^5;sbit BUSY = P0^7; //下面函数用于检测STA7是不是为0,为0为空闲。但是实际上,由于单片机的操作速度慢于液晶控制器的反应速度, //因此可以不进行读写检测,或只进行简短的延时,所以两个delay函数都是可以的/*void delay() { P0 = 0xFF; do { RS = 0; RW = 1; E= 0; E = 1;//拉高,数据就读出来了 }while (BUSY == 1); E = 0;} */void delay(){ uint8 i,j; for(i=0;i<100;i++) for(j=0;j<100;j++) {;}}void write_com(uint8 com)//写状态 { delay(); RS=0; RW=0; P0=com; E=1; E=0;} void write_date(uint8 date)//写数据{ delay(); RS=1; RW=0; P0=date; //P0=0x31; //会显示1 E=1; E=0;} void init_1602(){ RS=0; RW=0; E=0; write_com(0x38); write_com(0x0c); write_com(0x06); write_com(0x01);}void main(){ init_1602(); write_com(0x80); write_date(7+'0'); while(1);}