16F84 Sample LED Circuit Diagram

Microcontroller Topics
Post Reply
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

16F84 Sample LED Circuit Diagram

Post by Neo » Sat Apr 17, 2010 11:00 pm

1.gif
1.gif (5.17 KiB) Viewed 9797 times
Note that you can remove the switches and add LEDs to those pins as well. X1 can be either two 20pf capacitors with a 10 MHz oscillator or a single resonator (as explained below).

PIC 16f84 Pin Diagram
2.gif
2.gif (2.31 KiB) Viewed 9797 times
Power Regulator
78L05 is a very common regulator used to provide power to sensitive electronic devices like microcontrollers.
3.gif
3.gif (784 Bytes) Viewed 9797 times
Resonator
This is denoted as X1 in the circuit. You can use a 10-MHz resonator instead of oscillator and 2 capacitors. A Resonator is a combined unit of ceramic vibrator and capacitors.
4.jpg
4.jpg (2.03 KiB) Viewed 9797 times
Some of the patters you can make can be illustrated below. You can use either C or ASM to write routines for this micro.
p1.gif
p1.gif (57.83 KiB) Viewed 9797 times
p2.gif
p2.gif (57.83 KiB) Viewed 9797 times
p3.gif
p3.gif (51 KiB) Viewed 9797 times
p4.gif
p4.gif (94.63 KiB) Viewed 9797 times
p5.gif
p5.gif (11.65 KiB) Viewed 9797 times
You can use the Multi PIC programmer to program this device. Also see tutorial How to start with Microcontrollers to get an idea of the software tools required.

Hope this quick tutorial will give you a simple idea.
User avatar
Magneto
Major
Major
Posts: 430
Joined: Wed Jul 15, 2009 1:52 pm
Location: London

Re: 16F84 Sample LED Circuit Diagram

Post by Magneto » Sun Apr 18, 2010 8:40 am

Hi All ,

some notes on above circuit diagram

(1) Here LED's have connected as current sink devices, That mean current flow into the micro controller. So
remember when you give signals from micro controller , to light up each LED , make the output pin LOW.
that mean when you want to ON the LED , make relevant output pin of MCU LOW. ( Not High as usual)

(2) You can increase the number LED's which can light up, with few micro controller pins from a method called multiplexing.
mutiplex.JPG
mutiplex.JPG (34.17 KiB) Viewed 9773 times
Bottom 5 lines are Cathodes. ( that mean we have to ground them)

