用PROTEUS仿真单片机与LCD接口项目

发布时间: 2024-08-09
来源: 电子工程世界

设计要求:

在上一个项目中,介绍了如何使用8051微控制器进行串行通信,这是一个非常基础的项目,不需要太多的硬件。接下来将实现LCD与8051微控制器的接口。经常将LCD作为硬件工程项目的调试工具。使用LCD来显示不同的值。例如, ATM机,手机也都配有LCD。该项目将使用通常称为1602 的LCD。因此,我们使用8051单片机同LCD的连接。


还是放一下图和代码吧

#include

#define uchar unsigned char

#define uint unsigned int

   

sbit RS = P1^0;   

sbit RW = P1^2;

sbit EN = P1^1;    

void delay(uint x)

{

    while(x--);    


void write_command(uchar command)

{

    RW = 0;

    RS = 0;

    P2 = command;

    EN= 1;

    delay(100);

    EN = 0;

    RW = 1;


void write_data(uchar date)

{

    RW = 0;

    RS = 1;

    P2 = date;

    EN = 1;

    delay(100);

    EN = 0;

    RW = 1;


void FLCD1602_init(void)

{

    write_command(0x38);

    write_command(0x0f);

    write_command(0x06);

}  


void FLCD1602_clear()

{

    write_command(0x01);

    write_command(0x02);

}


void display_string(uchar *p)

{

    while(*p)

    {

        write_data(*p);

        p++;            

    }

}


 

void gotoxy(uchar y,uchar x)

{

    if(y == 1)

    write_command(0x40 + x);

    else if(y == 2)

    write_command(0x80 + 0x40 + x);

}

void main()

{

    uchar i,sec = 56;

    FLCD1602_init();

    FLCD1602_clear();

    while(1)

    {

        FLCD1602_clear();

        display_string("LBC MAKE THIS");

        gotoxy(2,0);

        display_string("2022/06/15");

        delay(50000);delay(50000);delay(50000);delay(50000);

        FLCD1602_clear();

        display_string("end");

        gotoxy(2,0);

        delay(50000);delay(50000);delay(50000);delay(50000);

        i++;

        if(i>100)i = 0;

    }

}     

代码的话输出是可以随意改动的,放一下运行后的东西看一下

到此就结束了



文章来源于: 电子工程世界 原文链接

本站所有转载文章系出于传递更多信息之目的,且明确注明来源,不希望被转载的媒体或个人可与我们联系,我们将立即进行删除处理。