LCD端口已改,但为什么LCD还是不显示?下面是和我的板子配套的程序,可以正常显示。麻烦楼主看一下,和您的LCD程序对比一下,要改哪些地方?谢谢!!!
#include <reg51.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
/*12864端口定义*/
#define LCD_data  0 //数据口
sbit LCD_RS =  3^5; //寄存器选择输入
sbit LCD_RW =  3^6; //液晶读/写控制
sbit LCD_EN =  3^4; //液晶使能控制
sbit LCD_PSB =  3^1; //串/并方式控制
sbit wela =  2^6;
sbit dula =  2^7;
unsigned char code zhu[]= //图片代码
{
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xD4,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x05,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x03,0x50,0x00,0x50,0x80,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x3C,0x04,0x00,0xA0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x40,0x01,0x0B,0x15,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x40,0x00,0x88,0x00,0x00,0x06,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x01,0x80,0x00,0x60,0x00,0x00,0x05,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x03,0x90,0x00,0x01,0xB6,0x36,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x40,0x00,0x01,0xFE,0x36,0x00,0x00,0x00,
0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x02,0x20,0x00,0x01,0xB6,0x36,0x00,0x00,0x00,
0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x02,0xA0,0x00,0x03,0x6F,0xFF,0x00,0x00,0x00,
0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x1D,0x00,0x00,0x00,0x00,0x2C,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x05,0xC0,0x00,0x00,0x00,0x28,0x00,0x00,0x00,
0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x38,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0A,0x80,0x40,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x10,0x80,0x00,0x00,0x1F,0x08,0x47,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x01,0x20,0x00,0x00,0x3D,0x13,0x0C,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x08,0x10,0x00,0x00,0x27,0xA0,0x18,0x06,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x02,0x10,0x00,0x00,0x3F,0x80,0x38,0xC7,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x04,0x03,0xE0,0x00,0x33,0x90,0x3F,0xC7,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x03,0xB0,0x00,0x33,0x10,0x7F,0x87,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x08,0x24,0xF0,0x0C,0x0E,0x00,0xFF,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x07,0xF0,0xC2,0x00,0x00,0xFE,0x1F,0x81,0xB3,0xE6,0xD8,0xF0,0x00,
0x00,0x00,0x08,0x46,0x71,0x06,0x00,0x08,0x3F,0x1F,0x01,0xF6,0x67,0xF9,0xB0,0x00,
0x00,0x00,0x00,0x03,0x20,0x98,0x00,0x00,0x3F,0xFF,0x01,0xB6,0xC6,0xD9,0x80,0x00,
0x00,0x00,0x08,0x40,0xC0,0x24,0x00,0x04,0x3F,0x1F,0x03,0x7F,0xFD,0xBE,0xFC,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x1E,0x1E,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x01,0x0E,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x87,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x02,0x08,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x88,0x00,0x01,0x8C,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x01,0x8E,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x01,0x00,0x00,0x01,0xB6,0x06,0xDB,0x6C,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xFF,0x06,0xDB,0x6C,0x00,
0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x40,0x00,0x01,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x94,0xA4,0x68,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x02,0x19,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x42,0x00,0x10,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x20,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x14,0x00,0x0A,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
#define delayNOP(); {_nop_();_nop_();_nop_();_nop_();};
void delay0(uchar x); //x*0.14MS
void beep();
void dataconv();
void lcd_pos(uchar X,uchar Y); //确定显示位置
void delay(int ms)
{
while(ms--)
{
uchar i;
for(i=0;i<250;i++)
{
_nop_();
_nop_();
_nop_();
_nop_();
}
}
}
/*******************************************************************/
/* */
/*检查LCD忙状态 */
/*lcd_busy为1时,忙,等待。lcd-busy为0时,闲,可写指令与数据。 */
/* */
/*******************************************************************/
bit lcd_busy()
{
bit result;
LCD_RS = 0;
LCD_RW = 1;
LCD_EN = 1;
delayNOP();
result = (bit)(P0&0x80);
LCD_EN = 0;
return(result);
}
/*******************************************************************/
/* */
/*写指令数据到LCD */
/*RS=L,RW=L,E=高脉冲,D0-D7=指令码。 */
/* */
/*******************************************************************/
void lcd_wcmd(uchar cmd)
{
while(lcd_busy());
LCD_RS = 0;
LCD_RW = 0;
LCD_EN = 0;
_nop_();
_nop_();
 0 = cmd;
delayNOP();
LCD_EN = 1;
delayNOP();
LCD_EN = 0;
}
/*******************************************************************/
/* */
/*写显示数据到LCD */
/*RS=H,RW=L,E=高脉冲,D0-D7=数据。 */
/* */
/*******************************************************************/
void lcd_wdat(uchar dat)
{
while(lcd_busy());
LCD_RS = 1;
LCD_RW = 0;
LCD_EN = 0;
 0 = dat;
delayNOP();
LCD_EN = 1;
delayNOP();
LCD_EN = 0;
}
/*******************************************************************/
/* */
/* LCD初始化设定 */
/* */
/*******************************************************************/
void lcd_init()
{
LCD_PSB = 1; //并口方式
lcd_wcmd(0x34); //扩充指令操作
delay(5);
lcd_wcmd(0x30); //基本指令操作
delay(5);
lcd_wcmd(0x0C); //显示开,关光标
delay(5);
lcd_wcmd(0x01); //清除LCD的显示内容
delay(5);
}
/*******************************************
函数名称raw_PM
功 能:在整个液晶屏幕上画图
参 数:无
返回值:无
********************************************/
void Draw_PM(const uchar *ptr)
{
uchar i,j,k;
wela=0;
dula=0;
lcd_wcmd(0x34); //打开扩展指令集
i = 0x80;
for(j = 0;j < 32;j++)
{
lcd_wcmd(i++);
lcd_wcmd(0x80);
for(k = 0;k < 16;k++)
{
lcd_wdat(*ptr++);
}
}
i = 0x80;
for(j = 0;j < 32;j++)
{
lcd_wcmd(i++);
lcd_wcmd(0x88);
for(k = 0;k < 16;k++)
{
lcd_wdat(*ptr++);
}
}
lcd_wcmd(0x36); //打开绘图显示
lcd_wcmd(0x30); //回到基本指令集
}
main()
{
wela=0;
dula=0;
lcd_init(); //初始化LCD
Draw_PM(zhu); //显示可爱猪的图片
while(1);
} |