8255 PPI Problem [8051 and 8255 LCD, ADC]

Status
Not open for further replies.
Joined
Dec 4, 2012
Messages
4,280
Helped
822
Reputation
1,654
Reaction score
791
Trophy points
1,393
Location
Bangalore, India
Visit site
Activity points
0
I have written a code for 8255 PPI but I am having three problems.

1. In the code comment out all code inside the while(1) loop and un-comment lcd_string(*msg); which is before while(1) loop and Compile and run.

LCD displays proper string if there is no character repeated i.e., string "EDABOARD" is printed as EDABOARD but "8255 PPI" is printed as 825 P I (as 2nd 5 and 2nd P is repeated)

2. If anything is printed on LCD then I can't print new data on LCD again.

3. ADC read has some problem and it is giving wrong value and INTR pin has logic contentions.

I hope somebody can solve the problems.

Code


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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
//MCU        89C51
//Fosc       11.0592 MHz
//Author     Jayanth Devarayanadurga
 
#include <REGX51.H>
 
sbit _RD = P2^7;
sbit _WR = P2^6;
sbit _A0 = P2^5;
sbit _A1 = P2^4;
sbit _CS = P2^3;
sbit INTR = P3^7;
#define DATA P1
 
void write_controlword(unsigned char data_);
void write_data(unsigned char data_, unsigned char A0, unsigned char A1);
void read_data(unsigned char A0, unsigned char A1);
void Delay_ms(unsigned mstime);
void lcd_init();
void lcd_cmd(unsigned char lcd_cmd);
void lcd_data(unsigned char lcd_data);
void lcd_string(unsigned char *lcd_str);
void adc_conv();
void adc_read();
 
 
unsigned char data_ = 0x00;
unsigned int adc_val = 0;
unsigned char str_adc_val[5];
unsigned char msg[] = "8055 PPI";
 
void main() {
    
        P1 = 0x00;
        P2 = 0x00;
        P3 = 0x00;
    
        write_controlword(0x90);
        lcd_init();
        lcd_cmd(0x80);
        //lcd_string(&msg);
        
        while(1) {
            
                
                adc_conv();
                adc_read();
                str_adc_val[0] = adc_val/100 + 48;
                str_adc_val[1] = (adc_val/10)%10 + 48;
                str_adc_val[2] = (adc_val/1)%10 + 48;
                lcd_string(&str_adc_val);
                
                
            
        }
}   
 
void write_controlword(unsigned char data_){
    _CS = 0;
    _RD = 1;
    _WR = 1;
    DATA = data_;
    _A0 = 1;
    _A1 = 1;
    _WR = 0;
    _WR = 1;
    
}
 
//PORTB Select A0 = 1, A1 = 0;
 
void write_data(unsigned char data_, unsigned char A0, unsigned char A1){
    _CS = 0;
    _RD = 1;    
    _A0 = A0;
    _A1 = A1;
    DATA = data_;
    _WR = 0;
    _WR = 1;
            
            
}
 
 
void read_data(unsigned char A0, unsigned char A1){
    _CS = 0;
    _WR = 1;
    _A0 = A0;
    _A1 = A1;
    _RD = 0;
    _RD = 1;
    
    //Data on 8255A PPI PORTA is placed on DATAPORT connected to 8051
                        
}
 
void MSDelay(unsigned mstime){
            unsigned int i, j;
    
            for(i=0;i<mstime;i++);
                for(j=0;j<1275;j++);
}   
 
void lcd_cmd(unsigned char lcd_cmd){
    write_controlword(0x90);        //8255 PPI PORTA Input, PORTB and PORTC Output, Mode 0
    write_data(lcd_cmd, 1, 0);  //8255 PPI PORTB Selected with LCD CMD value
    write_controlword(0x70);        //LCD RS = 0
    write_controlword(0x72);        //LCD RW = 0
    write_controlword(0x75);        //LCD EN = 1
    MSDelay(1);
    write_controlword(0x74);        //LCD EN = 0
}
 
void lcd_data(unsigned char lcd_data){
    write_controlword(0x90);
    write_data(lcd_data, 1, 0);
    write_controlword(0x71);        //LCD RS = 1
    write_controlword(0x72);        //LCD RW = 0
    write_controlword(0x75);        //LCD EN = 1
    MSDelay(1);
    write_controlword(0x74);        //LCD EN = 0
}
 
void lcd_init(){
  lcd_cmd(0x0E);                            //display and cursor ON. Writing 0x0F makes the cursor blink
  MSDelay(15);                              //delay
  lcd_cmd(0x01);                            //Clear LCD
  MSDelay(15);
  lcd_cmd(0x06);                            //shift the cursor to right
  MSDelay(15);
  lcd_cmd(0x0C);                            //Cursor OFF
  MSDelay(15);
  lcd_cmd(0x80);                            //line 1, position 0
  MSDelay(1);
}
 
void lcd_string(unsigned char *lcd_str){
        while(*lcd_str){
                    lcd_data(*lcd_str++);
                    MSDelay(5);
        }           
}
 
void adc_conv(){
 
    write_controlword(0x90);        
    write_controlword(0x78);            //adc CS = 0
    write_controlword(0x7C);            //adc WR = 0
    write_controlword(0x7D);            //adc WR = 1
    write_controlword(0x79);            //adc CS = 1
    while(INTR);
        //ADC Conversion completes
    
}
 
void adc_read(){
    
    //write_controlword(0x90);
    write_controlword(0x78);            //adc CS = 0
    write_controlword(0x7A);            //adc RD = 0
    //write_controlword(0x90);
    read_data(0,0);
    adc_val = DATA;                             //ADC value at P1 is assigned to adc_val
    write_controlword(0x7B);            //adc RD = 1
    write_controlword(0x79);            //adc CS = 1
    
}



