HOME - - - - - - - - - Other material for programmers - - - - - - - - - Pascalite, "How To Use It" main page

Pascalite hardware: Counter

The Counter

The following assumes you've got your Pascalite set up and working. If it gives you what you want, great. Be advised, however, that this page is subordinate to others. Visit my Pascalite, "How To Use It" main page if you came drectly here and there are things "missing".

(You can show numbers on the LCD if you have one, but the following programs will also send at least part of every number to the four LEDs for those of you without an LCD display.)

The Pascalite has a counter. Unless you've met counters before, you may not realise how clever this little facility is. Read on! It is very useful! To make sure it is working....

Connect a momentary switch to the counter input (Pins 1&2 on the Pascalite Plus). Connect the other side of the switch to GND. Also connect the counter input to an 18K resistor. (Other values would do... c. 5k minimum, 50k max). Connect the other side of the resistor to 5v. In other words, do again almost what you did for IntTut2.

program IntTutCount;
var bNum:byte;

procedure NumToLCD(bTmp:byte);
(As in IntTut4)

write(LCD,255); {Clears LCD}
until 4=5;

When you start the program, it should display "00". Each time you press the switch connected to the counter, the output should go up by 1. (Don't be alarmed if it goes up by more than one. See below.)

Why is the counter so cool? It counts inputs even when the processor is doing other things. See also the interrupt handler, which causes a procedure to run every time the counter reaches its maximum value (255). If the counter then receives another pulse, it rolls over back to zero.

Now... I mentioned above that the counter may go up by more than one each time you press the button. This is because mechanical switches are imperfect. As they open or close, they sometimes make and break the connection several times befor the closure or opeing becomes "final". You won't usually be counting presses on a mechnical switch. Use google to find out about "de-bouncing" if you need help here.
To search THIS site.... (Go to the site's above, and use their search buttons if you want to seach them.)... Way to search this site without using forms
Search this site or the web powered by FreeFind

Site search Web search

Ad from page's editor: Yes.. I do enjoy compiling these things for you... hope they are helpful. However.. this doesn't pay my bills!!! If you find this stuff useful, (and you run an MS-DOS or Windows pc) please visit my freeware and shareware page, download something, and circulate it for me? Links on your page to this page would also be appreciated!
Click here to visit editor's freeware, shareware page.

Link to editor's (Arunet) homepage
How to email or write this page's editor, Tom Boyd