Problems with Microcontroller Projects? You may face many Problems, but do not worry we are ready to solve your Problems. All you need to do is just leave your Comments. We will assure you that you will find a solution to your project along with future tips. On Request we will Mail you the Codes for Registered Members of this site only, at free service...Follow Me.

PushButton for Led Chaser with microcontroller

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:

Circuit Description: PIC 16F84A microcontroller device is programmed for Led Chaser with Push Button when the button is pressed. this device uses the capacitor C1, C2(33pf) and 4MHz crystal/Resonator oscillator to drive the oscillator1 and oscillator2. The Push Button is connected to the PortA RA0 and +5V and pull down Resistor R2(10k) is connected to the PortA RA0 and Gnd.(Gnd means ground)In this circuit Active High Input is used. Resistor R2(10k) is used to pull down the PIC input to Logic '0' or Low or Pull down the Voltage down to zero. when you press the switch it pulls the voltage from 0 to 5V and makes the input to Logic '1' or High. Resistor 1K is connected to the PortB and Leds. the other negative terminal of all the eight Led is connected to the ground.Resistor R is a Current Limiting Resistor R(1K) is used to prevent the damage to both the PIC and the Leds. Resistor R reduces the current to the sufficient level.Embedded C Program: PushButton for Led ChaserCompiler: PIC CCS C compilerEmbedded C program for PushButton for Led Chaser. its very easy to learn and you can able to understand the concept and logic of the program from the flowchart and comment lines of the program.
/* 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

Related Posts Plugin for WordPress, Blogger...

Recent Comments

Popular Projects

Give Support

Give Support
Encourage Me through Comments

Microcontroller Projects

Total Pageviews