' ========================================================================= ' File....... SW21-EX10-Clock-DB_blink.SXB ' Purpose.... Simple digital clock with software multiplexing ' Author..... (C) 2000 - 2005, Parallax, Inc. ' E-mail..... support@parallax.com ' Started.... 01 SEP 2005 ' Updated.... 23 MAR 2007 by TSaavik for SX28 ' ========================================================================= ' -----[ Program Description ]--------------------------------------------- ' This program takes an external 1 Hz signal from the pulse generator and ' synthesizes a simple clock/timer. This code will run, unmodified, on an SX28 '------{ Device Settings ]------------------------------------------------- DEVICE SX28,TURBO,BANKS8,OSCHS3,SYNC,OPTIONX FREQ 50_000_000 ID "EX10.1" IRC_CAL IRC_SLOW ' -----[ I/O Definitions ]------------------------------------------------- Segs VAR RB ' Segments on RB.0 - RB.7 Digs VAR RC ' Digit control pins Tic VAR RA.2 ' 1 Hz input ' -----[ Constants ]------------------------------------------------------- Blank CON %00000000 ' all segments off IsHigh CON 1 IsLow CON 0 ' -----[ Variables ]------------------------------------------------------- nTic VAR Byte ' new tic input oTic VAR Byte ' old tic value xTic VAR Byte ' change (1 when 0 -> 1) tenths VAR Word ' seconds mod_tenths VAR WORD ' seconds // 60 time VAR Word ' formatted time time_Minutes VAR WORD theDig VAR Byte ' current display digit dug VAR Byte tmpW1 VAR Word tmpW2 VAR Word tmpB1 VAR Byte tmpB2 VAR Byte ' -----[ Initialization ]------------------------------------------------- PROGRAM Start watch Segs, 8, UBIN watch Digs, 4, UBIN watch time,16, UDEC watch time_minutes,16, UDEC watch dug, 8, UDEC ' -----[Subs ]------------------------------------------------------------- Show_Clock sub DIG FUNC 1, 2, 3 ' -----[ Program Code ]---------------------------------------------------- Start: Tris_A = %1111 Tris_B = %00000000 ' make LEDs outputs Tris_C = %00000000 ' make LEDs outputs Digs = %00001111 ' all off Main: DO WHILE Tic = IsHigh ' wait during high cycle GOSUB Show_Clock LOOP DO WHILE Tic = IsLow ' wait during low cycle GOSUB Show_Clock LOOP inc tenths ' update, tenths = tenths // 36000 ' ,current time GOTO Main ' start again ' -----[ Subroutines ]----------------------------------------------------- Show_Clock: time_Minutes = Tenths / 600 ' get mins, time = time_Minutes * 100 ' ,move to MM of MM:SS mod_Tenths = Tenths // 600 mod_Tenths = mod_Tenths / 10 'convert from 10hz signal to 1hz 1hz=1sec time = time + mod_Tenths ' add seconds to existing MM:SS Segs = Blank ' clear display READ DigSel + theDig, Digs ' select digit ' DIG COMMAND: "value DIG #" #=0-4 dug = DIG time, theDig READ Digit0 + dug, Segs ' move digit pattern to segs IF theDig = 2 THEN Segs.7 = tenths.0 'Segs = Segs + DecPnt ' add decimal point ENDIF inc theDig ' Update, theDig = theDig // 4 ' ,digit pointer 'break RETURN ' Use: result = DIG value, position ' -- "value" is byte or word ' -- "position" is byte, 0 to 4 DIG: IF __PARAMCNT = 2 THEN tmpW1 = __PARAM1 tmpB1 = __PARAM2 ELSE tmpW1 = __WPARAM12 tmpB1 = __PARAM3 ENDIF tmpB2 = 0 IF tmpB1 < 5 THEN LOOKUP tmpB1, 1, 10, 100, 1000, 10000, tmpW2 tmpW1 = tmpW1 / tmpW2 tmpW1 = tmpW1 // 10 tmpB2 = tmpW1_LSB ENDIF RETURN tmpB2 ' -----[ EEPROM Data ]----------------------------------------------------- ' %.GFEDCBA Digit0: DATA %00111111 Digit1: DATA %00000110 Digit2: DATA %01011011 Digit3: DATA %01001111 Digit4: DATA %01100110 Digit5: DATA %01101101 Digit6: DATA %01111101 Digit7: DATA %00000111 Digit8: DATA %01111111 Digit9: DATA %01100111 DigSel: DATA %1110 ' digit 0 active DATA %1101 ' digit 1 active DATA %1011 ' digit 2 active DATA %0111 ' digit 3 active