Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Help with 89C51, 8255 and LCD

Status
Not open for further replies.

jawadlateef

New Member
Hi all
sorry to disturb you guys again.
please solve my little query regarding 89C51 and 8255 interfacing.

below is the code which i am using with the ckt attached.

1. plz tell me whether i need external pull up for port 0 of the controller for interfacing with 8255 and i think i dont need it for RAM 6264 as i saw in a book Scott MacKenzie's.

2. Is there any fault in the circuit you see plzz do mention it.

3. I want to drive LCD and later want to attach a keypad too. plzz help if you have any other code or suggestions.

i have tried alot but no result used the same LCD with other circuits and is fine but no result in this one.
Used 8255 as memory mapped IO even tried in assembly but no outcome.

Thanx alot in any event.




#include <REG52.H> /* special function register declarations */
/* for the intended 8051 derivative */
#include <intrins.h>
#include <stdio.h>
#include <string.h>

#define _8255_BASE_ADDR 0x8000

typedef unsigned char uchar_t;
typedef unsigned int uint_t;

uchar_t xdata _8255_mod _at_ _8255_BASE_ADDR + 0x3;
uchar_t xdata _8255_prt_a _at_ _8255_BASE_ADDR + 0x0;
uchar_t xdata _8255_prt_b _at_ _8255_BASE_ADDR + 0x1;
uchar_t xdata _8255_prt_c _at_ _8255_BASE_ADDR + 0x2;

void write_data_to_8255(uchar_t port, uchar_t *byte)
{
uchar_t control_reg = 0;

control_reg = _8255_mod;

switch (port) {
case 'A':
control_reg &= 0xEF;
_8255_mod = control_reg;
_8255_prt_a = *byte;
break;
case 'B':
control_reg &= 0xFD;
_8255_mod = control_reg;
_8255_prt_b = *byte;
break;
case 'C':
control_reg &= 0xF7;
_8255_mod = control_reg;
_8255_prt_c = *byte;
break;
}
}

void read_data_from_8255(uchar_t port, uchar_t *byte)
{
uchar_t control_reg = 0;

control_reg = _8255_mod;

switch (port) {
case 'A':
control_reg |= 0x10;
_8255_mod = control_reg;
*byte = _8255_prt_a;
break;
case 'B':
control_reg |= 0x02;
_8255_mod = control_reg;
*byte = _8255_prt_b;
break;
case 'C':
control_reg |= 0x09;
_8255_mod = control_reg;
*byte = _8255_prt_c;
break;
}
}

void set_mode_8255(uchar_t mode)
{
switch (mode) {
case 0:
_8255_mod = 0x80;
break;

/* FIXME: add code for handling below modes, not needed for now */
case 1:
case 2:
break;
}
}

void delay(uint_t t)
{
uint_t i, j;
for(i=0;i<t;i++)
for(j=0;j<10;j++)
_nop_ ();
}

void write_code_to_lcd(uchar_t cmd_code)
{
uchar_t byte;

byte = 0x80;
write_data_to_8255('C', &byte); //LCD_RW=0; LCD_RS=0; LCD_E=1;

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

delay(5);

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

delay(5);
}

void write_data_to_lcd(uchar_t disp_data)
{
uchar_t byte;

byte = 0xA0;
write_data_to_8255('C', &byte); //LCD_RW=0; LCD_RS=1; LCD_E=1;

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

delay(5);

byte = 0x20;
write_data_to_8255('C', &byte); //LCD_RW=0; LCD_RS=0; LCD_E=0;

delay(5);
}

void display_data_on_lcd(uchar_t code *s)
{
while(*s > 0)
{
write_data_to_lcd(*s);
s++;
delay(50);
}
}

void lcd_init(void)
{
delay(2000);
write_code_to_lcd(0x38);
delay(50);
write_code_to_lcd(0x0c);
delay(50);
write_code_to_lcd(0x01);
delay(50);
write_code_to_lcd(0x06);
delay(50);
}

/*------------------------------------------------
The main C function. Program execution starts
here after stack initialization.
------------------------------------------------*/
void main (void)
{
uchar_t byte;

set_mode_8255(0);

byte = 0x15;
write_data_to_8255('C', &byte);

byte = 0x74;
write_data_to_8255('A', &byte);

byte = 0xf3;
write_data_to_8255('B', &byte);


// byte = 0x00;
// write_data_to_8255('C', &byte);
//
// lcd_init();
//
// write_code_to_lcd(0x84);
//
// display_data_on_lcd("Alhamdollilah");
//
// write_code_to_lcd(0xc1);
//
// display_data_on_lcd("Akhir chal pari");

while(1);
}
 

