标题:
lcd1602光标我怎么控制,我要把光标移到一个地方,然后对某个数字操作加减
[打印本页]
作者:
哒劳德
时间:
2020-4-11 23:34
标题:
lcd1602光标我怎么控制,我要把光标移到一个地方,然后对某个数字操作加减
lcd1602光标我怎么控制,我要把光标移到一个地方,然后对某个数字操作加减。代码应该怎么写,求大神指导一下!
作者:
liuxuhe
时间:
2020-4-12 15:58
void init()
{
RW=0;
LCDEN=0;
writeComm(0x38); //显示模式,
writeComm(0x0c); //开显示, 关光标
writeComm(0x06); //写字符后地址加1, 光标加1
writeComm(0x01); //清屏
}
void writeComm(uchar comm) //写命令程序
{
RS = 0;
LCDEN = 1;
P2 = comm;
del_ms(1);
LCDEN = 0;
del_ms(1);
}
void writeData(uchar dat) //给1602液晶屏发送数据
{
RS = 1;
LCDEN = 1;
P2 = dat;
del_ms(1);
LCDEN = 0;
del_ms(1);
}
void writeString(uchar *str,uchar length)
{
uchar i;
for(i=0;i<length;i++)
{
writeData(str[i]);
}
}
writeComm(0x80+????);writeData(' ?????');
这里就是定位的光标
作者:
liuxuhe
时间:
2020-4-12 15:59
另外一种 主要看 LCD_set_xy( uchar x, uchar y )
void LCD_init(void) //液晶初始化
{
P1=0xFF;
P3=0xff; //输出
LCD_RS=0; //
del_ms(50);
LCD_write_char(0x30,0);
del_ms(6);
LCD_write_char(0x30,0); //
del_ms(1);
LCD_write_char(0x30,0); //上电即显示正常,无需复位
del_ms(1);
LCD_write_char(0x02,0);
del_ms(1);
LCD_write_char(0x28,0); //4bit test显示模式设置(不检测忙信号)
del_ms(1);
LCD_write_char(0x08,0); // 显示关闭
del_ms(1);
LCD_write_char(0x01,0); // 显示清屏
del_ms(1);
LCD_write_char(0x06,0); // 显示光标移动设置
del_ms(1);
LCD_write_char(0x0C,0); // 显示开及光标设置
del_ms(10);
}
//---------------------------------------------
void LCD_write_str(uchar X,uchar Y,uchar *s)
{
LCD_set_xy( X, Y ); //写地址
while (*s) // 写显示字符
{
LCD_write_char( 0, *s );
s ++;
}
}
void LCD_set_xy( uchar x, uchar y ) //写地址函数
{
uchar address;
if (y == 0) address = 0x80 + x;
else
address = 0xc0 + x;
LCD_write_char( address, 0 );
}
//------------------------------------------------
void LCD_en_write(void) //液晶使能
{
_nop_();
LCD_E=1;//EN=1
_nop_();
LCD_E=0;//EN=0
}
//------------------------------------------------
void LCD_write_char(uchar cd,uchar ab) // 写数据
{
delay_nus(20);
if(cd==0)
{
LCD_RS=1; //RS=1,写显示内容
LCD_byte(ab);
}
else
{
LCD_RS=0; //RS=0,写命令
LCD_byte(cd);
}
}
//-----------------------------------------------
void LCD_byte(uchar abc)//
{
delay_nus(50);
if(((abc<<0)&0x80)==0) //MSB is output first
LCD_D7=0; //abc=0
else LCD_D7=1; //abc=1
if(((abc<<1)&0x80)==0) //MSB is output first
LCD_D6=0; //abc=0
else LCD_D6=1; //abc=1
if(((abc<<2)&0x80)==0) //MSB is output first
LCD_D5=0; //abc=0
else LCD_D5=1; //abc=1
if(((abc<<3)&0x80)==0) //MSB is output first
LCD_D4=0; //abc=0
else LCD_D4=1; //abc=1
LCD_en_write();
if(((abc<<4)&0x80)==0) //MSB is output first
LCD_D7=0; //abc=0
else LCD_D7=1; //abc=1
if(((abc<<5)&0x80)==0) //MSB is output first
LCD_D6=0; //abc=0
else LCD_D6=1; //abc=1
if(((abc<<6)&0x80)==0) //MSB is output first
LCD_D5=0; //abc=0
else LCD_D5=1; //abc=1
if(((abc<<7)&0x80)==0) //MSB is output first
LCD_D4=0; //abc=0
else LCD_D4=1; //abc=1
LCD_en_write();
}
作者:
郑汉松
时间:
2020-4-12 16:36
LCD写命令模式,第一行是0x80+列位置,第二行是0xc0+列位置
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1