' {$STAMP BS2} ' {$PBASIC 2.5} ' ************************************************************** ' * Parallax Serial LCD and Solutions Cubed PocketWatch B Test * ' * By Vern Graner SSE, Texas Information Services * ' ************************************************************** ' * Code demonstrates the Serial LCD and the PWB being used as * ' * a simple digital clock. * ' ************************************************************** ' *Revision Info: V2.1 (VLG) 9-21-2005 * ' ************************************************************** ' ************************ ' * I/O Definitions * ' ************************ 'PIN 0 'PIN 1 'PIN 2 'PIN 3 'PIN 4 'PIN 5 'PIN 6 'PIN 7 'PIN 8 'PIN 9 LCD PIN 10 'Pin connected to LCD 'PIN 11 'PIN 12 FromAlarm PIN 13 'Pocket Watch Alarm Output ToPWB PIN 14 'Pocket Watch To Master (TM) FromPWB PIN 15 'Pocket Watch From Master (FM) ' ************************ ' * Variable Definitions * ' ************************ SS VAR Byte 'Seconds MM VAR Byte 'Minutes HH VAR Byte 'Hours DD VAR Byte 'Days MO VAR Byte 'Months YL VAR Byte 'Year Low (i.e. "05" in 2005) YH VAR Byte 'Year High (i.e. "20" in 2005) PM VAR Bit 'AM/PM flag ' ************************ ' * Constant Definitions * ' ************************ LcdBaud CON 32 ' 19.2k baud (BS2 @ rates) LcdLF CON $0A ' move cursor down 1 line LcdCls CON $0C ' clear LCD (use PAUSE 5 after) LcdCR CON $0D ' move pos 0 of next line LcdBLon CON $11 ' backlight on LcdBLoff CON $12 ' backlight off LcdOff CON $15 ' LCD off LcdOn1 CON $16 ' LCD on; cursor off, blink off LcdLine1 CON $80 ' move to line 1, column 0 LcdLine2 CON $94 ' move to line 2, column 0 PWBBaud CON 84 'Set Pocket Watch Baud rate to 9600 (BSII) ' ************************ ' * Pin Directions * ' ************************ INPUT FromPWB 'communication FROM Pocket Watch (i.e. "To Master") OUTPUT ToPWB 'communication TO Pocket Watch (i.e. "From Master") INPUT FromAlarm 'ALARM status pin ' ************************ ' * Initialize LCD/PWB * ' ************************ HIGH ToPWB ' SEROUT LCD, LcdBaud, [LcdBLon, LcdOn1, LcdCls] SEROUT LCD, LcdBaud, [LcdOn1, LcdCls] PAUSE 250 ' ************************ ' * Set the time * ' ************************ ' change the values to the current time, then uncomment the line and ' download the code to set the clock. ' ss,mm,hh,dd,mo,yl,yh 'SEROUT ToPWB,PWBBaud,[$55,$10,25,25,10,06,10,05,20] ' ************************ ' * Main Program Begin * ' ************************************************************************* TLOOP: 'Demos, Tricks & Fun '1- Toggle backlight on/off on 1 second intervals 'IF SS // 2 = 0 THEN ' SEROUT LCD, LcdBaud, [LcdBLon] 'ELSE ' SEROUT LCD, LcdBaud, [LcdBLoff] 'ENDIF '2- Turn the backlight off for the first 5 seconds of each minute 'IF SS >4 THEN ' SEROUT LCD, LcdBaud, [LcdBLon] 'ELSE ' SEROUT LCD, LcdBaud, [LcdBLoff] 'ENDIF '3- Turn the backlight on at 6:00pm and off at 6:00am IF HH=6 THEN IF PM=1 THEN SEROUT LCD, LcdBaud, [LcdBLon] ELSE SEROUT LCD, LcdBaud, [LcdBLoff] ENDIF ENDIF 'Get time from PWB: SEROUT ToPWB, PWBBaud, [$55,$12] 'send request for time SERIN FromPWB, PWBBaud, 100, nodat, [ss,mm,hh,dd,mo,yl,yh] 'populate variables with response from PWB nodat: ' Check AM/PM & set flag IF HH>12 THEN HH=HH-12: PM=1 ELSE PM=0 ENDIF ' Write time to liine 1 of the LCD SEROUT LCD, LCDBaud, [LcdLine1] SEROUT LCD, LCDBaud, [DEC hh,":",DEC2 mm,":",DEC2 ss] IF PM=1 THEN 'If PM var set then DONT print AM SEROUT LCD, LCDBaud, ["pm "] ELSE SEROUT LCD, LCDBaud, ["am "] ENDIF ' Write date to liine 2 of the LCD SEROUT LCD, LCDBaud, [LcdLine2] SEROUT LCD, LCDBaud, [DEC mo,"/",DEC2 dd,"/",DEC2 yh,DEC2 yl] GOTO TLOOP 'That was fun! Lets do it again! :)