PDA

View Full Version : 7-segment display with P16F84



spitfire
- 9th July 2007, 12:00
Hi all, I am new to PIC's but have been studying electronics for 3 years and work as a technician.

I recently came across this site http://www.melabs.com/resources/articles/ledart.htm
with instruction on how to run 7-segment display, i have built the circuit and programmed the PIC with this code: http://www.melabs.com/resources/samples/pbp/7segment.pbp
but the numbers run really fast and display 0 runs too fast to read it, I have tried adding a PAUSE 1000 under "mainloop" and just below GOSUB display but it only make the displays flash on and off

I am trying to get them to display a number for atleast 1 second each or atleast make it so i can read digit 0

PS I have tried contacting the site but they never got back to me.

Thanks is advance.
once I get this working and learn a little more I plan on adding push buttons and making it into a stopwatch or either a countdown timer.

Raf

Jerson
- 9th July 2007, 12:54
i Var Byte
n Var Byte
Value Var Word


TRISB = $80 ' Set segment pins to output
TRISA = $f0 ' Set digit pins to output

mainloop:
For Value = 0 To 9999
GoSub display ' Display the value
Next Value

GoTo mainloop ' Do it forever

You need to modify this patch to something like this


i Var Byte
n Var Byte
Value Var Word
timedelay var word

TRISB = $80 ' Set segment pins to output
TRISA = $f0 ' Set digit pins to output

mainloop:
For Value = 0 To 9999
for timedelay = 0 to 2000
GoSub display ' Display the value
next
Next Value

GoTo mainloop ' Do it forever



The value you choose for the timedelay will help you persist a value for as long as you choose.

Jerson

keithdoxey
- 9th July 2007, 12:56
Hi all, I am new to PIC's but have been studying electronics for 3 years and work as a technician.

I recently came across this site http://www.melabs.com/resources/articles/ledart.htm
with instruction on how to run 7-segment display, i have built the circuit and programmed the PIC with this code: http://www.melabs.com/resources/samples/pbp/7segment.pbp
but the numbers run really fast and display 0 runs too fast to read it, I have tried adding a PAUSE 1000 under "mainloop" and just below GOSUB display but it only make the displays flash on and off

I am trying to get them to display a number for atleast 1 second each or atleast make it so i can read digit 0

PS I have tried contacting the site but they never got back to me.

Thanks is advance.
once I get this working and learn a little more I plan on adding push buttons and making it into a stopwatch or either a countdown timer.

Raf


This is the section of code you should try to alter



display:
For i = 0 To 3 ' Loop through 4 digits
n = Value Dig i ' Get digit to display
GoSub display1 ' Display the digit
Pause 1 ' Leave it on 1 millisecond
Next i ' Do next digit
Return


This displays each digit for 1 millisecond. try increasing the length of the pause.

By adding your Pause 1000 in the main loop you are adding a 1 second delay between counting. The LEDs are only lit during the display subroutine so you have 4mS of display and then a second waiting to the next 4mS.

Try a 25mS delay (PAUSE 25) or longer to make the digits more visible but you may then notice a flicker across the digits.

Try adding another counting loop so that you only increment the 0-9999 count once every "x" passes through the main loop.

HTH

Keith

spitfire
- 9th July 2007, 13:04
Thank alot guys, I was hardly expecting such promt replys.
I will try your suggestions out now.

spitfire
- 9th July 2007, 14:58
I got it working using your method Jerson by setting "for timedelay = 0 to 100", works great.

I was wondering if someone could recomend some books or any other good sources of information for writing code?

Cheers,
Raf

Archangel
- 9th July 2007, 19:33
Hi Spitfire,
I have bought several books, and without this forum, I would be using them as table levelers, I do not have one I would recommend. Keep reading this forum and the PBP manual, read the archives . . every post, thats waaay better than any book I've seen. Bruce is writing one though :) and when it is published, I will buy one.
JS

hoops2006
- 4th October 2007, 19:26
Does anyone know where i can get one of those 3 digit seven segment displays that are designed to be multiplexed. aka has 12 pins instead of well loads more.

hoops2006
- 22nd October 2007, 19:57
quick one.
in the 7 seg display program what does ~dcd mean in the line
digits=~dcd i
thanks

spitfire
- 24th October 2007, 10:42
quick one.
in the 7 seg display program what does ~dcd mean in the line
digits=~dcd i
thanks


~ = NOT
and
DCD = it changes a bit number (0-15) into binary and set that bit to a Logic 1

Basicly it finds out what value digits is (0 to 3, 0 being the first display on the right and so on) and converts that into binary if 0 then to 00, if 1 then to 01, if 2 - 10, if 3 - 11 and instead of applying a logic 1 like DCD is supposed to do it does the opposite because there is ~ infront of it which make it 0

Its basicly applying a Logic 0 to pin RA0 on the PIC,completing the subroutine and then doing the same for pin RA1, RA2 and RA3. These are the pins that turn on and off each digit.
Logic 0 normally means 0 or close to 0 Volts but in this case transisors are being used to supply the current to the display. A transistor is basicly an inverting switch so if you input logic 1 (+5V) you get 0 at the output and the opposite if you apply 0 Volts to the input.

I got a little carried away there and have gone into more detail and answering more than you asked but it might help you understand what the code is doing a bit better. Or atleast I hope so.

hoops2006
- 24th October 2007, 19:34
Many thanks for your reply spitefire just what i needed. I made a boxing round timer a while back, now im trying to improve it by displaying the time on a 7 seg display. its proving to be tricker than i thought. As im still struggling to get my head round this one as im a newbie to pics your extra info helped alot.

spitfire
- 25th October 2007, 12:20
No worries hoops, nice project there. Have you got the hardware side finished yet?

I'm also somewhat of a newbie to PICs but after studying discrete logic and designing a 24 hour clock with cmos 4000 series IC's (made my own 4 digit 7-segment display on veroboard using 58 blue LEDs) I now unterstand abit better.

I'm interested to see how it turns out.

hoops2006
- 28th October 2007, 13:59
Yes i think i have a fair idea of the hard ware. Pretty much the same set up as the link you gave on the first post. Two microswitches for round selection .With a relay chunked in for the buzzer. But my objective for now is to get minutes and seconds counting down on the display. Once i have that ill start worrying about how to select the times i want ect,

So i have plenty to keep me going. ill keep you posted.

hoops2006
- 28th October 2007, 20:20
Would a count down timer be as simple as:

for sec=59 to 0
pause 1000
if sec=0
then minutes=minutes-1
gosub display.

the value for display would be (minutes*100)+sec eg if 3mins 59 sec value 359
then just display the value as per the code on the link.

hoops2006
- 30th October 2007, 20:43
Are u in the raf spitfire?

jasem700
- 23rd February 2009, 19:36
Hi all friend
there is someone can create this project in proteuse and poste it
and thanks

jasem700
- 26th February 2009, 13:58
Hi all friend

SOMRU
- 3rd March 2009, 19:22
I have used this listing for over two years without any problems...
and am happy to share it...
ENJOY!!