Pages

Saturday, August 23, 2014

Design a circuit connecting a binary coded decimal seven segment display to PIC 16F877A Microcontroller.

Today we are going to write a c program to display numbers from 0 to 9 automatically in the ascending and descending order on a circuit connecting a binary coded decimal seven segment display to PIC 16F877A Microcontroller.

I would like to explain it in two different ways. First let’s discuss the hardest way of doing it. :D Let’s think unfortunately you have created your circuit as below.


figure - 01




figure - 02

figure - 03



You can use an array and for loop to reduce the amount of codes. So shall we learn the easiest way of doing that? To do that you should create your circuit as below.

 
figure - 04

As it’s very easy I will only demonstrate display numbers from 0 to 9 automatically in the ascending order.

 
figure - 05

Below image will briefly explain what is meant by above code segment.

figure - 06


Now you need to use binary to hexadecimal converter (http://www.binaryhexconverter.com/binary-to-hex-converter ) just convert the number you need to display into binary and then convert that binary number into hexadecimal.

Here I convert the number into binary to show the current flow of ports. Otherwise the number can be directly converted into a hexadecimal number.

Tuesday, August 19, 2014

Knight Rider Circuit

Today we are going to create a simple knight rider circuit in two ways. Before the coding part let’s create the circuit using proteus. If you are not much familiar with proteus and MPLAB you can view my first post on embedded system.

This is the screen shot of the circuit, when you switch on the push button knight rider circuit will start to work.
figure - 01



I am gonna program this in two ways. First let’s see the long and descriptive method of doing that.


figure - 02

If I briefly explain the things above, I have used a delay function to make a delay in between two bulbs blink and the response for the selected delay will depend on your machine processor. That means delay_ms(1000) ;will behave differently in different machines, so you can adjust it according to your requirement.

Now you may wonder what’s meant by PORTB = 0x01, that simply used to select which bulb should light up at the moment. Easier way to do this is use online binary to hexadecimal converter. (http://www.binaryhexconverter.com/binary-to-hex-converter )

We can represent above 8 bulbs in a binary representation
If you need to light up 6 th bulb, the binary representation and hexadecimal representation should look like below.
figure - 03

So inside the program we can write it as POARTB = 0x020;

This is the second and short way of doing that, Just replace your while loop by using following code,
figure - 04


Good luck!  :)
How to create a simple application using Proteus ISIS and MPLAB


First open MPLAB IDE, go to project ->Project Wizard and go through following process.


figure - 01
figure - 02
Then select the device, in my case I select the PIC16F84A.

figure - 03

Now you need to select a language toolsuite. Select HI TECH Universal Toolsuite from the Active Toolsuit drop down list.

figure - 03





In any case if the language toolsuit HI-TECH toolsuit  is not visible just go to the select language toolsuit in project and add it.


figure - 04


figure - 05

figure - 06

Then browse the location for the project.

figure - 07



figure - 07


figure - 08


figure - 09


figure - 10

At the end of the project wizard you will get the below output.
figure - 11

Now you need to add a new file to the project, to do that, go to

file ->Add New file to project and create a c file.

figure - 12


figure - 13

Then you will get the below window.

figure - 14


Now you can give instructions to your microcontroller using your project1.c file. Let’s write a simple c program for the PIC we selected earlier (PIC16F84A).


figure - 15


Before going deep in code let’s have an idea about our micro-controller, Open proteus ISIS and click on component model.

figure - 16

Then click on the letter P to pick a device.

figure - 17

It will show you the below window.

figure - 18

After selecting the micro-controller click on OK button. Then it will show you the micro-controller which we are going to program.

figure - 19

First click on it and then click on the program board.

figure - 20



                                                                                
Now we are going to add a LED into our circuit, I just type LED in keyword box and select animated led in any color you wish, red, green and blue.
figure - 21



figure - 22


Now we need to add a power terminal to the circuit. So to do that click on Terminals Mode.

figure - 23



Then select the power terminal and place it on the circuit board.(Also add ground terminal to the circuit). After you place the terminal don’t forget to right click on your mouse. If not terminals will be placed everywhere :D.

figure - 24


Now our circuit board will looks like below.

figure - 25

Now draw lines (connect wires) and complete the circuit.

figure - 26

figure - 27

Now the time to write our codes. So let’s move on to the MPLAB IDE

figure - 28



We going to define all A ports as inputs and all B ports as outputs by giving them 1 (input) and 0(output). Now I need to give power to the LED. To do that I gave 5v to the diode by making RB0=1. Click on the red color button to build with compile our program.

figure - 29



figure - 30


Now we need to load our instructions (Program) to the micro-controller. Double click on the micro-controller.



figure - 32

Click on the folder mark and load the hex file.

figure - 33



Now run your circuit by clicking on the run button which is located in the left bottom corner of the proteus ISIS.

figure - 34


Enjoy your codes. Output will definitely looks like below.

figure - 35




Don’t forget to stop the application if you need to do any changes to the circuit.

Will meet u all with Knight Rider circuit soon..