最开始1602第一排只显示一排方块,在1602上加了排针之后(因为焊接原因1602需要高一点)就只亮不显示任何东西了。下面是1602部分的程序:
#include<at89x51.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
void delay(uint z)
{
uint a,b;
for(a=z;a>0;a--)
for(b=640;b>0;b--);
}
sbit LcdRs = P2^5;
sbit LcdRw = P2^6;
sbit LcdEn = P2^7;
#define DBPort P0
#define LCD_COMMAND 0
#define LCD_DATA 1
#define LCD_CLEAR_SCREEN 0x01
#define LCD_HOMING 0x02
void LCD_Write(bit style, unsigned char input)
{
LcdEn=0;
LcdRs=style;
LcdRw=0; _nop_();
DBPort=input; _nop_();
LcdEn=1; _nop_();
LcdEn=0; _nop_();
_nop_();
delay(1);//
}
#define LCD_SHOW 0x04
#define LCD_HIDE 0x00
#define LCD_CURSOR 0x02
#define LCD_NO_CURSOR 0x00
#define LCD_FLASH 0x01
#define LCD_NO_FLASH 0x00
void LCD_SetDisplay(unsigned char DisplayMode)
{
LCD_Write(LCD_COMMAND, 0x08|DisplayMode);
}
#define LCD_AC_UP 0x02
#define LCD_AC_DOWN 0x00
#define LCD_MOVE 0x01
#define LCD_NO_MOVE 0x00
void LCD_SetInput(unsigned char InputMode)
{
LCD_Write(LCD_COMMAND, 0x04|InputMode);
}
void LCD_Initial()
{
LcdEn=0;
LCD_Write(LCD_COMMAND,0x38);
delay(15);
LCD_Write(LCD_COMMAND,0x38);
delay(15);
LCD_Write(LCD_COMMAND,0x38);
delay(15);
LCD_Write(LCD_COMMAND,0x38);
delay(15);
LCD_SetDisplay(LCD_SHOW|LCD_NO_CURSOR);
delay(15);
LCD_Write(LCD_COMMAND,LCD_CLEAR_SCREEN);
delay(15);
LCD_SetInput(LCD_AC_UP|LCD_NO_MOVE);
delay(15);
}
void GotoXY(unsigned char x, unsigned char y)
{
if(y==0)
LCD_Write(LCD_COMMAND,0x80|x);
if(y==1)
LCD_Write(LCD_COMMAND,0x80|(x-0x40));
delay(2);
}
void Print(unsigned char *str)
{
while(*str!='\0')
{
LCD_Write(LCD_DATA,*str);
str++;
delay(2);
}
}
|