<?xml version="1.0" encoding="UTF-8"?> <rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
><channel><title>SulhanSetiawan.com &#187; Counter</title> <atom:link href="http://www.sulhansetiawan.com/tag/counter/feed" rel="self" type="application/rss+xml" /><link>http://www.sulhansetiawan.com</link> <description></description> <lastBuildDate>Sun, 05 Feb 2012 17:08:53 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>3 Digits Counter</title><link>http://www.sulhansetiawan.com/counter-3-digit</link> <comments>http://www.sulhansetiawan.com/counter-3-digit#comments</comments> <pubDate>Mon, 22 Sep 2008 03:27:44 +0000</pubDate> <dc:creator>Sulhan</dc:creator> <category><![CDATA[Experiments]]></category> <category><![CDATA[Microcontroller]]></category> <category><![CDATA[All]]></category> <category><![CDATA[Microcontroller Learning]]></category> <category><![CDATA[Counter]]></category><guid isPermaLink="false">http://sulhansetiawan.com/?p=224</guid> <description><![CDATA[A friend asked me for help to create a program to perform calculations that can go up or down. The data displayed on a three-digit seven segment. Meanwhile, the buttons mounted on the port 3 used to raise or lower the count. Actually, he asked me to place the digits control using P0, and P2 [...]]]></description> <content:encoded><![CDATA[<p>A friend asked me for help to create a program to perform calculations that can go up or down. The data displayed on a three-digit seven segment. Meanwhile, the buttons mounted on the port 3 used to raise or lower the count.</p><p>Actually, he asked me to place the digits control using P0, and P2 for segment data. However, because previously I had made the program with P0 as the control of digits and P1 for segment data, so that I don&#8217;t need to reconfigure when I tried on the simulator, I keep using P0 as the control of digits and P1 for segment data. Therefore if you have already used P0 as the control of digits and P1 for segment data, then you need to change the PortDigit and PortData constants at the top of the program.</p><p>To realize the friend request, I use the way I usually do if I want to display data on the seven segment, i.e. put seven segment manager procedure on the timer interrupt. This ensures our programs to be able to display data on the seven segment with good brightness. There are several examples of programs that put the seven segment scanning process in the main program. But we know that the seven segment which installed in a multiplex must continuously scanned to be able to display the data. If the program are less keen in doing the scanning, then the display will be disturbed. Probably will not light up, and this is the worst, or at least the light intensity of the seven segment will be dimmed. And it is very unpleasant. By using a timer interrupt to do the scanning, we can relieve our attention from the scanning process, because it has been fully handled the interrupt handler. So this way is the best way (at least I think so, you may leave a comment if you do not agree).</p><p>Then, because the program is indeed a very simple program, then we can use all facilities owned by the microcontroller without much consideration. For easier handling in counter addition or subtraction, we can use the external interrupts, i.e. ext0 and ext1. So we just attach the button at P3.2 (ext0) and P3.3 (ext1). Of course we must use the button that really bounce-free (bounceless), so that if we press the button once, then we also get only one count. To raise the count, we use ext0. As for lowering the count, we use ext1. In the main program, we do not even do anything.</p><p>Using interrupts to handle button is very simple in terms of response. But the drawback is that the button used should be a bounceless type. In addition, only P3.2 and P3.3 can be used. Therefore, using debouncing technique as I have discussed in the <a title="Mudah dan Menyenangkan Belajar Mikrokontroler" href="http://www.sulhansetiawan.com/mudah-dan-menyenangkan-belajar-mikrokontroler"><strong>Easy and Fun Learning Microcontroller</strong></a> book will probably be a better solution in handling button. For that, I also will feature a program that handles the button not on the external interrupt, but placed on the timer interrupt. Thus, in addition to the timer interrupt is used to perform seven segment scanning is also used for button scanning.</p><p>In scanning through the timer interrupt, we can use any button, does not have to use the bounceless. We just need to adjust how quickly button bounce will be addressed. To try it, you can change the value MaxWait to 255 to slow down the response of the button bounce. If you use a simulator, and a computer that used is quite a fast computer, it may be the key response is still too fast. You simply change the TimeOutDown and TimeOutUp type to be <span style="color: #800000;">unsigned int</span>, and change the MaxWait value to higher rates. After that, try to press the button on Tombol.exe with high frequency. You will find that if the button is pressed too quickly, then presses the button too fast will be considered as a bounce. Thus, we can use the buttons that are not really bounce free. All you need to do is adjusting how sensitive your buttons, i.e. by setting the MaxWait value. And generally, you will not use numbers higher than 255. Therefore, the data type I use is <span style="color: #800000;">unsigned char</span>.</p><p>Remember, if you use Tombol.exe as simulated buttons, then you must set the used port (in this case is P3) on the simulator to be linked in <strong>Link Message</strong>. This is necessary because Tombol.exe send the keystrokes signals to the simulator through Window Message. As for the program that handles button via the external interrupts, then you can not use Tombol.exe, because Tombol.exe could not provide an interrupt signal to the simulator. You must use the existing buttons on the simulator. To display this button port window is from the <strong>View-Port</strong> menu. Then from the window, double-click on the desired port, which is the name of the port, not on its value, because if you double-click on the value, then it will appear the dialog to change the value of the port or the relevant registers.</p><p>Another friend asked me, &#8220;How do I create a program that constantly monitor keystrokes, but other operations continue to run without being interrupted by the oversight of the key&#8221;. Well, two examples of the above program, whether using an external interrupt and those that use the button scanning on the timer interrupt, has conducted monitoring of key presses continuously, while at the main program does not even do anything. Thus, the above example is also an answer to this question. You simply put the other operations in the main program, while the supervision of the button has been continuously monitored.</p><p><strong><a title="Counter3Digit.zip" href="http://resource.sulhansetiawan.com/microsource/Counter3Digit.zip">I wrote the program in c and M51 language only</a></strong>. So if you just have a Micro v5.4, which is the IDE that I include in the <strong><a title="Mudah dan Menyenangkan Belajar Mikrokontroler" href="http://www.sulhansetiawan.com/mudah-dan-menyenangkan-belajar-mikrokontroler">Easy and Fun Learning Microcontroller</a></strong> book, then you should first download the <strong><a title="Microcontroller Project" href="http://www.sulhansetiawan.com/microcontroller-project#download">latest version of the IDE that supports the C language.</a></strong></p><p>Happy trying, hopefully useful.</p><div id="download" class="wp-caption aligncenter" style="width: 97px"><a href="http://resource.sulhansetiawan.com/microsource/Counter3Digit.zip"><img class="  " title="Source" src="http://resource.sulhansetiawan.com/img/download.gif" alt="Source" width="87" height="30" /></a><p class="wp-caption-text">Source</p></div> ]]></content:encoded> <wfw:commentRss>http://www.sulhansetiawan.com/counter-3-digit/feed</wfw:commentRss> <slash:comments>14</slash:comments> </item> </channel> </rss>
