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.

[SOLVED] Prob with input in C

Status
Not open for further replies.

bauche

Junior Member level 1
Joined
Oct 13, 2010
Messages
15
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,367
Hi there

a liitle prob in c

i have 2 input port A0 and port A1 i want to put on 1 led if both of them pressed (closed) together...i found out a solution but if 1 input is close
led not working ...but if my two input is close led goes on ...and when my two input is open led goes on too....

Code:
void main() {

ADCON1 |= 0x0F;


TRISA = 0xff;
TRISB = 0;

for(;;)
{
  if((RA0_bit=1)==(RA1_bit=1)) //if button is pressed
  {
   
  RB4_bit=1;
  }
  else
  {
  RB4_bit=0;
  }
}
}
 


Code C - [expand]
1
2
3
4
5
6
7
8
9
if((PORTA & 0x03) == 0x03)) //if button is pressed
{
    Delay_ms(50);
 
    while(PORTA & 0x03) == 0x03);
   
    RB4_bit= ~RB4_bit;
 
}

 

your if statement inside the main loop should be

Code:
if((RA0_bit==1) && (RA1_bit==1))
 

Thanks for all ....i finally found how to do it ....!!!

:grin:
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top