Discussion in "8051 Discussion Forum" started by    sufyan441    Aug 19, 2010.
Thu Aug 19 2010, 06:20 am
#1
Hi everyone.
Please help me in solving problem related to 8255 and LCD.
I have configured 8255 and the data pins of LCD are connected to Port A of 8255 and RS, WR, E connected to Port B.
Tell me what to do next when i send commands to LCD it does not work. With 8051 it works very well.
Many many thanks
Sufyan
Thu Aug 19 2010, 10:36 am
#2
hi,

If you know how to connect LCD to 8051, then you try this.
8255 is not bit addressable, So we have to send the commands in word type format like 0x05
(00000101) Rs and En selects.

here is small program where you can try out.
#include<reg51.h>

#include<string.h>

#include<absacc.h>

	
#define con_word XBYTE[0x4003]
#define port_a XBYTE[0x4000]
#define port_b XBYTE[0x4001]
#define port_c XBYTE[0x4002]
void set_mode_8255(unsigned char mode);
void write_code_to_lcd(unsigned char cmd_code);
void lcd_init(void);
void write_data_to_8255(unsigned char port, unsigned char byte);
void delay(unsigned int i);
void display_data_on_lcd(unsigned char *s);
void write_data_to_lcd(unsigned char disp_data);
void set_mode_8255(unsigned char mode)			   // initializing Ports of 8255
{
	switch (mode) 
	{
		case 0:
			con_word = 0x80;
		break;
	   	
		case 1:
			con_word = 0x88;
		break;		 
	}				  
}		   
		  
// command code for LCD
void write_code_to_lcd(unsigned char cmd_code)				
{
	unsigned char byte;

	byte = 0x04;
	write_data_to_8255('B', byte); //LCD_E=1; LCD_RW=0; LCD_RS=0; 
	
	byte = cmd_code;
	write_data_to_8255('A', byte);
	
	delay(1);
	
	byte = 0x00;
	write_data_to_8255('B', byte); //LCD_RW=0; LCD_RS=0; LCD_E=0;
	
	
}

void lcd_init(void)			 // LCD Initialization
{
	write_code_to_lcd(0x38);
	delay(1);
	write_code_to_lcd(0x0e);
	delay(1);
	write_code_to_lcd(0x01);
	delay(1);
	write_code_to_lcd(0x06);
	delay(1);
//	write_code_to_lcd(0x86);
	delay(1);
}
void write_data_to_8255(unsigned char port, unsigned char byte)
{

	switch (port) 
	{
		case 'A':
				port_a = byte;
		break;

		case 'B':
				port_b = byte;
		break;
	
	}
}
void display_data_on_lcd(unsigned char *s)
{
	while(*s >
 0)
	{
		write_data_to_lcd(*s++);
//		s++;
		//delay(20);
	}
}


void write_data_to_lcd(unsigned char disp_data)
{
	unsigned char byte;
	
	byte = 0x05;
	write_data_to_8255('B', byte); //LCD_RW=0; LCD_RS=1; LCD_E=1;
	
	byte = disp_data;
	write_data_to_8255('A', byte);
	
	delay(1);
	
	byte = 0x01;
	write_data_to_8255('B', byte); //LCD_RW=0; LCD_RS=1; LCD_E=0;
	
	}

void main()	   // Main function
{
	
	set_mode_8255(0); 
	lcd_init();
write_code_to_lcd(0x80);
display_data_on_lcd(" KIRANKUMAR ");
			delay(2);
}
 sufyan441 like this.
Thu Aug 19 2010, 10:40 am
#3
Connect your LCD data lines to Port A, and command line as follows.
RS-- PB0
E-- PB2
RW-- PB1.
Note:- You have change your port address according to your decoder logic.
 sufyan441 like this.
Thu Aug 19 2010, 05:41 pm
#4
Bro delay function definition is missing. tell me how much delay
Thu Aug 19 2010, 05:44 pm
#5
Code is working with 1 second delay. Many many thanks bro.
Regards
sufyan
Thu Aug 19 2010, 05:49 pm
#6
Dont just copy it.. try to build in your own logics which will retains for long days.
I have given for your reference.
Thu Aug 19 2010, 06:13 pm
#7
Ok Thanks. Yes you are right
Thu Aug 19 2010, 08:38 pm
#8
All is working perfect.
I used Y2 of 74138. Port A of 8255 is used for data and port B (RS,WR,E).The base address for 8255 in this case is 88Hex.
Code obtain from Kiran was changed a little. Below is code and schematic.
#include<reg52.h>
#include<string.h>
#include<absacc.h>

