Virtual LED Clock For Windows By Trent Jackson


Results 1 to 9 of 9

Threaded View

  1. #1
    T.Jackson's Avatar
    T.Jackson Guest

    Talking Virtual LED Clock For Windows By Trent Jackson

    <table width="100%" border="0" Cellpadding="5">
    <tr>
    <td width="50px">
    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1645&stc=1&d=117940513 9">
    </td>
    <td>
    Not your ordinary Windows-based desktop clock, this one's PIC-driven! Yes that's right, the Windows software is just a display, it's the PIC that actually keeps the time. The circuit connects to any spare serial port on your PC and feeds the Windows-based software with an accurate time string every second. Setting the time is snack, this is done directly via the Windows software. The time can be set or displayed in either 12 or 24 hour formats.

    An interesting aspect of this project is that, in the Windows software, instead of using MSCOMM32.ocx, it uses a relatively much easier-to-use API based approach. First initial tests with this protocol have proven flawless. I haven't confirmed this yet but I think it might actually be much faster too. So for Windows developers out there using VB, I strongly suggest that you take a close look at the protocol in the download.

    Anyhow, turning your attention back to the clock for a moment, if you take a look at the schematic below you'll see that the whole thing can be built for less than the cost of your lunch. The circuit relies on no dedicated RTC chip, but instead uses portions of Paul R. Borgmeier's EZCLOCK2 code which makes good use of TMR0 to enable for some relatively accurate time keeping. Arguably almost on par with the DS1302. Last but not least, some of you may be asking what's the buzzer and LED for? Well, as it stands with the software "as is", the buzzer briefly goes off every second making a sort of tick-tock sound.
    </td>
    </tr>
    </table>
    <table align="center" width="100px" border="2" >
    <tr>
    <td>
    Schematic
    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1644&stc=1&d=117940668 8">
    </td>
    </tr>
    </table>
    <hr/>
    Code:
    '******************************************************************************
    '*   Name    : VClock.BAS                                                     *
    '*   Author  : Trent Jackson                                                  *
    '*   Notice  : No Copyright                                                   *
    '*           :                                                                *
    '*   Date    : 17/5/2007                                                      *
    '*   Version : 1.0                                                            *
    '*                                                                            *
    '* Acknowledgements                                                           *
    '* Portions of Program extracted from: EZCLOCK2 By Paul R. Borgmeier, PhD     *
    '* Crux analysis & design, LLC www.cruxanalysis.com                           * 
    '******************************************************************************
    
       Include "modedefs.bas"             ' Serial Protocol
       Define   OSC 4                     ' 4MHz crystal used
                                          '
       '// Variables
       Counter    VAR Word                ' Track TMRO  
       Hours      VAR Byte                ' Total hrs (0-23)
       Minutes    VAR ByTE                ' Mins (0-59)
       Seconds    VAR Byte                ' Secs (0-59)
       RX_To_PC   VAR PORTA.0             ' RX line
       TX_To_PC   VAR PORTA.1             ' TX ...
       LED_Buzzer VAR PORTB.5             ' LED & Buzzer
       
       '// Init
       CMCON       = 7                    ' All digital
       OPTION_REG  = %10000111            ' TMRO prescale = 256
       TRISA       = %00000010            ' All outputs except RA1
       TRISB       = %00000000            ' All outputs ...
       TMR0        = 0                    ' Reset TMRO
       INTCON.2    = 0                    ' Clear TMRO overflow flag
       Hours       = 0                    ' Null  
       Minutes     = 0                    ' ^
       Seconds     = 0                    ' ^
       Counter     = $7A12                ' Load time counter
       
       '=============
       Wait_For_TMR0:                     ' Main loop  
       '=============
       IF INTCON.2 = 0 THEN Wait_For_TMR0 ' Wait for TMRO overflow
       INTCON.2    = 0                    ' Clear TMRO overflow flag
           Counter = Counter - $800       ' Dec counter until 1 sec has elapsed  
    
       '// Process hrs, mins secs accordingly ...
       IF Counter < $800 THEN
          Seconds = Seconds + 1
          If Seconds = 60 Then
             Seconds = 0
             Minutes = Minutes + 1
             If Minutes = 60 Then
                Minutes = 0
                Hours = Hours + 1
                If Hours = 24 Then
                   Hours = 0
                EndIf
             EndIf
          EndIf
       
       '// Add leading zeros to all single digits & output str serially to PC
          If Hours < 10 And Minutes > 9 And Seconds > 9 Then
             SEROUT RX_To_PC, N2400, ["@","0",#Hours,":",#Minutes,":",#Seconds]
          ELSE:IF Hours > 9 and Minutes < 10 and Seconds > 9 THEN
             SEROUT RX_To_PC, N2400, ["@",#Hours,":0",#Minutes,":",#Seconds]
          ELSE:IF Hours < 10 and Minutes < 10 and Seconds > 9 THEN
             SEROUT RX_To_PC, N2400, ["@","0",#Hours,":0",#Minutes,":",#Seconds]
          ELSE:IF Hours > 9 and Minutes > 9 and Seconds < 10 THEN
             SEROUT RX_To_PC, N2400, ["@",#Hours,":",#Minutes,":0",#Seconds]
          ELSE:IF Hours < 10 and Minutes > 9 and Seconds < 10 THEN
             SEROUT RX_To_PC, N2400, ["@","0",#Hours,":",#Minutes,":0",#Seconds]
          ELSE:IF Hours > 9 and Minutes < 10 and Seconds < 10 THEN
             SEROUT RX_To_PC, N2400, ["@",#Hours,":0",#Minutes,":0",#Seconds]
          ELSE:IF Hours < 10 and Minutes < 10 and Seconds < 10 THEN
             SEROUT RX_To_PC, N2400, ["@","0",#Hours,":0",#Minutes,":0",#Seconds]
          Else
             SEROUT RX_To_PC, N2400, ["@",#Hours,":",#Minutes,":",#Seconds]
          EndIf: EndIf: EndIf: EndIf: EndIf: EndIf: EndIf
    
          Counter = Counter + $7A12          ' Reset counter 
          Toggle LED_Buzzer                  '  
       '//
       Else 'Wait here for 50mS to see if the host(PC) is trying to set new time val                               
       '//
          SERIN TX_To_PC, N2400, 50, Wait_For_TMR0, ["@"], Hours, Minutes, Seconds
       EndIf
       GoTo Wait_For_TMR0                    ' Loop back
       end
    If you plan on running the Windows executable you'll firstly need to obtain msvbvm50.dll <a href="http://www.dll-files.com/dllindex/dll-files.shtml?msvbvm50" target="_blank">Click here!</a>.
    <br/>
    Happy time keeping !
    <hr/>
    Trent Jackson
    <br/>
    Attached Images Attached Images   
    Attached Files Attached Files
    Last edited by T.Jackson; - 17th May 2007 at 14:37. Reason: Correct link

Similar Threads

  1. Conway's Game Of Life
    By wellyboot in forum mel PIC BASIC Pro
    Replies: 45
    Last Post: - 28th May 2020, 06:14
  2. Free Project - 245 LED Display
    By T.Jackson in forum Code Examples
    Replies: 221
    Last Post: - 16th August 2009, 04:59
  3. Single digit 7 Seg LED clock - PIC16F88
    By thirsty in forum Code Examples
    Replies: 4
    Last Post: - 17th July 2009, 08:42
  4. Help with sound command in 2 programs
    By hyperboarder in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th July 2007, 20:36
  5. LCD will not start
    By btaylor in forum mel PIC BASIC Pro
    Replies: 49
    Last Post: - 24th May 2007, 02:30

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts