Tutorial on how to use if-else and else if condition for PIC16F877A MCU using MikroC for PIC .

Опубликовано: 18 Март 2026
на канале: Learning Microcontrollers
451
15

Guys, My lectures are free for everyone.
If you want to support my channel, then become a Youtube member by following link below:

   / @learningmicrocontrollers3561  

Seek knowledge from the cradle to the grave
/// /////////////////////////////////////////////////////**********************************///////////////////////////////// Hello guys,
Welcome to Learning Microcontrollers youtube Channel,

Guys I have also compiled course on Udemy as well. Where you will learn under my direct supervision in a more supervised way.
Here is the links to the courses I have on Udemy, By taking any of these courses you will be supporting my channel aswell.
This will help me to make more videos with better hardware in the future. I hope you look forward to it.
Courses Links:

1- https://www.udemy.com/course/pic16f87...
2- https://www.udemy.com/course/mikroc-f...
3- https://www.udemy.com/course/mikroc-f...
4- https://www.udemy.com/course/pic-micr...
5- https://www.udemy.com/course/learn-ar... ///////////////////////////////////////////////////// 1- MikroC for PIC code for if else condition:

void main() {
TRISC.F0 = 1;
PORTC.F0 = 0;
Delay_ms(100);

TRISC.F1 = 1;
PORTC.F1 = 0;
Delay_ms(100);

TRISB.F5 = 0;
PORTB.F5 = 0;
Delay_ms(100);

TRISB.F6 = 0;
PORTB.F6 = 0;
Delay_ms(100);

while(1)
{
if ( PORTC.F0 == 1 )
{
Delay_ms(20);
if ( PORTC.F0 == 1 )
{
PORTB.F5 = 1;
}
}
else
{
PORTB.F5 = 0;
}

if ( PORTC.F1 == 1 )
{
Delay_ms(20);
if ( PORTC.F1 == 1 )
{
PORTB.F6 = 1;
}
}
else
{
PORTB.F6 = 0;
}



}
}



////////////////////////////////////// End

2- MikroC for PIC code for if and else-if condition:

void main() {
TRISC.F0 = 1;
PORTC.F0 = 0;
Delay_ms(100);

TRISC.F1 = 1;
PORTC.F1 = 0;
Delay_ms(100);

TRISB.F5 = 0;
PORTB.F5 = 0;
Delay_ms(100);

TRISB.F6 = 0;
PORTB.F6 = 0;
Delay_ms(100);

while(1)
{
if ( PORTC.F0 == 1 )
{
Delay_ms(20);
if ( PORTC.F0 == 1 )
{
PORTB.F5 = 1;
}
}

else if ( PORTC.F1 == 1 )
{
Delay_ms(20);
if ( PORTC.F1 == 1 )
{
PORTB.F6 = 1;
}
}
else
{
PORTB.F5 = 0;
PORTB.F6 = 0;
}



}
}