cover1.qxp 3/2/2007 11:47 AM Page 1 #201 April 2007 CIRCUIT w w w . c i r c u i t c ® e CELLAR l l a r . c o m THE MAGAZINE FOR COMPUTER APPLICATIONS EMBEDDED PROGRAMMING MCU-Based Keyboard Interface Reverse-Engineered ECP Bus Create a Modbus Master Embedded RF Communication 04> 7 25274 75349 9 $4.95 U.S. ($5.95 Canada) C2.qxp 3/6/2007 1:38 PM Page 1 1.qxp 3/2/2007 11:51 AM Page 1 M C Y C Y M 5 9 5 7 0 5 5 Real 2 5 K Mixed-Signal 5 9 5 7 Programmability. 0 5 5 2 5 Y Get PSoC®. Because change happens. GET STARTED WITH PSoC NOW. PSoC flexibility enables changes anytime: at concept, through Download our “Change Happens” White Paper production, in the field. Specifications change constantly. Yet 5 and get 50% off a PSoC development kit: 9 pressures to differentiate, minimize costs, and speed time-to-market www.cypress.com/changepaper 5 7 remain the same. To stay ahead of the curve, you need flexibility, Download free PSoC Express™ visual embedded 0 programmability, and scalability. PSoC’s unique programmable software: www.cypress.com/changesoft 5 architecture delivers this and more. Futureproof your design; make 5 Request free PSoC device samples: 2 PSoC your agent of change. www.cypress.com/changechip 5 Free online training: PSoC delivers: www.cypress.com/changetrain M The configurability of an FPGA, the mixed-signal integration Purchase PSoC development tools: 95 of an ASIC, and the familiarity of an MCU. www.cypress.com/changetools 5 7 Reusable IP, compatible device families and variable 0 resource options ensure you can optimize design efforts 5 and accommodate changes. 5 2 5 The industry’s first visual embedded design tool, PSoC Express™, speeds design time, enabling you to generate a complete C design without writing a single line of code. PSoC includes programmable analog and digital blocks, a fast MCU, flash and SRAM memory, all in a compact package (as small as 3mm x 3mm). © 2007 Cypress Semiconductor Corporation. All rights reserved. PSoC is a registered trademark and PSoC Express is a trademark of Cypress Semiconductor Corporation. All other trademarks are properties of their respective owners. 2.qxp 2/2/2007 3:11 PM Page 1 Link Instruments PC-Based Test Equipment Digital Oscilloscopes • 2 Channel Digital Oscilloscope W ! N E (cid:129)500 MSa/s max single shot rate (cid:129) 1Mpt sample memory 250 MSa/S (Dual channel) 512 Kpts 500 MSa/S (Single channel) 1 Mpts (cid:129) Advanced Triggering (cid:129) Only 9 oz and 7” x 3.5” x 1.5” (cid:129) Portable and Battery powered (cid:129) USB 2.0 (cid:129) Advanced Math (cid:129) FFT Spectrum Analyzer (cid:129) $950 (DSO, Probes, Software & power supply) 5 0 0 M S a / s 1 M p t s Logic Analyzers (cid:129)40 to 160 channels (cid:129)up to 500 MSa/s (cid:129)Variable Threshold (cid:129)8 External Clocks (cid:129)16 Level Triggering (cid:129)up to 512K samples/ch (cid:129)USB 2.0 and Parallel Interface (cid:129)Pattern Generator option LA5240 (200MHz, 40CH) $1700 LA5280 (200MHz, 80CH) $2350 LA5540 (500MHz, 40CH) $2500 LA5580 (500MHz, 80CH) $3500 LA55160 (500MHz, 160CH) $7500 Link Instruments (973) 808-8990 17A Daniel Road East · Fairfield, NJ 07004 · Fax (973) 808-8786 www.Linkins4.com 3.qxp 3/2/2007 11:56 AM Page 1 For The Premium Application that took years to develop and must be instantly read under all lighting, temperature, and viewing angle conditions: 256 x 128 format now available in three sizes (cid:2) (cid:2) Multiple Built-in Windows Multiple Interfaces (cid:2) (cid:2) Many International Fonts Highest Brightness (cid:2) (cid:2) Font Magnification Extended Temperature Range (cid:2) (cid:2) Large Memory Widest Viewing Angles (cid:2) (cid:2) High Density Pixels Choose From 11 Models www.noritake-elec.com/52 Over 300 standard VFD modules available 201_Task_Masthead.qxp 3/6/2007 9:30 AM Page 4 TASK MANAGER The Cruelest Month? FOUNDER/EDITORIAL DIRECTOR CHIEF FINANCIAL OFFICER E Steve Ciarcia Jeannette Ciarcia ven if you spent your college years working with circuit boards and MANAGING EDITOR MEDIA CONSULTANT writing code, you’re probably familiar with the famous first sentence of C.J.Abate Dan Rodrigues the poet T.S.Eliot’s modernist masterpiece, The Waste Land(1922): WEST COAST EDITOR CUSTOMER SERVICE Tom Cantrell Debbie Lavoie “April is the cruelest month—” CONTRIBUTING EDITORS CONTROLLER You may have heard a few exhausted bookkeepers and accountants Jeff Bachiochi Jeff Yanco Ingo Cyliax mumble that line a few times too.Tax season, right? ART DIRECTOR Fred Eady Well, we here at Circuit Cellarhave a different take on April.It’s a George Martin KC Prescott great month.Not only are we now past the days of sleet, snow, and Ed Nisley GRAPHIC DESIGNER Mary (Turek) Sobuta dark commutes to and from the office, we have a lot of exciting things NEWPRODUCTSEDITOR on our plate—which is your plate too, of course. John Gorsky STAFF ENGINEER John Gorsky This month we’re off to the Embedded Systems Conference in San PROJECT EDITORS Steve Bedford Jose, where we plan to spend the entire week talking everything Ken Davidson embedded with our readers and advertisers.Look for our booth.We David Tweed hope to see you there! ASSOCIATE EDITOR The Microchip 16-Bit Embedded Control Design Contest also kicks Jesse Smolin off this month.As you know, we’ve brought you a lot of amazing con- tests over the years.This one is sure to create a lot of buzz in the design ADVERTISING community.With a handful of amazing eligible parts to choose from, this 860.875.2199 • Fax:860.871.0411 (cid:129) www.circuitcellar.com/advertise contest is going to get competitive quick.Ready to hit the workbench? PUBLISHER On the editorial front, we’re excited about the articles in this issue. Sean Donnelly On page 12, we begin with an article about Steven Savage’s award-win- Direct:860.872.3064, Cell:860.930.4326, E-mail:[email protected] ning ATir keyboard interface design.This project won him First Prize in ADVERTISINGREPRESENTATIVE the Atmel AVR Design Contest 2006.If you’re preparing a project for the Shannon Barraclough Direct:860.872.3064, E-mail:[email protected] new Microchip contest, be sure to check out this article.Steven shows ADVERTISINGCOORDINATOR what it takes to put together a winning project. Valerie Luster Another project-inspiring design is Tom Kibalo’s Java-based 1-Wire E-mail:[email protected] distributed watering system (p.20).Tom used his hardware and soft- ware skills to build a handy system to water plants in six EarthBoxes. Cover photography by Chris Rakoczy—Rakoczy Photography Even if gardening isn’t your thing, you can use the principles he covers www.rakoczyphoto.com to design and program a multiple-module system for other purposes. PRINTED IN THE UNITED STATES At the end of his article about the watering system, Tom writes that CONTACTS he plans to use ZigBee technology to extend the system’s range SUBSCRIPTIONS beyond its 1-Wire limitations.Well, you don’t need to wait until Tom Information:www.circuitcellar.com/subscribe, E-mail:[email protected] Subscribe:800.269.6301, www.circuitcellar.com/subscribe, Circuit Cellar Subscriptions, P.O.Box 5650, upgrades his system and writes another article.Why not take Fred Hanover, NH 03755-5650 Address Changes/Problems:E-mail:[email protected] Eady’s advice and implement the technology in a system of your own? GENERAL INFORMATION In“Uncomplicated RF Communication”(p.45), Fred shows you how to 860.875.2199, Fax:860.871.0411, E-mail:[email protected] EditorialOffice:Editor, Circuit Cellar, 4 Park St., Vernon, CT 06066, E-mail:[email protected] get your system on the air. NewProducts:New Products, Circuit Cellar, 4 Park St., Vernon, CT 06066, E-mail:[email protected] On page 28, Gordon Dick describes how he designed and built a three- AUTHORIZED REPRINTSINFORMATION 860.875.2199, E-mail:[email protected] axis CNC mill machine.The easy-to-move machine is a great project for AUTHORS Authors’e-mail addresses (when available) are included at the end of each article. anyone who loves design and woodworking.It features an old laptop, an intelligent motion controller, and an old X-ray machine. CIRCUIT CELLAR®, THE MAGAZINE FOR COMPUTER APPLICATIONS (ISSN 1528-0608) is published monthly by Circuit Cellar Have you tried Visual Basic 2005 yet? As you know, Aubrey has been Incorporated, 4 Park Street, Vernon, CT 06066.Periodical rates paid at Vernon, CT and additional offices.One-year (12 issues) putting it to use for some time now.This month, he finishes up his series subscription rate USA and possessions $23.95,Canada/Mexico $34.95,all other countries $49.95.Two-year (24 issues) sub- scription rate USA and possessions $43.95,Canada/Mexico $59.95,all other countries $85.All subscription orders payable in about a generic Modbus simulator (p.60).To put you on the right track, U.S.funds only via Visa, MasterCard, international postal money order, or check drawn on U.S.bank.Direct subscription orders and subscription-related questions to Circuit Cellar Subscriptions,P.O.Box 5650,Hanover,NH 03755-5650 or call he explains how he created the generic interface to gain access to any 800.269.6301. Modbus slave via an Excel workbook.As Aubrey explains, the application Postmaster:Send address changes to Circuit Cellar, Circulation Dept., P.O.Box 5650, Hanover, NH 03755-5650. simply pulls the information from Excel, presents it on the UI, formats it, Circuit Cellar® makes no warranties and assumes no responsibility or liability of any kind for errors in these programs or schematics or for the and sends and receives Modbus messages. ceor-nassesqeumebnlceeds p orof jaencyts s, uCcihrc ueirtr oCres.llaFru®rt hdeisrcmlaoimres, baencya ruessep oonf spiobsilistyib lfeo rv tahreia stiaofne iann tdh ep rqoupaelirt yfu anncdti ocno nodf irtieoand oefr -masasteermiablsle adn pdr owjeocrktsm baanssehdip u opfo rne aodr- from plans, descriptions, or information published by Circuit Cellar®. With projects like these to keep you occupied, it’s going to be a pro- The information provided by Circuit Cellar® is for educational purposes.Circuit Cellar® makes no claims or warrants that readers have a right to ductive month. bcounilds trthuicntg osr boapseerda teu paonny tohfe tshee i ddeeavsic eusn ddeers pcraibteendt hoer roetihne ur nredleerv athnet irnetleelvleacnttu paal tpernotp oerr toyt hlaewr iinnt ethlleeicrt ujuarli spdriocptieornt,y olar wth aotf rtheea dreerasd hear’vse j uar isridgihctt ioton. The reader assumes any risk of infringement liability for constructing or operating such devices. [email protected] Entire contents copyright © 2007 by Circuit Cellar, Incorporated.All rights reserved.Circuit Cellar is a registered trademark of Circuit Cellar, Inc. Reproduction of this publication in whole or in part without written consent from Circuit Cellar Inc.is prohibited. 4 Issue 201 April 2007 CIRCUIT CELLAR® www.circuitcellar.com 5.qxp 3/2/2007 11:54 AM Page 1 ILLUMINATED SOLUTIONS IMPROVE PROJECT TIMELINES Your production efficiency will shine with our brightly illuminated solutions. NKK’s SmartSwitch™ allows you to improve your processes by providing simple solutions to complex procedures. Our series of LCD programmable switches and displays feature high-contrast and wide viewing angles to simplify and accelerate your project timelines. IS Dev Kit-2 Power your designs with NKK. Visit us online to: Get Your FREE 3D CAD Model at: • ORDER Dev Kits to drive your creativity • DOWNLOADsoftware to expedite your design process http://cc.nkksmartswitch.com • PROTOTYPEand test new design ideas cost effectively 201_toc.qxp 3/5/2007 3:53 PM Page 6 April 2007: Embedded Programming FEATURES 12 ATir Keyboard Interface 38 Reverse-Engineered ECP Bus Steven Savage Miguel Sanchez First Prize Atmel AVR Design Contest 2006 45 Uncomplicated RF Communication 20 Java-Based EarthBox Watering System Fred Eady Tom Kibalo 60 Generic Modbus Simulator (Part 2) 28 Build a Three-Axis CNC Mill Machine Create a Modbus Master Using Visual Basic 2005 Gordon Dick Aubrey Kagan ATtiny45-Based Keyboard Electronic Watering System (p.20) Computer-Controlled Mill Interface (p.12) Machine (p.28) COLUMNS 56 ABOVETHEGROUNDPLANE Battery Capacity Charge USBUnplugged? (p.78) Ed Nisley 70 FROMTHEBENCH Local Interconnect Network Jeff Bachiochi 78 SILICON UPDATE What’s on the LIN Bus? (p.70) USB:(Wire)Less is More Tom Cantrell DEPARTMENTS 4 TASK MANAGER 94 INDEX OF ADVERTISERS The Cruelest Month? May Preview C.J.Abate 96 PRIORITY INTERRUPT 8 NEW PRODUCT NEWS Only Real Events Lead to Real Trends edited by John Gorsky Steve Ciarcia 93 CROSSWORD 6 Issue 201 April 2007 CIRCUIT CELLAR® www.circuitcellar.com 7.qxp 10/4/2006 1:48 PM Page 1 Dream of Darkness, Wasteman! What can AVR picoPower • True 1.8V supply voltage enabling operation of all features and core down to 1.8V do for your design? • Minimized leakage current enabling 100 nA Power Down sleep consumption • Sleeping brown-out detector enabling full protection with no power penalty • Ultra low power 32 kHz crystal oscillator enabling operation at only 650 nA npn.qxp 3/5/2007 3:55 PM Page 8 NEW PRODUCT NEWS Edited by John Gorsky RS08 C COMPILER The C6808 Code Development Systemthat supports Freescale Semiconductor’s advanced 8-bit RS08 microcontroller architecture is now shipping. The C6808 is one of the first C compilers for RS08. It allows easy migration of programs written for Freescale Semiconductor’s HC05 and HC08 to the high-volume 8-bit micro- controller platform. The C6808 supports all HC08, HCS08, and now RS08 parts in its optimizing C compiler and tools. The C6808 Code Development System includes an optimizing C cross-compiler with an inline macro-assembler, support libraries, full program optimization with the BClink optimizing linker, and the BCLIDE. The compiler produces industry-standard executables and code files, including the Byte Craft Limited .COD file format and ELF/DWARF. The .COD file and ELF/DWARF contain every- thing an emulator needs for C-source-level debugging. The C6808 supports ISO TR 18037 named address spaces and fixed-point math. It implements the full C language within the tion than conventional asynchronous program- limits of the hardware: Any potential application can be imple- ming. mented in C with greater ease and optimization than in assembly. The C6808 costs $1,750. Thread support in C complements the RS08 interrupt architecture and threads can model hardware interrupt arbitration in software. Byte Craft Limited They typically allow faster, smaller code and less RAM consump- www.bytecraft.com MODULAR KICKSTART KIT TARGETS R8C,M16C,AND M32C VGA CONTROLLERS FOR EMBEDDED APPLICATIONS The new IAR0018 KickStart kit contains all the necessary The ezVGA Graphics Controllerand ezVGA Serial tools for initial evaluation and prototyping on the Moduleare two new display controllers from Multilabs. R8C/M16C/M32C microcontroller range, giving developers The ezVGA Graphics Controller is an embedded graph- the opportunity to test 8-, 16-, and 32-bit microcontrollers ics controller within the same core family. It also provides the flexibility to that can be change the microcontroller during the course of the evalua- interfaced to tion. Using the same fully featured tools, which will be used any design via when real product development starts, makes it possible to an 8-bit data avoid the delays and errors that can be caused by changing bus and four tools and the development environment after the evaluation addressable proof-of-concept milestone is reached. control lines. The kit includes code-limited versions of the Embedded Through the Workbench for the M16C, the M32C, and the R8C. An applica- ezVGA Graph- tion baseboard fitted with a microcontroller from one of seven ics Controller, available device families such as the R8C, the M16C, or the your embedded M32C is also included. The board is fitted with three serial controller or interfaces: two MAX232s and one TTL along with a USB-to- processor will easily generate color VGA graphics. It serial interface, CAN with a transceiver, user LEDs, a 16 × 2 provides all the circuitry necessary for a host interface, character LCD module with an LED backlight, an LDR and video memory control, and generating color VGA potentiometer connected to the A/D-channel, an encoder graphics with high screen resolution. switch with a push button, a MMC/SD card interface, and The ezVGA Serial Module takes it one step further. other features. With the ezVGA Graphics Controller and an on-board The kit also includes microcontroller, it scales high-resolution color VGA a Renesas Technology graphics down to two serial communication lines and E8-USB debugger, with a handful of graphics and text commands. This makes all the necessary cables the ezVGA Serial Module a ready-to-use serial-con- and documentation. It trolled VGA video card that will deliver VGA func- works for all the rele- tionality to your design. The nine easy-to-learn com- vant microcontrollers mands give any embedded controller or processor the and can be driven from ability to draw high-resolution color, VGA text, and within an IAR Embed- graphics. ded Workbench. The The ezVGA starts at $24.95and the ezVGA Serial IAR0018 costs $495. Module is $64.95. IAR Systems Multilabs www.iar.com www.multilabs.net 8 Issue 201 April 2007 CIRCUIT CELLAR® www.circuitcellar.com