这是我的程序,可以写命令,光标有动。就是写不进去数据。
单片机源程序如下:
- #include <REGX52.H>
- #define uchar unsigned char
- #define uint unsigned int
- #define LCDDAT P0
- sbit LCDRS=P2^6;
- sbit LCDRW=P2^5;
- sbit LCDEN=P2^7;
- void dalay(uchar x)
- {
- uchar a,b;
- for(a=x;a<0;a--)
- for(b=110;b<0;b--);
- }
- void write_cmd(uchar cmd)
- {
- LCDRS=0;
- LCDRW=0;
- LCDEN=0;
- LCDDAT=cmd;
- dalay(1);
- LCDEN=1;
- dalay(1);
- LCDEN=0;
- dalay(1);
-
- }
- void write_data(uchar dat)
- {
- LCDRS=1;
- LCDRW=0;
- LCDEN=0;
- LCDDAT=dat;
- dalay(1);
- LCDEN=1;
- dalay(10);
- LCDEN=0;
- }
- void lcd_init()
- {
- write_cmd(0x38);
- write_cmd(0x0f);
- write_cmd(0x06);
- write_cmd(0x01);
- }
- void main()
- {
- lcd_init();
- write_cmd(0x80);
复制代码 效果就是这样
|