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.

[PIC] IO With PIC16F877A Help, How To Active Only One PORT With 4 Input

Status
Not open for further replies.

sacban

Junior Member level 3
Joined
Aug 20, 2015
Messages
29
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
412
Hi All,
I have create a little project for school controlled, this project already working and function if I setting for all PORT, but is something wrong if I use only per PORT.

Well, the scenario I want to configuring :
--> PORTA AN0-AN1-AN2-AN3-AN4 are an input /using button.
--> PORTB, used for LCD, visual information 4x20.
--> PORTC, used for indicator light or led.
--> PORTD, used for opto coupler or relay.
--> PORTE, I used for power on indicator led.

Below code first time power on, the text on LCD will blinking for few second.

Now is the problem :
When I put the button on PORTA AN0, PORTA AN1, PORT AN2.
Output at PORTD1, PORTD2, PORTD3, the led will blinking when I push the button.

The code will fine when I put at output for PORTD, PORTC.
I wanna to controlled 3 button in PORTA and PORTD1, PORTD2, PORTD3, push PORTA AN1 PORTD1 ON and one time push the button PORTD1 off and for PORTD2, PORTD3,

Anyone can help me please,

Below the 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
char i;
 char ff;
 bit oldstate;
 
 
void tunda() {
  Delay_ms(100);
}
 
