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.

If RA0 is pressed,LED blinks endlessly,while if RA1 is pressed,then LED is OFF...

Status
Not open for further replies.

Kaybee909

Newbie level 4
Joined
Aug 6, 2013
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
53
I need some help with my code using PIC16F84A...Now,my expectation is when RA0 is pressed,then all LEDs start "running-blinking" endlessly,but when RA1 is pressed then LEDs will stop(LED OFF) making PortB LOW...But my problem is that,when RA0 is preesed,the LEDs start perfectly but upon pressing RA1 it will never stop...So how do I stop the LEDs from blinking when RA1 is pressed? See attachment for the code.
 

Attachments

  • RA0_RA1.doc
    27 KB · Views: 81

Have you tried to just turn off port 1 with the RA_1 Bit? That is the only thing that I can see is that you are keeping that point high.
Also have you tried to move the if statement with the RA_1 bit into the loop that way you are actively sampling it? With that if statement just kick yourself out of the endless loop?

- - - Updated - - -

Have you tried to just turn off port 1 with the RA_1 Bit? That is the only thing that I can see is that you are keeping that point high.
Also have you tried to move the if statement with the RA_1 bit into the loop that way you are actively sampling it? With that if statement just kick yourself out of the endless loop?
 

hello,

you have a misplaced parenthesis and suppress the do.. while.

Code:
void main() {
TRISB= 0x00;    //Configure PORTB as output
TRISA = 0xFF;  //Configure PORTA as input
PORTB = 0x00;  //LED OFF
while(1)
 [B]{[/B]  // Infinite loop
if(PORTA.F0==1)//If switch is pressed LED is ON endless
{
PORTB = 0x80;  //Setting PortB as high
Delay_ms(100); // Maintain PortB as high for 100ms
PORTB = 0x40;
Delay_ms(100);
PORTB = 0x20;
Delay_ms(100);
PORTB = 0x10;
Delay_ms(100);
PORTB = 0x08;
Delay_ms(100);
PORTB = 0x04;
Delay_ms(100);
PORTB = 0x02;
Delay_ms(100);
PORTB = 0x01;
Delay_ms(100);
PORTB = 0x02;
Delay_ms(100);
PORTB = 0x04;
Delay_ms(100);
PORTB = 0x08;
Delay_ms(100);
PORTB = 0x10;
Delay_ms(100);
PORTB = 0x20;
Delay_ms(100);
PORTB = 0x40;
[B]Delay_ms(100);[/B]
PORTB = 0x80;
}

 if (RA1_bit==1)   //LED loop to stop if RA1 is pressed
 {
  PORTB= 0x00;}
  } 
[B]}[/B] // while
}

what happen if RA0 keep pressed and press RA1 in same time
you can add interlock condition
if((PortA.F0==1)&& (PortA.F1==0))
{
moving led
}
if ((PortA.F1==1)&&(PortA.F0==0))
{
PortB=0;
}
 

hello,

you have a misplaced parenthesis and suppress the do.. while.

Code:
void main() {
TRISB= 0x00;    //Configure PORTB as output
TRISA = 0xFF;  //Configure PORTA as input
PORTB = 0x00;  //LED OFF
while(1)
 [B]{[/B]  // Infinite loop
if(PORTA.F0==1)//If switch is pressed LED is ON endless
{
PORTB = 0x80;  //Setting PortB as high
Delay_ms(100); // Maintain PortB as high for 100ms
PORTB = 0x40;
Delay_ms(100);
PORTB = 0x20;
Delay_ms(100);
PORTB = 0x10;
Delay_ms(100);
PORTB = 0x08;
Delay_ms(100);
PORTB = 0x04;
Delay_ms(100);
PORTB = 0x02;
Delay_ms(100);
PORTB = 0x01;
Delay_ms(100);
PORTB = 0x02;
Delay_ms(100);
PORTB = 0x04;
Delay_ms(100);
PORTB = 0x08;
Delay_ms(100);
PORTB = 0x10;
Delay_ms(100);
PORTB = 0x20;
Delay_ms(100);
PORTB = 0x40;
[B]Delay_ms(100);[/B]
PORTB = 0x80;
}

 if (RA1_bit==1)   //LED loop to stop if RA1 is pressed
 {
  PORTB= 0x00;}
  } 
[B]}[/B] // while
}

what happen if RA0 keep pressed and press RA1 in same time
you can add interlock condition
if((PortA.F0==1)&& (PortA.F1==0))
{
moving led
}
if ((PortA.F1==1)&&(PortA.F0==0))
{
PortB=0;
}





Hello,it's not working fine yet,the LEDs only blink once(No endless Loop) and just stop there,but upon pressing RA1 it put OFF the LEDs.Oops!...but we are almost getting there,I belief.
 

suppress this extra parenthesis
if (RA1_bit==1) //LED loop to stop if RA1 is pressed
{
PORTB= 0x00; // this one }
}
 

suppress this extra parenthesis
if (RA1_bit==1) //LED loop to stop if RA1 is pressed
{
PORTB= 0x00; // this one }
}



Hi Paul,am still getting "Sucked" in here. Still ON forever,have tried the advices and many more! I guess it's a lil bug.
 

hello... just try while loop because of the IF condition like...
Code:
while(RA0==1 || RA0==1&&RA1==0); \\endless blinking
while(RA1==1&&RA0==0)
 

best way use single bit and toggle it when key is pressed!
your code will look like as follows.
Code:
void main() {
TRISB= 0x00;    //Configure PORTB as output
TRISA = 0xFF;  //Configure PORTA as input
PORTB = 0x00;  //LED OFF
while(1) {  // Infinite loop

if(PORTA.F0==1 && toggle==1)//If switch is pressed LED is ON endless
{
toggle =~toggle;
}

else if (RA1_bit==1 && toggle==0)//LED loop to stop if RA1 is pressed
{
toggle =~toggle;

}

use if ...else condition instead of if.....if

- - - Updated - - -

best way use single bit and toggle it when key is pressed!
your code will look like as follows.
Code:
void main() {
TRISB= 0x00;    //Configure PORTB as output
TRISA = 0xFF;  //Configure PORTA as input
PORTB = 0x00;  //LED OFF
while(1) {  // Infinite loop

if(PORTA.F0==1 && toggle==1)//If switch is pressed LED is ON endless
{
toggle =~toggle;
}

else if (RA1_bit==1 && toggle==0)//LED loop to stop if RA1 is pressed
{
toggle =~toggle;

}

use if ...else condition instead of if.....if
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top