sacban
Junior Member level 3
![Junior Member level 3](/styles/images/ranks/clevel3.gif)
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 :
I am using MIKROC.
Thanks for help,,,:-?:-?:-?:-?:-?:-?:-?:-?:-?
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: