• 51单片机学习:LCD12864液晶显示实验(带字库)


    实验名称:LCD12864液晶显示实验(带字库)
    接线说明:    
    实验现象:下载程序后,LCD12864上显示汉字字符信息
    注意事项:                                                                                  
    ***************************************************************************************/
    #include "public.h"
    #include "lcd12864.h"


    /*******************************************************************************
    * 函 数 名       : main
    * 函数功能         : 主函数
    * 输    入       : 无
    * 输    出         : 无
    *******************************************************************************/
    void main()
    {    
        lcd12864_init();//LCD12864初始化

        lcd12864_show_string(0,0,"Hello World!");//第1行字符串显示
        lcd12864_show_string(0,1,"大家好!");//第2行字符串显示
        lcd12864_show_string(0,2,"欢迎使用51开发板");//第3行字符串显示
        lcd12864_show_string(0,3,"好好学习天天向上");//第4行字符串显示
        while(1)
        {
            
        }    
    }

    #include "lcd12864.h"


    /*******************************************************************************
    * 函 数 名       : lcd12864_write_cmd
    * 函数功能         : LCD12864写命令
    * 输    入       : cmd:指令
    * 输    出         : 无
    *******************************************************************************/
    void lcd12864_write_cmd(u8 cmd)
    {
        LCD12864_RS=0;//选择命令
        LCD12864_WR=0;//选择写
        LCD12864_E=0;
        LCD12864_DATAPORT=cmd;//准备命令
        delay_ms(1);
        LCD12864_E=1;//使能脚E先上升沿写入
        delay_ms(1);
        LCD12864_E=0;//使能脚E后负跳变完成写入
    }

    /*******************************************************************************
    * 函 数 名       : lcd12864_write_data
    * 函数功能         : LCD12864写数据
    * 输    入       : dat:数据
    * 输    出         : 无
    *******************************************************************************/
    void lcd12864_write_data(u8 dat)
    {
        LCD12864_RS=1;//选择数据
        LCD12864_WR=0;//选择写
        LCD12864_E=0;
        LCD12864_DATAPORT=dat;//准备数据
        delay_ms(1);
        LCD12864_E=1;//使能脚E先上升沿写入
        delay_ms(1);
        LCD12864_E=0;//使能脚E后负跳变完成写入
    }

    /*******************************************************************************
    * 函 数 名       : lcd12864_init
    * 函数功能         : LCD12864初始化
    * 输    入       : 无
    * 输    出         : 无
    *******************************************************************************/
    void lcd12864_init(void)
    {
        LCD12864_PSB=1;//选择8位或4位并口方式
        lcd12864_write_cmd(0x30);//数据总线8位,基本指令操作
        lcd12864_write_cmd(0x0c);//整体显示关,游标显示关,游标正常显示
        lcd12864_write_cmd(0x06);//写入新数据后光标右移,显示屏不移动
        lcd12864_write_cmd(0x01);//清屏    
    }

    /*******************************************************************************
    * 函 数 名       : lcd12864_clear
    * 函数功能         : LCD12864清屏
    * 输    入       : 无
    * 输    出         : 无
    *******************************************************************************/
    void lcd12864_clear(void)
    {
        lcd12864_write_cmd(0x01);    

    /*******************************************************************************
    * 函 数 名       : lcd12864_show_string
    * 函数功能         : LCD12864显示字符串
    * 输    入       : x,y:显示坐标,x=0~7,y=0~3;
                       str:显示字符串数据
    * 输    出         : 无
    *******************************************************************************/
    void lcd12864_show_string(u8 x,u8 y,u8 *str)
    {
        if(y<=0)y=0;
        if(y>3)y=3;
        x&=0x0f;    //限制x,y不能大于显示范围

        switch(y)
        {
            case 0: x|=0x80;break;//第1行地址+x的偏移
            case 1: x|=0x90;break;//第2行地址+x的偏移
            case 2: x|=0x88;break;//第3行地址+x的偏移
            case 3: x|=0x98;break;//第4行地址+x的偏移
        }
        lcd12864_write_cmd(x);
        while(*str!='\0')
        {
            lcd12864_write_data(*str);
            str++;        
        }
            

     

    #include "public.h"

    /*******************************************************************************
    * 函 数 名       : delay_10us
    * 函数功能         : 延时函数,ten_us=1时,大约延时10us
    * 输    入       : ten_us
    * 输    出         : 无
    *******************************************************************************/
    void delay_10us(u16 ten_us)
    {
        while(ten_us--);    
    }

    /*******************************************************************************
    * 函 数 名       : delay_ms
    * 函数功能         : ms延时函数,ms=1时,大约延时1ms
    * 输    入       : ms:ms延时时间
    * 输    出         : 无
    *******************************************************************************/
    void delay_ms(u16 ms)
    {
        u16 i,j;
        for(i=ms;i>0;i--)
            for(j=110;j>0;j--);
    }

    纷传单片机学习资料放在纷传小程序里了,需要的可以加入圈子有资料百度网盘下载地址及提取码。

  • 相关阅读:
    基于 SpringBoot + MyBatis 的在线音乐播放器
    Day 44 MySQL
    Java 面试题:如何保证集合是线程安全的? ConcurrentHashMap 如何实现高效地线程安全?
    绘图问题记录
    CentOS7安装MySQL8
    我要涨知识——TypeScript 经典高频面试题(一)
    Apache网页优化
    每日一练——有效的括号
    壳聚糖-聚乙二醇-炔基|炔基-PEG-壳聚糖|Chitosan-PEG-Alkyne
    海外代购系统/代购网站怎么搭建
  • 原文地址:https://blog.csdn.net/qq_63964231/article/details/126917430