tag:blogger.com,1999:blog-57504497076826877362024-03-22T07:32:00.456+05:30Debu's InnovationsThis is my blog, this is where I write about, all my projects, experiments, general life stories etc.Devesh Raihttp://www.blogger.com/profile/04196213231447707146noreply@blogger.comBlogger16125tag:blogger.com,1999:blog-5750449707682687736.post-44579932756833330522010-06-15T00:16:00.001+05:302010-06-15T00:16:56.943+05:30The funniest code comments I ever read!<p align="justify"> </p> <p align="justify"> </p> <p align="justify">These have got to be the funniest code comments I have ever read in a while. </p> <pre class="code"><span style="color: green">// <br />// Dear maintainer:<br />// <br />// Once you are done trying to 'optimize' <br />// this routine,and have realized what a <br />// terrible mistake that was, please increment<br />// the following counter as a warning to <br />// the next guy: <br />//<br />// total_hours_wasted_here = 16<br />//</span></pre><br /><br /><p><img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" border="0" alt="Laughing" src="http://us.i1.yimg.com/us.yimg.com/i/mesg/emoticons7/21.gif" /><br /><br /> <br />Stay Tuned, and as always, Your comments make my day, so leave them. Cheers!!</p> Devesh Raihttp://www.blogger.com/profile/04196213231447707146noreply@blogger.com1tag:blogger.com,1999:blog-5750449707682687736.post-82688163593529392392010-05-18T01:48:00.001+05:302010-05-18T01:48:53.269+05:30Quick Update: Linux or CE6<p align="justify"> </p> <p align="justify">As promised, I’ve got a quick update about the system. I got my board <a href="http://lh3.ggpht.com/_uguLuW9NMog/S_Gkqg0j13I/AAAAAAAAAbg/MvQdlKSbfiI/s1600-h/CIMG0098%5B28%5D.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="CE6 on the Mini2440" border="0" alt="CE6 on the Mini2440" align="left" src="http://lh3.ggpht.com/_uguLuW9NMog/S_GkrJ_Vj5I/AAAAAAAAAbk/EgBYUjbVMww/CIMG0098_thumb%5B26%5D.jpg?imgmax=800" width="240" height="180" /></a>out and flashed a build of Windows CE 6.0 that I had lying around. I’m currently evaluating how well CE6 would work for my idea. At this point of time I’m rather inclined towards throwing in a build of Linux like Qtopia or OpenEmbedded and avoid the whole .NETCF thing I had planned. One of the reasons for that is, I’m unable to get a good driver for my OV9650 based CMOS camera module, and I don't want to use the (slow) C# I/O to write a new one. I <em>do</em> already have a driver and DLL written in eVC++ for the module but that is giving me erratic results in CE6 (works great in CE5), so I reason: If I’m using C++, I’d rather use it with Linux than CE6.</p> <p align="justify">So now the question, Qtopia (I think it’s being called QTextended now)or OpenEmbedded? The answer is also a question, which has better community support? Hmmm…</p> <p align="justify">That’s all for now folks. As always, leave your comments, it makes my day. <img style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" border="0" alt="Wave" src="http://us.i1.yimg.com/us.yimg.com/i/mesg/emoticons7/103.gif" /></p> Devesh Raihttp://www.blogger.com/profile/04196213231447707146noreply@blogger.com1tag:blogger.com,1999:blog-5750449707682687736.post-49086430862786085962010-05-11T01:14:00.004+05:302010-05-18T16:30:37.130+05:30Mini2440 – ARM9 Board<p> </p> <p><br /></p><p><a href="http://lh6.ggpht.com/_uguLuW9NMog/S-hiG1hCDGI/AAAAAAAAAbY/wTIuqBrprlQ/s1600-h/mini2440_1%5B1%5D.jpg"><img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" title="mini2440_1" border="0" alt="mini2440_1" align="left" src="http://lh6.ggpht.com/_uguLuW9NMog/S-hiIMX9ddI/AAAAAAAAAbc/1sDyNbFW_bs/mini2440_1_thumb%5B1%5D.jpg?imgmax=800" width="244" height="232" /></a></p><p>The thing about blogging on your spare time is that you tend to have long absences from it when the spare time gets more sparse. <img style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" border="0" alt="Striaght Face" src="http://us.i1.yimg.com/us.yimg.com/i/mesg/emoticons7/22.gif" /></p> <p align="justify">So, lets pretend that I was too busy to blog the last couple of months (<img style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" border="0" alt="Liar" src="http://us.i1.yimg.com/us.yimg.com/i/mesg/emoticons7/44.gif" />).</p> <p align="justify">Moving on to the more important things, I’ve been having an urge to build a robot for a while now, not just any ol’bot; something which really blows minds out! I mean, I’ve built line followers, maze solvers, wall huggers (really!! that’s a term!), image/object trackers, arms, legs, hexapods and Sumos, but I’m talking something different here.</p> <p align="justify">So, as it happens I’ve got an idea too! I could of course keep talking about what a genius I am <img style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" border="0" alt="Winking" src="http://us.i1.yimg.com/us.yimg.com/i/mesg/emoticons7/3.gif" />, but I’d rather pen my idea down. I propose building a robot, which uses a very small form factor brain, does many (all?) of my common household tasks like fetch the soda, vacuum the room, feed the cat, wake me up from my slumber, play my music, water my ferns and kill the ladybugs in my 7th floor apartment (damned bugs!).</p> <p align="justify">It just so happens, I recently acquired a Mini2440 ARM9 based board (only 100mmx100mm) which should be just right for the job. The reasons I chose my Mini2440 over my trusty and much easier to program NXP mbed module (ARM Cortex M3) is:</p> <ol> <li> <div align="justify">While the mbed is great and really easy to program with the mbed library, I need something with some real metal on this one, and the Samsung S3C2440 running at 400MHz just can’t be beat by my 100MHz mbed. </div> </li> <li> <div align="justify">I want to go <em>high level</em> on this one, and when I said <em>high level</em> I’m definitely understating how high I’m talking about. I’m talking Windows CE, and Webcam and possibly .NETCF.</div> </li> <li> <div align="justify">This one was simply the decider. My mbed isn’t available. Yup, its occupied, busy, engrossed, tied up, engaged, industriously absorbed in other tasks (you get the point). My mbed module is currently the part of my object tracking algorithm research project (more on that later), and simply cannot be spared for another six to eight weeks.</div> </li> </ol> <p align="justify">So that’s all for now folks, Stay tuned for another installment soon, I’ll post the finalized specifications of the bot very soon (I swear!). As always, leave your suggestions, ideas, comments, rants, death threats or anything else. It always makes my day. </p> <p align="justify"><img style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" border="0" alt="Wave" src="http://us.i1.yimg.com/us.yimg.com/i/mesg/emoticons7/103.gif" /></p>Devesh Raihttp://www.blogger.com/profile/04196213231447707146noreply@blogger.com3tag:blogger.com,1999:blog-5750449707682687736.post-18611007871092136612009-09-02T08:46:00.005+05:302010-05-18T16:52:34.452+05:30Slow on Updates<div><br /></div><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhyNYUWKfstJc5XJ5WW4ljOrWSClG_SmOvytRzzEHCeb-73vBd6yRYN7e-KKsmniby4Ih4fxegMLqFC4yKvon2hyphenhyphens48JZlqSgBWBpV_6wMUh8Z98XQKocf0Bn_BQZ-G8NY2GHxno1xi0RMg/s1600-h/bxp26161.jpg"><img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 156px; height: 170px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhyNYUWKfstJc5XJ5WW4ljOrWSClG_SmOvytRzzEHCeb-73vBd6yRYN7e-KKsmniby4Ih4fxegMLqFC4yKvon2hyphenhyphens48JZlqSgBWBpV_6wMUh8Z98XQKocf0Bn_BQZ-G8NY2GHxno1xi0RMg/s400/bxp26161.jpg" alt="" id="BLOGGER_PHOTO_ID_5376705402572713490" border="0" /></a><br />So, I admit it. I've been slow on the updates this past month or so. I could blame the fact that since I'll be leaving the country soon, I was really busy tying up loose ends (at the office or socially), but why lie. I've been lazy and no excuse. Got lots to write about, currently in the chute are:<br /><br /><br />+ Tweet-a-heat (tweets the temperature)<br />+ YAUO (Yet Another USB Oscilloscope)<br />+ Snake Game Ported to a Lego Mindstorm NXT<br />+ 3D Scanner using a distance sensor.<br /><br />Pretty cool, huh? Well unfortunate as it may be, but to write entries for each of these would take some time. So one by one I hope to write about these babies ASAP.<br /><br />Peace, I'm out.Devesh Raihttp://www.blogger.com/profile/04196213231447707146noreply@blogger.com3tag:blogger.com,1999:blog-5750449707682687736.post-16959404133002758492009-07-18T10:35:00.001+05:302009-07-18T10:35:17.244+05:30Classic Snake Game<p> </p> <p></p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:53357c8b-5919-4e32-8c25-305d27c17a37:d9509c26-c560-4fa4-b5da-6dea04aa95cf" class="wlWriterSmartContent"><embed src="http://www.youtube.com/v/wYkq07N3LPU" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></div> <p></p> <p>Another simple weekend project, the Classic Snake Game. This one should serve as an example for anyone who wants to learn the anatomy of a snake game (or its clones: Nibbles, Worms etc.). The code is open source and available under GNU GPLv3 for use and reuse. Both, the code and the binaries are available for download at the projects <a href="http://code.google.com/p/classicsnake/">Google Code repository</a>. Be sure to leave your view and comments, they always make my day.</p> Devesh Raihttp://www.blogger.com/profile/04196213231447707146noreply@blogger.com12tag:blogger.com,1999:blog-5750449707682687736.post-186894821267799692009-04-23T09:43:00.001+05:302009-04-23T09:43:56.010+05:30n00b Translator<p><a href="http://lh3.ggpht.com/_uguLuW9NMog/Se_q_rpZCmI/AAAAAAAAAZo/B8fFFk-EEB8/s1600-h/Screenshot24.jpg"></p><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="418" alt="Screenshot-2" src="http://lh4.ggpht.com/_uguLuW9NMog/Se_rArIOSOI/AAAAAAAAAZs/0vCmOuqBl1E/Screenshot2_thumb2.jpg?imgmax=800" width="394" border="0"></a> <p></p> <p>A simple fun project, which translates L337 to n00b readable English. Open source project, the code is available in the project's <a href="http://code.google.com/p/elitetranslstor/">Google Code Website</a>. This can serve as a great example for Java text processing.</p> <p> </p> <p>Stay tuned. :D</p> Devesh Raihttp://www.blogger.com/profile/04196213231447707146noreply@blogger.com4tag:blogger.com,1999:blog-5750449707682687736.post-56253451245002907742009-01-01T22:19:00.001+05:302009-01-01T22:19:50.229+05:30Digital Dice Using ATTiny 2313<div class="wlWriterSmartContent" id="scid:B3E14793-948F-49af-A347-D19C374A7C4F:ac89f57c-c81b-4c1a-a545-fac323428c25" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"> <script type="text/javascript"><!--<br />digg_bodytext = ' An AVR (Attiny 2313) based digital dice. Great for those geeky parties. Open Source project, contains source code, hardware schematics, pictures, videos. A great How-To for DIYers.';<br />digg_topic = 'programming';<br />//--></script> <script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script> </div> <p><a href="http://lh4.ggpht.com/_uguLuW9NMog/SVzp-FmXs8I/AAAAAAAAAX4/DzAJwNSStio/s1600-h/DSC000163.jpg"><img height="192" alt="DSC00016" src="http://lh4.ggpht.com/_uguLuW9NMog/SVzqL8-M4II/AAAAAAAAAX8/mq8gT1vnX6c/DSC00016_thumb3.jpg?imgmax=800" width="240" border="0"></a></p> <p>Not too long ago, during a game of Monopoly, I thought to myself; "How the hell do I always end up loosing? I bet these dice are loaded!", and right then the geeky idea of building my own <em>digital dice </em>was born.</p> <p><strong>Idea<br></strong>The Idea was to build a dice that:</p> <ul> <li>Produced 100% random result <li>Easy to use, Simple button press and ... result <li>Small enough to carry around with a board game <li>Low power consumption, should run on battery power for long <li>Ensure that every one knows that you are a geek ;)</li></ul> <p><strong>Construction<br></strong><a href="http://lh5.ggpht.com/_uguLuW9NMog/SVzzNzDhMrI/AAAAAAAAAZI/aVVaStwvqX8/s1600-h/schematic6.jpg"><strong><a href="http://lh5.ggpht.com/_uguLuW9NMog/SVzzNzDhMrI/AAAAAAAAAZI/aVVaStwvqX8/s1600-h/schematic6.jpg"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="415" alt="schematic" src="http://lh5.ggpht.com/_uguLuW9NMog/SVzqztGiNaI/AAAAAAAAAYI/VKBlzoifEf8/schematic_thumb4.jpg?imgmax=800" width="436" border="0"></a></strong></a><strong> </strong>The hardware is based on an ATTiny 2313 processor, the main features of the hardware:</p> <ul> <li>Processor: AVR, ATTiny 2313. <li>7-Segment LED display (common anode) to display the digits. <li>Thumb Switch to take input from the user<br><a href="http://lh6.ggpht.com/_uguLuW9NMog/SVzssEptvrI/AAAAAAAAAYU/NMECDwvQPJY/s1600-h/DSC00018%5B3%5D.jpg"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="183" alt="DSC00018" src="http://lh5.ggpht.com/_uguLuW9NMog/SVzsyi4KbUI/AAAAAAAAAYY/khVFjL-zoo4/DSC00018_thumb%5B1%5D.jpg?imgmax=800" width="240" border="0"></a> <br><em>Thumb Switch</em> <li>Battery as source of power.</li></ul> <p>So, first I designed the hardware as per the schematics above onto a simple breadboard<a href="http://lh6.ggpht.com/_uguLuW9NMog/SVzs7nCjSPI/AAAAAAAAAYc/uzOsn0Al6qI/s1600-h/DSC00011%5B8%5D.jpg">.<br><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="263" alt="DSC00011" src="http://lh5.ggpht.com/_uguLuW9NMog/SVztBo22_8I/AAAAAAAAAYg/KbpGDwDXwUc/DSC00011_thumb%5B6%5D.jpg?imgmax=800" width="328" border="0"></a> <br>No Problem, simple circuit. I used headers to connect the 7-Segment LED display, this way, I could remove the display as and when required.<br><a href="http://lh6.ggpht.com/_uguLuW9NMog/SVztQJdZNFI/AAAAAAAAAYk/8MwuHx4K0y8/s1600-h/DSC00008%5B5%5D.jpg"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="264" alt="DSC00008" src="http://lh3.ggpht.com/_uguLuW9NMog/SVztmCEqRdI/AAAAAAAAAYo/NMA1myvohsM/DSC00008_thumb%5B3%5D.jpg?imgmax=800" width="329" border="0"></a> <br>Ok, That's done! Now to work on the battery and regulator circuit. Here I decided to use a LM7805 regulator, along with a 1000uF and a 100uF capacitor, to deal with the casual drop in voltage when the circuit starts drawing current. I used common 9V 6LR61 batteries to power the regulator.<br><a href="http://lh5.ggpht.com/_uguLuW9NMog/SVztwEI4WyI/AAAAAAAAAYs/_BB80s91Hoc/s1600-h/DSC00012%5B5%5D.jpg"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="263" alt="DSC00012" src="http://lh4.ggpht.com/_uguLuW9NMog/SVzt5qVBziI/AAAAAAAAAYw/HMTy5xwO5oA/DSC00012_thumb%5B3%5D.jpg?imgmax=800" width="328" border="0"></a> <br>For the casing, I got some thin and light ABS Plastic pieces from my throw away waste.<br><a href="http://lh3.ggpht.com/_uguLuW9NMog/SVzuAC_iPXI/AAAAAAAAAY0/-LzPXhsUlvY/s1600-h/DSC00006%5B4%5D.jpg"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="263" alt="DSC00006" src="http://lh4.ggpht.com/_uguLuW9NMog/SVzuOrMBi4I/AAAAAAAAAY4/BbgTCw2zhdg/DSC00006_thumb%5B2%5D.jpg?imgmax=800" width="329" border="0"></a> <br>I cut and filed them to a somewhat desirable size.<br><a href="http://lh4.ggpht.com/_uguLuW9NMog/SVzuWGmDkYI/AAAAAAAAAY8/ApPzWVQjSyY/s1600-h/DSC00007%5B4%5D.jpg"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="263" alt="DSC00007" src="http://lh5.ggpht.com/_uguLuW9NMog/SVzugd-vSVI/AAAAAAAAAZA/0ytqoFPvWvI/DSC00007_thumb%5B2%5D.jpg?imgmax=800" width="329" border="0"></a> <br>Drilled a nice hole for thumb switch.<br><a href="http://lh6.ggpht.com/_uguLuW9NMog/SVzztcwYEdI/AAAAAAAAAZM/4u0cIDLWbzA/s1600-h/DSC00013%5B4%5D.jpg"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="263" alt="DSC00013" src="http://lh6.ggpht.com/_uguLuW9NMog/SVzz2h6DaSI/AAAAAAAAAZQ/BVcoAyH83HE/DSC00013_thumb%5B2%5D.jpg?imgmax=800" width="329" border="0"></a> <br>And.....Done!</p> <p><strong>Software</strong><br>I wrote the code for the processor in assembly, what I am showing here is only the skeleton structure. The complete code is available in the download package.</p> <p>First is the <em>Reset Vector</em> ,<em>GetButtonPress </em>and the<em> ButtonPressed</em> routines:</p> <div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"> <div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 1:</span> .include <span style="color: #006080">"tn2313def.inc"</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 2:</span> </pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 3:</span> .org 0x0000</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 4:</span> RJMP Reset <span style="color: #008000">//Code Starts from Address 0x0000</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 5:</span> </pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 6:</span> Reset: <span style="color: #008000">//Reset Vector</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 7:</span> RJMP Init</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 8:</span> RJMP GetButtonPress</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 9:</span> RJMP Reset</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 10:</span> </pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 11:</span> GetButtonPress:</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 12:</span> SBIC PORTD, 3 <span style="color: #008000">//Skip if Bit is Clear on PD3</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 13:</span> RJMP GetButtonPress <span style="color: #008000">//Relative Jump to Label</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 14:</span> RJMP ButtonPressed <span style="color: #008000">//Relative Jump to Label</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 15:</span> RJMP GetButtonPress</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 16:</span> </pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 17:</span> ButtonPressed:</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 18:</span> SBIC PORTD, 3 <span style="color: #008000">//Skip if Bit is Set on PD3</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 19:</span> RJMP ShowResult <span style="color: #008000">//Relative Jump to ShowResult</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 20:</span> INC R17 <span style="color: #008000">//Increment Register R17</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 21:</span> INC R16 <span style="color: #008000">//Increment Register R16</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 22:</span> CPI R17, 0xFF <span style="color: #008000">//Compare Immediate R17 and 0xFF</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 23:</span> BREQ ToggleDP <span style="color: #008000">//Branch if Equal to ToggleDP</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 24:</span> LDI R18, 0x06 <span style="color: #008000">//Load R18 with with Immediate 0x06</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 25:</span> CPSE R18, R16 <span style="color: #008000">//Compare, Skip if Equal</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 26:</span> RJMP ButtonPressed<span style="color: #008000">//Relative Jump to ButtonPressed</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 27:</span> CLR R16 <span style="color: #008000">//Clear Register R16</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 28:</span> RJMP ButtonPressed</pre></div></div><br /><p>The skeleton routine above does not take into account the debounce of the thumb switch. The thumb switch being used is spring loaded, and has a magnetic catch inside it, so the typical debounce would be around ~80ms. Now, running at 8MIPS (internal RC oscillator), in terms of processor cycles, that would be; 1 sec = 8,000,000 instructions; 1ms = 8,000 instructions; 80ms = 64,000 instructions; That means we need to call <strong><em>nop</em></strong> 64,000 times to debounce the switch correctly.</p><br /><p>Next we have the <em>ShowResult</em> routine. This basically displays on our 7-Segment display the value of the roll.</p><br /><div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"><br /><div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 1:</span> ShowResult:</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 2:</span> LDI R18, 0x01 <span style="color: #008000">//Load Immediate R18, with 0x01</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 3:</span> CP R16, R18 <span style="color: #008000">//Compare R16 and R18</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 4:</span> BREQ ShowOne<span style="color: #008000">//Branch if Equal to ShowOne</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 5:</span> LDI R18, 0x02 <span style="color: #008000">//Load Immediate R18, with 0x02</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 6:</span> CP R16, R18 <span style="color: #008000">//Compare R16 and R18</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 7:</span> BREQ ShowTwo<span style="color: #008000">//Branch if Equal to ShowOne</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 8:</span> LDI R18, 0x03 <span style="color: #008000">//Load Immediate R18, with 0x03</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 9:</span> CP R16, R18 <span style="color: #008000">//Compare R16 and R18</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 10:</span> BREQ ShowThr<span style="color: #008000">//Branch if Equal to ShowOne</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 11:</span> LDI R18, 0x04 <span style="color: #008000">//Load Immediate R18, with 0x04</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 12:</span> CP R16, R18 <span style="color: #008000">//Compare R16 and R18</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 13:</span> BREQ ShowFou<span style="color: #008000">//Branch if Equal to ShowOne</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 14:</span> LDI R18, 0x05 <span style="color: #008000">//Load Immediate R18, with 0x05</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 15:</span> CP R16, R18 <span style="color: #008000">//Compare R16 and R18</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 16:</span> BREQ ShowFiv<span style="color: #008000">//Branch if Equal to ShowOne</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 17:</span> LDI R18, 0x06 <span style="color: #008000">//Load Immediate R18, with 0x06</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 18:</span> CP R16, R18 <span style="color: #008000">//Compare R16 and R18</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 19:</span> BREQ ShowSix<span style="color: #008000">//Branch if Equal to ShowSix</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 20:</span> RJMP ShowResult</pre></div></div><br /><p>One more important consideration here is Low Power Mode, and automatic turn off (We are running on batteries here, after all). In the final code, I have included a low power and auto turn of routine. This checks to see if the dice is not used for 4 Seconds or more, and then turns off the display and puts the processor and other peripherals in a low power state. See the video of operation below to get a good idea of how this works.</p><br /><p><br>Ok, thats it!! All Done now!!<br><a href="http://lh5.ggpht.com/_uguLuW9NMog/SVzz8BBkNII/AAAAAAAAAZU/Bu8rk__nB-o/s1600-h/DSC00015%5B4%5D.jpg"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="267" alt="DSC00015" src="http://lh5.ggpht.com/_uguLuW9NMog/SVz0Fp1uY0I/AAAAAAAAAZY/fgE-XXNMwb4/DSC00015_thumb%5B2%5D.jpg?imgmax=800" width="334" border="0"></a> <br>And it Works!! :D<br></p><br /><p><br>Video of Operation:</p><br /><p></p><br /><div class="wlWriterSmartContent" id="scid:53357c8b-5919-4e32-8c25-305d27c17a37:6751ebd4-f683-486f-a7db-9407ed69e6c7" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"><embed src="http://www.youtube.com/v/tWxlEtj7ByE" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></div><br /><p></p><br /><p> </p><br /><p>Thats all folks, Untill Next Time!! If you like this entry, Leave a message and Digg this article. Messages always make my day. :)</p> Devesh Raihttp://www.blogger.com/profile/04196213231447707146noreply@blogger.com15tag:blogger.com,1999:blog-5750449707682687736.post-54746929117155301572008-11-09T21:03:00.001+05:302008-11-10T20:00:56.348+05:30The heights of geekiness<p><strong>Geek</strong> <em>noun</em> <em>\ˈgēk\</em>: Geek Used in a nice way it is someone who seems to know everything there is to know about computers.</p> <p>If I were to define myself as a geek, I would say:</p> <div class="csharpcode"><pre class="alt"><span class="lnum"> 1: </span> -----BEGIN GEEK CODE BLOCK-----</pre><pre><span class="lnum"> 2: </span> Version: 3.12</pre><pre class="alt"><span class="lnum"> 3: </span> GED/J d-- s:++>: a-- C+++(++++) </pre><pre><span class="lnum"> 4: </span> ULU++ P+ L++ E---- W+(-) N+++ </pre><pre class="alt"><span class="lnum"> 5: </span> o+ K+++ w--- O- M+ V-- PS++></pre><pre><span class="lnum"> 6: </span> $ PE++>$ Y++ PGP++ t- 5+++ </pre><pre class="alt"><span class="lnum"> 7: </span> X++ R+++>$ tv+ b+ DI+++ D+++</pre><pre><span class="lnum"> 8: </span> G+++++ e++ h r-- y++**</pre><pre class="alt"><span class="lnum"> 9: </span> ------END GEEK CODE BLOCK------</pre></div><br /><p><br /><style type="text/css">.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }<br /></style><br />(don't understand the above? refer to <a href="http://www.geekcode.com/geek.html">The Geek Code v3.12</a>, Yup, we have one) <img alt="smile_nerd" src="http://spaces.live.com/rte/emoticons/smile_nerd.gif"></p><br /><p>Even as a geek, there comes a point, where you need to draw the line. One such point came today. I found myself facing a dilemma, unable to decide, "How to get bored today". After much deliberation I found that I simply could not decide between five things to do. Under these circumstances I decided a coin toss would be ideal. This of course brought up another question how best to decide between 5 choices using a coin. At that time a brilliant geeky idea came to me, and I decided to whip together a "Random Choice Maker"</p><br /><p><a href="http://lh4.ggpht.com/_uguLuW9NMog/SRhFjKQrfmI/AAAAAAAAAXY/VAFCzWNUty0/Screenshot5.jpg"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="309" alt="Screenshot" src="http://lh4.ggpht.com/_uguLuW9NMog/SRhFmfvqYJI/AAAAAAAAAXc/nrlVVok6bIw/Screenshot_thumb3.jpg" width="439" border="0"></a> </p><br /><p>Took me 20 minutes to whip together this simple utility, I wrote a simple RNG function it went like:</p><br /><div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"><br /><div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 1:</span> <span style="color: #0000ff">class</span> myRandomizerClass</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 2:</span> {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 3:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">int</span> generateRandomValue(<span style="color: #0000ff">int</span> uValue)</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 4:</span> {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 5:</span> <span style="color: #0000ff">int</span> millisecondsNow = DateTime.Now.Millisecond, breakIndex = 1000/uValue;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 6:</span> <span style="color: #0000ff">return</span> millisecondsNow/breakIndex;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 7:</span> }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 8:</span> }</pre></div></div><br /><style type="text/css">.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }<br /></style><br /><br /><p>It uses a simple uValue for checking quantile density.</p><br /><p>So, that's it. Once again I ended up prooving that "Once a geek, always a Geek"</p><br /><p>Cheerio. <img alt="smile_tongue" src="http://spaces.live.com/rte/emoticons/smile_tongue.gif"></p> Devesh Raihttp://www.blogger.com/profile/04196213231447707146noreply@blogger.com3tag:blogger.com,1999:blog-5750449707682687736.post-92105592450134367922008-09-28T13:23:00.001+05:302008-09-28T13:23:04.140+05:30Digital Thermometer<p> </p> <p><a href="http://lh5.ggpht.com/devesh.rai/SN812aIsdsI/AAAAAAAAAUw/x85XpzZTBc8/s1600-h/Thermometer5.jpg"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="243" alt="Thermometer" src="http://lh5.ggpht.com/devesh.rai/SN8165v-5yI/AAAAAAAAAU0/A52w5Q2kIHk/Thermometer_thumb3.jpg?imgmax=800" width="431" border="0" /></a> </p> <p>Not too long ago, I took the plunge into the world of Linux. Only to find myself constantly requiring to skip down to the command line to perform even some of the simplest of tasks. So when I learned about KontrollerLab, I was itching to get creative with it, and the "Digital Thermometer Project" is born. </p> <p>Well to be quite honest, building a digital thermometer is a no-brainer. But I really had to do some building, or die of dull boredom. </p> <p>Those of us familiar with Unix/Linux (and other Posix based OSes) would understand why I felt frustrated when I had to keep getting down to the command line to do a simple $avr-gcc -mmcu=atxxxx -O0 -c /Projects/xxxxx/xxx.c. I wrote a few scripts to automate a few tasks, but that wasn't sufficient. When I learned of KontrollerLab IDE I wasn't too hopeful, I tried it not expecting much. Frankly, I was blown out of my mind. It was excellent! It is comparable to almost any good commercial Microcontroller Development IDE. Since it works with avr-gcc, it would be compatable with most of your existing code for the AVR. </p> <p><a href="http://lh3.ggpht.com/devesh.rai/SN82AMjnJzI/AAAAAAAAAU4/nccoIQU__A8/s1600-h/Screenshot2.jpg"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="270" alt="Screenshot" src="http://lh4.ggpht.com/devesh.rai/SN82ELO0DPI/AAAAAAAAAU8/PA9YmUA6CiM/Screenshot_thumb1.jpg?imgmax=800" width="430" border="0" /></a> </p> <p>Though it may seem that way, but this post is not about the development tool I have been emphasizing about so far! So lets discuss what we this post is really about. This weekend I'm building a Digital Thermometer. </p> <p>Here is what we need. </p> <p><a href="http://lh4.ggpht.com/devesh.rai/SN82IJmIWXI/AAAAAAAAAVA/5RIJlrpDtGk/s1600-h/dsc000325.jpg"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="324" alt="dsc00032" src="http://lh6.ggpht.com/devesh.rai/SN82MVXZ0tI/AAAAAAAAAVE/EwJFUEU0OMU/dsc00032_thumb3.jpg?imgmax=800" width="432" border="0" /></a> </p> <p>* Soldering Iron - Check. <br />* Random Wiring - Check. <br />* Some Discreets (Resistors, LED's etc.) - Check <br />* Headers and Sockets - Check. <br />* Microcontroller (ATMega32) - Check. <br />* LCD - Check. <br />* LM35 - Check.</p> <p>* Geeky Brain - Check. ;)</p> <p>OK, Good to go :D.</p> <p> <a href="http://lh5.ggpht.com/devesh.rai/SN82PAg1GUI/AAAAAAAAAVI/iTcHAVnT6PU/s1600-h/LM352.jpg"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="244" alt="LM35" src="http://lh6.ggpht.com/devesh.rai/SN82R3HPqsI/AAAAAAAAAVM/B-ayUo-ODCE/LM35_thumb.jpg?imgmax=800" width="130" border="0" /></a> </p> <p>Now, Some may be wondering why I preferred the National Semiconductor LM35 over the much easier to use Dallas DS18x20. Well, for starters, I have a huge load of LM35's lying with me (remnants of an old project :P), and the second reason is, the LM35 is analogue, and pre-calibrated (yes, so is the DS18x, I know). And lastly since the LM35 is linear (10.0 mV/°C) it makes for easy calculation of the temperature from the sensor voltage. The sensor voltage is sampled using the ADC of the ATMega32. I wrote a C function to sample the ADC, it goes like:</p> <pre style="border-right: #000000 1px solid; padding-right: 5px; border-top: #000000 1px solid; padding-left: 5px; font-size: 12px; min-height: 40px; padding-bottom: 5px; overflow: auto; border-left: #000000 1px solid; width: 300px; padding-top: 5px; border-bottom: #000000 1px solid; font-family: monospace; background-color: #000000"><span style="color: #0000ff">void</span> readAdcValue(<span style="color: #0000ff">int</span> channel)<br />{<br /> ADMUX=channel|0x40;<br /> ADCSRA|=0x40;<br /> <span style="color: #0000ff">while</span> ((ADCSRA & 0x10)==0);<br /> ADCSRA|=0x10;<br /> adcVal = ADCW;<br />}</pre><br /><br /><p>For those not in the know, basically the function is using the ADMUX register to select the ADC channel that we are using, then we trigger the ADC Conversion using the ADSC (ADC Start Conversion) bit (bit 6) of the ADC Control and Status register (ADCSRA, we OR it with 0x40 i.e 0b 0100 0000). We then wait for the ADIF (ADC Interrupt Flag) to get set, then we sample the ADC value using the ADCW (ADC Word). ADCW is *not* a register. It is basically a combination of the ADCH and ADCL register. Remember the ATMega32 is an 8-bit processor, so all registers are 8-bit, and since the ADC is 10-bit, the ADCH (ADC High Value) and ADCL (ADC Low Value) registers are used.</p><br /><br /><p>Ok, Now we have an ADC reading, we have to convert that into a Sensor Voltage value and then convert that into a temperature.</p><br /><br /><pre style="border-right: #000000 1px solid; padding-right: 5px; border-top: #000000 1px solid; padding-left: 5px; font-size: 12px; min-height: 40px; padding-bottom: 5px; overflow: auto; border-left: #000000 1px solid; width: 350px; padding-top: 5px; border-bottom: #000000 1px solid; font-family: monospace; background-color: #000000"><span style="color: #0000ff">void</span> showSensorVoltage(<span style="color: #0000ff">void</span>)<br />{<br /> <span style="color: #0000ff">char</span>* buff;<br /> lcd_gotoxy(0,0);<br /> lcd_puts("<span style="color: #8b0000">Sensor Voltage:</span>");<br /> sensorVoltage = (adcVal * 1024)/5;<br /> buff = intToString(sensorVoltage);<br /> lcd_gotoxy(0,1);<br /> lcd_puts(buff);<br />}<br /><br /><span style="color: #0000ff">void</span> showSensorTemp(<span style="color: #0000ff">void</span>)<br />{<br /> <span style="color: #0000ff">char</span>* buff;<br /> lcd_gotoxy(0,0);<br /> lcd_puts("<span style="color: #8b0000">Temperature:</span>");<br /> sensorTemp = (sensorVoltage * 500)/1024;<br /> buff = intToString(sensorTemp);<br /> lcd_gotoxy(0,1);<br /> lcd_puts(buff);<br />}</pre><br /><br /><p>I use the equation, <br /> <br />sensorVoltage = (adcVal * 1024)/5; <br /><br /> <br />and, <br /><br /> <br />sensorTemp = (sensorVoltage * 500)/1024;</p><br /><br /><p>Ok, the code is divided into the following functions:</p><br /><br /><pre style="border-right: #000000 1px solid; padding-right: 5px; border-top: #000000 1px solid; padding-left: 5px; font-size: 12px; min-height: 40px; padding-bottom: 5px; overflow: auto; border-left: #000000 1px solid; width: 300px; padding-top: 5px; border-bottom: #000000 1px solid; font-family: monospace; background-color: #000000"><span style="color: #0000ff">void</span> init(<span style="color: #0000ff">void</span>);<br /><span style="color: #0000ff">void</span> showWelcome(<span style="color: #0000ff">void</span>);<br /><span style="color: #0000ff">void</span> showAdcValue(<span style="color: #0000ff">void</span>);<br /><span style="color: #0000ff">void</span> showSensorVoltage(<span style="color: #0000ff">void</span>);<br /><span style="color: #0000ff">void</span> showSensorTemp(<span style="color: #0000ff">void</span>);<br /><span style="color: #0000ff">void</span> readAdcValue(<span style="color: #0000ff">int</span>);<br /><span style="color: #0000ff">char</span>* intToString(<span style="color: #0000ff">int</span>);<br /><span style="color: #0000ff">int</span> main(<span style="color: #0000ff">void</span>);</pre><br /><br /><p>You can get a more detailed Idea by looking at the attached code.</p><br /><br /><p>Ok, Time for the hardware assembly. I designed a schematic for the whole system:</p><br /><br /><p><a href="http://lh5.ggpht.com/devesh.rai/SN82VZ7UQuI/AAAAAAAAAVQ/l0eqGH6M_vc/s1600-h/Schematic3.jpg"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="314" alt="Schematic" src="http://lh6.ggpht.com/devesh.rai/SN82YzzP_rI/AAAAAAAAAVU/qbjuVtnjeeE/Schematic_thumb1.jpg?imgmax=800" width="432" border="0" /></a> </p><br /><br /><p>After hours of assembly and debugging:</p><br /><br /><p><a href="http://lh4.ggpht.com/devesh.rai/SN82cfFzuxI/AAAAAAAAAVY/Z7P67FEpNik/s1600-h/dsc000263.jpg"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="325" alt="dsc00026" src="http://lh3.ggpht.com/devesh.rai/SN82gNbDD1I/AAAAAAAAAVc/_H55WjwSII8/dsc00026_thumb1.jpg?imgmax=800" width="432" border="0" /></a> <br /><br /> <br /><a href="http://lh5.ggpht.com/devesh.rai/SN82kFIVZRI/AAAAAAAAAVg/uTswbWbD3RM/s1600-h/dsc000223.jpg"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="325" alt="dsc00022" src="http://lh3.ggpht.com/devesh.rai/SN82oTP2IXI/AAAAAAAAAVk/ORKQkcg3mUA/dsc00022_thumb1.jpg?imgmax=800" width="432" border="0" /></a></p><br /><br /><p>And it works!!!<a href="http://lh5.ggpht.com/devesh.rai/SN82tGoZreI/AAAAAAAAAVo/KWnMVcVyN6w/s1600-h/dsc000273.jpg"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="325" alt="dsc00027" src="http://lh4.ggpht.com/devesh.rai/SN82w8Sh6aI/AAAAAAAAAVs/kyzbJYofR4g/dsc00027_thumb1.jpg?imgmax=800" width="432" border="0" /></a> <br /><br /> <br /><a href="http://lh6.ggpht.com/devesh.rai/SN820QJt4TI/AAAAAAAAAVw/8tgZjWzMlww/s1600-h/dsc000293.jpg"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="325" alt="dsc00029" src="http://lh4.ggpht.com/devesh.rai/SN824_yRtxI/AAAAAAAAAV0/_MUCdrsuUAY/dsc00029_thumb1.jpg?imgmax=800" width="432" border="0" /></a> <br /><br /> <br /></p><br /><br /><p><strong>Case Modding</strong>:</p><br /><br /><p>Ok, so now I need to make a case for this thing. I got a standard SMPS casing (again, leftovers from an older project) lying around.</p><br /><br /><p><a href="http://lh3.ggpht.com/devesh.rai/SN8272ekK0I/AAAAAAAAAV4/zeCOAvy9_RI/s1600-h/dsc000373.jpg"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="325" alt="dsc00037" src="http://lh5.ggpht.com/devesh.rai/SN83TMPVZqI/AAAAAAAAAWU/nck6un4qdGc/dsc00037_thumb1.jpg?imgmax=800" width="432" border="0" /></a></p><br /><br /><p>The size is more or less right, but the insides are a bit messy</p><br /><br /><p><a href="http://lh6.ggpht.com/devesh.rai/SN83XrIkn4I/AAAAAAAAAWY/hN1NomOUEUg/s1600-h/dsc000403.jpg"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="325" alt="dsc00040" src="http://lh5.ggpht.com/devesh.rai/SN83cjBrMeI/AAAAAAAAAWc/Bff7XJa0kkI/dsc00040_thumb1.jpg?imgmax=800" width="432" border="0" /></a></p><br /><br /><p>Anyhow, after some work, I managed to fit it all.... Not too neat. But not unacceptable either. </p><br /><br /><p><a href="http://lh3.ggpht.com/devesh.rai/SN83hiYV9kI/AAAAAAAAAWg/mQe_ofJX5e4/s1600-h/dsc000153.jpg"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="325" alt="dsc00015" src="http://lh3.ggpht.com/devesh.rai/SN83l-joaaI/AAAAAAAAAWk/Z3bgocrfsQg/dsc00015_thumb1.jpg?imgmax=800" width="432" border="0" /></a>   </p><br /><br /><p><a href="http://lh3.ggpht.com/devesh.rai/SN83qJ_XbZI/AAAAAAAAAWo/YQ4fxBTujJk/s1600-h/dsc000173.jpg"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="325" alt="dsc00017" src="http://lh3.ggpht.com/devesh.rai/SN83ts2dVwI/AAAAAAAAAWs/yYAFXBBbKQc/dsc00017_thumb1.jpg?imgmax=800" width="432" border="0" /></a></p><br /><br /><p><a href="http://lh3.ggpht.com/devesh.rai/SN83yQZW5SI/AAAAAAAAAWw/ckAPKwar0to/s1600-h/dsc000203.jpg"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="325" alt="dsc00020" src="http://lh3.ggpht.com/devesh.rai/SN832O7zOfI/AAAAAAAAAW0/9U_HFjPMSH4/dsc00020_thumb1.jpg?imgmax=800" width="432" border="0" /></a></p><br /><br /><p> </p><br /><br /><p>Thats all folks!!</p><br /><br /><p>Stay Tuned! :)</p> Devesh Raihttp://www.blogger.com/profile/04196213231447707146noreply@blogger.com8tag:blogger.com,1999:blog-5750449707682687736.post-78833229527799122622008-09-28T11:16:00.001+05:302008-09-28T11:16:20.717+05:30Non-Geek: My Friends Blog<p> </p> <p> </p> <p>Well Guys long time since I posted anything around here, Its time to clean out the cobwebs and move in again. :)</p> <p>To start out, my Friend, and Clan member the one and only Mr. Riteek "VoLdEmOrT" Arora is on Blogger now, I'm sure all the Geeks and even the Non-Geeks (do we get that kind around here? ;) ) would enjoy his blog. His interests involve around F1, Linux (apparently Harry Potter Characters ;) ), well....You read his blog.</p> <p><a href="http://lh3.ggpht.com/devesh.rai/SN8aGo1B0eI/AAAAAAAAAUo/yMA_kRlSOug/s1600-h/DSC01153%5B3%5D.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="285" alt="DSC01153" src="http://lh5.ggpht.com/devesh.rai/SN8aKAAdiiI/AAAAAAAAAUs/ymZ_Id6SsSI/DSC01153_thumb%5B1%5D.jpg?imgmax=800" width="162" border="0" /></a>     <br /><em>Pictured above: Mr. Riteek "VoLdEmOrT" Arora</em></p> <p>Visit his blog: <a href="http://www.riteekarora.blogspot.com/" target="_blank">RiTeEk "VoLdEmOrT" aRoRa'S Blog</a></p> <p> </p> <p>Cheerio!! PS. A geeky entry is coming soon....Stay tuned!</p> Devesh Raihttp://www.blogger.com/profile/04196213231447707146noreply@blogger.com0tag:blogger.com,1999:blog-5750449707682687736.post-43502982704357137572008-04-20T21:39:00.001+05:302008-04-20T21:39:33.859+05:30TicTacToe Bot (Part 2)<h3></h3> <h3>PART-2 : The TicTacToe Robot Controller</h3> <p><a href="http://lh3.ggpht.com/devesh.rai/SAto8XP-AfI/AAAAAAAAAFY/uQFrHz76iXs/s1600-h/IMG_0140%5B3%5D.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="323" alt="IMG_0140" src="http://lh4.ggpht.com/devesh.rai/SAto-nP-AgI/AAAAAAAAAFg/I8i-7l74Tcs/IMG_0140_thumb%5B1%5D.jpg?imgmax=800" width="429" border="0" /></a> </p> <p>Now, that we have an algorithm working, what's next? Good question. Lets take a look again at the block diagram of our electronics:</p> <p> <a href="http://lh3.ggpht.com/devesh.rai/SAtpBXP-AhI/AAAAAAAAAFo/FtAE3V_UsJM/s1600-h/block-diagram%5B4%5D.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="262" alt="block-diagram" src="http://lh3.ggpht.com/devesh.rai/SAtpFXP-AiI/AAAAAAAAAFw/sp9LALlgInA/block-diagram_thumb%5B2%5D.jpg?imgmax=800" width="402" border="0" /></a> </p> <p>Roughly based on the above I whipped together a Schematic:</p> <p><a href="http://lh4.ggpht.com/devesh.rai/SAtpHnP-AjI/AAAAAAAAAF4/HTkJO2385aU/s1600-h/Schematic%5B6%5D.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="272" alt="Schematic" src="http://lh3.ggpht.com/devesh.rai/SAtpJXP-AkI/AAAAAAAAAGA/b4qgmt_Q69k/Schematic_thumb%5B4%5D.jpg?imgmax=800" width="426" border="0" /></a></p> <p>Basically a Atmel (AVR) ATMega32, with a 2x16 Character LCD,  a Keypad Matrix,  and A set of headers for interfacing with the motion driving circuitry and sensors. </p> <h5>Step 1: Preparing the firmware.</h5> <p>This was main part, apparently porting the windows 'C#' code to plain 'C' wasn't all that simple, after all. Well it would have been , except:</p> <p><a href="http://lh6.ggpht.com/devesh.rai/SAtpLHP-AlI/AAAAAAAAAGI/Vny024s5wXY/s1600-h/Error_mem%5B3%5D.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="159" alt="Error_mem" src="http://lh3.ggpht.com/devesh.rai/SAtpMXP-AmI/AAAAAAAAAGQ/RVddPKUee0o/Error_mem_thumb%5B1%5D.jpg?imgmax=800" width="361" border="0" /></a> </p> <p>So, I did a bit of optimization, and then some more, and then a <strong><em><u>LOT</u></em></strong> more. A poem would explain better:</p> <p>"<em>Till I had reduced each int to byte, </em></p> <p><em>and byte to bit,</em></p> <p><em>Till each hardware register was consumed,</em></p> <p><em>Till each register could be used,</em></p> <p><em>or Re-Used no more,</em></p> <p><em>and Lo... I present to you the 'Optimized Code-Size'" <img alt="smile_shades" src="http://spaces.live.com/rte/emoticons/smile_shades.gif" /></em></p> <p><a href="http://lh5.ggpht.com/devesh.rai/SAtpN3P-AnI/AAAAAAAAAGY/Ex2Uy5PjEZ0/s1600-h/new_mem%5B4%5D.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="450" alt="new_mem" src="http://lh6.ggpht.com/devesh.rai/SAtpRHP-AoI/AAAAAAAAAGg/kcjqjbq9QzI/new_mem_thumb%5B2%5D.jpg?imgmax=800" width="424" border="0" /></a> </p> <p>This I'm particularly proud <em>o</em>f. <img alt="clap" src="http://spaces.live.com/rte/emoticons/clap.gif" /></p> <p>Anyway, the code is divided into 5 Files:</p> <ul> <li>main.c</li> <li>game.h</li> <li>game.c</li> <li>UserInterface.h</li> <li>UserInterface.c</li> </ul> <p><a href="http://lh6.ggpht.com/devesh.rai/SAtpTHP-ApI/AAAAAAAAAGo/LB09COrv3og/s1600-h/Program%20Structure%5B4%5D.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="649" alt="Program Structure" src="http://lh3.ggpht.com/devesh.rai/SAtpVXP-AqI/AAAAAAAAAGw/sn2JLCt0sus/Program%20Structure_thumb%5B2%5D.jpg?imgmax=800" width="303" border="0" /></a></p> <h5>Step 2: Preparing the hardware.</h5> <p>After getting the code "Out of the way", it was time to do what I really wanted to do this weekend. Time to get some Solder Iron Burns and some spit, wire and breadboards, together!!</p> <p>Lets See what we need first. Hmmm....</p> <p><a href="http://lh3.ggpht.com/devesh.rai/SAtpXXP-ArI/AAAAAAAAAG4/yvlfeyFrbjQ/s1600-h/IMG_0120%5B6%5D.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="326" alt="IMG_0120" src="http://lh4.ggpht.com/devesh.rai/SAtpcnP-AsI/AAAAAAAAAHA/hL6yT5Iou58/IMG_0120_thumb%5B2%5D.jpg?imgmax=800" width="434" border="0" /></a> </p> <p>-Solder Iron. Check.</p> <p>-Bread Board. Check.</p> <p>-LCD. Check.</p> <p>-Microcontroller. Check</p> <p>r step -Random Headers and Stuff. Check.</p> <p>-Some Discreets. Check.</p> <p>-Lots-a-Buttons. Check.</p> <p>All clear. Lets go....<img alt="thumbs_up" src="http://spaces.live.com/rte/emoticons/thumbs_up.gif" /></p> <p>One Hour Later:</p> <p><a href="http://lh4.ggpht.com/devesh.rai/SAtpfnP-AtI/AAAAAAAAAHI/Jdiyuxl09pk/s1600-h/IMG_0121%5B6%5D.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="329" alt="IMG_0121" src="http://lh4.ggpht.com/devesh.rai/SAtponP-AuI/AAAAAAAAAHQ/lAqwuN3f_yg/IMG_0121_thumb%5B2%5D.jpg?imgmax=800" width="437" border="0" /></a></p> <p>Everything assembled to my satisfaction, and ready for testing. <img alt="fingerscrossed" src="http://spaces.live.com/rte/emoticons/fingerscrossed.gif" /></p> <p><a href="http://lh5.ggpht.com/devesh.rai/SAtpq3P-AvI/AAAAAAAAAHY/SwAgwRCGPY4/s1600-h/IMG_0122%5B3%5D.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="328" alt="IMG_0122" src="http://lh6.ggpht.com/devesh.rai/SAtptHP-AwI/AAAAAAAAAHg/5W_q_yp4tiA/IMG_0122_thumb%5B1%5D.jpg?imgmax=800" width="436" border="0" /></a> </p> <p>It Works!!! It Works!!! </p> <p>Some random screens:</p> <p><a href="http://lh3.ggpht.com/devesh.rai/SAtpuXP-AxI/AAAAAAAAAHo/rR-M36QnNm0/s1600-h/IMG_0128%5B2%5D.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="184" alt="IMG_0128" src="http://lh3.ggpht.com/devesh.rai/SAtpvXP-AyI/AAAAAAAAAHw/z_jkMNFSL2o/IMG_0128_thumb.jpg?imgmax=800" width="244" border="0" /></a> </p> <p><a href="http://lh3.ggpht.com/devesh.rai/SAtpwXP-AzI/AAAAAAAAAH4/9KMC5MxwpGc/s1600-h/IMG_0130%5B2%5D.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="184" alt="IMG_0130" src="http://lh3.ggpht.com/devesh.rai/SAtpxXP-A0I/AAAAAAAAAIA/4tnDT7EPqS8/IMG_0130_thumb.jpg?imgmax=800" width="244" border="0" /></a> </p> <p>Scrolling Up and Down the Menu:</p> <p><a href="http://lh5.ggpht.com/devesh.rai/SAtpz3P-A1I/AAAAAAAAAII/j7SN5bPYoHc/s1600-h/IMG_0123%5B2%5D.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="184" alt="IMG_0123" src="http://lh6.ggpht.com/devesh.rai/SAtp1HP-A2I/AAAAAAAAAIQ/Edx5mVSHNek/IMG_0123_thumb.jpg?imgmax=800" width="244" border="0" /></a> </p> <p><a href="http://lh6.ggpht.com/devesh.rai/SAtp2HP-A3I/AAAAAAAAAIY/6D9sd_eqPNk/s1600-h/IMG_0124%5B5%5D.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="184" alt="IMG_0124" src="http://lh3.ggpht.com/devesh.rai/SAtp3XP-A4I/AAAAAAAAAIg/WHNWinAeroY/IMG_0124_thumb%5B3%5D.jpg?imgmax=800" width="244" border="0" /></a> </p> <p><a href="http://lh5.ggpht.com/devesh.rai/SAtp43P-A5I/AAAAAAAAAIo/V_6QJ49FKHw/s1600-h/IMG_0127%5B5%5D.jpg"><a href="http://lh4.ggpht.com/devesh.rai/SAtp6nP-A6I/AAAAAAAAAIw/gI4hU8dknSU/s1600-h/IMG_0125%5B5%5D.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="184" alt="IMG_0125" src="http://lh5.ggpht.com/devesh.rai/SAtp73P-A7I/AAAAAAAAAI4/J9sC-VY2w9A/IMG_0125_thumb%5B3%5D.jpg?imgmax=800" width="244" border="0" /></a></a></p> <p><a href="http://lh3.ggpht.com/devesh.rai/SAtp9XP-A8I/AAAAAAAAAJA/x9fFmopP1jY/s1600-h/IMG_0126%5B5%5D.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="184" alt="IMG_0126" src="http://lh5.ggpht.com/devesh.rai/SAtp-3P-A9I/AAAAAAAAAJI/f-nGdI_Ns4I/IMG_0126_thumb%5B3%5D.jpg?imgmax=800" width="244" border="0" /></a> <img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="184" alt="IMG_0127" src="http://lh5.ggpht.com/devesh.rai/SAtp_3P-A-I/AAAAAAAAAJQ/MwGpTiFIiIE/IMG_0127_thumb%5B3%5D.jpg?imgmax=800" width="244" border="0" /> </p> <p><a href="http://lh5.ggpht.com/devesh.rai/SAtqA3P-A_I/AAAAAAAAAJY/W4vzp42ofnI/s1600-h/IMG_0131%5B5%5D.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="184" alt="IMG_0131" src="http://lh5.ggpht.com/devesh.rai/SAtqB3P-BAI/AAAAAAAAAJg/6MePrwHI5Es/IMG_0131_thumb%5B3%5D.jpg?imgmax=800" width="244" border="0" /></a> <a href="http://lh6.ggpht.com/devesh.rai/SAtqDHP-BBI/AAAAAAAAAJo/v4mnhy1i724/s1600-h/IMG_0133%5B5%5D.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="184" alt="IMG_0133" src="http://lh3.ggpht.com/devesh.rai/SAtqEXP-BCI/AAAAAAAAAJw/5wDJI-I1mYw/IMG_0133_thumb%5B3%5D.jpg?imgmax=800" width="244" border="0" /></a> <a href="http://lh4.ggpht.com/devesh.rai/SAtqFnP-BDI/AAAAAAAAAJ4/FcHWhCFmYfM/s1600-h/IMG_0134%5B5%5D.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="184" alt="IMG_0134" src="http://lh4.ggpht.com/devesh.rai/SAtqGnP-BEI/AAAAAAAAAKA/fMTs-aVyPfg/IMG_0134_thumb%5B3%5D.jpg?imgmax=800" width="244" border="0" /></a></p> <p>Preparing the Outer Box: (I wish I had taken my art and crafts class in High school seriously <img alt="smile_thinking" src="http://spaces.live.com/rte/emoticons/smile_thinking.gif" /></p> <p><a href="http://lh5.ggpht.com/devesh.rai/SAtqN3P-BFI/AAAAAAAAAKI/1URg-H8vRMo/s1600-h/IMG_0135%5B3%5D.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="328" alt="IMG_0135" src="http://lh4.ggpht.com/devesh.rai/SAtqQnP-BGI/AAAAAAAAAKQ/oBY9QgF9b5w/IMG_0135_thumb%5B1%5D.jpg?imgmax=800" width="436" border="0" /></a> </p> <p> Ooohhh the guts and wires.....<a href="http://lh6.ggpht.com/devesh.rai/SAtqTHP-BHI/AAAAAAAAAKY/DjY1CVxJE1M/s1600-h/IMG_0136%5B3%5D.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="326" alt="IMG_0136" src="http://lh3.ggpht.com/devesh.rai/SAtqVXP-BII/AAAAAAAAAKg/eduz4Xo5ON4/IMG_0136_thumb%5B1%5D.jpg?imgmax=800" width="434" border="0" /></a></p> <p>The Front Panel: (Before I got creative with a felt pen <img alt="smile_wink" src="http://spaces.live.com/rte/emoticons/smile_wink.gif" />)</p> <p><a href="http://lh5.ggpht.com/devesh.rai/SAtqW3P-BJI/AAAAAAAAAKo/TdE8UkFnqVU/s1600-h/IMG_0137%5B3%5D.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="326" alt="IMG_0137" src="http://lh4.ggpht.com/devesh.rai/SAtqYnP-BKI/AAAAAAAAAKw/2_xqwqUOPrI/IMG_0137_thumb%5B1%5D.jpg?imgmax=800" width="434" border="0" /></a>  AAaahhh Finished.... <img alt="clap" src="http://spaces.live.com/rte/emoticons/clap.gif" /><img alt="thumbs_up" src="http://spaces.live.com/rte/emoticons/thumbs_up.gif" /><img alt="beer" src="http://spaces.live.com/rte/emoticons/beer.gif" /></p> <p><a href="http://lh5.ggpht.com/devesh.rai/SAtqb3P-BLI/AAAAAAAAAK4/B64a2oQv0_E/s1600-h/IMG_0139%5B3%5D.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="324" alt="IMG_0139" src="http://lh6.ggpht.com/devesh.rai/SAtqeHP-BMI/AAAAAAAAALA/A9vFRDdL1xw/IMG_0139_thumb%5B1%5D.jpg?imgmax=800" width="430" border="0" /></a> </p> <p> </p> <p><a href="http://lh3.ggpht.com/devesh.rai/SAtqhXP-BNI/AAAAAAAAALI/XngkTihUFss/s1600-h/IMG_0140%5B7%5D.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="326" alt="IMG_0140" src="http://lh5.ggpht.com/devesh.rai/SAtqj3P-BOI/AAAAAAAAALQ/G0mlBXYsphQ/IMG_0140_thumb%5B3%5D.jpg?imgmax=800" width="434" border="0" /></a></p> <p>Still Works.... </p> <p><a href="http://lh5.ggpht.com/devesh.rai/SAtqm3P-BPI/AAAAAAAAALY/brFKRLuVSrY/s1600-h/IMG_0142%5B6%5D.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="330" alt="IMG_0142" src="http://lh3.ggpht.com/devesh.rai/SAtqqXP-BQI/AAAAAAAAALg/7viNSji-XKo/IMG_0142_thumb%5B4%5D.jpg?imgmax=800" width="438" border="0" /></a></p> <p>Under the hood: Easy Access to the Microcontroller, and I/O Headers. I know, I'm a genius. <img alt="smile_teeth" src="http://spaces.live.com/rte/emoticons/smile_teeth.gif" /></p> <p><a href="http://lh6.ggpht.com/devesh.rai/SAtqsHP-BRI/AAAAAAAAALo/Ab8B_14Nd1E/s1600-h/IMG_0138%5B6%5D.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="328" alt="IMG_0138" src="http://lh6.ggpht.com/devesh.rai/SAtquHP-BSI/AAAAAAAAALw/hY4tOrRzcU0/IMG_0138_thumb%5B4%5D.jpg?imgmax=800" width="436" border="0" /></a>  So, Thats it for now. What about the rest of the bot? Well the main part is over, I mean, the Code works on the Mega32, is now optimized, quite a bit, and I spent an entire long weekend (Long Weekend = Friday + Saturday + Sunday) on it, so it may be atleast another 3-4 weekends that this project will be on hold, so that I can work on other interesting projects. Nothing to be sad about... Next week, I'm working on Panasonic Servo based gantry (Ball Screw), with a Xilinx Spartan XC3S400. Nice....</p> <p> </p> <p>If you like this post, leave a message, it always makes my day.<img alt="smile_regular" src="http://spaces.live.com/rte/emoticons/smile_regular.gif" /></p> Devesh Raihttp://www.blogger.com/profile/04196213231447707146noreply@blogger.com4tag:blogger.com,1999:blog-5750449707682687736.post-13975283469269821982008-04-15T20:58:00.001+05:302008-04-15T20:58:30.160+05:30TicTacToe Algorithm<p> </p> <p><a href="http://lh3.ggpht.com/devesh.rai/SATJXNa602I/AAAAAAAAAD4/mW88xvG7_r8/s1600-h/Title%5B8%5D.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="280" alt="Title" src="http://lh4.ggpht.com/devesh.rai/SATJYda603I/AAAAAAAAAEA/n9phYQcR5Vo/Title_thumb%5B4%5D.jpg?imgmax=800" width="309" border="0" /></a> </p> <p>So, I've been thinking a while now, of constructing a robotic game playing machine. You know, the type which plays Chess, Checkers, Monopoly.... You name it. Sound big? It did so, to me too :P . So we start with some thing simpler. A TicTacToe playing bot, now, here is an Idea!! I thought about this one for some time, the Idea slowly matured in my mind, and I concluded: The first step was to design an algorithm to play a fairly intelligent game of TicTacToe with a human opponent. I have no real experience with writing any game AI, so this was nice and challenging, worthy of devoting a full Sunday to......</p> <p>So the algorithm is fairly simple. I played about a hundred games with myself to try to think of my thought processes during the game, and to my fair surprise, I found that my thought process was entirely linear (I blame it on the damn C-Addiction ;) ). Honestly the thinking was simple:</p> <ol> <li>Look for a place to make my own winning trio</li> <li>If found: make a play there</li> <li>If not found: look for opponents possible trio</li> <li>If found: make mark there </li> <li>If not found: make a mark, so that there is possibility of trio next time.</li> <li>goto 1</li> </ol> <p>Sounds about right, huh? So what was to do? I whipped together a list of conditional statements to do the job, and wrote a program in C# to test it out. The reason I used C# is: Since its entirely a 'C' compatible syntax, I should have no trouble porting my logic and code to CodeVision (AVR), which I intend to make a target for my TicTacToe Robot.</p> <p>Lets explore the program a little:</p> <p>In this example, the Human Player (A.K.A: me, lolz!!) has chosen 'X' to play. Human moves are highlighted in blue, the computers moves are highlighted in red.</p> <p> <a href="http://lh4.ggpht.com/devesh.rai/SATJZda604I/AAAAAAAAAEI/IJvTYCdI818/s1600-h/Play-0%5B3%5D.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="294" alt="Play-0" src="http://lh4.ggpht.com/devesh.rai/SATJbda605I/AAAAAAAAAEQ/rz8wJEfO3aM/Play-0_thumb%5B1%5D.jpg?imgmax=800" width="315" border="0" /></a> </p> <p>If you see the image above carefully, you will notice the first move I made is the top left corner, and the computer responded with a mid-right 'O'. </p> <p>Reason: the mid-right 'O' is unobstructed, in 2-directions, and the highest chances of success are currently in 2 directions. Ideally we should have 3-directions of obstruction free blocks, but with my corner move, there are none left. </p> <p><a href="http://lh4.ggpht.com/devesh.rai/SATJcda606I/AAAAAAAAAEY/qjodMrrglNo/s1600-h/Play-1%5B5%5D.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="337" alt="Play-1" src="http://lh4.ggpht.com/devesh.rai/SATJdda607I/AAAAAAAAAEg/-jKm8jZ-MC8/Play-1_thumb%5B3%5D.jpg?imgmax=800" width="319" border="0" /></a></p> <p>Now, I played the dead-center position for 'X', and the computer responded by blocking the 'X' with a bottom corner-right-placed 'O'. There really was no other move. 'O' blocked the trio, AND, started creating a trio of its own. Here there is a flaw. If you haven't figured it out, you will, when you see the next move.</p> <p><a href="http://lh5.ggpht.com/devesh.rai/SATJeta608I/AAAAAAAAAEo/DXrgaMoHt1w/s1600-h/Play-2%5B5%5D.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="312" alt="Play-2" src="http://lh5.ggpht.com/devesh.rai/SATJfta609I/AAAAAAAAAEw/lllMen7h8gA/Play-2_thumb%5B3%5D.jpg?imgmax=800" width="322" border="0" /></a> </p> <p>I responded then by placing the 'X' at the top-right corner, the only logical position to be in, really. I stopped the 'O' trio, and co-incidentally, created, what I call the 'Double-Move' in TicTacToe. I could now place a 'X' in 2 places to win, and 'O' has only one move to stop both (the aforementioned flaw, we have here :P)!! So it picks one of the two places to block me. It picks the bottom right corner. The reason for that is, If I somehow miss the trio that I am making, 'O' can place its mark on the bottom-mid and make its own trio. A trade-off.</p> <p><a href="http://lh4.ggpht.com/devesh.rai/SATJjda60-I/AAAAAAAAAE4/ETS_PclCLvo/s1600-h/Play-3%5B5%5D.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="316" alt="Play-3" src="http://lh5.ggpht.com/devesh.rai/SATJkta60_I/AAAAAAAAAFA/m3kRN2QI3Ds/Play-3_thumb%5B3%5D.jpg?imgmax=800" width="395" border="0" /></a> </p> <p>Seems like I didn't miss the possible trio after all. Lol!</p> <p>So where did my algorithm go wrong? One may argue, that I co-incidentally won, right? I respectfully disagree. Look back at play-1 by the computer. The computer should have foreseen the 'Double Move' back then. What we need is a multiple-pass algorithm, to foresee this kind flaw. If the algorithm runs multiple-congruence tests, we can determine, a depth-of-thought kind of scenario, where we determine, the shortest and most probable win. We score each win on the basis of no of moves, and the next move is always a step in that direction.</p> <p>This may sound like overkill for a simple TicTacToe algorithm right? But, remember what the real reason for this algorithm is? We want to play several games, chess, checkers, .... who knows? Maybe twister, and other crazy party sex games too ;)?? lolz!</p> <p>You can download my application, and try it for yourself from:</p> <p><a href="http://rapidshare.com/files/107704442/pub.zip.html">http://rapidshare.com/files/107704442/pub.zip.html</a></p> <p> </p> <p>Despite its shortcoming(s?), I deem this algorithm ready for the TicTacToe robot. What next? Make this algorithm ready to run on an AVR, and prepare the robot (electronics et al).</p> <p><a href="http://lh3.ggpht.com/devesh.rai/SATJmNa61AI/AAAAAAAAAFI/yYDawVOUN5o/s1600-h/block-diagram%5B4%5D.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="250" alt="block-diagram" src="http://lh3.ggpht.com/devesh.rai/SATJnNa61BI/AAAAAAAAAFQ/ex2epW0jU6Y/block-diagram_thumb%5B2%5D.jpg?imgmax=800" width="381" border="0" /></a> </p> <p>A simplistic block diagram to explain roughly the direction in which I will be working.</p> <p>Will keep posting updates here, So, Stay tuned..... :)</p> <p> </p> <p>Leave a message if you like this article. It always makes my day.</p> Devesh Raihttp://www.blogger.com/profile/04196213231447707146noreply@blogger.com7tag:blogger.com,1999:blog-5750449707682687736.post-69189974796354802582008-03-04T19:38:00.005+05:302008-03-04T20:15:25.401+05:30ARM7TDMI: RealView Compiler LCD and DELAY Headers<div style="text-align: center;"><span style="font-weight: bold;"><span style="font-size:100%;">My Own LCD and Delay Headers</span></span><br /></div><div style="text-align: center;"><span style="font-size:100%;"><span style="font-size:85%;">For the RealView Compiler for ARM<br /><br /></span></span><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikgip85v7jEwbWcqq_-e5ip9V6AJm5lodmZRUSNK8dUI8rHNXgIVF96LXBqE6oWcHpvytC-qWSmIA2eAwF8Eaay7JMOafvIdOpLiFjyvA0q9QEXlH9Gn03IHvF7qC2Ym9RNH2MloaDpzFp/s1600-h/DSC00083.JPG"><img style="cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikgip85v7jEwbWcqq_-e5ip9V6AJm5lodmZRUSNK8dUI8rHNXgIVF96LXBqE6oWcHpvytC-qWSmIA2eAwF8Eaay7JMOafvIdOpLiFjyvA0q9QEXlH9Gn03IHvF7qC2Ym9RNH2MloaDpzFp/s400/DSC00083.JPG" alt="" id="BLOGGER_PHOTO_ID_5173889089555030834" border="0" /></a><br /><span style="font-size:100%;"><span style="font-size:85%;"><span style="font-size:78%;">(Above: Usage Demonstrated on a NXP LPC2138 ARM7TDMI uC)<br /><br /><br /></span></span></span><div style="text-align: left;"><span style="font-size:85%;">Keil's RealView Microcontroller Development Kit (a.k.a The RealView MDK) is a (Pardon the expression ;) ) really <span style="font-style: italic;"><span style="font-weight: bold;">Phat</span> </span>piece of software. Considering the results from <a href="http://www.raisonance.com/files/pdf/AN52-ARM-C-Benchmark.pdf">this Benchmark(PDF)</a>, Keil produces object code which is no less then 15% smaller and 10% faster then its closest competitor, It's a whopping 1.5 times better code generation then the GNU (think WinARM) compiler.<br /><br />So whats wrong with it? (I mean, I'm sure that this post has got to have some meaning and conclusion right? Lol!) Well for starters the lack af a good library. Yes, It does contain all the ANSI/ISO - C libraries, and yes it contains a really <span style="font-style: italic;"><span style="font-weight: bold;">kick-ass</span></span> RTX-Kernel library, but it misses out on many simple libraries like the basic Character LCD library, the basic Delay libraries, and the simple things in life that we miss, like chocolate milk, and white roses, like the smell of dry leaves on green grass, the twitter of bir. . . . . . . . erm ....... you get the point.<br /><br />So what did I do? I made a library for all to use. Well not strictly speaking. I took Martin Thomas's LCD Library for WinARM, fully dissected it, and remade it for the RealView MDK. This was no easy task, since the RealView MDK uses different notations for the same Registers (which is quite irritating, especially if you constantly need to move back and forth from the GNU compiler). Any ways, the task is done. The file is available for downloading, <a style="font-weight: bold; font-style: italic;" href="http://rapidshare.com/files/96981291/myOwnHeaders.rar.html">from this link</a>, and thats that.<br /><br />To test the headers, I used a LPC2138, you can see the Header board that I used below. I used a simple character LCD (the 162A variants).</span><span style="text-decoration: underline;"></span><br /><span style="font-size:85%;"><br /></span></div><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiq_kLgcw1vLkBhCxm3tcPxfUq7uSsVoFejhXp2PQr_NOhJoawcQxc_TS7X72eL4svcDnl2m9VQgYautptWU_XwMh_ORvtZGoefkvrmBWJnRrJt0M0s9503GqzdLy-DkPtPh3E4ux3Q6UVV/s1600-h/DSC00086.JPG"><img style="cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiq_kLgcw1vLkBhCxm3tcPxfUq7uSsVoFejhXp2PQr_NOhJoawcQxc_TS7X72eL4svcDnl2m9VQgYautptWU_XwMh_ORvtZGoefkvrmBWJnRrJt0M0s9503GqzdLy-DkPtPh3E4ux3Q6UVV/s400/DSC00086.JPG" alt="" id="BLOGGER_PHOTO_ID_5173889076670128930" border="0" /></a><br /><br /><div style="text-align: left;"><span style="font-size:85%;">You can modify the code to suit your hardware, when you make a project. I suppose you will not need to change anything but the following lines in LCD.h</span><br /></div><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh9_RjkXiqloTWejYbZNIIgBMiHHJo20S-fMD9Ek6VURHw10M84-bqpV4Lux4R9eIiqdGdFFbeklPqyetOvWGYmmKOigNv5BBcT6h_Q6HzcluMJOzdXKGinXpkcva2bWjneyFaPfajqb7J0/s1600-h/LCD.JPG"><img style="cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh9_RjkXiqloTWejYbZNIIgBMiHHJo20S-fMD9Ek6VURHw10M84-bqpV4Lux4R9eIiqdGdFFbeklPqyetOvWGYmmKOigNv5BBcT6h_Q6HzcluMJOzdXKGinXpkcva2bWjneyFaPfajqb7J0/s400/LCD.JPG" alt="" id="BLOGGER_PHOTO_ID_5173889098144965442" border="0" /></a><br /><span style="font-size:100%;"><span style="font-size:85%;"><br /></span></span><div style="text-align: left;">Like this post? Leave a comment, it always makes my day. :)<br /></div><span style="font-size:100%;"><span style="font-size:85%;"><br /></span></span><span style="font-weight: bold;"><span style="font-size:100%;"><span style="font-size:85%;"><span style="font-weight: bold;"></span></span><br /></span></span></div>Devesh Raihttp://www.blogger.com/profile/04196213231447707146noreply@blogger.com4tag:blogger.com,1999:blog-5750449707682687736.post-18226978900517724452008-03-02T18:05:00.000+05:302008-03-02T18:36:21.593+05:30USB Bulk Transfer DeviceIn continuation of my previous post (<span class="blsp-spelling-error" id="SPELLING_ERROR_0">USB</span>-101), <span class="blsp-spelling-error" id="SPELLING_ERROR_1">USB</span> Human Interface Devices, have a disadvantage. HID devices have a maximum speed of 64Kb/s (or 512 KB/s) in <span style="font-weight: bold;">each direction.</span> Sounds like a lot? Not so much. Imagine building a <span class="blsp-spelling-error" id="SPELLING_ERROR_2">USB</span> based Scanner, or Image <span class="blsp-spelling-corrected" id="SPELLING_ERROR_3">acquisition</span> tool. A single image could be <span class="blsp-spelling-corrected" id="SPELLING_ERROR_4">up to</span> several <span class="blsp-spelling-corrected" id="SPELLING_ERROR_5">hundred</span> megs!! It could take several <span class="blsp-spelling-corrected" id="SPELLING_ERROR_6">minutes</span> (or hours :-O ) to transfer data.<br />But USB is supposed to be a high speed bus, right? Solution: Bulk Transfers. Bulk transfers utilize the full bus speed of USB. So transfer rates of 12MB/s in full speed devices (Like the 18f4550) or 480MB/s in high speed devices are possible.<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh7lsrnlrtMw3YUCDrVNHsn_RmzTQl_CrHuaOfhvuePQ73oSsJ4nuNgUr0npQwRCw7Khyphenhyphenpqb4Cblowpa1m99PLQeNF_EiObhYWVGkfCAa5LNLt4J1Ece9bjKHK-jwaI-acc0IbC-wJJm-Mr/s1600-h/Screen.bmp"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh7lsrnlrtMw3YUCDrVNHsn_RmzTQl_CrHuaOfhvuePQ73oSsJ4nuNgUr0npQwRCw7Khyphenhyphenpqb4Cblowpa1m99PLQeNF_EiObhYWVGkfCAa5LNLt4J1Ece9bjKHK-jwaI-acc0IbC-wJJm-Mr/s400/Screen.bmp" alt="" id="BLOGGER_PHOTO_ID_5173124884716200834" border="0" /></a><br /><br />I've included with this post a file <a href="http://rapidshare.com/files/96428339/Bulk_transfer_device.rar.html"><span><span style="color:red;">Bulk_transfer_device.rar (298 KB)</span></span></a> which contains the PIC's firmware (Once again using the CCS 'C' Compiler for PIC). Which uses Bulk mode transfers for the hardware we built before.<br /><br />Now, do note one thing: This firmware is NOT an USB HID device, so you will need drivers for this device. USB Bulk transfer devices require writing of drivers (With the exception of Mass Storage Profille devices, which also use bulk transfer endpoints). I've included all the necessary files in the RAR archive, including the INF file, the project written in C#, and the DLL file. I've made some use of the JUNGO WinDriver library for the project files.<br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjefVoRN5e1FUwssf4ZDadnPgNyf_oKLnvh9qJrkymSyAfUm-dC_W_erPO_c_dgEHf7CsYed2O_QgOkSoynjYblMS6x6vhLOrmt_hq5crxWVWdd4d1Tue7iHUZN3VlD9bJbHxxS1hje4IiX/s1600-h/Screen2.bmp"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjefVoRN5e1FUwssf4ZDadnPgNyf_oKLnvh9qJrkymSyAfUm-dC_W_erPO_c_dgEHf7CsYed2O_QgOkSoynjYblMS6x6vhLOrmt_hq5crxWVWdd4d1Tue7iHUZN3VlD9bJbHxxS1hje4IiX/s400/Screen2.bmp" alt="" id="BLOGGER_PHOTO_ID_5173124897601102738" border="0" /></a><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhK1y6_Ka69SI-6O6YSNulm01J2Qjp36Zq4h48CL2ZYr2RYUrwJdkYx-udu3vONYNOhdnf98aPT9gonqj4lGIRrpEjfJJmKq-t6jgl0elYstEQeJAG6Gqcgg6QHb9iaXhCb7UGUS1SLmD5f/s1600-h/Screen3.bmp"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhK1y6_Ka69SI-6O6YSNulm01J2Qjp36Zq4h48CL2ZYr2RYUrwJdkYx-udu3vONYNOhdnf98aPT9gonqj4lGIRrpEjfJJmKq-t6jgl0elYstEQeJAG6Gqcgg6QHb9iaXhCb7UGUS1SLmD5f/s400/Screen3.bmp" alt="" id="BLOGGER_PHOTO_ID_5173124897601102754" border="0" /></a><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAiyVvhk6z8Aojmha3xm2inpADChqaD4616kg9bh5tNxJ4albzfYYiQ0QcXXJGzyhS5HkfvstRIQeK9_w0o31goAF1-eUE4TahT-qjiF1InOz3b3UYQv3rYirnOX_pJa3UC_2lcqb6xXd9/s1600-h/Screen4.bmp"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAiyVvhk6z8Aojmha3xm2inpADChqaD4616kg9bh5tNxJ4albzfYYiQ0QcXXJGzyhS5HkfvstRIQeK9_w0o31goAF1-eUE4TahT-qjiF1InOz3b3UYQv3rYirnOX_pJa3UC_2lcqb6xXd9/s400/Screen4.bmp" alt="" id="BLOGGER_PHOTO_ID_5173124901896070066" border="0" /></a><br />The pictures above explain how the device is detected and installed, it should be no problem for anyone who has installed a device on their PC before.Devesh Raihttp://www.blogger.com/profile/04196213231447707146noreply@blogger.com7tag:blogger.com,1999:blog-5750449707682687736.post-10603775802405501702008-02-29T17:26:00.000+05:302008-02-29T18:20:53.730+05:30USB-101<div style="text-align: center;"><span style="font-weight: bold;font-size:180%;" ><span class="blsp-spelling-error" id="SPELLING_ERROR_0">USB</span>-101</span></div> <p class="MsoNormal" style="text-align: center;" align="center"><span style="font-size:85%;">(With a Microchip PIC 18F4550)</span></p> <p style="text-align: center;" class="MsoNormal"><b style="">-By <span class="blsp-spelling-error" id="SPELLING_ERROR_1">Devesh</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_2">Rai</span></b><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhCSxk32BFLdTAEQGGn5_kNHvkBTu9UaYphqVrxj1xMNeplsmM-3UAPKSXXoW30Nj-wPr2P7YjFpRh6UET4_6To00oWMyjRS_gHjeFoCz_ahSfasPRIdZlyG1py7B_biI5-LFhDVqiSiLfg/s1600-h/Opening.JPG"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhCSxk32BFLdTAEQGGn5_kNHvkBTu9UaYphqVrxj1xMNeplsmM-3UAPKSXXoW30Nj-wPr2P7YjFpRh6UET4_6To00oWMyjRS_gHjeFoCz_ahSfasPRIdZlyG1py7B_biI5-LFhDVqiSiLfg/s400/Opening.JPG" alt="" id="BLOGGER_PHOTO_ID_5172370954746995362" border="0" /></a><span style="font-size:7;"><span style="font-size:78%;">The <span class="blsp-spelling-error" id="SPELLING_ERROR_3">USB</span> “Trident” logo is property of the <span class="blsp-spelling-error" id="SPELLING_ERROR_4">USB</span>-IF. </span><span style="font-size:78%;">The author of this article does not have anything to do with <span class="blsp-spelling-error" id="SPELLING_ERROR_5">USB</span>-IF.</span><o:p></o:p></span></p><div style="text-align: center;"> </div><p style="text-align: center;" class="MsoNormal"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3CB1ojAYZDDe3RNvzaOQ64KVjm7LxHKLyLC3eZ_WT7vqO6QjmaOCR0yyEEQFtyXubxg4P4qrUS-J2cjd7hZiXlv_hZSe8a40bkSdEZ5aKeT5hp5h5nqNcCbEZ43ijNpDkAb1NSZKs8UTB/s1600-h/Opening.JPG"> </a></p> <span style="background: black none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:";font-size:78%;color:red;" ><span style="font-size:85%;">NOTE: Before Starting the tutorial, I suggest you download the complete accompanying ZIP package. The ZIP package contains all the source code, HEX files and <span class="blsp-spelling-error" id="SPELLING_ERROR_6">Executables</span> required for this tutorial. It <span class="blsp-spelling-error" id="SPELLING_ERROR_7">alo</span> contains a <span class="blsp-spelling-error" id="SPELLING_ERROR_8">PDF</span> version of this tutorial for offline viewing. You will find the link to download the ZIP file, at the bottom of this page.<br /></span><br /></span> <p class="MsoNormal"><span style="font-size:85%;">After scouting the <span class="blsp-spelling-error" id="SPELLING_ERROR_9">internet</span>, for tutorials to get started on <span class="blsp-spelling-error" id="SPELLING_ERROR_10">USB</span>. I found that:</span></p> <p class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;"><!--[if !supportLists]--><span style="font-size:85%;"><span style="">1)<span style=";font-family:";font-size:7;" > </span></span>Most of the tutorials concentrate on the theory behind the operation of <span class="blsp-spelling-error" id="SPELLING_ERROR_11">USB</span> Enumeration and spend little effort in explaining how it can be actually implemented. While I think that this information is useful, and required, I feel that the general electronics/robotics<span style=""> </span>hobbyist, <span class="blsp-spelling-error" id="SPELLING_ERROR_12">doesn</span>’t really want to spend his (rather sparse) “quality weekend time” understanding the “electrical characteristics of <span class="blsp-spelling-error" id="SPELLING_ERROR_13">USB</span> Cables”, or the “BUS Specifications”, he <span class="blsp-spelling-error" id="SPELLING_ERROR_14">doesn</span>’t want the read the terms “<span class="blsp-spelling-error" id="SPELLING_ERROR_15">NRZI</span>”, “<span class="blsp-spelling-error" id="SPELLING_ERROR_16">CRC</span>”, “<span class="blsp-spelling-error" id="SPELLING_ERROR_17">SIE</span>”, “<span class="blsp-spelling-error" id="SPELLING_ERROR_18">HC</span>”, “Frames”, “Protocol” etc. if he can avoid it.</span><!--[endif]--></p> <p class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;"><!--[if !supportLists]--><span style="font-size:85%;"><span style="">2)<span style=";font-family:";font-size:7;" > </span></span>The few tutorials which I found, which <i style="">did</i> actually concentrate on building your own <span class="blsp-spelling-error" id="SPELLING_ERROR_19">USB</span> device required you to have previously read the 11 chapters long ( + 3 Appendices) <span class="blsp-spelling-error" id="SPELLING_ERROR_20">USB</span> Specifications document (or at least a few hundred pages of it).</span><!--[endif]--></p> <p class="MsoNormal"><span style="font-size:85%;"><o:p> </o:p></span></p> <p class="MsoNormal"><span style="font-size:85%;">Let’s face it. We have some data on our PC, and we want to send it to our peripheral, or our peripheral has some data, and it wants to send it to our PC. (If you want to do anything apart form these two tasks, then <span class="blsp-spelling-error" id="SPELLING_ERROR_21">USB</span> can’t help you) Why should we need to waste so much time and effort studying unnecessary information for such a simple task. This tutorial aims to help you get started on <span class="blsp-spelling-error" id="SPELLING_ERROR_22">USB</span>, and build your own first <span class="blsp-spelling-error" id="SPELLING_ERROR_23">USB</span> peripheral in one weekend!</span></p> <p class="MsoNormal"><span style="font-size:85%;"><o:p> </o:p></span></p> <p class="MsoNormal"><span style="font-size:85%;">Why <span class="blsp-spelling-error" id="SPELLING_ERROR_24">USB</span>? We could use a PC’s parallel port, or we could use the RS232.</span></p> <p class="MsoNormal"><span style="font-size:85%;">Well the reasons to use <span class="blsp-spelling-error" id="SPELLING_ERROR_25">USB</span> are quite simple:</span></p> <p class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;"><!--[if !supportLists]--><span style="font-size:85%;"><span style="">1)<span style=";font-family:";font-size:7;" > </span></span><span class="blsp-spelling-error" id="SPELLING_ERROR_26">USB</span> requires only 2 of your <span class="blsp-spelling-error" id="SPELLING_ERROR_27">microcontroller</span>’s data lines.</span><!--[endif]--></p> <p class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;"><!--[if !supportLists]--><span style="font-size:85%;"><span style="">2)<span style=";font-family:";font-size:7;" > </span></span><span class="blsp-spelling-error" id="SPELLING_ERROR_28">USB</span> is fast.</span><!--[endif]--></p> <p class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;"><!--[if !supportLists]--><span style="font-size:85%;"><span style="">3)<span style=";font-family:";font-size:7;" > </span></span><span class="blsp-spelling-error" id="SPELLING_ERROR_29">USB</span> ports are available on every PC/Laptop. Both of the other options <span class="blsp-spelling-error" id="SPELLING_ERROR_30">aren</span>’t.</span><!--[endif]--></p> <p class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;"><!--[if !supportLists]--><span style="font-size:85%;"><span style="">4)<span style=";font-family:";font-size:7;" > </span></span><span class="blsp-spelling-error" id="SPELLING_ERROR_31">USB</span> is fast.</span><!--[endif]--></p> <p class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;"><!--[if !supportLists]--><span style="font-size:85%;"><span style="">5)<span style=";font-family:";font-size:7;" > </span></span>Despite what you may believe, a simplistic <span class="blsp-spelling-error" id="SPELLING_ERROR_32">USB</span> HID based system is easier to implement then both the other options.</span><!--[endif]--></p> <p class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;"><!--[if !supportLists]--><span style="font-size:85%;"><span style="">6)<span style=";font-family:";font-size:7;" > </span></span>Did I mention: <span class="blsp-spelling-error" id="SPELLING_ERROR_33">USB</span> is fast? ;-)</span><!--[endif]--></p> <p class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;"><!--[if !supportLists]--><span style="font-size:85%;"><span style="">7)<span style=";font-family:";font-size:7;" > </span></span>It’s easy to use.</span><!--[endif]--></p> <p class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;"><!--[if !supportLists]--><span style="font-size:85%;"><span style="">8)<span style=";font-family:";font-size:7;" > </span></span>Its bus powered, so there is no need for an external power supply.</span><!--[endif]--></p> <p class="MsoNormal"><span style="font-size:85%;"><o:p> </o:p></span></p> <p class="MsoNormal"><span style="font-size:85%;"><span class="blsp-spelling-error" id="SPELLING_ERROR_34">Ok</span>, Now who should be reading this tutorial?</span></p> <p class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;"><!--[if !supportLists]--><span style="font-size:85%;"><span style="">1)<span style=";font-family:";font-size:7;" > </span></span>Electronics/Robotics Hobbyists, wanting to move on to <span class="blsp-spelling-error" id="SPELLING_ERROR_35">USB</span> from other communication methods.</span><!--[endif]--></p> <p class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;"><!--[if !supportLists]--><span style="font-size:85%;"><span style="">2)<span style=";font-family:";font-size:7;" > </span></span>Students wanting to make a project, involving <span class="blsp-spelling-error" id="SPELLING_ERROR_36">USB</span>.</span><!--[endif]--></p> <p class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;"><!--[if !supportLists]--><span style="font-size:85%;"><span style="">3)<span style=";font-family:";font-size:7;" > </span></span>Those of you now starting to get scared with the scarcity of COM ports and <span class="blsp-spelling-error" id="SPELLING_ERROR_37">LPT</span> ports, on newer PC’s.</span><!--[endif]--></p> <p class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;"><!--[if !supportLists]--><span style="font-size:85%;"><span style="">4)<span style=";font-family:";font-size:7;" > </span></span>Those of you who now, feel the “Need for Speed” =P.</span><!--[endif]--></p> <p class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;"><!--[if !supportLists]--><span style="font-size:85%;"><span style="">5)<span style=";font-family:";font-size:7;" > </span></span>Those who don’t expect to become experts in the technology, after reading this tutorial, understand that this is just a drop in the ocean, and understand that this tutorial will only push them in the right direction. </span><!--[endif]--></p> <p class="MsoNormal"><span style="font-size:85%;">.</span></p> <p class="MsoNormal"><span style="font-size:85%;">.</span></p> <p class="MsoNormal"><span style="font-size:85%;">.</span></p> <p class="MsoNormal"><span style="font-size:85%;">.</span></p> <p class="MsoNormal"><span style="font-size:85%;">.</span></p> <p class="MsoNormal"><span style="font-size:85%;">.</span></p> <p class="MsoNormal"><span style="font-size:85%;">.</span></p> <p class="MsoNormal"><span style="font-size:85%;">.</span></p> <p class="MsoNormal"><span style="font-size:85%;">.</span></p> <p class="MsoNormal"><span style="font-size:85%;">.</span></p> <p class="MsoNormal"><span style="font-size:85%;">.</span></p> <p class="MsoNormal"><span style="font-size:85%;">.</span></p> <p class="MsoNormal"><span style="font-size:85%;">Still reading? Good. Now, before we start, there are a few prerequisites:</span></p> <p class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;"><!--[if !supportLists]--><span style="font-size:85%;"><span style="">1)<span style=";font-family:";font-size:7;" > </span></span>You should know what a <span class="blsp-spelling-error" id="SPELLING_ERROR_38">microcontroller</span> is. (If you have never worked on one its OK)</span><!--[endif]--></p> <p class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;"><!--[if !supportLists]--><span style="font-size:85%;"><span style="">2)<span style=";font-family:";font-size:7;" > </span></span>You should have a basic idea about using <span class="blsp-spelling-error" id="SPELLING_ERROR_39">google</span> to find solutions to your problems.</span><!--[endif]--></p> <p class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;"><!--[if !supportLists]--><span style="font-size:85%;"><span style="">3)<span style=";font-family:";font-size:7;" > </span></span>You should know how to write simple C or C++ programs.</span><!--[endif]--></p> <p class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;"><!--[if !supportLists]--><span style="font-size:85%;"><span style="">4)<span style=";font-family:";font-size:7;" > </span></span>You should have some basic electrical/electronics knowledge.</span><!--[endif]--></p> <p class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;"><!--[if !supportLists]--><span style="font-size:85%;"><span style="">5)<span style=";font-family:";font-size:7;" > </span></span>You should know how to plug in a <span class="blsp-spelling-error" id="SPELLING_ERROR_40">USB</span> cable into your Laptop/PC.</span><!--[endif]--></p> <p class="MsoNormal"><span style="font-size:85%;"><o:p> </o:p></span></p> <p class="MsoNormal"><span style="font-size:85%;">Some of you may find that I have stressed on very basic facts, this is because I intended to make this tutorial readable for all people, even those not acquainted with <span class="blsp-spelling-error" id="SPELLING_ERROR_41">microcontrollers</span>.</span></p> <p class="MsoNormal"><span style="font-size:85%;">Now that all this is out of the way, let’s start.</span></p> <p class="MsoNormal"><span style="font-size:85%;"><o:p> </o:p></span></p> <p class="MsoNormal"><span style="font-size:85%;">We will be using a PIC18F4550 <span class="blsp-spelling-error" id="SPELLING_ERROR_42">microcontroller</span> to make our first <span class="blsp-spelling-error" id="SPELLING_ERROR_43">USB</span> device. There are many others that we could have used, but we will be using this chip, because:</span></p> <p class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;"><!--[if !supportLists]--><span style="font-size:85%;"><span style="">1)<span style=";font-family:";font-size:7;" > </span></span>Its available in a DIP40 package, which in my opinion is one of the most hobbyist friendly packages.</span><!--[endif]--></p> <p class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;"><!--[if !supportLists]--><span style="font-size:85%;"><span style="">2)<span style=";font-family:";font-size:7;" > </span></span>Its optimized for ‘C’, which makes our job easier then ever.</span><!--[endif]--></p> <p class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;"><!--[if !supportLists]--><span style="font-size:85%;"><span style="">3)<span style=";font-family:";font-size:7;" > </span></span>Its cheap, and available at every nook and cranny that sells <span class="blsp-spelling-error" id="SPELLING_ERROR_44">microcontrollers</span>.</span><!--[endif]--></p> <p class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;"><!--[if !supportLists]--><span style="font-size:85%;"><span style="">4)<span style=";font-family:";font-size:7;" > </span></span>It requires no special connections (Minimum use of discreet components).</span><!--[endif]--></p> <p class="MsoNormal"><span style="font-size:85%;"><o:p> </o:p></span></p> <p class="MsoNormal"><span style="font-size:85%;">Our first project will be a <span class="blsp-spelling-error" id="SPELLING_ERROR_45">USB</span> LED Blinker. Those of you more ordained in electronics probably already know, a LED Blinker (often referred to as a “<span class="blsp-spelling-error" id="SPELLING_ERROR_46">Blinky</span>”), is the “Hello World” of all electronics. We want to make a simple project that blinks/toggles two LED’s when we send data from a PC to the <span class="blsp-spelling-error" id="SPELLING_ERROR_47">Blinky</span> via <span class="blsp-spelling-error" id="SPELLING_ERROR_48">USB</span>. In fact we will take it up a notch, we will even give an 8-bit wide parallel port to use as a general purpose I/O, After all, if you are an electronics/robotics hobbyist, this is what you are really looking for, right?</span></p> <p class="MsoNormal"><span style="font-size:85%;"><o:p> </o:p></span></p> <p class="MsoNormal"><span style="font-size:85%;">So lets see what all we will require</span></p> <ul style="margin-top: 0in;" type="disc"><li class="MsoNormal" style=""><span style="font-size:85%;">A Bread Board (or Prototyping Board, or whatever you prefer to call them). We will first make our design on a bread board, so we can work out the errors, before we make a Printed Board (PCB).</span></li><li class="MsoNormal" style=""><span style="font-size:85%;">A few wires. These are for making the connections.</span></li><li class="MsoNormal" style=""><span style="font-size:85%;">A PIC18F4550 (in a <span class="blsp-spelling-error" id="SPELLING_ERROR_49">PDIP</span>40 package). This is the main component, it’s the <span class="blsp-spelling-error" id="SPELLING_ERROR_50">microcontroller</span>.</span></li><li class="MsoNormal" style=""><span style="font-size:85%;">A few LED’s. I used 2. You can use as many as you require.</span></li><li class="MsoNormal" style=""><span style="font-size:85%;">.1 inch Headers. A single row consists of 40 headers, when you buy them. So one row should be enough.</span></li><li class="MsoNormal" style=""><span style="font-size:85%;">B-Type Female <span class="blsp-spelling-error" id="SPELLING_ERROR_51">USB</span> connector. Berg makes really good quality connectors, so I usually use them. These normally come in a strip of 25. Buy one strip.</span></li><li class="MsoNormal" style=""><span style="font-size:85%;">A Soldering Iron. Any soldering iron should do the job.</span></li><li class="MsoNormal" style=""><span style="font-size:85%;">A 20MHz Crystal. We need this in order for the <span class="blsp-spelling-error" id="SPELLING_ERROR_52">microcontroller</span> to work, the 18F4550 <span class="blsp-spelling-error" id="SPELLING_ERROR_53">microcontroller</span> has an internal RC oscillator too, but for our purpose we will use an external crystal.</span></li><li class="MsoNormal" style=""><span style="font-size:85%;">Two 33<span class="blsp-spelling-error" id="SPELLING_ERROR_54">pF</span> capacitors. These are used to make an oscillator circuit with the aforementioned crystal. I used 33<span class="blsp-spelling-error" id="SPELLING_ERROR_55">pF</span>, if you would prefer, you could use 22<span class="blsp-spelling-error" id="SPELLING_ERROR_56">pF</span> too. Neither would make any difference.</span></li><li class="MsoNormal" style=""><span style="font-size:85%;">A few (at least 3) 100<span class="blsp-spelling-error" id="SPELLING_ERROR_57">nF</span> Capacitors. These are decoupling capacitors, they are used to reduce electrical noise between the positive (<span class="blsp-spelling-error" id="SPELLING_ERROR_58">Vdd</span>) and negative (<span class="blsp-spelling-error" id="SPELLING_ERROR_59">Vss</span>) terminals of<span style=""> </span>your <span class="blsp-spelling-error" id="SPELLING_ERROR_60">microcontroller</span> and <span class="blsp-spelling-error" id="SPELLING_ERROR_61">USB</span> Connector. More experienced </span></li><li class="MsoNormal" style=""><span style="font-size:85%;">A 470<span class="blsp-spelling-error" id="SPELLING_ERROR_62">nF</span> capacitor. This is used to isolate the <span class="blsp-spelling-error" id="SPELLING_ERROR_63">Vusb</span> pin of the <span class="blsp-spelling-error" id="SPELLING_ERROR_64">microcontroller</span> (Pin 18), with the negative (<span class="blsp-spelling-error" id="SPELLING_ERROR_65">Vss</span> or <span class="blsp-spelling-error" id="SPELLING_ERROR_66">Gnd</span>) of the <span class="blsp-spelling-error" id="SPELLING_ERROR_67">USB</span>. This is required in the case of a Bus powered configuration (like ours). The actual value of this capacitor does not matter, the data sheet recommends a 330<span class="blsp-spelling-error" id="SPELLING_ERROR_68">nF</span>, <span class="blsp-spelling-error" id="SPELLING_ERROR_69">infact</span> I have seen people using anything between 270<span class="blsp-spelling-error" id="SPELLING_ERROR_70">nF</span> to 590<span class="blsp-spelling-error" id="SPELLING_ERROR_71">nF</span>, with varying degrees of success. As an observation 470<span class="blsp-spelling-error" id="SPELLING_ERROR_72">nF</span> always works and, it is cheaply and abundantly available.</span></li><li class="MsoNormal" style=""><span style="font-size:85%;">A 40 Pin <span class="blsp-spelling-error" id="SPELLING_ERROR_73">IC</span> base. These are what you would mount your <span class="blsp-spelling-error" id="SPELLING_ERROR_74">microcontroller</span> on.</span></li><li class="MsoNormal" style=""><span style="font-size:85%;">A push button. These are often called tactile switches, this will be used as a reset button. A reset in a <span class="blsp-spelling-error" id="SPELLING_ERROR_75">microcontroller</span> is similar to a reset on your PC. When you push the reset button, the <span class="blsp-spelling-error" id="SPELLING_ERROR_76">microcontroller</span> stops executing the current program, and it restarts.</span></li><li class="MsoNormal" style=""><span style="font-size:85%;">Two 330 Ohm resistors. These will act as pull up resistors for the LED’s.</span></li><li class="MsoNormal" style=""><span style="font-size:85%;">One 10<span class="blsp-spelling-error" id="SPELLING_ERROR_77">KOhm</span> resistor. This will act as a pull up resistor for the Reset Switch.</span></li></ul> <p class="MsoNormal"><span style="font-size:85%;"><o:p> </o:p></span></p> <p class="MsoNormal"><span style="font-size:85%;">First we assemble the components as per the schematic below.</span></p> <span style="font-size:85%;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPMOFyG1MFoOkNI410LiBkCelTa75nnLwl3-ua6WXyegdqlL5tAucG8Xz_6xBGKr2QgZ3xVqrqP0gRhw78SGfUawNt5ot_oMTCWU2J0dS93B1iBrF7CtYqxpWbPmMcid83-Kdiam9cU4sM/s1600-h/Schematic.JPG"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPMOFyG1MFoOkNI410LiBkCelTa75nnLwl3-ua6WXyegdqlL5tAucG8Xz_6xBGKr2QgZ3xVqrqP0gRhw78SGfUawNt5ot_oMTCWU2J0dS93B1iBrF7CtYqxpWbPmMcid83-Kdiam9cU4sM/s400/Schematic.JPG" alt="" id="BLOGGER_PHOTO_ID_5172372277596922546" border="0" /></a><br /></span><p class="MsoNormal"><span style="font-size:85%;">One thing you must be wary about is the pin numbering of a <span class="blsp-spelling-error" id="SPELLING_ERROR_78">USB</span> B-Type connector. The connector <span class="blsp-spelling-error" id="SPELLING_ERROR_79">doesn</span>’t have any markings indicating the pin numbers. Follow the following scheme to connect the correct pin numbers.</span></p><span style="font-size:85%;"><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiE4zFXG98SN5sqvKM088BMaBaTUPOvkoCCNWV9X6kEPz9BQetRYjc_bYQNkGbutL4VsMZWpWqcYysEYZA9KK3s-02vzAVWOBVPrMDBDBVRqqpW7Loi2ct1T6KL2QYAupjwLiYfhDJow4nY/s1600-h/pin+numbering+diagram.JPG"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiE4zFXG98SN5sqvKM088BMaBaTUPOvkoCCNWV9X6kEPz9BQetRYjc_bYQNkGbutL4VsMZWpWqcYysEYZA9KK3s-02vzAVWOBVPrMDBDBVRqqpW7Loi2ct1T6KL2QYAupjwLiYfhDJow4nY/s400/pin+numbering+diagram.JPG" alt="" id="BLOGGER_PHOTO_ID_5172372831647703746" border="0" /></a></span><span style="font-size:85%;"><br /><span style=";font-family:";font-size:12;" ><span style="font-size:85%;"><span class="blsp-spelling-error" id="SPELLING_ERROR_80">Ok</span>, now our basic hardware is </span><span style="font-size:85%;">ready. Your bread board <span class="blsp-spelling-error" id="SPELLING_ERROR_81">USB</span> “<span class="blsp-spelling-error" id="SPELLING_ERROR_82">Blinky</span>” peripheral should look something like this:<br /></span></span><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgkWsOMa3CXmZyGFGQpw9i3KF_WBlIHlMpnVP3DC_EudtKSauGt0uDQwHpAybHkHVyaHqur6Dpqf9BnFzu-lXkTWE3nE8pBA8jkSznz1ZEb4UVUBuvzCK9Z6nLL6sc5Diuwd2KB16CCciO8/s1600-h/Photo_022308_001.jpg"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgkWsOMa3CXmZyGFGQpw9i3KF_WBlIHlMpnVP3DC_EudtKSauGt0uDQwHpAybHkHVyaHqur6Dpqf9BnFzu-lXkTWE3nE8pBA8jkSznz1ZEb4UVUBuvzCK9Z6nLL6sc5Diuwd2KB16CCciO8/s400/Photo_022308_001.jpg" alt="" id="BLOGGER_PHOTO_ID_5172373226784694994" border="0" /></a><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQj_fjI6gEWdxuf3cKzHXVTbj9td5-5kAu6_OtqnjAJ76swU591kt8p10Hwra3zYiYdmU7zPvxJz3ZxSiUhe2-ZyLcsB0TC1OvPFXwgMVoioJVQKwlgs90lTzIyHmPL1vSbfjRdkkuUf1l/s1600-h/Photo_022308_002.jpg"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQj_fjI6gEWdxuf3cKzHXVTbj9td5-5kAu6_OtqnjAJ76swU591kt8p10Hwra3zYiYdmU7zPvxJz3ZxSiUhe2-ZyLcsB0TC1OvPFXwgMVoioJVQKwlgs90lTzIyHmPL1vSbfjRdkkuUf1l/s400/Photo_022308_002.jpg" alt="" id="BLOGGER_PHOTO_ID_5172373226784695010" border="0" /></a><br /><br /></span><p class="MsoNormal"><span style="font-size:85%;"><o:p> </o:p></span></p> <p class="MsoNormal"><span style="font-size:85%;">Now, we are going to program the PIC18F4550. I used a <span class="blsp-spelling-error" id="SPELLING_ERROR_83">JDM</span> programmer, which I built. I’m not going to cover building the programmer in this tutorial, there are plenty of good tutorials available on the <span class="blsp-spelling-error" id="SPELLING_ERROR_84">internet</span> for <span class="blsp-spelling-error" id="SPELLING_ERROR_85">JDM</span> Programmers. These are cheap to build, and very easy to use, all they require is a few resistors, diodes, and transistors. I built it on some waste pieces of bread board.</span></p> <p class="MsoNormal"><span style="font-size:85%;">I used <span class="blsp-spelling-error" id="SPELLING_ERROR_86">WinPic</span> to download my Hex file to the PIC.</span></p> <p class="MsoNormal"><span style="font-size:85%;"><o:p> </o:p></span></p> <p class="MsoNormal"><span style="font-size:85%;">Now, we will dissect the software which is used in this tutorial. This section may be divided into two parts</span></p> <ol style="margin-top: 0in;" start="1" type="1"><li class="MsoNormal" style=""><span style="font-size:85%;">The firmware which runs on the 18F4550 (Written in C, using the <span class="blsp-spelling-error" id="SPELLING_ERROR_87">CCS</span> Compiler).</span></li><li class="MsoNormal" style=""><span style="font-size:85%;">The Host software (written in C#) which runs on your PC.</span></li></ol> <p class="MsoNormal"><span style="font-size:85%;"><o:p> </o:p></span></p> <p class="MsoNormal"><span style="font-size:85%;">We will start with the firmware.</span></p> <p class="MsoNormal"><span style="font-size:85%;">Includes and Defines:</span></p> <p class="MsoNormal"><span style="font-size:85%;"><o:p> </o:p></span></p> <p class="MsoNormal"><span style="font-size:85%;">#include "C:\Source Code\PIC\LED_Blinker\main.h"</span></p> <p class="MsoNormal"><span style="font-size:85%;">This line includes into the source, the ‘main.h’ file. This file initializes the PIC’s registers, ad oscillator speed, etc.</span></p> <p class="MsoNormal"><span style="font-size:85%;"><o:p> </o:p></span></p> <p class="MsoNormal"><span style="font-size:85%;">#define USB_HID_DEVICE<span style=""> </span>TRUE</span></p> <p class="MsoNormal"><span style="font-size:85%;">#define USB_EP1_TX_ENABLE<span style=""> </span>USB_ENABLE_INTERRUPT </span></p> <p class="MsoNormal"><span style="font-size:85%;">#define USB_EP1_TX_SIZE<span style=""> </span>1 </span></p> <p class="MsoNormal"><span style="font-size:85%;">#define USB_EP1_RX_ENABLE<span style=""> </span>USB_ENABLE_INTERRUPT</span></p> <p class="MsoNormal"><span style="font-size:85%;">#define USB_EP1_RX_SIZE<span style=""> </span>64</span></p> <p class="MsoNormal"><span style="font-size:85%;">These lines define the type of USB device we are using and informing the compiler to treat it accordingly. We are defining our device to be a HID Class device. HID or Human Interface Device, is a class of USB devices which are generally used for Human Interaction (Example : Mouse, Keyboard, Front Panels etc.). However, we are using this class of devices, because they don’t require any special drivers, or any special files to be used. Windows natively support for these types of devices. We specify in the lines above the size of the Rx (Receive) Buffer, and Tx (Transmit) Buffer. The maximum being 64 Byte.</span></p> <p class="MsoNormal"><span style="font-size:85%;"><o:p> </o:p></span></p> <p class="MsoNormal"><span style="font-size:85%;">#include <pic18_usb.h></pic18_usb.h></span></p> <p class="MsoNormal"><span style="font-size:85%;">#include <usb_desc_hid.h></usb_desc_hid.h></span></p> <p class="MsoNormal"><span style="font-size:85%;">#include <usb.c> </usb.c></span></p> <p class="MsoNormal"><span style="font-size:85%;">These are the header files which are absolutely required by the compiler for USB. The first file “pic18_usb.h” contains the functions and register definitions specifically for the 18F4550, and its smaller counterpart 18F2550. The second file “usb_desc_hid.h” contains the USB Descriptors, It tell the operating system, what the name of the device is, what all end points it uses, etc. The third file “USB.C” contains the definitions of the functions declared automatically by the compiler.</span></p> <p class="MsoNormal"><span style="font-size:85%;"><o:p> </o:p></span></p> <p class="MsoNormal"><span style="font-size:85%;">#define LED0 PIN_A0</span></p> <p class="MsoNormal"><span style="font-size:85%;">#define LED1 PIN_A1</span></p> <p class="MsoNormal"><span style="font-size:85%;">These defines are, so that we can remember which pins our LED’s are connected to.</span></p> <p class="MsoNormal"><span style="font-size:85%;"><o:p> </o:p></span></p> <p class="MsoNormal"><span style="font-size:85%;">void processIO()</span></p> <p class="MsoNormal"><span style="font-size:85%;">{</span></p> <p class="MsoNormal"><span style="font-size:85%;"><span style=""> </span>int8 i;</span></p> <p class="MsoNormal"><span style="font-size:85%;"><span style=""> </span>output_toggle(LED0);</span></p> <p class="MsoNormal"><span style="font-size:85%;"><span style=""> </span>output_toggle(LED1);</span></p> <p class="MsoNormal"><span style="font-size:85%;"><span style=""> </span>for(i = 0;i<64;i++)</span></p> <p class="MsoNormal"><span style="font-size:85%;"><span style=""> </span>{</span></p> <p class="MsoNormal"><span style="font-size:85%;"><span style=""> </span>output_b(data[0]);</span></p> <p class="MsoNormal"><span style="font-size:85%;"><span style=""> </span>output_d(0x02);</span></p> <p class="MsoNormal"><span style="font-size:85%;"><span style=""> </span>output_d(0x00);</span></p> <p class="MsoNormal"><span style="font-size:85%;"><span style=""> </span>}</span></p> <p class="MsoNormal"><span style="font-size:85%;">}</span></p> <p class="MsoNormal"><span style="font-size:85%;"><o:p> </o:p></span></p> <p class="MsoNormal"><span style="font-size:85%;">This function is constantly called by the ‘while(1)’ loop in the “void main(void)”. It is called after a ‘usb_kbhit()’ returns true. ‘usb_kbhit()’ return true only is the host has sent some data to the peripheral. The first thing ‘processIO()’ does, is toggles the LED’s On or Off. Then it<span style=""> </span>sends the 64 bytes of data to PortB, and pulses on PortD.2.</span></p> <p class="MsoNormal"><span style="font-size:85%;"><o:p> </o:p></span></p> <p class="MsoNormal"><span style="font-size:85%;">That pretty much sums up the PIC Firmware.</span></p> <p class="MsoNormal"><span style="font-size:85%;"><o:p> </o:p></span></p> <p class="MsoNormal"><span style="font-size:85%;">Before we continue on to the program running on the host, we need to learn a few things about the Human Interface Devices (HID) Profile of USB peripherals. The HID Profile is used for devices which, as the name suggests, are used to interact with human beings. These may include keyboards, mice, front panels, displays of various kinds, maybe printers. The main advantage of using it (at least in our case) is that, Microsoft Windows versions later then Windows 98SE, contain a pre included generic driver for HID devices. I mean, it would be quite silly if you can’t use your keyboard or mouse, or monitor until you install a driver!! For our purpose this means, we don’t have to write any “Kernel Mode” drivers or have to deal with any low level device initialization code. Windows come with several HID handling DLLs (Dynamic Link Libraries, these are just like Header files in ‘C/C++’, except, unlike header files, they are already compiled), we will be using the most basic one called ‘HID.DLL’, and the wrapper around it, namely ‘HIDLibray.dll’</span></p><p class="MsoNormal"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjSbI1lEbWb2vx48vdbuHvUGphDDE-JiKe2Ny4Il3PyawAk-isTa8dve8ZJLr79m_f4OvyySkHGZKDk-uruxawnBzZvrKDwjGjZx97PlfKTRg56e34Ws5eOytabr6PZODvZ9YloJ8Ejhuho/s1600-h/screen1.bmp"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjSbI1lEbWb2vx48vdbuHvUGphDDE-JiKe2Ny4Il3PyawAk-isTa8dve8ZJLr79m_f4OvyySkHGZKDk-uruxawnBzZvrKDwjGjZx97PlfKTRg56e34Ws5eOytabr6PZODvZ9YloJ8Ejhuho/s400/screen1.bmp" alt="" id="BLOGGER_PHOTO_ID_5172379918343742290" border="0" /></a><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEitwqjaCfbUKfGwA7_uHChn2QEW4hWg_qQ8NUACRTSB1Enwn1JkEu8x4urdaRPS_n5wR2KMYwz6jBjOIruZE8my_5KGMJXgilpP9z3i0wci1AAEY5x_1NG75xeOznIpFSDJXvMD2KUNrmsB/s1600-h/screen2.bmp"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEitwqjaCfbUKfGwA7_uHChn2QEW4hWg_qQ8NUACRTSB1Enwn1JkEu8x4urdaRPS_n5wR2KMYwz6jBjOIruZE8my_5KGMJXgilpP9z3i0wci1AAEY5x_1NG75xeOznIpFSDJXvMD2KUNrmsB/s400/screen2.bmp" alt="" id="BLOGGER_PHOTO_ID_5172379922638709602" border="0" /></a></p><p style="text-align: center;" class="MsoNormal"> <span style="font-size:78%;">On plugging in your new USB Hardware, you should see a message as above. You can double check on your hardware, from "Device Manager", in the control panel.</span><br /></p> <p class="MsoNormal"><span style="font-size:85%;"><o:p> </o:p></span></p> <p class="MsoNormal"><span style="font-size:85%;">The host program was created by me using Microsoft Visual C# 2008 Express Edition. This is the free version of Microsoft’s latest C# tool, and can be downloaded for free from the Visual Studio 2008 Express Editions website.</span></p> <p class="MsoNormal"><span style="font-size:85%;"><o:p> </o:p></span></p> <p class="MsoNormal"><span style="font-size:85%;">Lets see what the Host code contains:</span></p> <span style="font-size:85%;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhm6Vi3AO34SMn0ND9u-BLKo9bCj5g73537GgZs6F8QOL9lNklBbW7QOko-U3wkzp2dLdL3tHE2pYcnGHK157JVm5JYJvAfhhBEr4DmM9847QOUu1RwtRCHKkT3_dwMsiXswPJU1k4t3tdR/s1600-h/Screen0.bmp"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhm6Vi3AO34SMn0ND9u-BLKo9bCj5g73537GgZs6F8QOL9lNklBbW7QOko-U3wkzp2dLdL3tHE2pYcnGHK157JVm5JYJvAfhhBEr4DmM9847QOUu1RwtRCHKkT3_dwMsiXswPJU1k4t3tdR/s400/Screen0.bmp" alt="" id="BLOGGER_PHOTO_ID_5172376224671867634" border="0" /></a><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQTEo42xLHhNhQkzHS48YyhEAO6zm2IoHzcRZyA5Z4wXbYFWIuK1sji_yG4Ejpb4wpLb4uucvlgHJcEA_sRDf2MXc5-UKaWHlDcOx6q-TDIQcwO0eRRjt75OEJPRnWb5lHu1P7OPxJ12nN/s1600-h/Screen0-1.bmp"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQTEo42xLHhNhQkzHS48YyhEAO6zm2IoHzcRZyA5Z4wXbYFWIuK1sji_yG4Ejpb4wpLb4uucvlgHJcEA_sRDf2MXc5-UKaWHlDcOx6q-TDIQcwO0eRRjt75OEJPRnWb5lHu1P7OPxJ12nN/s400/Screen0-1.bmp" alt="" id="BLOGGER_PHOTO_ID_5172376228966834946" border="0" /></a><br /></span> <p class="MsoNormal"><span style="font-size:85%;">As I mentioned above, the ‘HIDLibrary.dll’ file is used to act as a wrapper between your source code and the ‘HID.dll’ file from your operating system. So, we include this file in the list of references required for this project. When you include the DLL file, you can see the ‘HIDLibrary’ namespace in your class view, under Project References. So when we start writing our USB_class class, we first need to include the line:<br /><o:p> </o:p></span></p> <p class="MsoNormal" style=""><span style="font-family:";font-size:85%;color:blue;">using</span><span style=";font-family:";font-size:85%;" > HIDLibrary;<o:p></o:p></span></p> <p class="MsoNormal"><span style="font-size:85%;"><o:p> </o:p></span></p> <p class="MsoNormal"><span style="font-size:85%;">After this line has been included, we now have access to the classes inside the DLL. This is similar to a header file in C/C++. So now that we have access to the classes inside the dll, we are ready to do some serious USB I/O!!! Let’s see how our class ‘USB_class’ is turning out:</span></p> <p class="MsoNormal" style=""><span style="font-size:85%;"><span style=";font-family:";font-size:10;color:blue;" ><o:p> </o:p></span></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;color:blue;" >class</span><span style=";font-family:";font-size:85%;" > <span style="color: rgb(43, 145, 175);">USB_Class<o:p></o:p></span></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span>{<o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span><span style="color: rgb(43, 145, 175);">HidDevice</span>[] deviceList;<o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span><span style="color: rgb(43, 145, 175);">HidDevice</span> myDevice;<o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span><span style="color:blue;">int</span> vid = 0x0461; <span style="color:green;">//Change as per need<o:p></o:p></span></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span><span style="color:blue;">int</span> pid = 0x0020; <span style="color:green;">//Change as per need<o:p></o:p></span></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span><span style="color:blue;">public</span> <span style="color:blue;">bool</span> initialize()<o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span>{<o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span>deviceList = <span style="color: rgb(43, 145, 175);">HidDevices</span>.Enumerate(vid, pid);<o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span><span style="color:blue;">if</span> (deviceList.Length > 0)<o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span>{<o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span>myDevice = deviceList[0];<o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span><span style="color:blue;">return</span> myDevice.IsConnected;<o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span>}<o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span><span style="color:blue;">else<o:p></o:p></span></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span>{<o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span><span style="color:blue;">return</span> <span style="color:blue;">false</span>;<o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span>}<o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span>}<o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span><span style="color:blue;">public</span> <span style="color:blue;">bool</span> refresh()<o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span>{<o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span><span style="color:blue;">return</span> myDevice.IsConnected;<o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span><span style=""> </span>}<o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span><span style="color:blue;">public</span> <span style="color:blue;">void</span> send_n_toggle(<span style="color:blue;">string</span> str)<o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span>{<o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span><span style="color:blue;">byte</span>[] data = {<o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span>0x00,<o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span><span style="color:blue;">byte</span>.Parse(str)<o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span>};<o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span>myDevice.Write(data);<span style=""> </span><o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span><span style=""> </span>}<o:p></o:p></span></p> <p class="MsoNormal"><span style=";font-family:";font-size:85%;" ><span style=""> </span>}<o:p></o:p></span></p> <p class="MsoNormal"><span style="font-size:85%;"><o:p> </o:p></span></p> <p class="MsoNormal"><span style="font-size:85%;">Not so bad, huh? Let’s discuss this line by line. We will start with:</span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><o:p> </o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span><span style="color: rgb(43, 145, 175);">HidDevice</span>[] deviceList;<o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span><span style="color: rgb(43, 145, 175);">HidDevice</span> myDevice;<o:p></o:p></span></p> <p class="MsoNormal"><span style="font-size:85%;"><o:p> </o:p></span></p> <p class="MsoNormal"><span style="font-size:85%;">If you haven’t already figured this one out, ‘HidDevice’ is one of the classes in the HIDLibrary namespace, that we declared earlier. The first identifier that we declared is called ‘deviceList’. This as the code suggests is an array of HidDevice type, you might be asking now, ‘Why an array?’ well the answer is quite simple, Each USB device is uniquely identified to your PC with a combination of a Vendor ID and a Product ID. I guess the USB-IF figured, if each vendor has a unique Vendor ID, and if each vendor used a unique Product ID, for each product, then these two can be used to identify the device on the PC. If you still haven’t figured out the reason for having an Array, well allow me to spell it out to you. USB as an architecture allows multiple devices to be connected to a single host, using a hub. Now, these could be two or more of the same device right? So, how do we decide which one is which? We put it in an array, in first-come-first-serve basis. This concept if not quite clear will become apparent, a few lines later. The second identifier, which is once again of the type ‘HidDevice’, called ‘myDevice’, is the one we will be working more closely with. Let us proceed, to the next two lines of code.</span></p> <p class="MsoNormal"><span style="font-size:85%;"><o:p> </o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span><span style="color:blue;">int</span> vid = 0x0461; <span style="color:green;">//Change as per need<o:p></o:p></span></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span><span style="color:blue;">int</span> pid = 0x0020; <span style="color:green;">//Change as per need<o:p></o:p></span></span></p> <p class="MsoNormal"><span style="font-size:85%;"><o:p> </o:p></span></p> <p class="MsoNormal"><span style="font-size:85%;">Ok, this is overkill. ‘vid’ has got to be the Vendor ID, and ‘pid’ has got to be the Product ID. Right? Very much so. </span></p> <p class="MsoNormal"><span style="font-size:85%;">These lines however do tell us three fairly interesting things, 1) both Vid and Pid are 16-bit long. 2) they are normally represented in Hexadecimal format, and 3) the Vid for our device is 0x0461, and the Pid is 0x0020.</span></p> <p class="MsoNormal"><span style="font-size:85%;">(My sincere apologies to Primax Electronics Ltd, for using their Vid. I solemnly swear that I won’t be using it for any commercial activities. No offence to Primax, but the reason I used their Vid, is because I have never heard of them before, and I doubt I will find myself using any product of theirs, so I don’t think any question of conflicting Vid or Pid would arise. Besides, Primax has no products registered under the Pid 0x0020).</span></p> <p class="MsoNormal"><span style="font-size:85%;"><o:p> </o:p></span></p> <p class="MsoNormal"><span style="font-size:85%;">Let’s move on.</span></p> <p class="MsoNormal"><span style="font-size:85%;"><o:p> </o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span><span style="color:blue;">public</span> <span style="color:blue;">bool</span> initialize()<o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span><span style=""> </span>{<o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span>deviceList = <span style="color: rgb(43, 145, 175);">HidDevices</span>.Enumerate(vid, pid);<o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span><span style="color:blue;">if</span> (deviceList.Length > 0)<o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span>{<o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span>myDevice = deviceList[0];<o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span><span style="color:blue;">return</span> myDevice.IsConnected;<o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span>}<o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span><span style="color:blue;">else<o:p></o:p></span></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span>{<o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span><span style=""> </span><span style="color:blue;">return</span> <span style="color:blue;">false</span>;<o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span>}<o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span>}<o:p></o:p></span></p> <p class="MsoNormal"><span style="font-size:85%;">Aah, finally a function, something of substance. This function ‘initialize()’ needs to be called whenever you need the Host program to recognize your device. The first line:</span></p> <p class="MsoNormal"><span style="font-size:85%;"><o:p> </o:p></span></p> <p class="MsoNormal"><span style=";font-family:";font-size:85%;" >deviceList = <span style="color: rgb(43, 145, 175);">HidDevices</span>.Enumerate(vid, pid);<o:p></o:p></span></p> <p class="MsoNormal"><span style="font-size:85%;"><o:p> </o:p></span></p> <p class="MsoNormal"><span style="font-size:85%;">Enumerates all devices with the Vid and Pid, that we declared before. ‘deviceList’,<span style=""> </span>the array of<span style=""> </span>‘HidDevice’ type contains the list. Checks</span></p> <p class="MsoNormal"><span style="font-size:85%;"><o:p> </o:p></span></p> <p class="MsoNormal" style="margin-left: 0.5in; text-indent: 0.5in;"><span style=";font-family:";font-size:85%;color:blue;" >if</span><span style=";font-family:";font-size:85%;" > (deviceList.Length > 0)<o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span>{<o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span>myDevice = deviceList[0];<o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span><span style="color:blue;">return</span> myDevice.IsConnected;<o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span>}<o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span><span style="color:blue;">else<o:p></o:p></span></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span>{<o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span><span style="color:blue;">return</span> <span style="color:blue;">false</span>;<o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span>}<o:p></o:p></span></p> <p class="MsoNormal"><span style="font-size:85%;"><span style=";font-family:";font-size:10;" ><o:p> </o:p></span></span></p> <p class="MsoNormal"><span style="font-size:85%;">Checks if there is at least one device connected, and ‘myDevice’ is assigned the first device. </span></p> <p class="MsoNormal"><span style="font-size:85%;"><o:p> </o:p></span></p> <p class="MsoNormal"><span style="font-size:85%;"><o:p> </o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span><span style="color:blue;">public</span> <span style="color:blue;">void</span> send_n_toggle(<span style="color:blue;">string</span> str)<o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span>{<o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span><span style="color:blue;">byte</span>[] data = {<o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span>0x00,<o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span><span style="color:blue;">byte</span>.Parse(str)<o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span>};<o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span>myDevice.Write(data);<span style=""> </span><o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><span style=""> </span>}<o:p></o:p></span></p> <p class="MsoNormal" style=""><span style=";font-family:";font-size:85%;" ><o:p> </o:p></span></p> <p class="MsoNormal"><span style="font-size:85%;">This is the function which sends the data to the USB peripheral. The function accepts some string, it declares a byte array (called ‘data’), it then uses the ‘write()’ method of the ‘HidDevice’ class to send the data to the USB peripheral. The data array contains 2 bytes. The first is 0x00, and the second byte is the data we want to send to the microcontroller over USB. The first byte, 0x00 is the report descriptor, an must always be 0x00.</span></p> <p class="MsoNormal"><span style="font-size:85%;"><o:p> </o:p></span></p> <p class="MsoNormal"><span style="font-size:85%;">That concludes the host software. I recommend that you play around with both the firmware and the software to get a better understanding of how you can tailor the software and firmware to your need.</span></p> <p class="MsoNormal"><span style="font-size:85%;"><o:p> </o:p></span></p> <p class="MsoNormal"><span style="font-size:85%;">Now that we have built the prototype blinky on a bread board, and successfully tested it. Its time for us to build our own Printed Circuit Board, these are more stable as compared to a bread board.</span></p> <p class="MsoNormal"><span style="font-size:85%;">I made the following artwork in Eagle, the original Eagle files are included in the ZIP file included with this tutorial. I won’t go into DIY methods pf manufacturing PCB’s here, there are several methods to make them at home, but there are plenty of good tutorials on the internet, and I’m sure they will be more helpful then anything I may write here.</span></p> <span style="font-size:85%;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-M2n1Mlx9dKY-YNNdgaUxy9B4LNxLplby3U5jPuPkaF6mEqCdziZClKkq5OF7BHbA7e4gWb0FgnMa7VcLCyINRSAqBG1NLMPYbZOgvF5IMifc07ipoGpifM16ytuB3qggGvDAnHrLSP2g/s1600-h/Layout.JPG"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-M2n1Mlx9dKY-YNNdgaUxy9B4LNxLplby3U5jPuPkaF6mEqCdziZClKkq5OF7BHbA7e4gWb0FgnMa7VcLCyINRSAqBG1NLMPYbZOgvF5IMifc07ipoGpifM16ytuB3qggGvDAnHrLSP2g/s400/Layout.JPG" alt="" id="BLOGGER_PHOTO_ID_5172378402220286738" border="0" /></a><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhBwKpc9FWlZtdEYNLXs_25wDjxN-PF1pJ9fm7HQsg3d0OnrHbryKyfgmbTKBPZM5IG1_HeRQArlBup6QtSvL4u2z9rw9tDvS0ix6PEAAVpwKqTraRlGrYvGaoX5wSd61HvuZK85fJb_9AI/s1600-h/Photo_022308_003.jpg"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhBwKpc9FWlZtdEYNLXs_25wDjxN-PF1pJ9fm7HQsg3d0OnrHbryKyfgmbTKBPZM5IG1_HeRQArlBup6QtSvL4u2z9rw9tDvS0ix6PEAAVpwKqTraRlGrYvGaoX5wSd61HvuZK85fJb_9AI/s400/Photo_022308_003.jpg" alt="" id="BLOGGER_PHOTO_ID_5172378406515254050" border="0" /></a><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1VKVTSl9Csv6pCUIluNfvHA_6-Q2aU87ZgdytXd1idFf4JcJlGMOLJh-GAs6rc4IxnZrav2ZGv0quMG0JFVmTB7OWPdTtaN1qGUEV4RldwSAKTOlM9lqGbNg1jeEE6ZueuUw7cvuAWQrx/s1600-h/Photo_022308_004.jpg"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1VKVTSl9Csv6pCUIluNfvHA_6-Q2aU87ZgdytXd1idFf4JcJlGMOLJh-GAs6rc4IxnZrav2ZGv0quMG0JFVmTB7OWPdTtaN1qGUEV4RldwSAKTOlM9lqGbNg1jeEE6ZueuUw7cvuAWQrx/s400/Photo_022308_004.jpg" alt="" id="BLOGGER_PHOTO_ID_5172378410810221362" border="0" /></a><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQzK3T1ug2l0jGbpHZJDys55JA_Hcwq6JMHffB6DS2WPIOdRFNHqV7Rg_5At-QBwl1Uh5Hf4l71Fwn7qNCUL3p4qxpfIhp199Um7IvoRK39M9VVAyYzn4Ekos3GJJu9sv3vnikWUC9WlHG/s1600-h/Photo_022308_005.jpg"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQzK3T1ug2l0jGbpHZJDys55JA_Hcwq6JMHffB6DS2WPIOdRFNHqV7Rg_5At-QBwl1Uh5Hf4l71Fwn7qNCUL3p4qxpfIhp199Um7IvoRK39M9VVAyYzn4Ekos3GJJu9sv3vnikWUC9WlHG/s400/Photo_022308_005.jpg" alt="" id="BLOGGER_PHOTO_ID_5172378415105188674" border="0" /></a><br /></span><div style="text-align: center;"><iframe allowfullscreen='allowfullscreen' webkitallowfullscreen='webkitallowfullscreen' mozallowfullscreen='mozallowfullscreen' width='320' height='266' src='https://www.blogger.com/video.g?token=AD6v5dxEjs8clH95_CGA5ukDzOB55h2huGX_dt-fiiJe2R2rBS0Ip4v_8565NjZDvkHwD3Y3WufPN4US-_Mhc-OLog' class='b-hbp-video b-uploaded' frameborder='0'></iframe><br /><br /><div style="text-align: left;"><span style="font-size:100%;">You can download the ZIP package which is accompanying this tutorial from: </span><a href="http://rapidshare.com/files/95880770/USB_18f.zip.html" target="_blank">http://rapidshare.com/files/95880770/USB_18f.zip.html</a><br /></div><div style="text-align: left;">the file USB_18f.zip contains:<br /></div><ol style="text-align: left;"><li>PDF format of this tutorial</li><li>The USB descriptor header file for the accompanying C Source for the PIC</li><li>The PIC18F4550's firmware HEX file</li><li>The PIC18F4550's Firmware Source</li><li>The C# Host Code</li><li>The 'HIDLibrary.dll' DLL file</li></ol><br /> </div><p class="MsoNormal"><span style="font-size:85%;">How did you find this tutorial? Let me know how I can improve it. You can leave messages for me here</span></p>Devesh Raihttp://www.blogger.com/profile/04196213231447707146noreply@blogger.com15tag:blogger.com,1999:blog-5750449707682687736.post-83699219764619505602008-02-27T19:46:00.000+05:302008-02-27T19:58:44.094+05:30Welcome!!Hi! Welcome to my blog. The main reason I'm writing this very first entry is so that I get the hang of this thing. It feels nice to have an outlet to write and publish my ideas. I feel I will be having a lot of fun in the days to come, and a lot of it will be around here. If you want to know more about me, you can read my tiny self introduction in my profile.<br/><br/>If you are visiting my blog for the first time, and are seeing just this post, <br/>then I suppose you have come too early for the action. If you check back in a few hours you may find some good stuff.<br/><br/>The main articles I will be posting here will be regarding my technical forays, my everlasting quest to learn about the latest technologies, and my projects and experiments <br/>that I want to share with the world.<br/> <br/><br/>-<span class="blsp-spelling-error" id="SPELLING_ERROR_0">Devesh</span> (aka <span class="blsp-spelling-error" id="SPELLING_ERROR_1">Debu</span>)<br/>Devesh Raihttp://www.blogger.com/profile/04196213231447707146noreply@blogger.com0