#include<reg52.h>
#define LCD_DATA P1//lcd的数据口 sbit lcd_busy=LCD_DATA^7;//lcd忙信号位 sbit rw=P0^1;//读写控制线 sbit rs=P0^0;//数据/指令选择控制线 sbit en=P0^2;//使能控制线
void lcd_check_busy(void)//忙信号检测 { while(1) { en=0; rs=0;//指令寄存器通信 rw=1; LCD_DATA=0xff; en=1; if(!lcd_busy)break; } en=0; }
void lcd_cls(void)//清屏 { lcd_check_busy(); rs=0; rw=0; LCD_DATA=1; en=1; en=0; }
void lcd_write_instruction(unsigned char lcd_instruction)//写指令到LCD { lcd_check_busy(); rs=0; rw=0;//写数据 LCD_DATA=lcd_instruction; en=1; en=0; }
void lcd_write_data(unsigned char lcd_data)//输出一个字节数据到LCD { lcd_check_busy(); rs=1; rw=0; LCD_DATA=lcd_data; en=1; en=0; }
void lcd_set_position(unsigned char x)//LCD光标定位到X处 { lcd_write_instruction(0x80+x); }
void lcd_printc(unsigned char lcd_data)//输出一个字符到LCD { lcd_write_data(lcd_data); }
void lcd_prints(unsigned char *lcd_string)//输出一个字符串到LCD { unsigned char i=0; while(lcd_string!=0x00) { lcd_write_data(lcd_string); i++; } }
void lcd_initial(void)//初始化LCD { lcd_write_instruction(0x3c); lcd_write_instruction(0x0c); lcd_write_instruction(0x06);//显示屏一定要不移动 lcd_cls(); }
void main() { lcd_initial(); lcd_set_position(0); lcd_prints("0123456789012345678901234567890123456789"); lcd_set_position(0x40); lcd_prints("0123456789012345678901234567890123456789"); while(1) {} } 请问这个程序在LCM20*4的液晶显示中,对不对? |