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.


Wednesday, 6 June 2012

Software for PIC16F877A

PIC 16F877A needs to be programmed in order to ask it what to do. Therefore, we have many languages that can be written to program the PIC. In the old days, people use assembly language and it was hard for other people to understand it. Then comes the C++ where it is easier to write and understand the sequence of the program. All of this languages can be written using MPLab v8.30 thought there are many more software out there that can deliver the job.

I have been using Microcode Studio v2.2.1.1 with a compiler of PICBasic Pro v2.46 since 2009 and it is much simpler and easy for people to understand without having any background programming or engineering. The language to be written are called Basic Language with an extension of .pbp at the end of file. If you are thinking where to buy to download the program, please click the link below:


Another thing is that i never installed the software on a Window 7 before cause i only use Window XP SP3.So if you are using Window XP, i can help with the installation.

There are a lot of example on the internet for Basic Language. I will be using Basic Language for PIC16F877A through out this blog. 

Tuesday, 5 June 2012

Bootloader

Previously (around 8 hours after the previous post), we have discussed about the lifestyle of a hobbyist in microcontroller and the pin diagram of PIC 16F877A. Now to use a microcontroller, we must have a boot-loader. Boot-loader is used to download .hex file extension into the PIC or some people like to call it as burning procedure. 

In the old days, people like to download the program using MAX232 via RS232 cable. Yes...that brings back the old time of mine... But as life goes on, i am now using Cytron's bootloader which I will explain briefly. The boot-loader are as follows:

Bootloader: Cytron's UIC00B                                        ICSP Programmer Socket: UIC-S
                                     

The two hardwares above are to be used with the software called PICkit 2 v2.61. The software would look like this:

Ensure that the value at Vdd PICkit 2 is changed from 2.5 to 5.0 like below:

If there is a PIC in the ZIF socket, then the PICkit 2 will recognize it by displaying the device type as follows:
For the time being, I will not explain on how to use this software. We will discover it as we go on to the next post. If your are a first timer, then buying this boot-loader may help you in the next tutorial. However it can be easily bought via online order in Malaysia. If you already have a boot-loader, then this is just to add up to your knowledge.

Monday, 4 June 2012

Pin Diagram 16F877A

Before doing any circuit on the 16F877A, we must understand and memorize the pin diagram of the 16F877A. Let's us review on the picture below,


Basically, this is a DIP (Dual in Line) package having 40 pins. The first impression on some students of mine are "what a lot of pins you have there...(while drooling)". Yes there are a lot of pins but let us simplify the pin diagram.

There are 7 main pins that need to be wired first. If there are any problems in the PIC system, I will check these 7 pins before looking to any interfaces on the PIC. The 7 pins are:
  • Pin 1   - MCLR (always give +5V. if momentarily give a 0V, it will reset)
  • Pin 11 & 32 - Vdd (give +5V)
  • Pin 12 & 31 - Vss  (give 0V)
  • Pin 13 & 14 - OSC1 & OSC2 (connect a resonator / crystal oscillator ranging from 4MHz to 20MHz)
  *reset refers to the program to jump back at the 1st line of the programming.
  *for Pin 1, if supplied with +5V at all time the PIC will be on standby but cannot reset. To do that, we must     
    add a push button and a resistor to supply with 0V. The circuit symbol are as follows:

  *crystal oscillator and resonator are like this:


Now we have stated that 7 pins needs to be connected to PIC16F877A, therefore 40 - 7 = 33pins. These 33 pins are bidirectional meaning that it can be an input or an output. 16F877A have 5 ports and each ports have different pins as described below:

Programming for the beginners

Before we start with the basics, i believe that those who are really interested in this discipline will have their lives at least 70% the same with the picture below. Mine is around 99.13%. I'll try my best to share the knowledge and experience to those who are in need (although you can just google it...).

I will explain I will not explain the theoretical aspects such as the function registers, memory allocation, architecture and the boring stuff that you can get anywhere in a class (or again...the google way). We will be mostly do some wiring, programming and stuffs that geeks do every minute of their lives.