欢迎来到天天文库
浏览记录
ID:21184707
大小:15.98 KB
页数:10页
时间:2018-10-20
《单片机,lcd.c液晶驱动程序》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、附录二LCD.C液晶驱动程序#include"REG51F.h"#include"intrins.h"#include"USEH1.h"#include"lcd.h"#include"HZcode.h"bitbusy_bit=1;//函数声明==============================voidnop(void);bitCheckBusy(void);//状态检查//写显示数据//dat:显示数据voidWriteByte(uchardat);//向LCD发送命令//command:命令SendComman
2、dToLCD(ucharcommand);//函数定义==============================voidnop(void){_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();}//状态检查bitCheckBusy(void){ucharstate=0;P1=0xFF;//空读操作RW=1;DI=0;EN=1;state=P1;EN=0;P1=0xFF;//再读才有效RW=1;DI
3、=0;EN=1;state=P1;EN=0;busy_bit=(bit)(state>>7);return(busy_bit);}//写显示数据//dat:显示数据voidWriteByte(uchardat){while(CheckBusy());DI=1;RW=0;LCD_P=dat;EN=1;EN=0;}/*-------------------------------------------------------------*///向LCD发送命令//command:命令SendCommandToLCD(uch
4、arcommand){while(CheckBusy());RW=0;DI=0;LCD_P=command;EN=1;EN=0;}/*-------------------------------------------------------------*///设定行地址(页)--X0-7voidSetLine(ucharline){line&=0x07;//0<=line<=7line
5、=0xb8;//10111xxxSendCommandToLCD(line);}//设定列地址--Y0-63voidSetColum
6、n(ucharcolumn){column&=0x3f;//0=7、=0x40;//01xxxxxxSendCommandToLCD(column);}//设定显示开始行--XXvoidSetStartLine(ucharstartline)//0--63{//startline&=0x07;startline8、=0xc0;//11000000SendCommandToLCD(startline);}//开关显示voidSetOnOff(ucharonoff){onoff9、=0x3e;//10、0011111xSendCommandToLCD(onoff);}/*-----------------------------------------------------------*///选择屏幕//screen:0-全屏,1-左屏,2-右屏voidSelectScreen(ucharscreen){//显示器:负有效CS1:0--右;CS2:0--左switch(screen){case0:CS1=0;//全屏nop();CS2=0;nop();break;case1:CS1=1;//左屏nop();CS2=011、;nop();break;case2:CS1=0;//右屏nop();CS2=1;nop();break;default:break;}}/*------------------------------------------------------------*///清屏//screen:0-全屏,1-左屏,2-右voidClearScreen(ucharscreen){uchari,j;SelectScreen(screen);for(i=0;i<8;i++){SetLine(i);for(j=0;j<64;j++)12、{SetColumn(j);WriteByte(0x00);}}}/*-------------------------------------------------------------*///显示8*8点阵//lin:行(0-7),column:列(0-127)//address:字模区首地址voidShow
7、=0x40;//01xxxxxxSendCommandToLCD(column);}//设定显示开始行--XXvoidSetStartLine(ucharstartline)//0--63{//startline&=0x07;startline
8、=0xc0;//11000000SendCommandToLCD(startline);}//开关显示voidSetOnOff(ucharonoff){onoff
9、=0x3e;//
10、0011111xSendCommandToLCD(onoff);}/*-----------------------------------------------------------*///选择屏幕//screen:0-全屏,1-左屏,2-右屏voidSelectScreen(ucharscreen){//显示器:负有效CS1:0--右;CS2:0--左switch(screen){case0:CS1=0;//全屏nop();CS2=0;nop();break;case1:CS1=1;//左屏nop();CS2=0
11、;nop();break;case2:CS1=0;//右屏nop();CS2=1;nop();break;default:break;}}/*------------------------------------------------------------*///清屏//screen:0-全屏,1-左屏,2-右voidClearScreen(ucharscreen){uchari,j;SelectScreen(screen);for(i=0;i<8;i++){SetLine(i);for(j=0;j<64;j++)
12、{SetColumn(j);WriteByte(0x00);}}}/*-------------------------------------------------------------*///显示8*8点阵//lin:行(0-7),column:列(0-127)//address:字模区首地址voidShow
此文档下载收益归作者所有