Tuesday 27 November 2012

Basic Circuit for PIC 16F877A

Before doing any fancy circuits, we need to build the most basic circuit for PIC 16F877A. There are basically 2 circuits that I usually build which are:


  1. Power circuit. (Skip this circuit if you are lazy and using an adapter for 5V).
  2. Basic circuit for controller pic.
Below are an example of a power circuit for any output voltage to regulate to a 5V. I'm using a voltage regulator or some might call it as a control voltage namely 7805 which is giving an output of 5V and 1.5A current.

The input voltage for a 7805 is within 7V and 25V. If you give below 7V, than the output coltage will not be an accurate +5V.

The below circuit is for the main controller of a pic.


For PIC 16F877A, there are 7 compulsory wiring for it to be in standby mode which are:

  1. Pin 1 - Memory Clear. Must be given +5V at all time. If given a momentarily 0V, the PIC will reset (active low configuration)
  2. Pin 11 & 32 - Vdd (+5V).
  3. Pin 12 & 31 - Vss (0V)
  4. Pin 13 & 14 - Oscillator / Resonator ranging 4MHz until 20MHz. (No polarity).
I will post an update for the picture of the power and the basic circuit later on. 


Sunday 18 November 2012

Initialization

Before we start to program, bear in mind (not that bear...!!) that we need to initialize the ports for the pic. From the previous tutorial, 16F877A have 33 pin for i/o which means it can be either 33 pin inputs or 33 pins outputs or any combinations that is up to 33 pins. (get the idea?).

Initialization (in my definition of understanding...) have 2 meaning which is:

  1. To tell the PIC on how to define the pins whether it is an input or an output (TRIS function).
  2. To tell what is the initial state of the respected pin for 2 conditions (PORT function) which is:
    • if input - to tell whether it is an active high or active low state.
    • if output - to tell whether the output is initially HIGH or LOW
How to use? Refer to the program below:


  • The first line of the program above tells us that we are using PORTA and all of the pins are used as outputs.
  • The next line tells us that from RA0 until RA1, the output is initially ON and from RA2 until RA7, the output is initially OFF.
Let's try the example below,


  • The first line of the program tells us that we are using PORTB and from RB0 until RB3, it is an input while from RB4 until RB7, the pins are output.
  • The next line tells us that RB7 and RB5 are having output which is initially ON and for the output at RB6 and RB4, it is initially OFF.
  • For RB0 until RB3 which are inputs, the connection are initially to the ground (active high).           

Sequence of Programming PIC16F877A

It's been a long time since the last time i posted for the software that we will be using to program a PIC. Below is to clarify the sequence that will be followed to get the job done.


 Remember, build the circuit first. After that is done, the image below applies.