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 of 8051 with 8255a

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.. I am connected ppi 8255a with 8051 on address of 4000h . How can i write the control word for 8255a in c programming?
Thanks in advance.:)hi.. I am connected ppi 8255a with 8051 on address of 4000h . How can i write the control word for 8255a in c programming?
Thanks in advance.:)
 

Before write to the control register of 8255, set the A0 = 1 and A1 = 1 then send the data to D0-D7. Sometime this may be 4003H based on your circuit diagram.
 

CODE:

xdata[4003]=0x9b;

But keil shows the below error,

syntax error near '['

Tanks in advance..:)
 

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

MY CODING:

//Program to make a digital thermometer with display in centigrade scale


Code C++ - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#include<reg51.h>
#include<absacc.h>
#define port P1
#define sec 100
 
char xdata lcdctr _at_ 0x4001;        //8255 ppi 1 portB for sending control signal to lcd
 
char xdata adc_input _at_ 0x8000;   // adc data connected to portA of 8255 ppi 2
char xdata dataport _at_ 0x4000;     // 8255 ppi 1 portA for sending data to lcd
 
 
unsigned char xdata[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[i]!='\0')
{
  lcd_data(str[i]);
  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[i]=adc_input/10;
    delay(1);
    intr=1;
   }
   for(i=0;i<10;i++)
   test_intermediate2[j]=test_intermediate1[i]+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 by a moderator:

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


unsigned char xdata[0x4003]==0x83;

The first 3 lines are wrong. If you want to declare a variable at some absolute address you have to use something like this

char xdata _at_ 0x4001;

In your declaration how does the compiler interpret space between xdata and lcdctr?

And in unsigned char xdata[0x4003] == 0x83; which is wrong because 0x4003 = d16387. So it created an array named xdata of 16387 elements and you are assigning only one value to the array and you are using == instead of =. In array initialization you have to initialize all the elements of the array.

You should use something like

char xdata _at_ 0x4001; which will create variable xdata at address 0x4001.

I don't know much about 8051 but in mikroE Compiler we use something like

unsigned char readbuff[64] absolute 0x500;
unsigned char writebuff[64] absolute 0x540;

It created an array of type unsigned char of 64 bytes starting at the addresses mentioned.

This might help you. https://sites.google.com/site/controlandelectronics/interface-lcd-with-8051-using-8255-pia
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top