BGAmodz
Member
Hello everyone .
AS always am doing a lot of programming training , as a preparation for my project .
So 2 days ago i decided to make this simple program
In human language :
- I have 4 leds , one puch-on button , a pic16f84a .
- when i press the first press , led 1 light up , another press , the second one lights up the first shuts down .........and so on , till i redo the cycle .
Now this is Computer language , the program seems to work with respect to my logic but the problem is that leds light up randomly , and there is a lot of flickering .
So is there a possibility to do the software debounce as easy as possible ??
AS always am doing a lot of programming training , as a preparation for my project .
So 2 days ago i decided to make this simple program
In human language :
- I have 4 leds , one puch-on button , a pic16f84a .
- when i press the first press , led 1 light up , another press , the second one lights up the first shuts down .........and so on , till i redo the cycle .
Now this is Computer language , the program seems to work with respect to my logic but the problem is that leds light up randomly , and there is a lot of flickering .
So is there a possibility to do the software debounce as easy as possible ??
Code:
#define start porta.b0
#define led1 portb.b0
#define led2 portb.b1
#define led3 portb.b2
#define led4 portb.b3
int x0,x1,x2,x3;
void main() {
porta=0x00;
portb=0xff;
trisa=0xff;
trisb=0x00;
x0=1;x1=0;x2=0;x3=0;
while(1){
if((start==1)&&(x0==1)){
x0=0;x1=1;led4=1;led1=0;
}
if((start==1)&&(x1==1)){
x1=0;x2=1;led1=1;led2=0;
}
if((start==1)&&(x2==1)){
x2=0;x3=1;led2=1;led3=0;
}
if((start==1)&&(x3==1)){
x3=0;x0=1;led3=1;led4=0;
}
}
}