View previous topic :: View next topic |
Author |
Message |
kaizer002
Joined: 13 Mar 2010 Posts: 1
|
source code for multiplexing |
Posted: Sat Mar 13, 2010 8:09 am |
|
|
Hello everyone!
I'm trying to make a 4-Digit Counter using PIC16F877A but the problem is, I don't have any idea how to program this project. Please help me.
Here's the schematic diagram:
I will use CCS C compiler.
Thanks in advance! |
|
|
John P
Joined: 17 Sep 2003 Posts: 331
|
|
Posted: Sat Mar 13, 2010 10:22 am |
|
|
You're wasting hardware by having U2 in the design. You can easily make the processor generate the correct segment outputs. You do have to use 7 pins of port d instead of 4, though.
There must be lots of ways to do this, but if it were my project I'd set up a repetitive interrupt at (say) 1KHz and have it do something like
Code: |
// This code could be made tighter, but this is easier to read
static int8 count;
if (++count > 3)
count = 0;
trisd = 0xF; // All off
portc = (1 << count);
portd = lookup_segments[digits[count]];
trisd = 0; // Turn on again
|
This assumes that the number you want to display has its digits in a 4-element array named digits[] and that there is a lookup table for the segments in a 10-element array of constants named lookup_segments[].
I'd turn off the portd outputs using trisd while loading new data, because otherwise there would be a slight mismatch between the setting of port c and port d, which might lead to "ghost" operation of unwanted LED segments. |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
Re: source code for multiplexing |
Posted: Sat Mar 13, 2010 2:47 pm |
|
|
kaizer002 wrote: | Hello everyone!
I'm trying to make a 4-Digit Counter using PIC16F877A but the problem is, I don't have any idea how to program this project. Please help me. |
You hardware design is not optimal and, depending on the brand, model and colour of the LED the LED may or may not illuminate as expected. The LED intensity is a function of how close the PIC output can be driven to the +5volt rail. Instead of using the 2n3704, if you use a PNP transistor connecting the emitter to +5v and the collector to the LED's common anode with a series resistor between the base and the PIC, this will result in the transistor turning fully on (saturate) with minimal power dissipation in the transistor. To turn on a display the ENx pin would need to go low (logic 0 output).
The modified circuit will result in the transistor turning fully on (saturate) with minimal power dissipation in the transistor. _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
|