Programming doubt

Status
Not open for further replies.
i want write a program for switch control.when RD7 and RA4=1 then only the switch wil work.

this is my program

#include<pic.h>
#include<stdio.h>


void main()

{
int i;
char map[10]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
TRISD=0x00;
TRISC=0x00;
TRISB=0X00;
PORTC=0x02;
PORTC=0X00;
TRISA=0x08;
i=0;

while(RD7&&RA4=1) //<============ is it correct?
{


i++;
PORTD=map;
PORTB=0x01;
_delay(196999);
PORTB=0x00;
}


}
 
Make sure that the two inputs must have two pull down resisters - ex 4.7K

What will be the value when i=11 onwards??
 
Last edited:
The line
while(RD7&&RA4=1)
is wrong

whatever is inside the () of while must evaluate to zero or 1
if one the while does the code following it

The major problem here is that you are using an = which assigns the value on the right to the variable on the left.

An example of this is
p-123;
Here p is assigned the value 123

when we want to check for equality we use ==
so we could say
while(p==1)

if you are using a bit variable like RA0 you would do
while(RA0==1)
but because RA0 can only be 1 or 0 we can write
while(RA0)

You also need to look at logical vrs bitwise operators
There is a diff between & and &&

Lets go back to you code
while(RD7&&RA4=1)
it is clear you do not want to assign a value so th = should be a ==
and because these are both 1 bit variables they will be 0 or 1
so we can just say
while(RD7 && RD4)
this will only be true when both are 1 which is what you want

I know you are in a hurry but you have to start reading about C
if you want to use it.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…