首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

液晶显示不了?附图及代码

液晶显示不了?附图及代码

ZbcMVoKh.gif


#include <reg52.h>
#include <absacc.h>
#include "intrins.h"

typedef unsigned int WORD;
typedef unsigned char BYTE;

sbit wdi=P1^7;
sbit lcd_bg=P1^6;
sbit en =P2^7; // 读\写使能
sbit rw =P2^6; // 读\写 选择
sbit di =P2^5; // 数据\指令 选择
sbit cs1 =P2^4; // 片选1,
sbit cs2 =P2^3; // 片选2,

//#define LCD12864DataPort P0

const BYTE CHAR_0[5]={0x3E,0x51,0x49,0x45,0x3E};

void port_ini(void)
{
cs1=1;
cs2=1;
_nop_();
_nop_();
en=1;
_nop_();
_nop_();
en=0;
_nop_();
_nop_();
}
void write_command( BYTE nByte )
{
rw=0;
di=0;
_nop_();
_nop_();
P0=nByte;
en=1;
_nop_();
_nop_();
en=0;
_nop_();
_nop_();
}
void write_char( BYTE nByte, BYTE CS11, BYTE CS22 )
{
if(CS11) cs1=1;
else cs1=0;

if(CS22) cs2=1;
else cs2=0;

di=1;
rw=0;

P0=nByte;
en=1;
_nop_();
_nop_();
en=0;
_nop_();
_nop_();

}
void clear_lcd( void )
{
BYTE i,j;
for(i=0;i<8;i++)
{
write_command(i|0xB8);
write_command(0x40);
for(j=0;j<128;j++)
{
if(j<=63) write_char(0,1,0);
else write_char(0,0,1);
_nop_();
}
}
}
void display_char( BYTE *chr, BYTE nRow, BYTE nCol )
{
BYTE i,tmpCol;

write_command(0xB8|nRow);
tmpCol=nCol;
for(i=0;i<5;i++)
{
if(tmpCol<=63)
{
write_command(0x40|tmpCol);
write_char(chr,1,0);
}
else
{
write_command(0x40|(tmpCol-64));
write_char(chr,0,1);
}
tmpCol++;
}
}

void delay()
{
BYTE m,n;
for(m=0;m<200;m++)
{
for(n=0;n<500;n++);
}
}


void main()
{
lcd_bg=0;
port_ini();
write_command(0xc0);
write_command(0x3f);
clear_lcd();
display_char((BYTE *)&CHAR_0[0],4,20);

while(1)
{
wdi=!wdi;
delay();
}

}

请大侠指教,哪儿出问题了

液晶有背光,但显示区一片黑


tiao beiguang

[em02]
返回列表