Edit:

I have modified the code a little and the Logic Contention is gone but adc is giving a value of 127 instead of 255.

New Code


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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
//MCU        89C51
//Fosc       11.0592 MHz
//Author     Jayanth Devarayanadurga
 
#include <REGX51.H>
 
sbit _RD = P2^7;
sbit _WR = P2^6;
sbit _A0 = P2^5;
sbit _A1 = P2^4;
sbit _CS = P2^3;
sbit INTR = P3^7;
#define DATA P1
 
void write_controlword(unsigned char data_);
void write_data(unsigned char data_, unsigned char A0, unsigned char A1);
void read_data(unsigned char A0, unsigned char A1);
void Delay_ms(unsigned mstime);
void lcd_init();
void lcd_cmd(unsigned char lcd_cmd);
void lcd_data(unsigned char lcd_data);
void lcd_string(unsigned char *lcd_str);
void adc_conv();
void adc_read();
 
 
unsigned char data_ = 0x00;
unsigned int adc_val = 0, old_val = 0;
unsigned char str_adc_val[5];
unsigned char msg[] = "8055 PPI";
 
void main() {
    
        P1 = 0x00;
        P2 = 0x00;
        P3 = 0x80;
    
        write_controlword(0x90);
        lcd_init();
        lcd_cmd(0x80);
        //lcd_string(&msg);
        
        while(1) {
            
                
                adc_conv();
                adc_read();
                P1 = 0x00;
                if(adc_val != old_val){
                            lcd_cmd(0x01);
                            lcd_cmd(0x80);
                            str_adc_val[0] = adc_val/100 + 48;
                            str_adc_val[1] = (adc_val/10)%10 + 48;
                            str_adc_val[2] = (adc_val/1)%10 + 48;
                            str_adc_val[3] = '\0';
                            lcd_string(&str_adc_val);
                            old_val = adc_val;
                }       
                
            
        }
}   
 
void write_controlword(unsigned char data_){
    _CS = 0;
    _RD = 1;
    _WR = 1;
    DATA = data_;
    _A0 = 1;
    _A1 = 1;
    _WR = 0;
    _WR = 1;
    
}
 
//PORTB Select A0 = 1, A1 = 0;
 
void write_data(unsigned char data_, unsigned char A0, unsigned char A1){
    _CS = 0;
    _RD = 1;    
    _A0 = A0;
    _A1 = A1;
    DATA = data_;
    _WR = 0;
    _WR = 1;
            
            
}
 
 
void read_data(unsigned char A0, unsigned char A1){
    _CS = 0;
    _WR = 1;
    _A0 = A0;
    _A1 = A1;
     P1 = 0xFF;
    _RD = 0;
    adc_val = DATA;
    _RD = 1;
    
    //Data on 8255A PPI PORTA is placed on DATAPORT connected to 8051
                        
}
 
void MSDelay(unsigned mstime){
            unsigned int i, j;
    
            for(i=0;i<mstime;i++);
                for(j=0;j<1275;j++);
}   
 
void lcd_cmd(unsigned char lcd_cmd){
    write_controlword(0x90);        //8255 PPI PORTA Input, PORTB and PORTC Output, Mode 0
    write_data(lcd_cmd, 1, 0);  //8255 PPI PORTB Selected with LCD CMD value
    write_controlword(0x70);        //LCD RS = 0
    write_controlword(0x72);        //LCD RW = 0
    write_controlword(0x75);        //LCD EN = 1
    MSDelay(1);
    write_controlword(0x74);        //LCD EN = 0
}
 
void lcd_data(unsigned char lcd_data){
    write_controlword(0x90);
    write_data(lcd_data, 1, 0);
    write_controlword(0x71);        //LCD RS = 1
    write_controlword(0x72);        //LCD RW = 0
    write_controlword(0x75);        //LCD EN = 1
    MSDelay(1);
    write_controlword(0x74);        //LCD EN = 0
}
 
void lcd_init(){
  lcd_cmd(0x0E);                            //display and cursor ON. Writing 0x0F makes the cursor blink
  MSDelay(15);                              //delay
  lcd_cmd(0x01);                            //Clear LCD
  MSDelay(15);
  lcd_cmd(0x06);                            //shift the cursor to right
  MSDelay(15);
  lcd_cmd(0x0C);                            //Cursor OFF
  MSDelay(15);
  lcd_cmd(0x80);                            //line 1, position 0
  MSDelay(1);
}
 
 
void lcd_string(unsigned char *lcd_str){
        while(*lcd_str){
                    lcd_data(*lcd_str++);
                    MSDelay(5);
        }           
}
 
void adc_conv(){
 
    write_controlword(0x90);        
    write_controlword(0x78);            //adc CS = 0
    write_controlword(0x7C);            //adc WR = 0
    write_controlword(0x7D);            //adc WR = 1
    write_controlword(0x79);            //adc CS = 1
    while(INTR);
    //ADC Conversion completes
    
}
 
void adc_read(){
    
    write_controlword(0x78);            //adc CS = 0
    write_controlword(0x7A);            //adc RD = 0
    write_controlword(0x90);
    read_data(0,0);                             //Read 8255 PORTA
    write_controlword(0x7B);            //adc RD = 1
    write_controlword(0x79);            //adc CS = 1
    
}




Edit 2:

If I use Vref/2 = 2.5 V for 0804 then I am getting the right adc value. Is it right to use 2.5V for Vref/2? LCD still has problem. When value is varied some characters doesn't display. Is it a problem with the LCD delays?

 

Attachments

  • 8051 8255.rar
    83.6 KB · Views: 97
Last edited:

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…