Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

C programming for 8051 to use 8255 PPI?

Status
Not open for further replies.

logukalipal

Junior Member level 2
Joined
Jan 8, 2012
Messages
21
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Coimbatore, India
Activity points
1,476
Hi...!

Beginner's voice: I want to set portA of 8255 is O/P in mode 0 to 8051.
So i need write hex code(0x83) to control register( 0x4003) of 8255 ppi ,
how can I achieve this in c language?

I use keil as assembler.

My error code:

xdata[0x4003]=0x83;

But keil shows the below error,

syntax error near '['

Thanks in advance..
 

Yes jayanth sir, and I also Thanks to u a lot..:)

i read that but in that paper they dont assign value to control word of 8255 ppi.
so while simulating defaultly 8051 take as PORT A,B,C of 8255 as INPUT.

But I need 1 port as Output. So i need to assign control word..

So my question is:

I want to set portA of 8255 is O/P in mode 0 to 8051.
So i need write hex code(0x83) to control register( 0x4003) of 8255 ppi ,
how can I achieve this in c language?

I use keil as assembler.

My error code:

xdata[0x4003]=0x83;

But keil shows the below error,

syntax error near '['

Thanks in advance..
 

Post your Circuit. To write the control word to 8255 you have to first make CS and WR pins low and A0 and A1 selects the PORTS or Control Words. In the link I gave PORTA of 8255 is connected to LCD and hence it is used a output port.
 
I checked that conditions and my code and circuit satisfy that.

I think you are telling problem about while simulate in proteus.
(i.e) The c program executed in keil and got hex file.

In that link where u assign the value for ControlWord of 8255 to work portA as O/P
and also control signals for LCD is given by portB. it also used as O/P.,

The code in that link does not contain assigning of the control words to set operation mode of 8255 which define the ports to work as I/P or O/P.
 

Attachments

  • 8255+LCD+keypad+TEMP1234 schematic.PDF
    72.4 KB · Views: 84

char xdata dataport _at_ 0x4000; // this make a0 a1 as low to select port a of 8255

dataport=0x23; // this is writing operation to porta of 8255
 

I don't know 8051. Can you explain how this statement works? char xdata dataport _at_ 0x4000; // this make a0 a1 as low to select port a of 8255. I think 0x4000 is some address in 8051 memory.
 
xdata represents external memory. so ppi memory mapped with 8051 at 4000H (exmple).
4000H represents portA of 8255.. A0A1 are 00
4001H represents portB of 8255..A0A1 are 01
4002 represents portC of 8255.. A0A1 are 10
4003 represents control word of 8255.. A0A1 are 11
 

I want to set portA of 8255 as O/P port in mode 0 to 8051.

So to make above one i have to put the corresponding hex code(0x83) to control register( 0x4003) of 8255 ppi ,
how can I achieve this in embedded c language(I know C only I have problem with accessing 8255 ports)?

I use keil as IDE tool.

#My error code:

xdata[0x4003]=0x83; // write hex value to control word of 8255

But keil shows the below error,

syntax error near '['

Thanks in advance..

- - - Updated - - -

In below link example C programs are there to access 8255a ,But I used the same , i got error in keil.

https://what-when-how.com/8051-microcontroller/8051-c-programming-for-the-8255/
 

I think you write control word to 8255 through its data lines D0-D7, right? Then why don't you make CS, WR, A0, A1 pins low and then send the control word to 8255? Post the absacc.h file mentioned in that code.

You have to send the control word 0x80 and not 0x83 to make PORTA output.

Edit:

I have written a code for 8255 PPI. Check it and use it in your code. If you have any problem then let me know. The control word is written first to set mode 0 and porta as output for 8255 and then data is written for 8255.
 

Attachments

  • 8051 8255.rar
    56.5 KB · Views: 58
Last edited:
First of all I want to thank a lot to You sir..:)

We use The PPI 8255(programmable peripheral interface) for expansion of I/O ports of 8051.
So PPI interfaced with 8051 is memory mapped interfacing(i.e accessing one ppi using address at a time among many others ) in this method only we can interface many 8255 ics(ex: 10/15). Then only we accesss many sensors ,adc, displays...etc

