View Full Version : bs2 7 segment led counter

02-17-2010, 06:55 AM
http://forums.parallax.com/images/smilies/lol.gif·http://forums.parallax.com/images/smilies/roll.gif·http://forums.parallax.com/images/smilies/lol.gif·lol, want to use 1 maybe 2 7 segment led's 2 count wen i press a button. i dont know where 2 start but i really need help with da programming. not so much the schematic. oh and please comment 4 me. i'd really, really, really, appreciate it! http://forums.parallax.com/images/smilies/confused.gif http://forums.parallax.com/images/smilies/cool.gif http://forums.parallax.com/images/smilies/freaked.gif http://forums.parallax.com/images/smilies/lol.gif http://forums.parallax.com/images/smilies/eyes.gif

Post Edited (bs2-man) : 2/17/2010 12:58:43 AM GMT

02-17-2010, 07:03 AM
There is a thread on this here some where if Parallax ever fixes the search function you can search for it.

- Stephen

02-17-2010, 07:19 AM
i cant find it.

02-17-2010, 07:41 AM
wat should i do?

Mike Green
02-17-2010, 07:56 AM
You will probably find some useful information in the Nuts and Volts Columns that you can reach from the main Parallax webpage by clicking on the Resources tab.

For learning how to program, start with the "What's a Microcontroller?" tutorial and the "BASIC Stamp Syntax and Reference Manual". Both are through the Downloads & Press link. The Manual is under BASIC Stamp Documentation and the tutorials are under Stamps in Class Downloads.

02-17-2010, 07:58 AM
ill start looking around and if i find it, ill let u know. thanks!

02-17-2010, 08:10 AM
ok, i just realized somthing, one of the displays is common anode and the other is common cathode.

02-18-2010, 12:44 AM
bs2-man I started a thread on this a couple weeks ago here is a link let me know if I can help I got the first 7 segment to count but I 'm having a little difficulty multiplexing to the 2nd 3rd and 4th.



02-18-2010, 05:24 AM
ok, what is the code 4 one 7 segment display?

02-18-2010, 05:24 AM
ok, what is the code 4 one 7 segment display?

02-18-2010, 08:48 PM
bs2-man said...
ok, what is the code 4 one 7 segment display?

Sorry about the formatting. I copy-pasted it.

' {$STAMP BS2}
' {$PBASIC 2.5}

Digit0 DATA %11101111
Digit1 DATA %10001100
Digit2 DATA %11010011
Digit3 DATA %11010110
Digit4 DATA %10110100
Digit5 DATA %01110110
Digit6 DATA %01110111
Digit7 DATA %11000100
Digit8 DATA %11110111
Digit9 DATA %11110110

DATaddr VAR Word ' Word variable for our pointer
counter VAR byte ' Keep track of current digit
Dchar VAR byte ' Variable to keep digit in
INPUT 3 ' Make pin 3 an input for the button
DIRH = %11111111 ' Make pins 8-15 outputs for the display

' -----[ Program Code ]----------------------------------------------------

counter=0 ' initialize counter
DATaddr = Digit0 ' Make pointer = start of data table

Main: ' Main program loop

READ DATaddr + counter, Dchar ' Read the character (byte size by default) from our marker (Digit0) + counter
OUTH = Dchar ' Send the value to port
DEBUG DEC Dchar ' Send value to console

IF IN3=0 THEN waitkey ' Has the button been pressed? No? try it again
PAUSE 250 ' For a little button debounce, wait 250ms

counter = counter + 1 ' increment counter
if counter > 9 then counter = 0 ' limit the counter and roll it back over to zero

goto main

"puff"...... crap, there went another one.

02-20-2010, 02:16 AM

There·are·detailed examples of controlling a 7-segment display with the BS2 in What's A Microcontroller? text·we offer. It is in chapter 6 "Digital Display" and it covers the programming and explanations very well; the book can be downloaded for free so it can be used for a quick reference. Here is a link for your review and reference.

What's A Microcontroller?:


Joshua Donelson
www.parallax.com (http://www.parallax.com)

02-20-2010, 09:13 AM
If you wanted to do a little more work on the hardware side to make the software side a little easier, you could use a BCD to seven-segment decoder (I have used the 4511 with a manual input, but it only works with common cathode displays). this would also require fewer I/O pins (four for BCD input). You output the required digit in binary form (Write to OUTA, OUTB, OUTC, or OUTD, use the DIG command and store value in a Nibble). OUTA is the first four I/O pins, OUTB for the second set, and so on.

' {$STAMP BS2}
' {$PBASIC 2.5}

'displays the first digit of a two-digit number with a seven segment decoder
'decoder conneced to I/O pins 0-3

dispnum VAR Byte 'number to be displayed
digit VAR Nib 'variable to hold first digit
DIRA = %1111 'sets pins 0-3 to outputs

DEBUG "enter number: " 'get a number
DEBUGIN DEC2 dispnum

digit = dispnum DIG 1 'get first digit
OUTA = digit ' send digit to decoder (I belive that pin 0 is connected to the LSB pin
'on the decoder)

02-20-2010, 09:22 AM
Note: the decoder could allow you to use four displays

02-22-2010, 08:05 PM
ok, ill try that.

04-26-2010, 11:36 PM
I need the 7 segment display to act as an UP/DOWN counter with 2 push pins. What do I need to add to the code pasted above to add an additional push pin & cause the 7 segment to count down or subtract from the pin1 up code?

04-27-2010, 06:08 AM
fallen said...
I need the 7 segment display to act as an UP/DOWN counter with 2 push pins. What do I need to add to the code pasted above to add an additional push pin & cause the 7 segment to count down or subtract from the pin1 up code?
Well, what I would suggest you do is try and understand the code that makes it count up. Once you do that you can move on to trying your own code to make it count down.

What I mean is, it is a very simple thing to do if you understand the up counting. I assume you do not understand the code and you should ask questions about the existing code that you do not understand. Then you will be using much more of your own brain cells to come up with a solution.· You need to try your own code, if it dosen't work then ask questions after you toy with it for an hour or so.

Typically, the good programmers here and on other forums have spent thousands of hours testing code while making thousands of mistakes. When I started coding commodore 64 computers I was coding for at least 12 hours a day perhaps 18 and pulling all nighters debugging those programs. That is how i learned and i will bet most here remember those days with a feeling of satisfaction when they whip up a complicated project and understand it will typically involve many hours of head banging, debugging the logic that somehow gets twisted even now.

Just get in there and make some changes, if going up uses addition, what do you think would make the counter go down?

Think Inside the box first and if that doesn't work..
Re-arrange what's inside the box then...
Think outside the BOX!