#include<reg52.h> #define uchar unsigned char #define uint unsigned int sbit rs=P2^6; sbit rw=P2^5; sbit lcden=P2^7; uchar table1[]="WENDELL"; void delay(uint z) { uint x,y; for(x=z;x>0;x--) for(y=110;y>0;y--); } void write_com(uchar com) //写命令函数 { lcden=0; rs=0; rw=0; P0=com; delay(5); lcden=1; delay(5); lcden=0; } void write_date(uchar date) //写数据函数 { lcden=0; rs=1; rw=0; P0=date; delay(5); lcden=1; delay(5); lcden=0; } void init() //LCD1602初始化 { lcden=0; write_com(0x38); //开显示 write_com(0x0c); //开显示不显示光标 write_com(0x06); //写一个指针加一 write_com(0x01); //清屏 } void main() { uchar a; init(); write_com(0x80); //起始位置指针起点 delay(5); for(a=0;a<7;a++) { write_date(table1[a]); delay(5); } while(1); } |