void main(){
  {
 //ANSEL = 0b00000000; // Semua I/O Pin Adalah Digital
 oldstate=0;
  ADCON1 = 6;
  CMCON = 7 ;     // Matikan Komparator
  TRISA = 0b11111111; // Semua PORTA Adalah Input
  TRISB = 0b00000000; // Semua PORTB Adalah Output
  TRISC = 0b00000000; // Semua PORTC Adalah Output Kecuali RC0
  TRISD = 0b00000000; // Semua PORTD Adalah Output Kecuali RD4, RD5, RD6
  // PORTD = 0b00011111;
 
  PORTA = 0b00000000;      // Mulai Aktif PORTA-PORTD-PORTE
  PORTD = 0b00000000;
 
 
  PORTC = 0b00000000;
 
   //PORTE = 0x01;                    // Power Led Indikator
 
  Lcd_Init();                             // Inisialisasi LCD
  Lcd_Cmd(_LCD_CLEAR);           // Bersihkan Display/Layar
  Lcd_Cmd(_LCD_CURSOR_OFF); // Matikan Kursor
  
// START FOR BLINKING FOR FEW SECOND //
  
for(i=0; i<5; i++) {                  //i<1 maka kedipan akan lebih cepat, menghitung waktu kedipan
   Lcd_Out(1,3,rdf0);                 //Tulis Pesan Pada Line 1, Mulai Baris 1
   //PORTD = 0b00000001 ;
   tunda();
}
for(i=0; i<5; i++) {
   Lcd_Cmd(_LCD_CLEAR);      // Bersihkan Display/Layar
   Lcd_Cmd(_LCD_CURSOR_OFF); // Matikan Kursor
   // PORTD = 0b00000000 ;
   tunda();
 }
for(i=0; i<5; i++) {
   Lcd_Out(1,3,rdf0);
   // PORTD = 0b00000001 ;
   tunda();
}
for(i=0; i<5; i++) {
   Lcd_Cmd(_LCD_CLEAR);      // Bersihkan Display/Layar
   Lcd_Cmd(_LCD_CURSOR_OFF); // Matikan Kursor
   //PORTD = 0b00000000 ;
   tunda();
}
for(i=0; i<5; i++) {
   Lcd_Out(1,3,rdf0);
   //PORTD = 0b00000001 ;
   tunda();
}
for(i=0; i<5; i++) {
   Lcd_Cmd(_LCD_CLEAR);      // Bersihkan Display/Layar
   Lcd_Cmd(_LCD_CURSOR_OFF); // Matikan Kursor
   //PORTD = 0b00000000 ;
   tunda();
}
for(i=0; i<5; i++) {
   Lcd_Out(1,3,rdf0);
   //PORTD = 0b00000001 ;
   tunda();
}
for(i=0; i<5; i++) {
   Lcd_Cmd(_LCD_CLEAR);      // Bersihkan Display/Layar
   Lcd_Cmd(_LCD_CURSOR_OFF); // Matikan Kursor
   //PORTD = 0b00000000 ;
   tunda();
}
for(i=0; i<5; i++) {
   Lcd_Out(1,3,rdf0);
   //PORTD = 0b00000001 ;
   tunda();
}
for(i=0; i<5; i++) {
   Lcd_Cmd(_LCD_CLEAR);      // Bersihkan Display/Layar
   Lcd_Cmd(_LCD_CURSOR_OFF); // Matikan Kursor
   //PORTD = 0b00000000 ;
   tunda();
}
for(i=0; i<5; i++) {
   Lcd_Out(1,3,rdf0);
   //PORTD = 0b00000001 ;
   tunda();
}
for(i=0; i<5; i++) {
   Lcd_Cmd(_LCD_CLEAR);      // Bersihkan Display/Layar
   Lcd_Cmd(_LCD_CURSOR_OFF); // Matikan Kursor
   //PORTD = 0b00000000 ;
   tunda();
}
for(i=0; i<5; i++) {
   Lcd_Out(1,3,rdf0);
   //PORTD = 0b00000001 ;
   tunda();
}
for(i=0; i<3; i++) {
    Lcd_Cmd(_LCD_CLEAR);      // Bersihkan Display/Layar
    Lcd_Cmd(_LCD_CURSOR_OFF); // Matikan Kursor
    //PORTD = 0b00000001 ;
    tunda();
}
for(i=0; i<2; i++) {
    Lcd_Out(1,3,rdf0);
    //PORTD = 0b00000001 ;
    tunda();
}
for(i=0; i<1; i++) {
    Lcd_Cmd(_LCD_CLEAR);      // Bersihkan Display/Layar
    Lcd_Cmd(_LCD_CURSOR_OFF); // Matikan Kursor
    //PORTD = 0b00000001 ;
    tunda();
 
// END of BLINKING //
     
    // Lcd_Init();
    Lcd_Cmd(_LCD_CLEAR);      // Bersihkan Display/Layar
    Lcd_Cmd(_LCD_CURSOR_OFF); // Matikan Kursor
    Lcd_Out(1,1,rdf1);
    Lcd_Out(2,2,rdf2);        // Tulis Pesan Pada Line 2, Mulai Baris 3
    Lcd_Out(3,6,rdf3);        // Tulis Pesan Pada Line 3, Mulai Baris
    Lcd_Out(4,9,rdf4);        // Tulis Pesan Pada Line 3, Mulai Baris
    Delay_ms(100);
    
 
    TRISE = 0b0000000; // Semua PORTE Adalah Input
    PORTE = 0x01;            // Power Led Indikator
    
    Delay_ms(2000);
    Lcd_Cmd(_LCD_CLEAR);      // Bersihkan Display/Layar
    Lcd_Cmd(_LCD_CURSOR_OFF); // Matikan Kursor
 
 
// THIS FUNCTION BUTTON PORTA and OUTPUT PORTD //
    
 do {
    if (Button(&PORTA,0,0,1)) oldstate = 1;                //Button at PORTA AN0
    Delay_ms(80);
    if (oldstate &&Button(&PORTA,0,0,1))    {
                                PORTD.F0 = ~PORTD.F0 ;       //Invert function
                                 oldstate = 0;
                                  delay_ms(1000);
} ;
                                 PORTD.F0=1 ;
                                // PORTD.RD0 =1 ;
                                 //PORTD=0b00000001;  }
                                // else
                               
{
                                 PORTD.F0=0   ;
                                 //PORTD.RD0 =0 ;
                               // PORTD=0b00000000;
 
 
    if (Button(&PORTA,1,0,1)) oldstate = 1;              //Button at PORTA AN1
    Delay_ms(50);
    if (oldstate &&Button(&PORTA,1,0,1)) {
                                      PORTD.RD1 = ~PORTD.RD1  ;
                                      oldstate = 0;
                                     //PORTD.RD1 =1 ;
                                    PORTD=0b00000010;  }
                                     else
                                      //PORTD.RD1=0;
                                    PORTD=0b00000000;
 
    // NOTE, If I use below function for all PORTC work will fine // 
 
 // if (Button(&PORTA,2,0,1)) oldstate = 1;                         //Button at PORTA AN2
  //  Delay_ms(80);
  //  if (oldstate &&Button(&PORTA,2,0,1)) {
 
                                    // PORTC = ~PORTC  ;
                                    // oldstate = 0;
                                    // PORTC=0b11111111; }
                                    // else
                                    // PORTC=0b11111101;
 
 
 
 
    } while(1);                     
//}
//}
 
 
 
 
//
//}
//}
//}



I am using MIKROC.

Thanks for help,,,:-?:-?:-?:-?:-?:-?:-?:-?:-?
 
Last edited:

Post the circuit if possible in Proteus format. I will have a look at your code and try to fix the problems. Also zip and post the complete mikroC project files. In your code it doesn't show the sbit defines for the LCD.
 

Post the circuit if possible in Proteus format. I will have a look at your code and try to fix the problems. Also zip and post the complete mikroC project files. In your code it doesn't show the sbit defines for the LCD.

Hi PIC,
I already solved my problem according above issue, but I have other problem, When I Pressed the button on PORTA for BELL and Character on LCD also appears and blinking, I want when this BELL button on press Character is not blinking, same like for MUSIC button, and also for PORTA AN2, PORTA AN3.

I attached the file and schematic here.

- - - Updated - - -

Post the circuit if possible in Proteus format. I will have a look at your code and try to fix the problems. Also zip and post the complete mikroC project files. In your code it doesn't show the sbit defines for the LCD.

PIC,
My issue on this problem already solved by me, but I have other problem.

You can press button BELL on this Proteus, then BELL will appears with blinking text, how to make a BELL character not blinking like MUSIC character.

Also, I want to make same like PORTA AN0 and PORTA AN1 for PORTA AN2-AN3-AN4 with same method.


View attachment Almanak.zip
 

Attachments

  • Almanak.zip
    91.5 KB · Views: 89

The code is badly written but I can help you solve the problem if you tell what has to happen when each button is pressed. At some places you have used the button library in a wrong way.

I have fixed the code used for blinking text on the LCD after Initialization. I have commented out the buttons code. If you tell exactly what each button press has to do then I will make changes to the buttons code so that it works as you need.

In the initialization part you have used many for loops to create 500 ms delay and I have removed them. You had repeateadly called LCD_Out() and LCD Clear functions to create the blinking effect and to toggle RD0 pin. I have used one for loop to create the blinking effect.
 

Attachments

  • Almanak.rar
    114.8 KB · Views: 71
  • Almanak.png
    Almanak.png
    58.5 KB · Views: 89
Last edited:

The code is badly written but I can help you solve the problem if you tell what has to happen when each button is pressed. At some places you have used the button library in a wrong way.

I have fixed the code used for blinking text on the LCD after Initialization. I have commented out the buttons code. If you tell exactly what each button press has to do then I will make changes to the buttons code so that it works as you need.

In the initialization part you have used many for loops to create 500 ms delay and I have removed them. You had repeateadly called LCD_Out() and LCD Clear functions to create the blinking effect and to toggle RD0 pin. I have used one for loop to create the blinking effect.

When the button is toggle or press and character on LCD appears with blinking, what I want is not blinking, this for all button at PORT A.

Can you please attach your code here ?, let me see please.

Thanks.
 

I have attached the project in post #4 but you did not mention what each button press has to do. If you want to display different messages when different DIP switch are turned ON then tell what button (DIP Switch) displays what message.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top