找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 997|回复: 0
打印 上一主题 下一主题
收起左侧

常用lcd12864驱动

[复制链接]
跳转到指定楼层
楼主
ID:879069 发表于 2021-1-20 09:19 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#include "lcd12864.h"
#include "intrins.h"
void Lcd12864_ByteShow_String(uint8 *str1)
        {         
                                while(*str1!='\0')
                                        {
                                          Lcd12864_Write_Data(*str1);
                                          str1++;
                                  }
                                                               
  }


void Lcd12864_Show_String(uint8 row, uint8 col,uint8 *str){
        uint8 *defaultValue = "parameter error" ;
        switch(row){
                case 1:
                                Lcd12864_Write_Cmd(0x80+col-1);//第一行第y个空格
                                while(*str!='\0')
                                        {
                                        Lcd12864_Write_Data(*str);
                                        str++;
                                 }
                                break;       
                case 2:
                                Lcd12864_Write_Cmd(0x90+col-1);//第二行第y个空格
                                while(*str!='\0'){
                                        Lcd12864_Write_Data(*str);
                                        str++;
                                }
                                break;
                case 3:
                                Lcd12864_Write_Cmd(0x88+col-1);//第一行第y个空格
                                while(*str!='\0'){
                                        Lcd12864_Write_Data(*str);
                                        str++;
                                }
                                break;       
                case 4:
                                Lcd12864_Write_Cmd(0x98+col-1);//第二行第y个空格
                                while(*str!='\0'){
                                        Lcd12864_Write_Data(*str);
                                        str++;
                                }
                                break;

           default:
                                   Lcd12864_Write_Cmd(0x00+0x80);//parameter error
                                while(*defaultValue!='\0'){
                                        Lcd12864_Write_Data(*defaultValue);
                                        defaultValue++;
                                }                                       
        }       
}


/******************************************************************************/
// 函数名称:Lcd12864_Busy_Check
// 输入参数:无
// 输出参数:无
// 函数功能:LCD1602忙信号检查
/******************************************************************************/
void Lcd12864_Busy_Check(void){
        uint8 tmp;
        lcdPort = 0xff;//一开始的时候,lcdPort设置成输入状态

        do{
                RS2 = 0;
                RW2 = 1;
                EN2 = 0;
                EN2 = 1;
                _nop_();
                _nop_();//延时CP
                tmp = lcdPort;
                _nop_();//延时PQ
                EN2 = 0;
                _nop_();
        }while(tmp&0x80);       
}


/******************************************************************************/
// 函数名称:Lcd12864_Init
// 输入参数:无
// 输出参数:无
// 函数功能:LCD12864初始化
/******************************************************************************/
void Lcd12864_Init(void)
        {
        Lcd12864_Write_Cmd(0x30);//基本指令设置
        Lcd12864_Write_Cmd(0x01);//清屏
        Lcd12864_Write_Cmd(0x06);//显示光标移动设置
        Lcd12864_Write_Cmd(0x0c);//显示开及光标设置
        vout2 = 0;
        rst2 = 1;
}


/******************************************************************************/
// 函数名称:Lcd12864_Write_Cmd
// 输入参数:cmd
// 输出参数:无
// 函数功能:LCD12864发送命令
/******************************************************************************/
void Lcd12864_Write_Cmd(uint8 cmd){
        Lcd12864_Busy_Check();//busycheck
        PSB2 = 1;
        RS2 = 0;
        RW2 = 0;
        EN2 = 0;

        EN2 = 1;
        _nop_();
        _nop_();
        lcdPort = cmd;
        _nop_();
        _nop_();
        EN2 = 0;
        _nop_();
        _nop_();               
}

/******************************************************************************/
// 函数名称:Lcd12864_Write_Data
// 输入参数:Data-写入数据
// 输出参数:无
// 函数功能:LCD12864写一个字节数据
/******************************************************************************/
void Lcd12864_Write_Data(uint8 Data){
        Lcd12864_Busy_Check();//busycheck
        PSB2 = 1;
        RS2 = 1;
        RW2 = 0;
        EN2 = 0;

        EN2 = 1;
        _nop_();
        _nop_();
        lcdPort = Data;
        _nop_();
        _nop_();
        EN2 = 0;
        _nop_();
        _nop_();               
}


/******************************************************************************/
// 函数名称:Lcd12864_Screen_Flash
// 输入参数:无
// 输出参数:无
// 函数功能:LCD12864屏幕闪烁
/******************************************************************************/
//void Lcd12864_Screen_Flash(void){
//        Lcd12864_Write_Cmd(0x08);
//        Delay400ms();Delay400ms();
//        Lcd12864_Write_Cmd(0x0c);
//        Delay400ms();Delay400ms();
//        Lcd12864_Write_Cmd(0x08);
//        Delay400ms();Delay400ms();
//        Lcd12864_Write_Cmd(0x0c);
//        Delay400ms();Delay400ms();               
//}


/******************************************************************************/
// 函数名称:Lcd12864_Show_Specific_Symbol
// 输入参数:无
// 输出参数:无
// 函数功能:LCD12864显示特殊符号
/******************************************************************************/
//void Lcd12864_Show_Specific_Symbol(void){
//        uint8 i;
//        Lcd12864_Write_Cmd(0x01);//清屏
//        for(i=0;i<32;i++){
//                Lcd12864_Write_Cmd(0x80+i); //显示位置
//                Lcd12864_Write_Data(0x02+i);//显示内容       
//        }       
//}

/******************************************************************************/
// 函数名称:Lcd12864_Screen_Clear
// 输入参数:无
// 输出参数:无
// 函数功能:LCD12864清屏
/******************************************************************************/
void Lcd12864_Screen_Clear(void){
        Lcd12864_Write_Cmd(0x01);
}

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表