Hi,
i am new to pic and I recently started a project. but in that i not getting the correct output using if else statement. I don't know what is wrong.
//LCD INITIALISATION
sbit LCD_RS at RC2_bit;
sbit LCD_EN at RC3_bit;
sbit LCD_D4 at RC4_bit;
sbit LCD_D5 at RC5_bit;
sbit LCD_D6 at RC6_bit;
sbit LCD_D7 at RC7_bit;
sbit LCD_RS_Direction at TRISC2_bit;
sbit LCD_EN_Direction at TRISC3_bit;
sbit LCD_D4_Direction at TRISC4_bit;
sbit LCD_D5_Direction at TRISC5_bit;
sbit LCD_D6_Direction at TRISC6_bit;
sbit LCD_D7_Direction at TRISC7_bit;
void main() {
char txt[14];
int c;
TRISC == 0x00; // set port c as output for lcd
TRISB == 0xff; //set port b as input
LATB.B4 == 0x00; //initially portB B4 PIN IS SET TO LOGIC LOW VALUE
Lcd_Init(); //FOR LCD INITILISATION
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Out(1,1, "WELCOME");
Delay_ms(1000);
while(1)
{
if(PORTB.B4 == 0xff)
{
c == 1;
Delay_ms(500);
}
else
{
c == 0;
Delay_ms(500);
}
c == 0;
IntToStr(c, txt);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1, txt); //DISPLAYING THE VALUE OF c THROUGH LCD.
Delay_ms(1000);
}
}
The above program checks the codition and displays the value of 'c' in lcd. But as i run the simulation through proteus it displays "0" even if change the value PORTB.B4 pin. The value"0" doesnot changes even if change the value of 'c' from the program. Plz help...
How to Use if else statement in mikroc using pic18f452
- dusan.poluga
- mikroElektronika team
- Posts: 780
- Joined: 02 Feb 2017 14:21
Re: How to Use if else statement in mikroc using pic18f452
Hi,
You need to do it like this if you want to test if the bit is high:
And if you want to test it if the bit has the value of zero:
Because you are asking for a value of a single bit with this statement.
And on the top. You ave not assigned any value to the buffer.
You need to assign it like this
Regards,
Dusan Poluga.
You need to do it like this if you want to test if the bit is high:
Code: Select all
if(PORTB.B4 == 1)
Code: Select all
if(PORTB.B4 == 0)
And on the top. You ave not assigned any value to the buffer.
Code: Select all
char text[14]
Code: Select all
char text[14]="c"
Dusan Poluga.
-
- Posts: 27
- Joined: 21 Jan 2017 10:44
- Location: Lahore
- Contact:
Re: How to Use if else statement in mikroc using pic18f452
while(1)
{
if(PORTB.B4 == 0xff)
{
c == 1;
Delay_ms(500);
}
else
{
c == 0;
Delay_ms(500);
}
c == 0; // remove this because you are again and again initialized the c as 0
IntToStr(c, txt);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1, txt); //DISPLAYING THE VALUE OF c THROUGH LCD.
Delay_ms(1000);
}
}
{
if(PORTB.B4 == 0xff)
{
c == 1;
Delay_ms(500);
}
else
{
c == 0;
Delay_ms(500);
}
c == 0; // remove this because you are again and again initialized the c as 0
IntToStr(c, txt);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1, txt); //DISPLAYING THE VALUE OF c THROUGH LCD.
Delay_ms(1000);
}
}
Re: How to Use if else statement in mikroc using pic18f452
Hi,
I think i finally figured out what's wrong. i am using
and instead of using and . when i changed this i got the correct output.
I think i finally figured out what's wrong. i am using
Code: Select all
c == 0
Code: Select all
c == 1
Code: Select all
c = 0;
Code: Select all
c =1;
-
- Posts: 27
- Joined: 21 Jan 2017 10:44
- Location: Lahore
- Contact:
Re: How to Use if else statement in mikroc using pic18f452
that's great keep it up and if any kind of help you need you can just ask
Re: How to Use if else statement in mikroc using pic18f452
Hi..
Sure. And thankyou for the support..
Sure. And thankyou for the support..
-
- Posts: 27
- Joined: 21 Jan 2017 10:44
- Location: Lahore
- Contact:
Re: How to Use if else statement in mikroc using pic18f452
It's my pleasure to help you, by the way my job is to help students to program their logic and developed their final year projects.