1602的液晶 采用4位驱动的方式 这个屏只能4位驱动
显示出来的字母数字都是镜像的 摸不清楚怎么回事 有没有懂的朋友指点指点!
write_com(0x33); //16*2显示,5*7点阵,8位数据
delay(100);
write_com(0x32);
delay(100);
write_com(0x28);
delay(100);
write_com(0x0c); //显示开,关光标
delay(100);
write_com(0x04); //移动光标
delay(100);
while(0);
write_com(0x01); //清除LCD的显示内容
delay(100);
以上是初始化部分的函数!
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
- #include "LCD1602.H"
- //mode:bit 4
- #define LCD_DATA_DDR DDRF
- #define LCD_DATA_PORT PORTF
- #define LCD_RS_DDR DDRF
- #define LCD_RS_PORT PORTF
- #define LCD_EN_DDR DDRF
- #define LCD_EN_PORT PORTF
- #define LCD_RS BIT(PF2)
- #define LCD_EN BIT(PF3)
- #define LCD_DATA BIT(PF2) | BIT(PF2) | BIT(PF2) | BIT(PF2)
- void LCDWriteEn(void)
- {
- LCD_EN_PORT |= LCD_EN; //en high
- delayNus(10);
- LCD_EN_PORT &= ~LCD_EN; //en low
- }
- void LCDWriteCommandorWriteData(unsigned char CommandorData,unsigned char Mode)
- {
- delayNus(26);
- switch (Mode)
- {
- case 0: LCD_RS_PORT &= ~LCD_RS; break; //RS在写命令时候为L
- case 1: LCD_RS_PORT |= LCD_RS; break; //RS在写命令时候为H
- }
- LCD_DATA_PORT &= 0X0F;
- LCD_DATA_PORT |= CommandorData & 0XF0; //把数据准备好
- LCDWriteEn();
- CommandorData = CommandorData << 4;
- LCD_DATA_PORT &= 0x0f;
- LCD_DATA_PORT |= CommandorData & 0XF0; //把数据准备好
- LCDWriteEn();
- }
- void LCDUsePortInitial(void)
- {
- LCD_DATA_DDR |= LCD_DATA;
- LCD_RS_DDR |= LCD_RS;
- LCD_EN_DDR |= LCD_EN;
- }
- //--------------------------------------------------
- //函数名称:初始化
- // ->RS RW D7 D6 D5 D4 D3 D2 D1 D0
- //清屏 ->0 0 0 0 0 0 0 0 0 1
- //功能设置 ->0 0 0 0 0 0 1 DL N F
- //显示开关控制->0 0 0 0 1 D C B * *
- //输入方式 ->0 0 0 0 0 0 0 1 I/D S
- //--------------------------------------------------
- void LCDdisplayInitial(void)
- {
- LCDWriteCommandorWriteData(0x28,0); LCDWriteEn();
- LCDWriteCommandorWriteData(0x28,0); delayNms(10);
- LCDWriteCommandorWriteData(0x01,0); delayNms(10);
- LCDWriteCommandorWriteData(0x0c,0); delayNms(10);
- }
- //----------------------------------
- //函数名称:指定位置写数据
- //入口参数:unsigned char X,unsigned char Y,unsigned char dataSend
- //返回的值:--
- //----------------------------------
- void LCDWriteoneChar(unsigned char X,unsigned char Y,unsigned char dataSend)
- {
- LCDWriteCommandorWriteData((0x80 + (Y << 6) + X),0);
- LCDWriteCommandorWriteData(dataSend,1);
- }
-
- //----------------------------------
- //函数名称:写字符串
- //入口参数:unsigned char X,unsigned char Y,unsigned char *dataSend
- //返回的值:--
- //----------------------------------
- void LCDWriteString(unsigned char X,unsigned char Y,unsigned char *dataSend)
- {
- LCDWriteCommandorWriteData((0x80 + (Y << 6) + X),0);
- while(*dataSend != ' ')
- {
- LCDWriteCommandorWriteData(*dataSend,1);
- dataSend++;
- }
- }
- //----------------------------------
- //函数名称:写自定义字符
- //入口参数:unsigned char Address,unsigned char *Per
- //返回的值:--
- //备 注:地址Address范围<0-7>
- //----------------------------------
- void LCDWriteCgram(unsigned char Address,unsigned char *Per)
- {
- if (Address > 7)
- {
- Address = 0;
- }
- LCDWriteCommandorWriteData(0x40 + (Address * 8),0); //写入自定义数据初始地址
- while(*Per != ' ')
- {
- LCDWriteCommandorWriteData(*Per,1); //写如自定义数据
- Per++;
- }
- }
复制代码抄的~参考吧。可用
一周热门 更多>