51单片机+LCD1602显示字符程序问题
程序是从网上找的,是把字符显示为移动的,就改了下一开始的端口定义,下载到单片机里后只显示一个个方块块,不清楚哪里错了。源程序链接是http://wenku.baidu.c...
程序是从网上找的,是把字符显示为移动的,就改了下一开始的端口定义,下载到单片机里后只显示一个个方块块,不清楚哪里错了。源程序链接是http://wenku.baidu.com/link?url=ztzWw2GhaKa6BG6NNCIGzxacSza8fBijLlazBVFYKNwgnjqCdXe3UtPAhSqo6zwZogdFfXT9p_TcrZRZr0ZAMQoExGuPLobK-7q9ufb4du7
程序如下:
#include<reg52.h>#define uchar unsigned char#define uint unsigned intuchar code table[]="qwertyuiop";uchar code table1[]="12345678901";sbit lcden=P1^2; //这行本来是=P3^4sbit lcdrs=P1^0; //这行本来是=P3^5sbit dula=P2^6; //这行不清楚怎么改sbit wela=P2^7; //这行不清楚怎么改uchar num;void delay(uint z){uint x,y;for(x=z;x>0;x--)for(y=110;y>0;y--);}void write_com(uchar com){lcdrs=0;P0=com;delay(5);lcden=1;delay(5);lcden=0;}void write_data(uchar date){lcdrs=1;P0=date;delay(5);lcden=1;delay(5);lcden=0;}void init(){dula=0;wela=0;lcden=0;write_com(0x38);write_com(0x0e);write_com(0x06);write_com(0x01);write_com(0x80+0x10);}void main(){init();for(num=0;num<10;num++){write_data(table[num]);delay(20);}write_com(1);write_com(0x80+0x53);for(num=0;num<11;num++){write_data(table1[num]);delay(20);}for(num=0;num<16;num++){write_com(0x18);delay(20);}while(1);} 展开
程序如下:
#include<reg52.h>#define uchar unsigned char#define uint unsigned intuchar code table[]="qwertyuiop";uchar code table1[]="12345678901";sbit lcden=P1^2; //这行本来是=P3^4sbit lcdrs=P1^0; //这行本来是=P3^5sbit dula=P2^6; //这行不清楚怎么改sbit wela=P2^7; //这行不清楚怎么改uchar num;void delay(uint z){uint x,y;for(x=z;x>0;x--)for(y=110;y>0;y--);}void write_com(uchar com){lcdrs=0;P0=com;delay(5);lcden=1;delay(5);lcden=0;}void write_data(uchar date){lcdrs=1;P0=date;delay(5);lcden=1;delay(5);lcden=0;}void init(){dula=0;wela=0;lcden=0;write_com(0x38);write_com(0x0e);write_com(0x06);write_com(0x01);write_com(0x80+0x10);}void main(){init();for(num=0;num<10;num++){write_data(table[num]);delay(20);}write_com(1);write_com(0x80+0x53);for(num=0;num<11;num++){write_data(table1[num]);delay(20);}for(num=0;num<16;num++){write_com(0x18);delay(20);}while(1);} 展开
3个回答
展开全部
感觉这代码有点乱
试一下我的吧
#include<reg52.h>
#ifndef unsi8
#define unsi8 unsigned char
#endif
#ifndef unsi_16
#define unsi_16 unsigned short
#endif
#define OUT P0
#define DELAY
sbit LCD_RS = P2^0;
sbit LCD_RW = P2^1;
sbit LCD_E_ = P2^2;
#define LCD_WR_CMD 0
#define LCD_WR_DATA 1
struct Passer
{
unsi8 String[12];
unsi8 String2[11];
};
struct Passer Disp={
'7','4','2','6','1','5','0','5','5','0','2','5',
'H','e','l','l','o',',','W','o','r','l','d'
};
#ifdef DELAY
void Delay_1ms(unsi_16 x)
{
unsi8 i;
while(x--)
{
for(i=0;i<125;i++);
}
}
#endif
static void LCD_Busy()
{
unsi8 i;
do
{
LCD_RS = 0;
LCD_RW = 1;
LCD_E_ = 1;
i = OUT;
LCD_E_ = 0;
}while(i&0x80);
}
static void LCD_WriteByte(unsi8 Dat,bit Mode)
{
unsi8 i;
LCD_Busy();
LCD_RS = Mode;
LCD_RW = 0;
OUT = Dat;
LCD_E_ = 1;
for(i=0;i<251;i++);
LCD_E_ = 0;
}
static void LCD_Set_Register()
{
LCD_WriteByte(0x38,LCD_WR_CMD);
LCD_WriteByte(0x01,LCD_WR_CMD);
LCD_WriteByte(0x06,LCD_WR_CMD);
LCD_WriteByte(0x0f,LCD_WR_CMD);
}
void Display()
{
unsi8 i;
LCD_WriteByte(0x82,LCD_WR_CMD);
for(i=0;i<sizeof(Disp.String);i++)
{
LCD_WriteByte(Disp.String[i],LCD_WR_DATA);
Delay_1ms(300);
}
LCD_WriteByte(0xc2,LCD_WR_CMD);
for(i=0;i<sizeof(Disp.String2);i++)
{
LCD_WriteByte(Disp.String2[i],LCD_WR_DATA);
Delay_1ms(300);
}
}
void main()
{
while(1)
{
LCD_Set_Register();
Display();
}
}
如有问题可再咨询
试一下我的吧
#include<reg52.h>
#ifndef unsi8
#define unsi8 unsigned char
#endif
#ifndef unsi_16
#define unsi_16 unsigned short
#endif
#define OUT P0
#define DELAY
sbit LCD_RS = P2^0;
sbit LCD_RW = P2^1;
sbit LCD_E_ = P2^2;
#define LCD_WR_CMD 0
#define LCD_WR_DATA 1
struct Passer
{
unsi8 String[12];
unsi8 String2[11];
};
struct Passer Disp={
'7','4','2','6','1','5','0','5','5','0','2','5',
'H','e','l','l','o',',','W','o','r','l','d'
};
#ifdef DELAY
void Delay_1ms(unsi_16 x)
{
unsi8 i;
while(x--)
{
for(i=0;i<125;i++);
}
}
#endif
static void LCD_Busy()
{
unsi8 i;
do
{
LCD_RS = 0;
LCD_RW = 1;
LCD_E_ = 1;
i = OUT;
LCD_E_ = 0;
}while(i&0x80);
}
static void LCD_WriteByte(unsi8 Dat,bit Mode)
{
unsi8 i;
LCD_Busy();
LCD_RS = Mode;
LCD_RW = 0;
OUT = Dat;
LCD_E_ = 1;
for(i=0;i<251;i++);
LCD_E_ = 0;
}
static void LCD_Set_Register()
{
LCD_WriteByte(0x38,LCD_WR_CMD);
LCD_WriteByte(0x01,LCD_WR_CMD);
LCD_WriteByte(0x06,LCD_WR_CMD);
LCD_WriteByte(0x0f,LCD_WR_CMD);
}
void Display()
{
unsi8 i;
LCD_WriteByte(0x82,LCD_WR_CMD);
for(i=0;i<sizeof(Disp.String);i++)
{
LCD_WriteByte(Disp.String[i],LCD_WR_DATA);
Delay_1ms(300);
}
LCD_WriteByte(0xc2,LCD_WR_CMD);
for(i=0;i<sizeof(Disp.String2);i++)
{
LCD_WriteByte(Disp.String2[i],LCD_WR_DATA);
Delay_1ms(300);
}
}
void main()
{
while(1)
{
LCD_Set_Register();
Display();
}
}
如有问题可再咨询
追问
非常感谢 另外我想问下两行字符显示完后就一直固定在那里 而不是又重头开始显示要如何改程序?
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
意法半导体(中国)投资有限公司
2023-06-12 广告
2023-06-12 广告
STM32F4是由ST(意法半导体)开发的一种高性能微控制器系列。其采用了90nm的NVM工艺和ART技术(自适应实时存储加速器,Adaptive Real-Time MemoryAccelerator)。STM32F4是一款基于ARM C...
点击进入详情页
本回答由意法半导体(中国)投资有限公司提供
展开全部
#include<reg52.h>
#ifndef unsi8
#define unsi8 unsigned char
#endif
#ifndef unsi_16
#define unsi_16 unsigned short
#endif
#define OUT P0
#define DELAY
sbit LCD_RS = P2^0;
sbit LCD_RW = P2^1;
sbit LCD_E_ = P2^2;
#define LCD_WR_CMD 0
#define LCD_WR_DATA 1
struct Passer
{
unsi8 String[12];
unsi8 String2[11];
};
struct Passer Disp={
'7','4','2','6','1','5','0','5','5','0','2','5',
'1','5','7','2','7','6','5','7','4','3','0'
};
#ifdef DELAY
void Delay_1ms(unsi_16 x)
{
unsi8 i;
while(x--)
{
for(i=0;i<125;i++);
}
}
#endif
static void LCD_Busy()
{
unsi8 i;
do
{
LCD_RS = 0;
LCD_RW = 1;
LCD_E_ = 1;
i = OUT;
LCD_E_ = 0;
}while(i&0x80);
}
static void LCD_WriteByte(unsi8 Dat,bit Mode)
{
unsi8 i;
LCD_Busy();
LCD_RS = Mode;
LCD_RW = 0;
OUT = Dat;
LCD_E_ = 1;
for(i=0;i<251;i++);
LCD_E_ = 0;
}
static void LCD_Set_Register()
{
LCD_WriteByte(0x38,LCD_WR_CMD);
LCD_WriteByte(0x01,LCD_WR_CMD);
LCD_WriteByte(0x06,LCD_WR_CMD);
LCD_WriteByte(0x0f,LCD_WR_CMD);
}
void Display()
{
unsi8 i;
LCD_WriteByte(0x82,LCD_WR_CMD);
for(i=0;i<sizeof(Disp.String);i++)
{
LCD_WriteByte(Disp.String[i],LCD_WR_DATA);
Delay_1ms(300);
}
LCD_WriteByte(0xc2,LCD_WR_CMD);
for(i=0;i<sizeof(Disp.String2);i++)
{
LCD_WriteByte(Disp.String2[i],LCD_WR_DATA);
Delay_1ms(300);
}
}
void main()
{
while(1)
{
LCD_Set_Register();
Display();
}
}
#ifndef unsi8
#define unsi8 unsigned char
#endif
#ifndef unsi_16
#define unsi_16 unsigned short
#endif
#define OUT P0
#define DELAY
sbit LCD_RS = P2^0;
sbit LCD_RW = P2^1;
sbit LCD_E_ = P2^2;
#define LCD_WR_CMD 0
#define LCD_WR_DATA 1
struct Passer
{
unsi8 String[12];
unsi8 String2[11];
};
struct Passer Disp={
'7','4','2','6','1','5','0','5','5','0','2','5',
'1','5','7','2','7','6','5','7','4','3','0'
};
#ifdef DELAY
void Delay_1ms(unsi_16 x)
{
unsi8 i;
while(x--)
{
for(i=0;i<125;i++);
}
}
#endif
static void LCD_Busy()
{
unsi8 i;
do
{
LCD_RS = 0;
LCD_RW = 1;
LCD_E_ = 1;
i = OUT;
LCD_E_ = 0;
}while(i&0x80);
}
static void LCD_WriteByte(unsi8 Dat,bit Mode)
{
unsi8 i;
LCD_Busy();
LCD_RS = Mode;
LCD_RW = 0;
OUT = Dat;
LCD_E_ = 1;
for(i=0;i<251;i++);
LCD_E_ = 0;
}
static void LCD_Set_Register()
{
LCD_WriteByte(0x38,LCD_WR_CMD);
LCD_WriteByte(0x01,LCD_WR_CMD);
LCD_WriteByte(0x06,LCD_WR_CMD);
LCD_WriteByte(0x0f,LCD_WR_CMD);
}
void Display()
{
unsi8 i;
LCD_WriteByte(0x82,LCD_WR_CMD);
for(i=0;i<sizeof(Disp.String);i++)
{
LCD_WriteByte(Disp.String[i],LCD_WR_DATA);
Delay_1ms(300);
}
LCD_WriteByte(0xc2,LCD_WR_CMD);
for(i=0;i<sizeof(Disp.String2);i++)
{
LCD_WriteByte(Disp.String2[i],LCD_WR_DATA);
Delay_1ms(300);
}
}
void main()
{
while(1)
{
LCD_Set_Register();
Display();
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
驴头不对马嘴,图上画的是数码管,也没有锁存器,结果程序里定义锁存器
最终显示函数又变成是液晶显示函数
一定要弄清硬件原理后再说程序问题
最终显示函数又变成是液晶显示函数
一定要弄清硬件原理后再说程序问题
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询