Pages

PIC 16f84a LED on/off with delay project

Flowchart Explanation:

Set the Port B of the PIC 16F84A device as output Port. Turn the Led-on by sending the data one to the Port B and create a Delay of 0.5 seconds to keep the Led in on-state. Turn the Led-off by sending the data zero to the Port B and create a Delay of 0.5 seconds to keep the Led in off-state. this process is repeated untill the power supply to the PIC 16F84A goes off.Flowchart and Circuit Diagram:

Circuit Description:PIC 16F84A microcontroller device is programmed to turning a LED on/off continuously with delay. this device uses 4MHz crystal/Resonator oscillator to drive osc1 and osc2. Port B RB0 is used as output port and it output the positive current with some delay to blink the LED and this delay timing depends on the program. A 100 or120 ohms resistance is connected to the LED to limiting the output current from RB0. VDD(Pin 14) and pin 4 is connected to the +5V power supply. Vss(Pin 5) is connected to the -5V or ground.Embedded C Program: LED on/off with delayCompiler: PIC CCS C compilerEmbedded C program for Turning a Led On/Off with delay. 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: LED on/off with 0.5 second delay*/

#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=6                  /* defines memory location of register */

void main()
  {
     set_tris_b(0x00);        /* it sets the portb as output port */

     loop1: portb=0x01;    /* sends 1 to portb RB0 to turn the LED-on */

     delay_ms(500);    /* creates half second delay between LED on/off*/

     portb=0x00;            /* sends 0 to portb RB0 to turn the LED-off */

     delay_ms(500);     /*creates half second delay between LED off/on*/

     goto loop1;
  }
     /* loop1 just turns-on/off the LED continuously until the power supply             OFF */


Delay: delay is used to keep the processor output as constant for the period of specified time. this period of time is called as Delay time. Delay time can be programmed according to your specified timings. for example
delay in milli seconds
delay in seconds
250
0.25
500
0.5
1000
1
2000
2

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*/
              }
         }
      }
    }
  }

0 comments:

Post a Comment