20 Digit Virtual LED Counter


Results 1 to 10 of 10

Threaded View

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

    Talking 20 Digit Virtual LED Counter

    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1658&stc=1&d=117965309 4" align="right">

    Large scale, "real World" - LED counters can be quite expensive to build. Plus sometimes extremely difficult to drive if there's more than half a dozen or so digits. Purely hardware-based counters become increasingly more complex in circuitry with the more digits you have. But if you're using a µcontroller, writing the required software can be a daunting task. The biggest problem being, 20 digit variables as a whole simply just don't exist. Most programming languages for Windows provide direct support for the largest variable type being double precision. So as you can see, this virtual simulated approach is becoming increasingly more realistic by the second. Using your PC's monitor to display the counter which can be directly controlled by one of the PC's ports, in this case it's the serial - we can effectively achive almost anything that a real-World counter could. But before we press on, how in the World do manage 20 digits when we don't have a variable large enough? My solution here was to concatenate two double precision variables together. Messy stuff, but it works!, resulting with 20 usable digits that can be manipulated in almost any way. The counter can be fully controlled via a PIC or (similar) connected to the serial port. The PIC can load the counter with a starting value, increment or decrement that value with definable weights. The refresh rate measures in at a very modest 5 times a second @2,400 bps. Possibly much faster rates may be obtainable @9,600. (No testing done with this yet, in fact I don't even know that it works at this speed) Turning your attention to the screen shot of the Windows GUI, as you can see it's mostly all self explanatory - so I'll just make mention of a couple of things. RX control bytes are the bytes that the software expects to receive from the PIC for any given task. These are limited to 4 characters in length. You can assign anything that you wish. The first byte is critical, this is the synchronization byte that the Windows software expects to see, if it doesn't then it will totally discard any bytes that follow. The RX Values, other than shown haven't been tested but should be O.K. As you may have gathered after taking a glimpse at the screen shot of the Windows GUI, yes you can also directly control the counter via it!

    <table width="100%" Border="0" align="center" Cellpadding="5">
    <tr>
    <td>
    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1661&stc=1&d=117965501 6">
    </td>
    <td>
    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1660&stc=1&d=117965504 5">
    </td>
    </tr>
    </table>
    <hr/>
    Code:
    <font color="#000000">   <font color="#008000"><i>''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
       ' -    Demo Program For Windows-Based 20 Digit Virtual LED Counter   - '
       ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
     
       </i></font><font color="#0000FF"><b>INCLUDE </b></font><font color="#FF0000">&quot;modedefs.bas&quot;              </font><font color="#008000"><i>' Serial Protocol
       </i></font><font color="#0000FF"><b>DEFINE   </b></font>OSC <font color="#0000FF">4                      </font><font color="#008000"><i>' 4MHz crystal 
       </i></font>CMCON    <font color="#FF0000">= </font><font color="#0000FF">7                        </font><font color="#008000"><i>' All digital
       </i></font>TRISA    <font color="#FF0000">= </font><font color="#0000FF">%00000000                </font><font color="#008000"><i>' All outputs 
       </i></font>TRISB    <font color="#FF0000">= </font><font color="#0000FF">%00001101                </font><font color="#008000"><i>' Button inputs
                                           '
       </i></font>Inc_Button <font color="#0000FF"><b>VAR </b></font>PORTB<font color="#FF0000">.</font><font color="#0000FF">0              </font><font color="#008000"><i>' 3 push buttons inc, dec &amp; reset
       </i></font>Dec_Button <font color="#0000FF"><b>VAR </b></font>PORTB<font color="#FF0000">.</font><font color="#0000FF">2              </font><font color="#008000"><i>'
       </i></font>Rst_Button <font color="#0000FF"><b>VAR </b></font>PORTB<font color="#FF0000">.</font><font color="#0000FF">3              </font><font color="#008000"><i>'
       </i></font>RX_To_PC   <font color="#0000FF"><b>VAR </b></font>PORTA<font color="#FF0000">.</font><font color="#0000FF">0              </font><font color="#008000"><i>' RX line
          
       </i></font><font color="#0000FF"><b>SEROUT </b></font>RX_To_PC<font color="#FF0000">, </font>N2400<font color="#FF0000">, [&quot;@rst&quot;]    </font><font color="#008000"><i>' Reset counter
       </i></font><font color="#0000FF"><b>PAUSE </b>200                           </font><font color="#008000"><i>' Min required delay between commands  
    
       '================
       </i></font>Wait_For_Buttons<font color="#FF0000">:                   </font><font color="#008000"><i>' Send commands if buttons are pressed
       '================
       </i></font><font color="#0000FF"><b>IF </b></font>Inc_Button <font color="#FF0000">= </font><font color="#0000FF">0 <b>THEN              </b></font><font color="#008000"><i>' Increment button pressed ? 
           </i></font><font color="#0000FF"><b>SEROUT </b></font>RX_To_PC<font color="#FF0000">, </font>N2400<font color="#FF0000">, [&quot;@inc&quot;, &quot;1&quot;]
           </font><font color="#0000FF"><b>PAUSE </b>200                       </font><font color="#008000"><i>' Debounce delay + required delay
       </i></font><font color="#0000FF"><b>ELSE</b></font><font color="#FF0000">:</font><font color="#0000FF"><b>IF </b></font>Dec_Button <font color="#FF0000">= </font><font color="#0000FF">0 <b>THEN         </b></font><font color="#008000"><i>' Dec ?
           </i></font><font color="#0000FF"><b>SEROUT </b></font>RX_To_PC<font color="#FF0000">, </font>N2400<font color="#FF0000">, [&quot;@dec&quot;, &quot;1&quot;]
           </font><font color="#0000FF"><b>PAUSE </b>200                       </font><font color="#008000"><i>'
       </i></font><font color="#0000FF"><b>ELSE</b></font><font color="#FF0000">:</font><font color="#0000FF"><b>IF </b></font>Rst_Button <font color="#FF0000">= </font><font color="#0000FF">0 <b>THEN         </b></font><font color="#008000"><i>' Reset ?
           </i></font><font color="#0000FF"><b>SEROUT </b></font>RX_To_PC<font color="#FF0000">, </font>N2400<font color="#FF0000">, [&quot;@res&quot;]
           </font><font color="#0000FF"><b>PAUSE </b>200
       <b>ENDIF</b></font><font color="#FF0000">: </font><font color="#0000FF"><b>ENDIF</b></font><font color="#FF0000">: </font><font color="#0000FF"><b>ENDIF      
    
       GOTO </b></font>Wait_For_Buttons               <font color="#008000"><i>' Maintain loop checking for buttons
    </i></font>
    <hr/>
    The code above shows a brief sample of everything except for loading a particular value to the counter. Here's an example ...
    Code:
    SEROUT RX_To_PC, N2400, ["@set", "255"] 'Load counter with 255
    Same as with inc & dec, rx bytes followed by the weight / value. So if we wished to increment the counter by 5 at a time we would do the following ...
    Code:
    SEROUT RX_To_PC, N2400, ["@inc", "5"] 'Inc counter by 5
    <br/><hr/>You may download the Windows software counter.zip which is freeware but copyrighted.
    But firstly you'll need to obtain msvbvm50.dll <a href="http://www.dll-files.com/dllindex/dll-files.shtml?msvbvm50" target="_blank">Click here to get it</a>.
    <hr/>
    Happy counting !!!

    ◄Trent Jackson►
    <br/>
    Attached Images Attached Images    
    Attached Files Attached Files
    Last edited by T.Jackson; - 20th May 2007 at 15:42.

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. Virtual LED Clock For Windows By Trent Jackson
    By T.Jackson in forum Code Examples
    Replies: 8
    Last Post: - 10th November 2009, 08:20
  3. Single digit 7 Seg LED clock - PIC16F88
    By thirsty in forum Code Examples
    Replies: 4
    Last Post: - 17th July 2009, 08:42
  4. Dual 7-segment LED display counter
    By mosbc69 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 17th November 2008, 22:53
  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