You are interfaced directly to MCU. I want to say again thank a lot.:smile:

Now i cleared that assigning command word problem but i encountered new problem that is linking error in Keil.

Keil shows the below error.

_________________________________

compiling tmpmdfy.c...
linking...
*** ERROR L107: ADDRESS SPACE OVERFLOW
SPACE: XDATA
SEGMENT: ?XD?TMPMDFY
LENGTH: 8006H
*** ERROR L105: PUBLIC REFERS TO IGNORED SEGMENT
SYMBOL: G
SEGMENT: ?XD?TMPMDFY
Program Size: data=50.0 xdata=32777 code=954
Target not created

___________________________________

Below code is little part of my project.


#include<reg51.h>
#include<string.h>
#include<absacc.h>
#define port P1
#define sec 100

char xdata lcdctr _at_ 0x4001;

char xdata adc_input _at_ 0x8000;
char xdata dataport _at_ 0x4000;

xdata g[0x4003]=0x83;


//sbit rs = port^0;
//sbit rw = port^1;
//sbit e = port^2;

sbit wr= port^0;
sbit rd= port^1;
sbit intr= port^2;

int test_intermediate3=0, test_final=0,test_intermediate1[10],test_intermediate2[3]={0,0,0};

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

void lcd_cmd(unsigned char item) //Function to send command to LCD
{
dataport = item;
lcdctr=0x04;
//rs= 0;
//rw=0;
//e=1;
delay(1);
lcdctr=0x00;
//e=0;

return;
}

void lcd_data(unsigned char item) //Function to send data to LCD
{
dataport = item;
lcdctr=0x05;
//rs= 1;
//rw=0;
//e=1;
delay(1);
lcdctr=0x01;
//e=0;
//delay(100);
return;
}

void lcd_data_string(unsigned char *str) // Function to send string to LCD
{
int i=0;
while(str!='\0')
{
lcd_data(str);
i++;
delay(10);
}
return;
}

void shape() // Function to create the shape of degree
{
lcd_cmd(64);
lcd_data(2);
lcd_data(5);
lcd_data(2);
lcd_data(0);
lcd_data(0);
lcd_data(0);
lcd_data(0);
lcd_data(0);
}

void convert() // Function to convert the values of ADC into numeric value to be sent to LCD
{
int s;
test_final=test_intermediate3;
lcd_cmd(0xc1);
delay(2);
lcd_data_string("TEMP:");
s=test_final/100;
test_final=test_final%100;
lcd_cmd(0xc8);
if(s!=0)
lcd_data(s+48);
else
lcd_cmd(0x06);
s=test_final/10;
test_final=test_final%10;
lcd_data(s+48);
lcd_data(test_final+48);
lcd_data(0);
lcd_data('c');
lcd_data(' ');
delay(2);
}

void main()
{
int i,j;
//adc_input=0xff; ////////////
lcd_cmd(0x38);
lcd_cmd(0x0c); //Display On, Cursor Blinking
delay(2);
lcd_cmd(0x01); // Clear Screen
delay(2);

while(1)
{
for(j=0;j<3;j++)
{
for(i=0;i<10;i++)
{
delay(1);
rd=1;
wr=0;
delay(1);
wr=1;
while(intr==1);
rd=0;
lcd_cmd(0x88);
test_intermediate1=adc_input/10;
delay(1);
intr=1;
}
for(i=0;i<10;i++)
test_intermediate2[j]=test_intermediate1+test_intermediate2[j];
}

test_intermediate2[0]=test_intermediate2[0]/3;
test_intermediate2[1]=test_intermediate2[1]/3;
test_intermediate2[2]=test_intermediate2[2]/3;
test_intermediate3=test_intermediate2[0]+test_intermediate2[1]+test_intermediate2[2];
shape();
convert();
}
}
 

Last edited:
Thank you Bro...That link is very useful for me..:)

In 8051 while using port 0 as

1.) I/O port,it is need to use pull up resisters for port0

2.) addressdata port, No need to use pull up resisters for port0..

I will try out.If any problem I will post here..
thanks a lot again..:)
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top