LED Stamp Project

I worked for a while today (okay, like all day) on this Stamp project. I wanted to get a program to count from 0 to 99 and display its current counter (waiting 1 second between loops) on an LED display. Here’s the set up (showing the number 28):

Stamp project

It works like a dream. Kinda geeky, I know. My wife looked at me like, “Okay, it displays some numbers. yeah?”

Here’s the source code:

' Version 3 of this program. Powers two LED arrays from 0 - 99
'' The outer loop controls the 10^1 LED display. The inner loop
'' controls the 10^0 LED display.
'{$STAMP BS2}
' Index for the outer loop
outer VAR Byte
' Index for the inner loop
inner VAR Byte
' The current bit being evaluated to see if the corresponding
'' LED display anode needs to be turned on
current_bit VAR Byte
' The amount of time in milliseconds to pause the index on
'' the inner loop between iterations.
PAUSE_INTERVAL CON 1000
' General purpose index variable
index VAR Byte
' The bits to be made HIGH according to the current state of
'' the counter.
high_bits VAR Word
'
' Outer loop - "spins" once for each 10 times of the inner loop
'
FOR outer = 0 TO 9
  IF outer = 1 THEN OUTER_ONE
  IF outer = 2 THEN OUTER_TWO
  IF outer = 3 THEN OUTER_THREE
  IF outer = 4 THEN OUTER_FOUR
  IF outer = 5 THEN OUTER_FIVE
  IF outer = 6 THEN OUTER_SIX
  IF outer = 7 THEN OUTER_SEVEN
  IF outer = 8 THEN OUTER_EIGHT
  IF outer = 9 THEN OUTER_NINE
  IF outer = 0 THEN OUTER_ZERO
    return_outer:
    '
    ' I/O pins 8 - 14 control the 10^1 LED display
    '
    FOR index = 8 TO 14
      current_bit = index
      IF high_bits.LOWBIT(current_bit) = 1 THEN turnon_outer_bit
      compare_outer_bits:
    NEXT
  '
  ' Inner loop - "spins" once every PAUSE_INTERVAL milliseconds
  '
  FOR inner = 0 TO 9
    IF inner = 1 THEN ONE
    IF inner = 2 THEN TWO
    IF inner = 3 THEN THREE
    IF inner = 4 THEN FOUR
    IF inner = 5 THEN FIVE
    IF inner = 6 THEN SIX
    IF inner = 7 THEN SEVEN
    IF inner = 8 THEN EIGHT
    IF inner = 9 THEN NINE
    IF inner = 0 THEN ZERO
    return_inner:
    FOR index = 0 TO 6
      current_bit = index
      IF high_bits.LOWBIT(current_bit) = 1 THEN turnon_inner_bit
      compare_inner_bits:
    NEXT
    PAUSE PAUSE_INTERVAL
    '
    ' Clear the LED dispay so we can "draw" the next number
    '
    GOSUB INNER_LOW
  NEXT
  '
  ' Clear the LED display so we can "draw" the next number
  '
  GOSUB OUTER_LOW
NEXT
STOP
turnon_outer_bit:
  HIGH current_bit
  GOTO compare_outer_bits
turnon_inner_bit:
  HIGH current_bit
  GOTO compare_inner_bits
INNER_LOW:
  FOR index = 0 TO 6
    LOW index
  NEXT
RETURN
OUTER_LOW:
  FOR index = 8 TO 14
    LOW index
  NEXT
RETURN
OUTER_ONE:
  high_bits = %0011000000000000 ' bits 12, 13
  GOTO return_outer
ONE:
  high_bits = %0000000001010000 ' bits 4, 6
  GOTO return_inner
OUTER_TWO:
  high_bits = %0110111000000000 ' bits 9, 10, 11, 13, 14
  GOTO return_outer
TWO:
  high_bits = %0000000001101110 ' bits 1, 2, 3, 5, 6
  GOTO return_inner
OUTER_THREE:
  high_bits = %0111101000000000 ' bits 9, 11, 12, 13, 14
  GOTO return_outer
THREE:
  high_bits = %0000000001111010 ' bits 1, 3, 4, 5, 6
  GOTO return_inner
OUTER_FOUR:
  high_bits = %0011001100000000 ' bits 8, 9, 12, 13
  GOTO return_outer
FOUR:
  high_bits = %0000000001010011 ' bits 0, 1, 4, 6
  GOTO return_inner
OUTER_FIVE:
  high_bits = %0101101100000000 ' bits 8, 9, 11, 12, 14
  GOTO return_outer
FIVE:
  high_bits = %0000000000111011 ' bits 0, 1, 3, 4, 5
  GOTO return_inner
OUTER_SIX:
  high_bits = %0101111100000000 ' bits 8-12, 14
GOTO return_outer
SIX:
  high_bits = %0000000000111111 ' bits 0-5
GOTO return_inner
OUTER_SEVEN:
  high_bits = %0111000000000000 ' bits 12-14
GOTO return_outer
SEVEN:
  high_bits = %0000000001110000 ' bits 4-6
GOTO return_inner
OUTER_EIGHT:
  high_bits = %0111111100000000 ' bits 8-14
GOTO return_outer
EIGHT:
  high_bits = %0000000001111111 ' bits 0-6
GOTO return_inner
OUTER_NINE:
  high_bits = %0111001100000000 ' bits 8, 9, 12, 13, 14
GOTO return_outer
NINE:
  high_bits = %0000000001110011 ' bits 0, 1, 4, 5, 6
GOTO return_inner
OUTER_ZERO:
  HIGH_bits = %0111110100000000 ' bits 8, 10-14
GOTO return_outer
ZERO:
  HIGH_bits = %0000000001111101 ' bits 0, 2-6
GOTO return_inner

Advertisements

One Response to “LED Stamp Project”

  1. […] I got my Javelin Stamp microprocessor the other day, and have converted my Basic Stamp 2 project code to Java. The wiring is exactly the same. All I did was pop out the BS2 chip and pop in the Javelin. Well, that and rewrite the code. I decided to create a class to represent the LED as an object. I had a few requirements in mind: […]

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: