标题: 1602液晶写屏函数 [打印本页]

作者: hujia    时间: 2015-2-18 01:01
标题: 1602液晶写屏函数
/***************************************************************************************
** 函数名称: void LCD_1602_write_string(unsigned char x,unsigned char y,unsigned char *s)
** 功能描述: 写入字符串到第x(0-1)行y(0-15)列
** 输   入: unsigned x 第x(0-1)行;unsigned char y(0-15)列;unsigned char *s要写ude字符串。
** 输   出: 无
** 全局变量: 无
** 调用模块: LCD_Write_Command( ),LCD_Write_DATA()
** 说    明: 未写下标越界检查 x,y起点均为0,无论是单字符或字符串均用双引扩号
****************************************************************************************/
void LCD_1602_write_string(unsigned char x,unsigned char y,unsigned char *s)
{
unsigned char i;
i=15-y;
if(x)
{                                //如果是第二行
    y+=0xc0;                     //地址是偏移量y加第二行首地址0xC0
}
else
{                                //如果是第一行
    y+=0x80;                     //地址是偏移量y加第一行首地址0x80
    LCD_Write_Command(y);        //向LCD写第一行地址命令
    while(*s)      
    {                            //直到字符串读到最后一位
        LCD_Write_DATA(*s++);    //写字符数据到LCD
        if(y++>=0x8f)
        {                        //y自加,如果第一行写完
            y=0xc0;              //地址y设定为第二行起头
            i=15;                //最大写入次数
            break;               //如果第一行写完则强退本次循环
        }
    }  
}
LCD_Write_Command(y);
while(*s)
{
    LCD_Write_DATA(*s++);
    if(!(i--)) break;
}
}







欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1