PushButton Led Chaser:
PushButton micro switch is used as an input to ON and OFF Led chaser. when you press the pushbutton then it starts(ON) the Led chaser. Led chaser means Led blinks one by one in continuous motion. if you press the pushbutton when an Led chaser in ON condition then it stops(OFF) Led chaser.Flowchart Explanation:Set the PortA RA0 as input and PortB RB0 as output of the PIC 16F84A device. Create a never ending while loop and inside the while loop read the PortA RA0 bit.Check whether the PushButton switch is pressed or not. If the Button is Pressed means PortA RA0 = 1 or RA0 goes High and it enters into the while loop and starts the Led Chaser by shifting the data 1 stored in the variable value using Left Shift Operator with a 0.25 second delay and again checks for button is pressed if it is pressed again then Stops the Led Chaser by sending 0x00 to PortB and the control comes out of the second while loop and the same process is repeated. If the Button is not Pressed means it will go to while loop and again checks for switch press.Circuit Diagram:/* Project Name: PushButton for Led Chaser */ #include<16F84A.h> /*defines type of device to include device files*/ #use delay(clock=4mhz) /* defines crystal frequency 4MHz */ #fuses xt, nowdt, noprotect, noput /* xt oscilator used and no watch dog timer, no code protection, no power up timer is used */ #byte portb=5 /* defines memory location of register */ #byte portb=6 /* defines memory location of register */ void main() { byte c,d; set_tris_a(0x01); /* it sets the portA RA0 as input port */ set_tris_b(0x00); /* it sets the portB RB0 as output port */ while(true) { if(porta == 0x01) /* if switch pressed starts Disco Led */ { while(true) { c = 0; /*initialize the count c equal to zero */ d = 0x01; /* assigns the content of d to 0x01 */ while(c < 8) { portb = d; /*sends content of d to portb to turn-on 1st Led*/ delay_ms(250); /* creates 0.25 second delay */ d = d << 1; /* shifts the value of data to the left by 1*/ c++; /* increments the value of c by 1*/ } if(porta == 0x01) /*if switch pressed again stops DiscoLed*/ { portb = 0x00; /*assigns portB RB0 to 0x00 to turn-offLed*/ break; /* comes out of the loop*/ } } } } } |
No comments:
Post a Comment