1602LCD显示器的使用
DB==P0
RD==P2.6
WR==P2.5
指令码:
清屏:
光标归位:
。。。。。。。。
读状态输入:RS=L,RW=H,E=H 输出:DB0~DB7=状态字
写指令输入:RS=L,RW=L,E=下降沿脉冲,DB0~DB7=指令码输出:无
读数据输入:RS=H,RW=H,E=H 输出:DB0~DB7=数据
写数据输入:RS=H,RW=L,E=下降沿脉冲,DB0~DB7=数据输出:无
上次写的驱动:
#include
#include"LCD1602.h"
#include
#include
#include
#include
#include
sbit lcdrs =P3^0;//数据/命令选择端(H/L)
sbit lcdrw =P3^1;//读/写选择端(H/L)
sbit lcden =P3^2;//使能信号端
char
char
char LCDBuffer[16]={""};
char ctrlStr[7]={".4f"};
void delayms(int xms)
{
int i, j;
for(i=xms;i>0;i--)
for(j=121;j>0;j--);
}
void write_com(char com)//写命令
{
lcdrs=0;
P0=com;
delayms(1);
lcden=1;
delayms(1);
lcden=0;
}
void write_data(char mydata)////写数据
{
lcdrs=1;
P0=mydata;
delayms(1);
lcden=1;
delayms(1);
lcden=0;
}
void initLCD()//初始化
{
//02,显示回车:1,数据指针清零。
}
void write_position(char position)//字符要显示在LCD哪个位置
{
lcdrs=0;
lcdrw=0;
lcden=0;
P0=position;
delayms(1);
lcden=1;
delayms(1);
lcden=0;
}
///功能函数部分
void displayOneCharacter(char mydata,char position)
{
write_position(position);
write_data(mydata);
}
void loadAndDisplay(bit judge)
{
if(judge==0)
{
displayOneCharacter(LCDBuffer[0],0x80);
displayOneCharacter(LCDBuffer[1],0x81);
displayOneCharacter(LCDBuffer[2],0x82);
displayOneCharacter(LCDBuffer[3],0x83);
displayOneCharacter(LCDBuffer[4],0x84);
displayOneCharacter(LCDBuffer[5],0x85);
displayOneCharacter(LCDBuffer[6],0x86);
displayOneCharacter(LCDBuffer[7],0x87);
displayOneCharacter(LCDBuffer[8],0x88);
displayOneCharacter(LCDBuffer[9],0x89);
displayOneCharacter(LCDBuffer[10],0x8A);
displayOneCharacter(LCDBuffer[11],0x8B);
displayOneCharacter(LCDBuffer[12],0x8C);
displayOneCharacter(LCDBuffer[13],0x8D);
displayOneCharacter(LCDBuffer[14],0x8E);
displayOneCharacter(LCDBuffer[15],0x8F);
}
if(judge==1)
{
displayOneCharacter(LCDBuffer[1],0xC1);
displayOneCharacter(LCDBuffer[2],0xC2);
displayOneCharacter(LCDBuffer[3],0xC3);
displayOneCharacter(LCDBuffer[4],0xC4);
displayOneCharacter(LCDBuffer[5],0xC5);
displayOneCharacter(LCDBuffer[6],0xC6);
displayOneCharacter(LCDBuffer[7],0xC7);
displayOneCharacter(LCDBuffer[8],0xC8);
displayOneCharacter(LCDBuffer[9],0xC9);
displayOneCharacter(LCDBuffer[10],0xCA);
displayOneCharacter(LCDBuffer[11],0xCB);
displayOneCharacter(LCDBuffer[12],0xCC);
displayOneCharacter(LCDBuffer[13],0xCD);
displayOneCharacter(LCDBuffer[14],0xCE);
displayOneCharacter(LCDBuffer[15],0xCF);
}
}
void setCursorPosition(char position) //移动光标位置
{
write_com(0x02);//光标归位
for(i=0;i write_com(0x14);//右移 } //下面的代码用于动态显示字符的,主要的东西在上面 void moveLeftOneStep(void)//左右移动 { if(cursorPosition==0)//表明要通过翻页左移 { if(startAddress!=0)//表明还可左移一次 剩下情况没法移动 { startAddress--;//确定显示的结束位置 if(expressLength-startAddress>=16)//表明显示满了 { endAddress=startAddress+15; return; } else//表明后面还有几个空要填满 { endAddress=expressLength-1; } } } else//表明无需翻页 { c
1602LCD显示 相关文章:
- 1602LCD显示驱动程序(11-24)
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)