If you look on the above 5 seventh segment displays , if you control them using normal way , we want 36 I/O pins in a micro controller. ( each Segment unit contain 7 LED's , so 7*5 + common ground = 36 )
But if we connect them as in the above diagram , we want only 12 I/O pins.

Here trick is you have to switch between segments , in some bit high frequency for display some thing in all 5 segments.
As Human eye can not identify the changes , which occur above 20 Hz , if you do this switching with a frequency larger than 20 Hz , you may display the content in segments ,even they do not have power.

Magneto
User avatar
Rksk
Major
Major
Posts: 730
Joined: Thu Jan 07, 2010 4:19 pm
Location: Rathnapura, Sri Lanka

Re: 16F84 Sample LED Circuit Diagram

Post by Rksk » Sun Apr 18, 2010 3:02 pm

Can any one give a code for this diagram????????? :?:
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: 16F84 Sample LED Circuit Diagram

Post by Neo » Sun Apr 18, 2010 3:26 pm

Hey, the fun part of Microcontrollers is programming mostly with ASM (though C is easier). After you make your hardware design by using your electronic skills (you can get advises from professionals like Magneto for this), the most fun part is to do programming. In my case, I'm mostly interested when there is a mathematics part involved :)

So please do not ask for codes. Firmware development is my everyday job so personally I don't have time to write codes for anybody. Magneto will not as well. You need to write your own code. However, you can ask questions that arise when you are coding.

We find time very hardly to write these tips since we believe we need to do something for young people like you. Please don't expect things to be done by us for you ;)
User avatar
Rksk
Major
Major
Posts: 730
Joined: Thu Jan 07, 2010 4:19 pm
Location: Rathnapura, Sri Lanka

Code for 16F84 Sample LED Circuit Diagram

Post by Rksk » Mon Apr 19, 2010 5:42 pm

I wrote a simple code for above given Circuit Diagram. :lol:

Code: Select all

#include <pic.h>
#include "delay.h"

#define sleep 50 //set the time between changes in miliseconds

int start()
{
PORTB = 1; 

  if(RA0==0)
    {
        rata1(); //if RA0 is low then goto rata1
    }
  else if(RA1==0)
    {
        rata2(); //if RA1 is low then goto rata2
    }
  else if(RA2==0)
    {
        rata3(); //if RA2 is low then goto rata3
    }
  else if(RA3==0)
    {
        rata4(); //if RA3 is low then goto rata4
    }
  else if(RA4==0)
    {
        rata5(); //if RA4 is low then goto rata5
    }
   else { 
    start(); //if any RA is not low then goto start again
    }
 }
 
 
 
 
 
 
 
  int rata1()
  {
      RB0=0; //set RB0 to low
     DelayBigMs(sleep);//sleep a time
      RB0=1; //set RB0 to high
      RB1=0; //set RB1 to low
     DelayBigMs(sleep);//sleep a time
      RB1=1; //set RB1 to high
      RB2=0; //set RB2 to low
     DelayBigMs(sleep);//sleep a time
      RB2=1; //set RB2 to high
      RB3=0; //set RB3 to low
     DelayBigMs(sleep);//sleep a time
      RB3=1; //set RB3 to high
      RB4=0; //set RB4 to low
     DelayBigMs(sleep);//sleep a time
      RB4=1; //set RB4 to high
      RB5=0; //set RB5 to low
     DelayBigMs(sleep);//sleep a time
      RB5=1; //set RB5 to high
      RB6=0; //set RB6 to low
     DelayBigMs(sleep);//sleep a time
      RB6=1; //set RB6 to high
      RB7=0; //set RB7 to low
     DelayBigMs(sleep);
     start();//goto start after 1 round for cheking switches
  }

  int rata2()
  {
      RB7=0;
     DelayBigMs(sleep);
      RB7=1;
      RB6=0;
     DelayBigMs(sleep);
      RB6=1;
      RB5=0;
     DelayBigMs(sleep);
      RB5=1;
      RB4=0;
     DelayBigMs(sleep);
      RB4=1;
      RB3=0;
     DelayBigMs(sleep);
      RB3=1;
      RB2=0;
     DelayBigMs(sleep);
      RB2=1;
      RB1=0;
     DelayBigMs(sleep);
      RB1=1;
      RB0=0;
     DelayBigMs(sleep);
    start();
  }

  int rata3()
  {
      RB3=0;
      RB4=0;
     DelayBigMs(sleep);
      RB3=1;
      RB4=1;
      RB2=0;
      RB5=0;
     DelayBigMs(sleep);
      RB2=1;
      RB5=1;
      RB1=0;
      RB6=0;
     DelayBigMs(sleep);
      RB1=1;
      RB6=1;
      RB0=0;
      RB7=0;
     DelayBigMs(sleep);
      RB0=1;
      RB7=1;
     DelayBigMs(sleep);
      RB0=0;
      RB7=0;
     DelayBigMs(sleep);
      RB1=0;
      RB6=0;
      RB0=1;
      RB7=1;
     DelayBigMs(sleep);
      RB2=0;
      RB5=0;
      RB1=1;
      RB6=1;
     DelayBigMs(sleep);
    start();
  }

  int rata4()
  {
      RB0=0;
     DelayBigMs(sleep);
      RB0=1;
      RB1=0;
     DelayBigMs(sleep);
      RB0=0;
      RB1=1;
      RB2=0;
     DelayBigMs(sleep);
      RB0=1;
      RB1=0;
      RB2=1;
      RB3=0;
     DelayBigMs(sleep);
      RB0=0;
      RB1=1;
      RB2=0;
      RB3=1;
      RB4=0;
     DelayBigMs(sleep);
      RB0=1;
      RB1=0;
      RB2=1;
      RB3=0;
      RB4=1;
      RB5=0;
     DelayBigMs(sleep);
      RB1=1;
      RB2=0;
      RB3=1;
      RB4=0;
      RB5=1;
      RB6=0;
     DelayBigMs(sleep);
      RB2=1;
      RB3=0;
      RB4=1;
      RB5=0;
      RB6=1;
      RB7=0;
     DelayBigMs(sleep);
      RB3=1;
      RB4=0;
      RB5=1;
      RB6=0;
      RB7=1;
     DelayBigMs(sleep);
      RB4=1;
      RB5=0;
      RB6=1;
      RB7=0;
     DelayBigMs(sleep);
      RB5=1;
      RB6=0;
      RB7=1;
     DelayBigMs(sleep);
      RB6=1;
      RB7=0;*/
     DelayBigMs(sleep);
    start();
  }

  int rata5()
  {
    PORTB = 0;
    DelayBigMs(sleep);
    DelayBigMs(sleep);
    DelayBigMs(sleep);
    PORTB = 0xff;
    DelayBigMs(sleep);
    DelayBigMs(sleep);
    DelayBigMs(sleep);
    start();
  }
   
   
   
   
main()
{
   TRISB = 0; //set all RB 8pins as output
   TRISA = 0xff; //set all RA 5pins as input
   PORTB = 1;  //set all RB 8pins high at startup
  start(); //goto start function

}
 

 
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: 16F84 Sample LED Circuit Diagram

Post by Neo » Mon Apr 19, 2010 7:32 pm

Looks correct to me.
Try it on the Proteus or actual micro and confirm the code so others will benefit too.
User avatar
Rksk
Major
Major
Posts: 730
Joined: Thu Jan 07, 2010 4:19 pm
Location: Rathnapura, Sri Lanka

Re: 16F84 Sample LED Circuit Diagram

Post by Rksk » Mon Apr 19, 2010 9:01 pm

I tested this on Proteus before posting here. it worked correctly.
Post Reply

Return to “Microcontrollers”