好生奇怪,lcd1602在我的电路里就不正常了非对比度问题←_←
时间:10-02
整理:3721RD
点击:
在我买的开发板上显示正常
但是我用单片机最小系统,连接好电路,打开电源,
显示变成了下面这样 ( ̄△ ̄;)
好奇怪呀, 其他的都和开发板上的一样 ,就是显示字符串不对
( ﹁ ﹁ ) ~→
我在网上查到lcd1602里面有上拉电阻,所以我接电路就直接相连.
程序如下 :
#include<reg52.h>
#define LCD P0
#define delaytime 500
sbit E = P2^7;
sbit RS = P2^6;
sbit RW = P2^5;
unsigned char code display1[] = "My name is Cjl ";
unsigned char code display2[] = "I want to ";
unsigned char code display3[] = "master 89c52 ";
unsigned char code display4[] = "I think that ";
unsigned char code display5[] = "It's interesting";
unsigned char code display6[] = "It's so cool!";
void LCD_Com(unsigned char x);
void LCD_Data(unsigned char x);
void Init1();
void Init2();
void delay(unsigned int x);
void main()
{
unsigned char i;
while(1){
Init1();
for(i = 0; i < 16; i++)
LCD_Data(display1);
delay(delaytime);
Init2();
for(i = 0; i < 16; i++)
LCD_Data(display2);
delay(delaytime);
Init1();
for(i = 0; i < 16; i++)
LCD_Data(display3);
delay(delaytime);
Init2();
for(i = 0; i < 16; i++)
LCD_Data(display4);
delay(delaytime);
Init1();
for(i = 0; i < 16; i++)
LCD_Data(display5);
delay(delaytime);
Init2();
for(i = 0; i < 16; i++)
LCD_Data(display6);
delay(delaytime);
}
}
void LCD_Com(unsigned char x)
{
RS = 0;
RW = 0;
LCD = x;
delay(10);
E = 1;
delay(10);
E = 0;
}
void LCD_Data(unsigned char x)
{
RS = 1;
RW = 0;
LCD = x;
delay(10);
E = 1;
delay(10);
E = 0;
}
void Init1()
{
LCD_Com (0x38);
LCD_Com (0x0c);
LCD_Com (0x06);
LCD_Com (0x01);
LCD_Com (0x80);
}
void Init2()
{
LCD_Com (0x38);
LCD_Com (0x0c);
LCD_Com (0x06);
// LCD_Com (0x01);
LCD_Com (0xc0);
}
void delay(unsigned int x)
{
unsigned int i, j;
for(i = x; i > 0; i--)
for(j = 110; j > 0; j--)
;
}
但是我用单片机最小系统,连接好电路,打开电源,
显示变成了下面这样 ( ̄△ ̄;)
好奇怪呀, 其他的都和开发板上的一样 ,就是显示字符串不对
( ﹁ ﹁ ) ~→
我在网上查到lcd1602里面有上拉电阻,所以我接电路就直接相连.
程序如下 :
#include<reg52.h>
#define LCD P0
#define delaytime 500
sbit E = P2^7;
sbit RS = P2^6;
sbit RW = P2^5;
unsigned char code display1[] = "My name is Cjl ";
unsigned char code display2[] = "I want to ";
unsigned char code display3[] = "master 89c52 ";
unsigned char code display4[] = "I think that ";
unsigned char code display5[] = "It's interesting";
unsigned char code display6[] = "It's so cool!";
void LCD_Com(unsigned char x);
void LCD_Data(unsigned char x);
void Init1();
void Init2();
void delay(unsigned int x);
void main()
{
unsigned char i;
while(1){
Init1();
for(i = 0; i < 16; i++)
LCD_Data(display1);
delay(delaytime);
Init2();
for(i = 0; i < 16; i++)
LCD_Data(display2);
delay(delaytime);
Init1();
for(i = 0; i < 16; i++)
LCD_Data(display3);
delay(delaytime);
Init2();
for(i = 0; i < 16; i++)
LCD_Data(display4);
delay(delaytime);
Init1();
for(i = 0; i < 16; i++)
LCD_Data(display5);
delay(delaytime);
Init2();
for(i = 0; i < 16; i++)
LCD_Data(display6);
delay(delaytime);
}
}
void LCD_Com(unsigned char x)
{
RS = 0;
RW = 0;
LCD = x;
delay(10);
E = 1;
delay(10);
E = 0;
}
void LCD_Data(unsigned char x)
{
RS = 1;
RW = 0;
LCD = x;
delay(10);
E = 1;
delay(10);
E = 0;
}
void Init1()
{
LCD_Com (0x38);
LCD_Com (0x0c);
LCD_Com (0x06);
LCD_Com (0x01);
LCD_Com (0x80);
}
void Init2()
{
LCD_Com (0x38);
LCD_Com (0x0c);
LCD_Com (0x06);
// LCD_Com (0x01);
LCD_Com (0xc0);
}
void delay(unsigned int x)
{
unsigned int i, j;
for(i = x; i > 0; i--)
for(j = 110; j > 0; j--)
;
}
可以看看这个:w w w.emhom.com/thread-30-1-1.html?_dsign=5c1ed461
亲测可用
有需要12864电子钟套件不?我QQ:176798246