unsigned char xdata port_a _at_ 0x88;
unsigned char xdata port_b _at_ 0x89;
unsigned char xdata port_c _at_ 0x8A;
unsigned char xdata con_word _at_ 0x8B; //connected to Y2
/*
unsigned char xdata P8255_PG _at_ 0x8C;
unsigned char xdata P8255_PH _at_ 0x8D;
unsigned char xdata P8255_PI _at_ 0x8E;
unsigned char xdata P8255_GHI_config _at_ 0x8F; //connected to Y3

unsigned char xdata P8255_PG _at_ 0x90;
unsigned char xdata P8255_PH _at_ 0x91;
unsigned char xdata P8255_PI _at_ 0x92;
unsigned char xdata P8255_GHI_config _at_ 0x93; //connected to Y4

unsigned char xdata port_a _at_ 0x4000;
unsigned char xdata port_b _at_ 0x4001;
unsigned char xdata port_c _at_ 0x4002;
unsigned char xdata con_word _at_ 0x4003; //connected to Y2
*/
void set_mode_8255(unsigned char mode);
void write_code_to_lcd(unsigned char cmd_code);
void lcd_init(void);
void write_data_to_8255(unsigned char port, unsigned char byte);
void delay(unsigned int i);
void display_data_on_lcd(unsigned char *s);
void write_data_to_lcd(unsigned char disp_data);
void set_mode_8255(unsigned char mode) // initializing Ports of 8255
{
switch (mode)
{
case 0:
con_word = 0x80; //all ports are output ports
break;

case 1:
con_word = 0x90; //Port a input and port b and port c are output
break;
}
}

// command code for LCD
void write_code_to_lcd(unsigned char cmd_code)
{
unsigned char byte;

byte = 0x04;
write_data_to_8255('B', byte); //LCD_E=1; LCD_RW=0; LCD_RS=0;

byte = cmd_code;
write_data_to_8255('A', byte);

delay(1);

byte = 0x00;
write_data_to_8255('B', byte); //LCD_RW=0; LCD_RS=0; LCD_E=0;


}

void lcd_init(void) // LCD Initialization
{
write_code_to_lcd(0x38);
delay(1);
write_code_to_lcd(0x0C);
delay(1);
write_code_to_lcd(0x01);
delay(1);
write_code_to_lcd(0x06);
delay(1);
}
void write_data_to_8255(unsigned char port, unsigned char byte)
{

switch (port)
{
case 'A':
port_a = byte;
break;

case 'B':
port_b = byte;
break;

}
}
void display_data_on_lcd(unsigned char *s)
{
while(*s)

write_data_to_lcd(*s++);
}


void write_data_to_lcd(unsigned char disp_data)
{
unsigned char byte;

byte = 0x05;
write_data_to_8255('B', byte); //LCD_RW=0; LCD_RS=1; LCD_E=1;

byte = disp_data;
write_data_to_8255('A', byte);

delay(1);

byte = 0x01;
write_data_to_8255('B', byte); //LCD_RW=0; LCD_RS=1; LCD_E=0;

}

void delay(unsigned int i)
{
unsigned int x,y;
for(x=0;x<i;x++)
for(y=0;y<1275;y++);
}

void main() // Main function
{

set_mode_8255(0);
lcd_init();
write_code_to_lcd(0x80);
display_data_on_lcd(" 8255_LCD ");
delay(2);
}

Regards
Sufyan

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

KevinTab
Sun Apr 28 2024, 05:35 am
Tumergix
Sun Apr 28 2024, 12:59 am
StevenDrulk
Sat Apr 27 2024, 08:47 pm
StephenHauct
Sat Apr 27 2024, 09:38 am
Adamsaf
Sat Apr 27 2024, 07:12 am
Robertphype
Sat Apr 27 2024, 12:23 am
ktaletrryp
Fri Apr 26 2024, 10:55 pm
Robertrip
Fri Apr 26 2024, 11:20 am