#picaxe 28x2
#no_data
#no_table
'#terminal 76800
symbol LED_pins = w1
symbol high_Pin = b2
symbol low_pin = b3
symbol ticked = b4 ' value toggles on each clock tick
symbol LEDdelay = b6 ' Brightness control
symbol LED_Sec = b7 ' Seconds LED
symbol LED_Min = b8 ' Minutes LED
symbol LED_Hour = b9 ' Hours LED
symbol LED_Hd1 = b10 ' Dim LED 1
symbol LED_Hd2 = b11 ' Dim LED 2
symbol LED_Hd3 = b12 ' Dim LED 3
symbol LED_Hd4 = b13 ' Dim LED 4
symbol TimeDiv = b14 ' only used in demo to simulate RTC
symbol oldtime = b15 ' only used in demo to simulate RTC
symbol newtime = b16 ' only used in demo to simulate RTC
' Constants
' ---------
'( Define the min and max values to match the LED arrangement )
#define Hourminval 54
#define Hourmaxval 62
#define Minuteminval 63
#define Minutemaxval 71
#define Secondminval 72
#define Secondmaxval 80
'( Define the brightness levels )
#define LEDdelayDim 1
#define LEDdelayBright 100
#define TimeDivRate 1 ' only used in demo to simulate RTC
' Define macros
' -------------
#Macro macShowLed(var)
b0 = var ' see http://www.picaxeforum.co.uk/showthread.php?29354
if b0 <> 255 then ' if LED = 255 then don't light it
ptr = b0 << 1
Low @ptrInc
High @ptr
PauseUS LEDdelay
dirsB = 0
dirsC = 0
endif
#EndMacro
' ---------------------------------------------------------------------------
' Code starts here
' ---------------------------------------------------------------------------
setfreq em64
pause 8000
sertxd(cr,lf,ppp_filename," ",PPP_DateTime,cr,lf)
tmr3setup %00110011 ' tmr3 only used in demo to simulate RTC
' copy lookup data to ram
' -----------------------
' gosub lookup_oracacle
gosub lookup_buzby
' Preset intial LED positions
LED_Hour = Hourminval + 3
LED_Min = Minuteminval + 3
LED_Sec = Secondminval + 3
LED_hd1 = LED_hour - 2
LED_hd2 = LED_hour - 1
LED_hd3 = LED_hour + 1
LED_hd4 = LED_hour + 2
timediv = TimeDivRate ' only used in demo to simulate RTC
' Main loop
' ---------
do
' Light the bright LEDs
LEDdelay = LEDdelayBright
' Flash hour LED at tick rate
if ticked = 1 then
macShowLED(LED_Hour)
endif
macShowLED(LED_Min)
macShowLED(LED_Sec)
' Light the dim LEDs
LEDdelay = LEDdelayDim
macShowLED(LED_Hd1)
macShowLED(LED_hd2)
macShowLED(LED_Hd3)
macShowLED(LED_Hd4)
' Detect time change
newtime = timer3
if newtime <> oldtime then
oldtime = newtime
dec timediv
if timediv = 0 then
timediv = timedivrate ' Reset time divider
gosub clockticked ' Go do stuff
endif
endif
loop ' End of main loop
' *****************************************************************************
' Subroutines
' *****************************************************************************
clockticked:
ticked = ticked xor 1 ' Toggle activity flag
inc LED_Sec
if LED_Sec > Secondmaxval then
LED_Sec = Secondminval
inc LED_Min
if LED_Min > Minutemaxval then
LED_Min = Minuteminval
inc LED_Hour
if LED_Hour > Hourmaxval then
LED_Hour = Hourminval
endif
' Calculate positions of dim LEDs
LED_hd1 = LED_Hour - 2
if LED_hd1 < Hourminval then
LED_hd1 = 255
endif
LED_hd2 = LED_Hour - 1
if LED_hd2 < Hourminval then
LED_hd2 = 255
endif
LED_hd3 = LED_Hour + 1
if LED_hd3 > Hourmaxval then
LED_hd3 = 255
endif
LED_hd4 = LED_Hour + 2
if LED_hd4 > Hourmaxval then
LED_hd4 = 255
endif
endif
endif
return
lookup_oracacle: 'lookup LED pins( Used once to populate scratch ram. )
let ptr = 0
for b0 = 0 to 179
lookup b0, (770,515,1541,1286,2312,2057,3597,3342,1026,516,2568,2058,1283,_
773,3337,2317,1539,774,1025,260,3850,2575,3336,2061,3592,2062,_
3849,2319,1795,775,1280,5,3334,1549,2051,776,1793,263,2049,_
264,2307,777,3333,1293,2305,265,2561,266,2562,522,3330,525,_
3588,1038,3587,782,3844,1039,3845,1295,513,258,1284,1029,_
2055,1800,3338,2573,512,2,2054,1544,769,259,2311,1801,768,_
3,3593,2318,2567,1802,2053,1288,2052,1032,2309,1289,2566,_
1546,2308,1033,1537,262,3591,1806,3590,1550,1792,7,2306,_
521,2564,1034,2048,8,2560,10,3329,269,270,3585,3331,_
781,3842,527,3843,783,3846,1551,256,1,1027,772,1798,_
1543,2569,2314,3854,3599,1540,1030,3594,2574,1797,1287,3853,_
3343,2310,1545,1796,1031,1282,517,1024,4,1281,261,1538,_
518,3335,1805,2565,1290,1794,519,1536,6,3847,1807,2050,_
520,2563,778,3332,1037,2304,9,3328,13,3584,14,3586,_
526,3841,271,2063,3848,3589,1294),LED_pins
@ptrinc = high_pin
@ptrinc = low_pin
next b0
return
lookup_buzby: 'lookup LED pins( Used once to populate scratch ram. )
let ptr = 0
for b0 = 0 to 125
lookup b0, ($205, $206, $207, $208, $209, $20A, $20D, $20C, $20B,_
$502, $602, $702, $802, $902, $A02, $D02, $C02, $B02,_
$005, $006, $007, $008, $009, $00A, $00D, $00C, $00B,_
$500, $600, $700, $800, $900, $A00, $D00, $C00, $B00,_
$105, $106, $107, $108, $109, $10A, $10D, $10C, $10B,_
$501, $601, $701, $801, $901, $A01, $D01, $C01, $B01,_
$50B, $60B, $70B, $80B, $90B, $A0B, $D0B, $C0B, $B0C,_
$50C, $60C, $70C, $80C, $90C, $A0C, $D0C, $C0D, $B0D,_
$50D, $60D, $70D, $80D, $90D, $A0D, $D0A, $C0A, $B0A,_
$50A, $60A, $70A, $80A, $90A, $A09, $D09, $C09, $B09,_
$509, $609, $709, $809, $908, $A08, $D08, $C08, $B08,_
$508, $608, $708, $807, $907, $A07, $D07, $C07, $B07,_
$507, $607, $706, $806, $906, $A06, $D06, $C06, $B06,_
$506, $605, $705, $805, $905, $A05, $D05, $C05, $B05 _
),LED_pins
@ptrinc = high_pin
@ptrinc = low_pin
next b0
return