微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 1602LCD显示器的使用

1602LCD显示器的使用

时间:11-21 来源:互联网 点击:

ursorPosition--;

}

}

void moveRightOneStep(void)

{

if(startAddress+cursorPosition==endAddress+1)

return;

if(cursorPosition==15)//表明要考虑是否进行翻页

{

if(startAddress+16

//表明 startAddress+15得到的是LCD最后一位对应express的地址 再加1表示长度

{

startAddress++;

endAddress=startAddress+15;

displayExpress();

}

else if(startAddress+16==expressLength)//表明当前已是最后一个字符

{

startAddress++;

endAddress=startAddress+14;//光标处应该是空

displayExpress();

}

else//表明光标处并没有显示字符

{

return;

}

}

else//表明无需翻页

{

if(cursorPosition==endAddress+1)//已到最后一个位置,光标不能再动了

{

return;

}

cursorPosition++;

endAddress=expressLength-1;

setCursorPosition(cursorPosition);

}

}

void moveLeft(void)//startAddress+cursorPosition是光标对应express中的地址

{

if(startAddress+cursorPosition==0)//跳转到最后

{

if(expressLength>15)

{

endAddress=expressLength-1;

startAddress=endAddress-14;

}

cursorPosition=endAddress-startAddress+2;

}

if(startAddress+cursorPosition-1>=0&&express[startAddress+cursorPosition-1]==n)//tan,sin,ln

{

if(startAddress+cursorPosition-6>=0&&express[startAddress+cursorPosition-6]==a&&express[startAddress+cursorPosition-6+1]==r) //arctan,arcsin……

{

moveLeftOneStep();

moveLeftOneStep();

moveLeftOneStep();

moveLeftOneStep();

moveLeftOneStep();

moveLeftOneStep();

}

else if(express[startAddress+cursorPosition-2]==l)//表明为ln

{

moveLeftOneStep();

moveLeftOneStep();

}

else //表明为sin或tan

{

moveLeftOneStep();

moveLeftOneStep();

moveLeftOneStep();

}

}

else if(startAddress+cursorPosition-1>=0&&startAddress+cursorPosition-1>=0&&express[startAddress+cursorPosition-1]==g)//lg

{

moveLeftOneStep();

moveLeftOneStep();

}

else if(startAddress+cursorPosition-1>=0&&express[startAddress+cursorPosition-1]==s)

{

if(startAddress+cursorPosition-6>=0&&express[startAddress+cursorPosition-6]==a&&express[startAddress+cursorPosition-6+1]==r) //arctan,arcsin……

{

moveLeftOneStep();

moveLeftOneStep();

moveLeftOneStep();

moveLeftOneStep();

moveLeftOneStep();

moveLeftOneStep();

}

else

{

moveLeftOneStep();

moveLeftOneStep();

moveLeftOneStep();

}

}

else//表明为单个字符

{

moveLeftOneStep();

}

}

void moveRight(void)

{

if(endAddress-startAddress+1==cursorPosition)//表明光标到了最后

{

if(expressLength>15)

{

endAddress=15;

startAddress=0;

}

cursorPosition=0;

}

else if(express[startAddress+cursorPosition]==s||express[startAddress+cursorPosition]==t||express[startAddress+cursorPosition]==c)//sin,tan

{

moveRightOneStep();

moveRightOneStep();

moveRightOneStep();

}

else if(express[startAddress+cursorPosition]==a)//arctan,arcsin之类的

{

moveRightOneStep();

moveRightOneStep();

moveRightOneStep();

moveRightOneStep();

moveRightOneStep();

moveRightOneStep();

}

else if(express[startAddress+cursorPosition]==l)//lg,ln

{

moveRightOneStep();

moveRightOneStep();

}

else//表明为单字符

moveRightOneStep();

}

void displayExpress(void)//从startAddress显示到endAddress

{

char i;

write_position(0x80);//从这里开始显示

for(i=startAddress;i<=endAddress;i++)

{

write_data(express[i]);

}

for(i=endAddress+1;i<16+startAddress;i++)//后面的写空格

{

write_data( );

}

}

void insertOneAndDisplay(void)

{

expressLength++;

if(cursorPosition>=0&&cursorPosition<15)//表明是在和前面当中插入的 startAddress可以不变

{

//查看当前显示状态

if(endAddress-startAddress==15)//表明当前已经满显了

{

endAddress--;

}

else//表明未满显

{

endAddress++;

}

cursorPosition++;

}

else if(cursorPosition==15)//表明光标在显示器第16个显示单元处 此时 startAddress得变

{

if(endAddress-startAddress==15)//表明当前已经满显未满显的情况已在isModifyInput中处理

{

startAddress++;

endAddress++;

}

}

}

void deleteOneAndDisplay(void)

{

moveExpressForward(cursorPosition+startAddress,1);

expressLength--;

if(cursorPosition==0)

{

startAddress--;

//确定endAddress的位置

if(expressLength-startAddress>=16)//表明显示满了

{

endAddress=startAddress+15;

}

else//表明后面还有几个空要填满

{

endA

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top