Introduction: Stopwatch Using Pic18f4520 in Proteus With 7 Segment
I just started working with pic controller, one of my friend requested me to build a stopwatch from it. So i don't have hardware image to share, I have written code and simulated it on Proteus software.
here i have shared the schematic for the same.
three variable milliseconds, seconds, minutes are defined
here we have used timer interrupt of 10 ms, for every 1000 milliseconds, seconds variable will increase, for every 60 seconds minutes variable will increase.
Step 1: Things Required
1 pic18f4520 controller
2 seven segment displays
3 bc547 transistors
4 switches for start/stop/reset
5 resistors 330E,10K ,1K
6 download mikroC for pic https://www.mikroe.com/mikroc-pic
7 download proteus https://izofile.com/proteus-8-6-professional-full-...
Step 2: Code Logic and Display
What is a Seven Segment Display?
A Seven Segment Display (SSD) is one of the most common, cheap and simple to use display. It looks like above.
here we have to use Common cathode type of 7 segment display – In the common cathode type SSD, the –ve terminal of all the LEDs is commonly connected to the ‘COM’ pin. A segment can be lighted up when ‘1’ is given to the respective LED segment and ground is connected to the common. The internals are given in figure 2.
Step 3: Driving Display With Microcontroller
In my circuit, I have used the NPN BC547 Transistor.
For the simple use of a BJT as a switch, the emitter-collector junctions get shorted when there is an input signal at the base terminal, else it remains cut-off. The input should be given through a suitable resistor.
Step 4: Why Multiplexing?
Often we need to use two, three or more SSDs and that too using only a single MCU, but one problem that we face is the lack of I/O pins in the MCU, as one SSD would take 8 pins, and so three SSDs would take 24 pins. In pic18, we have only 48 I/O pins. So what is the solution?
One possibility is that we use a bigger MCU with more I/O pins. But then we are still restricted to only a maximum of 3 SSDs that can be used. Another much better and recommended solution to this problem is to multiplex the Seven Segment Displays.
Wikipedia says ‘ In telecommunications and computer networks, multiplexing (also known as muxing) is a method by which multiple analog message signals or digital data streams are combined into one signal over a shared medium. The aim is to share an expensive resource.’
What we mean by multiplexing of seven-segment display is that we will be using only 7 output ports to give the display on all of the SSDs.
Step 5: How to Achieve This?
Here, we will use ‘Persistence of Vision‘. Now you must have across this term already before. Yes, this is the same technique which is used in cinematography (display images so fast that our brain cannot distinguish any lag between two consecutive images). Similarly, when we mux more than one SSD, we display only one SSD at a time, and we switch between them so fast that our brain cannot distinguish between them.
Lets say each display is active for only 5 milliseconds at a time, i.e. it gets lighted up 1/0.0045 times a seconds, that’s roughly equal to 222 times/second. Our eyes cannot sense a change so fast, and thus what we see is that all the displays are working simultaneously. What is actually happening in the hardware is that the MCU gives ‘1’ to the pin (remember, giving ‘1’ to the base of a BJT shorts the Collector and emitter junction?), which is connected to the base of the transistor of the respective displays, keeps the port ‘ON’ for 5 milliseconds, and then turns it off again. This procedure is put in an endless loop, so that we see the display continuously.
Step 6: Multiplexing Algorithm
Define two ports in code, one for segment data port and segment control port.
trick here is you display the data on all 7 segment . and activate the one control pin on which you have to display that data. change the data and shift control pin.
here in this instructable we have used 6 digit multiplexing, just go through the c file attached and you will get it cleared.
We have a be nice policy.
Please be positive and constructive.