794 views|2 replies

69

Posts

0

Resources
The OP
 

The LCD display does not display, but the program can run normally? [Copy link]

#include<reg51.h>
#include<intrins.h> //Include _nop_() empty function instruction
#define out P2 //P2 port output display
#define uchar unsigned char
#define uint unsigned int

sbit RS=P3^0;
sbit RW=P3^1;
sbit E=P3^2;

void lcd_initial(void); //lcd initialization function
void cheek_busy(void); //check busy flag function
void write_command(uchar com); //write command function
void write_data(uchar dat); //write data function
void string(uchar ad,uchar *s); //display character function
void delay(uint); //delay function

void main(void)
{
lcd_initial();
while(1)
{
string(0x85,"welcome"); //Call function to display characters
string(0xc2,"harbin CHINA");
delay(100);
write_command(0x01); //Call write command function to clear screen
delay(100);
}
}

void delay(uint j) //延时函数
{
uchar i=250;
for(;j>0;j--)
{
while(--i);
i=249;
while(--i);
i=250;
}
}

void cheek_busy(void) //Check busy flag function
{
uchar dt;

do
{
dt=0xff;
E=0;
RS=0;
RW=1;
E=1;
dt=out;
}while(dt&0x80);
E=0;
}

void write_command(uchar com) //write command function
{
cheek_busy();
E=0;
RS=0;
RW=0;
out=com;
E=1;
_nop_();
E=0;
delay(1);
}

void write_data(uchar dat) //Write display function
{
cheek_busy();
E=0;
RS=1;
RW=0;
out=dat;
_nop_();
_nop_();
_nop_();
_nop_();
E=1;
_nop_();
_nop_();
_nop_();
_nop_();
E=0;
delay(1);
}

void lcd_initial(void) //LCD初始化函数
{
delay(15);
write_command(0x38);
delay(5);
write_command(0x38);
delay(5);
write_command(0x38);
delay(5);
write_command(0x0c);
delay(5);
write_command(0x06);
write_command(0x01);
delay(1);
}

void string(uchar ad,uchar *s) //output display string function
{
write_command(ad);
while(*s>0)
{
write_data(*s++);
delay(100);
}
}

This post is from MCU
 

69

Posts

0

Resources
2
 
This post was last edited by ayld on 2023-6-23 13:43

The screenshot on the right has nothing to do with the previous code. It is used to check other codes. The computer has dual screens.

This post is from MCU
 
 

69

Posts

0

Resources
3
 

Problem solved.

void write_data(uchar dat) //Write display function

This function is written incorrectly.

This post is from MCU
 
 
 

Guess Your Favourite
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list