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

[求助]1602LCD显示不正常

[求助]1602LCD显示不正常

以前用过1602液晶,但是昨天重新写了一定程序,结果我要显示的字母都显示在第一行的第一个位置,光标就是不往后移动,大家给看看是哪出毛病了。郁闷...

#define LCD_DATA_PORT PC
#define LCD_DATA_PORT_DIR PCC
#define LCD_CONTRL_PORT PB
#define LCD_CONTRL_PORT_DIR PCB

#define RS 0x01
#define RW 0x02
#define E 0x04
#define BUSY 0x80

void Dealay6502 (void) { //延时
BYTE i,j;
for (i=0;i<255;i++){
for (j=0;j<20;j++);
}
}


void ReadStatus (void){ / /判忙程序

BYTE Pcstate;

do {
LCD_DATA_PORT_DIR = 0; //数据端口输入
LCD_DATA_PORT = 0xff;

LCD_CONTRL_PORT &= ~RS;
LCD_CONTRL_PORT |= RW;

LCD_CONTRL_PORT &= ~E;
Dealay6502();

LCD_CONTRL_PORT |= E;
Pcstate = PC;

}while (Pcstate & BUSY);

LCD_DATA_PORT_DIR = 0xff;
//return 0;

}

void WriteLcdData (BYTE data){ //写数据

ReadStatus();

LCD_DATA_PORT = data;

LCD_CONTRL_PORT |= RS;
LCD_CONTRL_PORT &= ~RW;
Dealay6502();
LCD_CONTRL_PORT &= ~E;
Dealay6502();
LCD_CONTRL_PORT |= E;

}

void WriteLcdCommand (BYTE command) { //写命令

ReadStatus();

LCD_DATA_PORT = command;

LCD_CONTRL_PORT &= ~RS;
LCD_CONTRL_PORT &= ~RW;
Dealay6502();
LCD_CONTRL_PORT &= ~E;
Dealay6502();
LCD_CONTRL_PORT |= E;

}

void InitDisplay( void ) {

LSEL &= 0xe0; //PB&C used as nomal I/O port
PMCR |= 0x80;

LCD_CONTRL_PORT |= E;
WriteLcdCommand (0x01); //clear display
Dealay6502();
WriteLcdCommand (0x38); //2 lines display,5*7 pix
Dealay6502();
WriteLcdCommand (0x0f); //display on,cursor off,glint off
Dealay6502();
WriteLcdCommand (0x06); //cursor shift to right,text no shift
Dealay6502();

WriteLcdCommand (0x80); //send addr

WriteLcdData (0x41); //send data'A'

WriteLcdData (0x42); //send data'B'

WriteLcdData (0x43); //send data'C'

WriteLcdData (0x44); //send data'D'

}

初始化程序要在第一行的第一个到第四个位置依次显示'A' 'B' 'C' 'D',结果四个字母都显示在第一个位置上,不知道为什么,大家帮帮忙吧,郁闷死了。

[em06][em06][em06]

void InitDisplay( void ) {

LSEL &= 0xe0; //PB&C used as nomal I/O port
PMCR |= 0x80;

LCD_CONTRL_PORT |= E;

WriteLcdCommand (0x38); //2 lines display,5*7 pix
Dealay6502();

WriteLcdCommand (0x38); //2 lines display,5*7 pix
Dealay6502();
WriteLcdCommand (0x38); //2 lines display,5*7 pix
Dealay6502();

WriteLcdCommand (0x0f); //display on,cursor off,glint off
Dealay6502();
WriteLcdCommand (0x06); //cursor shift to right,text no shift
Dealay6502();

WriteLcdCommand (0x01); //clear display
Dealay6502();

WriteLcdCommand (0x80); //send addr

WriteLcdData (0x41); //send data'A'

WriteLcdData (0x42); //send data'B'

WriteLcdData (0x43); //send data'C'

WriteLcdData (0x44); //send data'D'

}

还有个问题就是C语言的没主函数能成么?

返回列表