```' LED_7SEG.Bas (PICAXE-18X)
'
' Sequentially displays a three digit value on a single 7-segment LED using
' a 74HC595 shift register with a decimal point between the second and third digits.
' Thus, the quantity 728 is displayed as 7 followed by 2 followed by .8

'
'  PICAXE			                74HC595 (16-pin DIP)
'
'  Output 2 (term 8) ----------------- Latch (term 12)
'  Output 1 (term 7) ----------------- Clk (term 11)
'  Output 0 (term 6) ----------------- Dat (term 14)
'
' On 74HC595;
'
'   +5 VDC  on Vcc (term 16)
'   GRD on GRD (term 8)
'
'   GRD on OE (term 13)
'   +5 VDC on RESET (term 10)
'
' Connect common anode LED such that DP is connected to QH (term 7), segment g to QG (term 6),
' etc.  Be sure to limit currect in any LED segment to 10 mA max.  Usually, a series 330 Ohm
' resistor.
'
' Use a common anode LED display such as Jameco Part #24740.  This LED has a left hand decimal point.
'
' Might be used with a Dallas DS18B20 or an LM34DZ temperature sesnor to sequentially display a
' temperature.
'
' Uses 130 bytes of 2048.
'
' copyright, Charise Byers, Peter H Anderson, Baltimore, MD, April, '04

Symbol SCK = 0
Symbol DAT =  1
Symbol LATCH = 2

Symbol Val = W0	' variables used in main

Symbol Digit = B2	' variables used in DisplayVal
Symbol DecPoint = B3

Symbol Patt = B4
Symbol N = B5

Low Latch
Low SCK
Low DAT

Top:
Val = 728	' this may the result of a temperature measurement
GoSub DisplayVal
Pause 5000
Goto Top:

DisplayVal:		' displays value in the form of xxx as xx.x sequntially on 7-seg LED

Digit= Val/100	' strip off the hundreds
DecPoint = 0
Gosub DisplayDigit
Pause 1000

Val = Val % 100	' obtain remainder
Digit = Val/10	' tens
DecPoint = 0
Gosub DisplayDigit
Pause 1000

Val = Val % 10	' units
Digit = Val
DecPoint = 1	' display a dec point
Gosub DisplayDigit
Pause 1000
Return

DisplayDigit:
' 0  1   2   3   4   5   6   7   8   9
Lookup Digit,(\$C0,\$F9,\$A4,\$B0,\$99,\$92,\$83,\$F8,\$80,\$90), Patt
'lights decimal
If DecPoint = 0 Then DisplayDigit_1	' no decimal point
Patt = Patt & \$7f	' insert a zero in the most sig bit to light dec point
DisplayDigit_1:
GoSub Shift
Return

Shift:
For N= 1 to 8
' set Dat output to value of most sig bit
If Patt >= 128 then Shift_1	' most sig bit
Low DAT
Goto Shift_2

Shift_1:
High DAT
Goto Shift_2

Shift_2:
High SCK		' clock pulse
Low SCK
Patt = Patt * 2	' next bit in most sig bit position

Next N

High Latch		' transfer shift register to latch
Low Latch
Return
```