C51---LCD1602显示一行字符
创始人
2024-06-02 18:40:04

1.器件:C51、LCD1602

2.code:

#include "reg52.h"
#include "intrins.h"
#define     databuffer  P0//定义8位数据线,Po端口组

sbit        RS = P1^0;
sbit        RW = P1^1;
sbit        EN = P1^4;

void check_busy()
{
    char tmp = 0x80;
    databuffer = 0x80;
    
    while (tmp & 0x80 ){
        RS  = 0;
        RW  = 1;
        EN  = 0;
        _nop_();
        EN  = 1;
        _nop_();
        _nop_();
    tmp = databuffer;
        EN = 0;
        _nop_();
    }

}

void Write_Cmd_Func(char cmd)
{
    check_busy();
        RS  = 0;
        RW  = 0;
    
        EN  = 0;
        _nop_();
    databuffer = cmd;
        EN  = 1;
        _nop_();
        _nop_();
        EN = 0;
        _nop_();
    
}

void Write_Data_Func(char dataShow)
{
        check_busy();
        RS  = 1;
        RW  = 0;
    
        EN  = 0;
        _nop_(); 
    databuffer = dataShow;
        _nop_();
        EN  = 1; 
        _nop_();
        _nop_();
        EN = 0;
        _nop_();

}

void Delay15ms()        //@11.0592MHz
{
    unsigned char i, j;

    i = 27;
    j = 226;
    do
    {
        while (--j);
    } while (--i);
}

void Delay5ms()        //@11.0592MHz
{
    unsigned char i, j;
    i = 9;
    j = 244;
    do
    {
        while (--j);
    } while (--i);
}


void LCD1602_INIT()
{
     //延时15ms
    Delay15ms();
    //写指令38H(不检测忙信号)
    Write_Cmd_Func(0x38);
    //延时5ms
    Delay5ms();
    //以后每次写指令,读/写数据操作均需要检测忙信号
    //写指令38H,显示模式设置
    Write_Cmd_Func(0x38);
    //写指令08H,显示关闭
    Write_Cmd_Func(0x08);
    //写指令01H,显示清屏
    Write_Cmd_Func(0x01);
    //写指令06H,显示光标移动设置
    Write_Cmd_Func(0x06);
    //写指令0CH,显示开光标设置
    Write_Cmd_Func(0x0C);
}

void LCD1602_showline(char row,char col,char *string)
{
         switch(row){
            
             case 1:
             Write_Cmd_Func(0x80+col);
                while(*string){
                            Write_Data_Func(*string);
                            string++;
                }
                break;
                
              case 2:
                Write_Cmd_Func(0x80+0x40+col); 
                while(*string){
                            Write_Data_Func(*string);
                            string++;
                }
                break;
    }
}

void main()
{
    char position = 0x80+0x05;
    //char dataShow = 'C';
    LCD1602_INIT();
    LCD1602_showline(1,5,"NO.1");
    LCD1602_showline(2,0,"Tayminy Fuo");
    //Write_Cmd_Func(position);//选择要显示的地址
    //Write_Data_Func(dataShow);//发送要显示的字符
}
    
    
     
    
    
    
    
    
    
    
    

3.效果

 

 

相关内容

热门资讯

豆神教育:董事长窦昕辞职 唐颖... 3月23日,豆神教育(维权)(300010)发布公告,董事长窦昕因工作安排调整辞去董事长及非独立董事...
RadexMarkets瑞德克... 3月23日,近期,加密货币市场在关键周线收官之际遭遇剧烈波动,比特币价格在周末跌破69000美元关口...
吉林省一地拍到“巨鸟”过马路,... (来源:长春相遇)老铁别急!“座山雕”国道溜达,东北大哥大姐齐让路老话说得好,“春江水暖鸭先知”,可...
03月23日 美元兑泰铢跌破3... Hehson外汇消息2026年03月23日,截至19时31分,外汇市场上美元兑泰铢汇率跌破1美元兑换...
冠石科技2025年报解读:净亏... 营业收入:微增0.44%,内部结构分化明显2025年冠石科技实现营业收入13.65亿元,较上年同期的...