在用Proteus中的LCD1602运行一个程序时,无显示,但该程序在C51开发板上实物运行OK,这是怎么回事?(排除RS、RW、E及I\O口PIN脚定义、使用问题,因为运行仿真其它程序是OK的)
程序如下:
//lcd1602 drive program for 51 mcu
// 信利MCC162A4-5屏 牛屎的,驱动IC不知
#include "reg52.h"
#define LINE1 0
#define LINE2 1
#define LINE1_HEAD 0x80
#define LINE2_HEAD 0xC0
#define LCD_DELAY_TIME 40
#define DATA_MODE 0x38
#define OPEN_SCREEN 0x0C
#define DISPLAY_ADDRESS 0x80
#define CLEARSCREEN LCD_en_command(0x01)
/*******************************************************************/
//change this part at different board
#define LCDIO P0
sbit LCD1602_RS=P2^4; //data command select 1 data 0 command pin 4
sbit LCD1602_RW=P2^3; //read write select 1 read 0 write pin 5
sbit LCD1602_EN=P2^2; //LCD enable signal pin 6
/********************************************************************/
void LCD_delay(void);//lcd delay
void LCD_en_command(unsigned char command);//write command
void LCD_en_dat(unsigned char temp);//write data
void LCD_set_xy( unsigned char x, unsigned char y );//set display address
void LCD_write_char( unsigned x,unsigned char y,unsigned char dat);//write lcd a character
void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s);//write lcd string
void LCD_init(void);//lcd initize
void delay_nms(unsigned int n);//delay
/************************************************************************/
void main(void)
{
LCD_init();
while(1)
{
CLEARSCREEN;
delay_nms(2);
LCD_write_string(0,LINE1,"Wellcome to here ");
LCD_write_string(0,LINE2,"www.amobbs.com");
delay_nms(500);
CLEARSCREEN;
delay_nms(2);
LCD_write_string(0,LINE1," lcd test ");
LCD_write_string(0,LINE2," successful! ");
delay_nms(500);
CLEARSCREEN;
delay_nms(2);
LCD_write_string(0,LINE1," I'm amobbs.com ");
LCD_write_string(0,LINE2," Thank You! ");
delay_nms(500);
}
}
/********************************************************************/
/******************** LCD PART *************************************/
void LCD_delay(void)
{
unsigned char i;
for(i=LCD_DELAY_TIME;i>0;i--) //be sure lcd reset
;
}
/********************************************************************/
void LCD_en_command(unsigned char command)
{
LCDIO=command;
LCD1602_RS=0;
LCD1602_RW=0;
LCD1602_EN=0;
LCD_delay();
LCD1602_EN=1;
}
/********************************************************************/
void LCD_en_dat(unsigned char dat)
{
LCDIO=dat;
LCD1602_RS=1;
LCD1602_RW=0;
LCD1602_EN=0;
LCD_delay();
LCD1602_EN=1;
}
/********************************************************************/
void LCD_set_xy( unsigned char x, unsigned char y )
{
unsigned char address;
if (y == LINE1)
address = LINE1_HEAD + x;
else
address = LINE2_HEAD + x;
LCD_en_command(address);
}
/********************************************************************/
void LCD_write_char( unsigned x,unsigned char y,unsigned char dat)
{
LCD_set_xy( x, y );
LCD_en_dat(dat);
}
/********************************************************************/
void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s)
{
LCD_set_xy( X, Y ); //set address
while (*s) // write character
{
LCDIO=*s;
LCD_en_dat(*s);
s ++;
}
}
/********************************************************************/
void LCD_init(void)
{
CLEARSCREEN;//clear screen
LCD_en_command(DATA_MODE);//set 8 bit data transmission mode
LCD_en_command(OPEN_SCREEN);//open display (enable lcd display)
LCD_en_command(DISPLAY_ADDRESS);//set lcd first display address
CLEARSCREEN;//clear screen
}
/********************************************************************/
/*********************** OTHER PART *********************************/
void delay_nms(unsigned int n)
{
unsigned int i=0,j=0;
for (i=n;i>0;i--)
for (j=0;j<1140;j++);
}
|