微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 源码 5 -- LCD 1602 显示字符

源码 5 -- LCD 1602 显示字符

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

itLCD_Busy(void)
{
DataPort = 0xFF;
RS = 0;
RW = 1;
EN = 0;
_nop_();
EN = 1;// 读操作是 EN = 1 驱动
return(bit)(DataPort & 0x80);// 强制转换到 bit 时,除非原数据等于 0,bit = 0,否则 bit = 1
}

voidLCD_Clear(void)
{
LCD_Write_Com(0x01);
Delay_ms(5);
}

voidLCD_Set_Argument(unsigned charDL,unsigned charN,unsigned charF)
{
DL <= 4;// 指令格式决定了要移位,具体看指令格式要求
N <= 3;
F <= 2;
LCD_Write_Com(0x20 | DL | N | F);
Delay_ms(5);
}

voidLCD_Set_InputMode(unsigned charID,unsigned charS)
{
ID <= 1;
LCD_Write_Com(0x04 | ID | S);
Delay_ms(5);
}

voidLCD_Set_DisplayMode(unsigned charD,unsigned charC,unsigned charB)
{
D <= 2;
C <= 1;
LCD_Write_Com(0x08 | D | C | B);
Delay_ms(5);
}

voidLCD_Write_Char(unsigned charrow,unsigned charcol,unsigned charc)
{
if(row == 1) LCD_Write_Com(0x80 + col - 0x01); // 由指令格式可知,DB7 = 1,因此要加上 80H
else if(row == 2) LCD_Write_Com(0xC0 + col - 0x01);
LCD_Write_Data(c);
}

voidLCD_Write_String(unsigned charrow,unsigned charcol,unsigned char*s)
{
if(row == 1) LCD_Write_Com(0x80 + col - 0x01);
else if(row == 2) LCD_Write_Com(0xC0 + col - 0x01);
while(*s) {
LCD_Write_Data(*s);
s++;
}
}

voidDelay(unsigned intt)
{
while(t--);
}

voidDelay_ms(unsigned intt)// 根据测试,可以相当近似的表示 t ms
{
while(t--) {
Delay(245);
Delay(245);
}
}

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

网站地图

Top