Attachments

  • ckt.JPG
    ckt.JPG
    205 KB · Views: 802
I don't think people use such ancient parts these days?, as you're mentioning RAM presumably you're talking about a micro-processor based system, rather than a microcontroller?. The 8255 was never a very good PIO either, limited and difficult to use, the 6522 was a much more sensible device.
 
jawadlateef said:
atleast tell me do i need pull ups resisitor with RAM and 8255 on Port 0.
thanx
hi,
Looking thru your circuit I cannot see why you would require pullups to the 8255.

Long ago, I have used the 8255 many times in Z80 based units driving the Hitachi LCD controller, never had a problem with them.
Replaced them in new designs with the Z84C90.

As you have asked the question, I expect you are having a problem driving the display, ????
Perhaps you should tell us whats the problem.:)
 
Muhammad Zubair Bhamani

ericgibbs said:
hi,
Looking thru your circuit I cannot see why you would require pullups to the 8255.

Long ago, I have used the 8255 many times in Z80 based units driving the Hitachi LCD controller, never had a problem with them.
Replaced them in new designs with the Z84C90.

As you have asked the question, I expect you are having a problem driving the display, ????
Perhaps you should tell us whats the problem.:)


hi,
i am the group member of Jawad Lateef, and he is actually asking will he be requiring any pull -ups resistors at the port 0 of AT89C51 and not asking for the pull -ups at 82C55, please correct, and tell us will we be requiring any pull- ups resistors at port 0 of 89C51.....
Thanx
with regards,
Muhammad Zubair Bhamani
 
muzubair said:
hi,
i am the group member of Jawad Lateef, and he is actually asking will he be requiring any pull -ups resistors at the port 0 of AT89C51 and not asking for the pull -ups at 82C55, please correct, and tell us will we be requiring any pull- ups resistors at port 0 of 89C51.....
Thanx
with regards,
Muhammad Zubair Bhamani

hi,
The AT89C52 is a device I do not normally use, however I have read the datasheet and from the following extract I would conclude that PORT0 will not require pullups. IF it is configured as described in the extract, paragraph #2

IF you are designing a PCB layout, it would be an easy task to include the copper pads for a 9 pin SILR [+v and 8*10K].
This would give you the option for the pullups if the Vhi levels are lower than expected.

Hope this is helpful.
 
Last edited:
I don't remember where I found this but it helped me.
Using an 8255 PPI chip
Well I had the hardest time getting one of this chips to work so I thought I'd post some information on how to use the chip (namely what I was doing wrong).
When working with these chips it is very handy to have a white paper (data sheet) in your hand:
8255A.PDF
Mode 0
Since my application was working with all outputs, I'll assume we're going to work in Mode 0. The basic steps needed to get one of these chips initialized are:
1. power on
2. reset the 8255 using the RESET pin
3. set the write pin (WR) high
4. put the control word on the data bus (selects the Mode)
5. set A0 and A1 pins high
6. set the write pin (WR) low for a very short duration, keeping A0 & A1 high
7. set the write pin (WR) high again
When step seven happens, it causes the chip to "take note" of the data bus and pins A0 & A1. When both of the Ax pins are high, the 8255 knows that the data present on the data bus is a control word and from that data, it goes into the appropriate mode. You only have to do the above seven steps once (on power up), unless one wishes to reset the chip during operation. Then just start from step 2 (since you already have power to the chip). Please note that when an 8255 is reset, all three of it's ports go into input mode.
Now that the chip is initialized, the steps to use it are as follows:
1. set A0 & A1 to what 8255 port (A, B, or C) you want to work with
2. make the data bus look like what you want the 8255 port you're working with to look like (highs and lows)
3. set the write pin (WR) low for a very short duration
4. set the write pin (WR) high again
5. go back to step one
Please note that we are assuming 8255 mode 0 here (all three 8255 ports are outputs). One needs to keep the write pin (WR) high at all times until you're ready to "program" the chip. This is where I messed up. I left WR high all the time, assuming that would keep the 8255 in 'write' mode. It needs to go from high to low and back to high in order to 'program' the chip.
 
programming 8255 ic using parallel port

hi guys
i am trying to program the 8255 IC through parallel port using assembly language.....when i send the data it reaches at the out put of parallel port.....i have initialized the 8255 IC using address 37A..........when i send data i see nothing on the leds connected to the ports of 8255 IC.......plz help me to tell what the problem is? am i not properly initializing the 8255 IC or there some other problem.......tell me as soon as possible
thanks
 
The most important part is the initialization sequence and making sure it has time to initialize.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top