for loop error

General discussion on mikroBasic.
Post Reply
Author
Message
kshitijnov
Posts: 4
Joined: 02 Feb 2016 14:18

for loop error

#1 Post by kshitijnov » 26 Feb 2016 18:57

I am trying to implement a situation where when the switch (connected to porta pin7) is closed the led connected to port b blinks 4 times. the program itself has no error but when i try to simulate it on proteus it doesnt work. here is the program

unsigned int n= 0;

void main()
{
CMCON0 =0x07;
TRISA= 0b10000000;
PORTA =0b00000000;
TRISB = 0;
PORTB = 0;
if(Button(PORTA,0,0,1))
{
for(n=0;n<8;n++)
{
PORTB=~PORTB;
Delay_ms(300);
}
}
}

checker
Posts: 77
Joined: 22 May 2011 10:58

Re: for loop error

#2 Post by checker » 29 Feb 2016 05:35

**** wrote: if(Button(PORTA,0,0,1))
{
for(n=0;n<8;n++)
{
PORTB=~PORTB;
Delay_ms(300);
}
}
}

maybe try this:

Code: Select all

     while (1){
     if(Button(PORTA,0,0,1)) {                                                         
          for(n=0;n<8;n++){                                                          
               PORTB=~PORTB;                                   
               Delay_ms(300);
              }
          }
     }
}
you are not in a while loop so it does not check for more button pushes so unless you have the button pushed at startup, nothing will happen because it is a one shot.

Post Reply

Return to “mikroBasic General”