Microcontroller Programming using MikroC & Fritzing for PCB layout: A step by step guide in PIC programming of a basic (0-9) ONE DIGIT COUNTER using 7-segment display
Hello everyone!
Today, I will share with you my contribution to the field of electronics and technology. I hope you will like it.
In this activity, you will be able to learn how to create a one digit counter using common cathode seven segment displays. It is quite different from the previous one because we will not use the function of a pushbutton in order to count 0-9, instead it will automatically count from 0-9 based from our programmed codes.
Let’s start with the materials and software that we will be using in this topic
Materials
♦ Push button
♦ Capacitor
♦ Crystal oscillator
♦ Seven segment
♦ PIC16F84A
♦ Resistor
♦ 7448 IC decoder
Software
◘ Fritzing
◘ MikroC compiler for PIC
Part 1: MikroC compiler for PIC
Step 1: Open the MikroC then click project. Then choose new project.
Step 2. Click the “New Project” for us to create our onedigit counter tutorial.
Input our project name , example “onedigitcounter”, project path is the folder path we like to save our project. The device we will use, the PIC16F84A. Check the necessary configuration as you can see in the picture below. Click “save” then click “ok”.
Step 3: New window will pop up. With the project name “onedigitcounter”. In this window, we will program our codes. So here, I have created my own program. Programming is an art, so you can create or program with your own strategy. The shorter the codes the better, because it can only consume small memory size.
In the code, it is important to analyze the possible syntax that we can use to display our desired output. In this activity we will use looping and if statement. There are two types of loop.
Namely, the For Loop & the While Loop.
"For" Loop is used to repeat a specific block of code a known number of times. For example, if we want to check the number of voters in a country, we loop from 1 to that number. When the number of times is not known before hand, we use a "While" loop.
While the if statement executes a block of code if a specified condition is true. If the condition is false, another block of code can be executed.
As you can see in the code, if (x==10), it will execute and display 0 and then begin to count from the start (y++).
So it will only count 0-9. If we add another seven segment display, it will continue counting up to 99.
The initial value is x=0.
As you can see in the code, x++, it execute adding the initial value by 1 then continues to add up until it reach number 9.
Then the if (x==10) triggers and make x=0. Then it will start from the beginning.
Make sure after clicking the Build Project, a Success will be displayed below.
These are codes that I had program for this tutorial
int unsigned x=0;
int unsigned y=0;
void main ()
{
trisb=0;
while (1)
{
portb=y*16 + x;
delay_ms(500);
x++;
if (x==10)
{
x=0;
y++;
}
if (y==10)
{
y=0;
}
} }
Part II. Circuit design using Fritzing PCB layout
Step 1: Let’s open the Fritzing software for our circuit layout
Step 2: Click on schematic then choose all the necessary components needed for circuit. Just click and drag to the schematic area.
Then right click each components then choose add bin then click my parts. All the components will be added to the my parts window.
Now let’s start constructing the circuit diagram under the schematic feature.
After constructing, save your work.
Now we can construct the circuit and arrange all the components in the breadboard
Click each line to display the wire connection. Then right click each wire to choose wire color.
Then to make the wire bend just press ctrl + click and hold the wire then bend it.
Application of this activity
By knowing how to create a simple counter, we can build our foundation in creating a large digit numbers. We already know some applications of this counter for example in a basketball game, the 24 sec shot clock or in our digital clock, the timer. Though we ignore how it works but we cannot deny the fact that we need it in our life. A simple counter can be used in displaying priority number.