Silicon ChipBuild Your Own MP3 Jukebox; Pt.1 - September 2001 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Publisher's Letter: MP3 format will change our music listening
  4. Subscriptions
  5. Feature: MP3: Changing The Way You Listen To Music by Jim Rowe
  6. Feature: Making MP3s: Rippers & Encoders by Greg Swain
  7. Review: Sony's VAIO Notebook Computer by Ross Tester
  8. Project: Build Your Own MP3 Jukebox; Pt.1 by Peter Smith
  9. Weblink
  10. Project: PC-Controlled Mains Switch by Trent Jackson & Ross Tester
  11. Product Showcase
  12. Project: Personal Noise Source For Tinnitus Sufferers by John Clarke
  13. Project: The Sooper Snooper by Ross Tester
  14. Feature: Using Linux To Share An Internet Connection; Pt.4 by Greg Swain
  15. Order Form
  16. Vintage Radio: The Healing R401E/S401E mantel radio by Rodney Champness
  17. Feature: Writing Articles For Silicon Chip by Leo Simpson
  18. Book Store
  19. Feature: Newsgroups: Common Terms & Abbreviations by Silicon Chip
  20. Back Issues
  21. Notes & Errata
  22. Market Centre
  23. Advertising Index
  24. Outer Back Cover

This is only a preview of the September 2001 issue of Silicon Chip.

You can view 35 of the 104 pages in the full issue, including the advertisments.

For full access, purchase the issue for $10.00 or subscribe for access to the latest issues.

Items relevant to "Build Your Own MP3 Jukebox; Pt.1":
  • Software for the "Build Your Own MP3 Jukebox" articles (Free)
  • AT90S2313 firmware and source code for the PC IR Interface & LCD Display (Software, Free)
  • IR Remote Receiver & LCD Display PCB pattern (PDF download) [07109011] (Free)
Articles in this series:
  • Build Your Own MP3 Jukebox; Pt.1 (September 2001)
  • Build Your Own MP3 Jukebox; Pt.1 (September 2001)
  • Build Your Own MP3 Jukebox; Pt.2 (October 2001)
  • Build Your Own MP3 Jukebox; Pt.2 (October 2001)
  • Computer Tips (January 2002)
  • Computer Tips (January 2002)
  • Computer Tips (April 2002)
  • Computer Tips (April 2002)
Items relevant to "PC-Controlled Mains Switch":
  • Software for the PC-Controlled Mains Switch (Free)
  • PC-Controlled Mains Switch PCB pattern (PDF download) [10109011] (Free)
  • Panel artwork for the PC-Controlled Mains Switch (PDF download) (Free)
Items relevant to "Personal Noise Source For Tinnitus Sufferers":
  • Personal Noise Source PCB pattern (PDF download) [01109011] (Free)
  • Panel artwork for the Personal Noise Source (PDF download) (Free)
Items relevant to "Using Linux To Share An Internet Connection; Pt.4":
  • Linux script files for Internet Connection Sharing (Software, Free)
Articles in this series:
  • Using Linux To Share An Internet Connection; Pt.1 (May 2001)
  • Using Linux To Share An Internet Connection; Pt.1 (May 2001)
  • Using Linux To Share An Internet Connection; Pt.2 (June 2001)
  • Using Linux To Share An Internet Connection; Pt.2 (June 2001)
  • Using Linux To Share An Internet Connection; Pt.3 (August 2001)
  • Using Linux To Share An Internet Connection; Pt.3 (August 2001)
  • Using Linux To Share An Internet Connection; Pt.4 (September 2001)
  • Using Linux To Share An Internet Connection; Pt.4 (September 2001)

Purchase a printed copy of this issue for $10.00.

MP3 Jukebox Build your own Want to impress your friends? Build this neat little project to control your PC’s MP3 player remotely! Alternatively, if you’re interested in adding remote control and/or LCD readout to an existing project, read on! Part 1: By PETER SMITH 24  Silicon Chip www.siliconchip.com.au O VER THE COMING months, we will describe how you can transform your PC into a veritable jukebox, able to play any of your favourite MP3s at the press of a button. And if you’re really serious about your MP3 music, you can even build a standalone PC-based player without a monitor or keyboard. We’ve received so many requests for MP3 projects that we just couldn’t ignore them. This project includes the most-requested features but omits some of the more radical – such as a Pentium III PC strapped in the car boot with a custom power supply, up-front console and remote control! What will the finished project do, exactly? Essentially, we’ve taken one of the most popular freeware music players on the Internet, Winamp, and added some software to allow it to be controlled remotely. IR Remote Receiver & Display Features • Works with most off-the-shelf • • • • • universal remote controls 16 character, 2-line LCD with backlighting Simple serial interface In-built mini-terminal makes programming easy Microcontroller (IC1) can be programmed in-circuit No messy wiring Next, we designed a small board to do the remote bit. It receives codes from any universal remote control and also provides an LCD readout big enough for MP3 track data. Plug it into a free serial port on your PC (or even build it right into your PC) and you’ve got a mean MP3 machine! This month, we describe the hardware part of the project. Next month, we’ll look at the Windows-based software, including Winamp and the control software that makes it all work as an MP3 player. The hardware – it ain’t hard! The brains of our little project is an AT90S2313 microcontroller chip from Atmel. We’ve chosen this particular microcontroller because it has plenty Fig.1: an Atmel AT90S2313-4P microcontroller (IC1) does most of the work in the circuit. It outputs control signals to a MAX232 RS232 receiver/driver IC (IC4), which in turn driver the serial port of your PC. IC3 is the IR receiver chip. www.siliconchip.com.au September 2001  25 Table.1: all the characters that can be displayed by the LCD module, along with their respective ASCII codes. characters received from the serial input are displayed on the LCD. In addition to displaying the usual ASCII characters (listed in Table 1), the program (or firmware) in the microcontroller allows our little board to recognise a number of “control” codes. If you’ve worked with ASCII before, you’ll know that the first 32 bytes of the character set are used as “control” codes – they’re not displayable and are intended solely for, strangely enough, control purposes. Using control codes, the programmer can change the cursor type, position the cursor, clear the display, and so forth. Table 2 lists all the control codes our project supports. Two codes in the table require further explanation. The first is the cursor positioning code, Ctrl-P. Unlike other control codes that are just one byte in length, to set the cursor position you need to send two bytes – Ctrl-P (16) followed by the required position (0 = first position of first line, 31 = last position of second line) plus an offset of 64. For example, to position the cursor at the beginning of the second line, you would send 16 and then 80 (16 + 64). The second code of interest is Ctrl-[, also known as “escape”. This code is used as the prefix for functions that require more than a single byte. Typically, a character identifying the function, then one or more characters containing the relevant parameters follows the escape code. This is known as an escape sequence. Our project defines just one escape sequence, which we’ve used to program the custom LCD characters – we’ll look at how these work a little later. The IR receiver of memory and runs fast enough to be able to handle all the tasks that we’ve thrown at it. What’s a microcontroller? Put simply, it’s a microcomputer integrated with a bunch of useful devices that makes interfacing to things like our LCD and infrared receiver really easy. In short, the microcontroller connects the LCD and infrared receiver to the outside world via a simple 4-wire serial interface. For our MP3 Jukebox project, the outside world is the serial port on a PC but it could just as easily be any microcontroller or computer 26  Silicon Chip project (see our Basic Stamp example later). The whole lot fits on a PC board not much bigger than the LCD module itself and is easily mounted behind any flat panel. As you can see from our photos, we’ve mounted ours behind a drive-bay blanking plate on a standard ATX PC computer case. So what can it do? Well, let’s look at the display part first. The liquid crystal display The display part functions as a simple serial terminal, meaning that This project differs from past infrared remote control projects described in Silicon Chip in that it doesn’t require a purpose-built transmitter. It works with most off-the-shelf universal transmitters, like the one you’re probably already using with your TV and VCR! Why do we need a different remote control for every new piece of equipment we buy anyway? Simply because there is no single remote control standard in use for consumer equipment. Many households have at least two (usually more) remote www.siliconchip.com.au The completed IR receiver & LCD module is attached to a modified drive-bay blanking plate and simply clips into the front of the PC. The cable from the PC board is then plugged into a serial port on the PC’s motherboard. controls, while some have opted for a “universal” unit that can be set up to work with equipment from different manufacturers. Naturally, we chose a “standard” that is probably supported by all universal remotes. This is the RC5 system, developed by Philips and in wide use throughout Europe. If you want to know a little about the workings of the RC5 system, then refer to the accompanying panel: “The RC5 Remote Control Specification”. To prove our system, we obtained two completely different universal remotes; one from Jaycar Electronics (model BC-3000, Cat AR-1710) and one from Coles Supermarket (Remote Master brand). When selecting a remote, you need to make sure that it has all the keys you would typically use to control a VCR or CD player (play, fast-forward, rewind, etc), as these aren’t included on the simpler TV-only models. Another important consideration is the number and type of devices it can control. If you only intend to use the remote for this project, then all you need is support for “VCR” or “CD” control. If, however, you want to use the same remote for other equipment, then you need to make sure that it will accommodate all intended devices. Our MP3 player can masquerade as a VCR or CD player, so in most cases you will be able to work it in with www.siliconchip.com.au what you already have. An exception to this would be if you already have a Philips brand VCR and a Philips brand CD player – a fairly unlikely (and in our case, unlucky) situation. To reliably receive data from one of these infrared transmitters, we need quite a bit of electronics, specifically an IR diode, amplifier, limiter, band­ pass filter and demodulator. Thankfully, all of these circuits are available in a single IC package. Jaycar Electronics has just what we are looking for in their ZD-1952 IR receiver IC, while Dick Smith Electronics has the Z1955. The output from this IC is the recovered digital signal, which we pipe directly into the microcontroller chip for decoding. After successfully decoding, the microcontroller flashes the “received” LED and sends the codes out the serial transmit line. To maintain data integrity, the codes are packaged with a couple of extra bytes, as follows: Byte 1 – Start byte (254) Byte 2 – Control bit (bit 7) + System    address (bits 4-0) Byte 3 – Command (bits 5-0) Byte 4 – Checksum of bytes 2 & 3 The start byte serves as a simple synchroniser, indicating the start of incoming data. The second and third bytes are the expected address and Table 2: Display Control Codes Code Ctrl-<at> Ctrl-A Ctrl-D Ctrl-E Ctrl-F Ctrl-H Ctrl-I Ctrl-J Ctrl-K Ctrl-L Ctrl-M Ctrl-P Ctrl-S Ctrl-T Ctrl-[ ASCII 00 01 04 05 06 08 09 10 11 12 13 16 19 20 27 HEX 00 01 04 05 06 08 09 0A 0B 0C 0D 10 13 14 1E Function Null (ignored) Home cursor Hide cursor Underline cursor Blinking block cursor Backspace Horizontal tab Linefeed (cursor down one line) Vertical tab (cursor up one line) Formfeed (clear screen) Carriage return (cursor to start of line) Set cursor position Auto-scroll on Auto-scroll off Escape (start of multi-byte instruction) September 2001  27 command codes. The fourth byte allows simple verification of the previous two bytes. If bytes 2, 3 and 4 are added together (modulus 256), then the result should always be zero. Construction A number of components in this project are static sensitive and should be treated accordingly. This applies particularly to the LCD module and IC1, the microcontroller. Wear a properly earthed anti-static wrist strap and use a soldering iron with an earthed tip during the following steps. All parts, including the LCD module, are mounted on a single PC board measuring 115 x 36mm. Referring to the overlay diagram (Fig.2), begin by installing the 9 tinned copper wire links, taking care to keep the links as straight as possible, as many of them will pass quite close to component leads. Next, install all the resistors, diode D1, and then the socket for IC1. The crystal (X1) can be installed next. Its leads should be bent at 90° about 2mm from the body so that they slip easily into their holes with the package lying flat against the PC board. Before soldering, make sure that you can just see the hole in the PC board at the top edge of the crystal. You need to use a short length of tinned copper wire to solder the body of the crystal to the pad underneath at this point. Next, install IC2, S1, VR1, CON1 & CON3. Note: CON1 is option­al; it isn’t needed if you have a pre-programmed microcontroller (IC1). Fig.2: the assembly details for the PC board. The body of the crystal (X1) is anchored to an earth track on the board using tinned copper wire. Fig.3: install the 5V regulator on the copper side of the board, as shown here (see also Fig.5). Fig.4: this is the full-size etching pattern for the PC board. This view shows the fully assembled PC board, prior to mounting the LCD module. The LCD module plugs into a 16-way header socket and is secured using 12mm spacers and machine screws. This photo shows how the 5V regulator is installed on the back of the board. 28  Silicon Chip www.siliconchip.com.au Now flip the board over and install REG1 on the copper side, following the mounting details shown in Fig.5. The insulator is necessary to prevent the tab of the regulator shorting out the tracks that pass underneath. Solder the regulator’s leads and flip the board over again. You will note that the regulator’s leads protrude through the top (component) side – cut these off flush with the surface of the board. Now we can install all the capacitors. Take special care with the five 10µF electrolytic capacitors. As you can see from the photos, they need to have their leads bent at 90° (about 2mm from the body) so that they lie flat against the PC board. These are polarised components – it is important which “way around” they’re installed, and getting it wrong on this board is dead easy! CON2 and the sockets for LED1 and IC3 can be installed next. We’ve socketed both LED1 and IC3 using part of the 40-pin single row header socket, so begin by cutting down the header socket into one 16-pin length, one 3-pin length and one 2-pin length. Use a sharp utility knife, and watch the pinkies! Install your newly-fashioned sockets into their respective positions, making sure that they are seated squarely against the PC board before soldering. We won’t plug in LED1 or IC3 just yet, because we need to fit the LCD module first to get height measurements. Note that we haven’t installed IC1 or IC4 yet either (tempting, isn’t it?). We need to apply power first and check that the +5V rail is OK. To do this, you’ll need to make up the power/data cable, using Fig.6 as a guide. Hook up the cable and apply power. If you don’t want to power the unit from your PC just yet, then any DC power source capable of supplying between about 8-12V DC at 100mA will do the job. Using a digital multimeter, measure between pins 10 and 20 of the IC1 socket. You meter should read 5V ±0.25V. If all is OK, remove power and install IC1 and IC4. Mounting the LCD module. Now we’re making progress! First, we need to install the header pins along the top edge of the LCD module. It’s important that the pins are inserted on the correct side of the board (see photos) – once they’re soldered in, www.siliconchip.com.au Fig.5: the mounting details for the 7805 regulator. It must be isolated from the copper on the PC board using an insulating pad. they’re very difficult to remove! Using side-cutters or a sharp knife, separate a 16-pin section (for modules with backlighting) or 14-pin section (for modules without backlighting) from the 40-pin single row header. Insert it on the bottom side of the LCD module and solder on the top (display) side. Ensure that the entire row of pins is seated squarely (sitting at 90° to the PC board) before soldering. Now plug the module into CON2 and secure to the main PC board with the four 12mm untapped spacers and M2.5 screws and nuts. You will note that the header doesn’t quite go all the way home – it sits about 1mm proud of the socket edge. This is perfectly acceptable, as the socket contacts have already done their job. Don’t fit washers under the nuts or screw heads, as they may short out nearby tracks. By the way, we’ve specified a particular LCD module from Dick Smith Electronics as not all modules have identical mounting hole or connector positions. In other words, you may have difficulties if you try to fit a module from a different source. The final step is installing LED1 and IC3, the IR receiver chip. As you can see from the photos, we have not plugged these components directly into their sockets. Rather, to ensure reliable mating to the socket contacts, we’ve soldered them to header pins first. Separate one 2-pin length and one 3-pin length from the remaining portion of the single row header for the LED and IR receiver. Before soldering them to the header pins, you might find it easier to prepare the front panel first so that you can accurately determine how much lead length will be required. Bolting it up An easy way to get everything to fit nicely up front is to photocopy the template in Fig.7, cut it out and tape it on to the panel. Use a sharp knife to mark the display cutout outline, and a centre punch to mark the hole positions for drilling. Four long spacers are used to mount the assembly behind the panel, so lets fit these next. Slip an M3 x 10mm screw into one of the corner holes on the PC board from the copper side. If your LCD module has backlighting, it is 4.5mm “thicker” than ones that don’t, so install two M3 washers and an M3 nut to provide extra mounting depth. Finish with a 20mm tapped spacer and then repeat the above for Fig.6: how to wire up your cable. If you’re installing it in your PC, then allow about 200mm for the power cable and about 700mm for the data cable, depending on the size of your case. September 2001  29 Fig.7: the is the drilling and cutting template for the drive-bay blanking plate. Note that the two IR sensors specified in the parts list require different hole sizes. Fig.8: this drawing shows how the LCD module is mounted. Note how the leads of the IR receiver (IC3) are bent, so that it fits neatly against the front panel. Make sure that the LED leads cannot come into contact with the IR receiver leads. the other three corners. Invert the works on a flat surface (LCD module and spacers facing down) and check that no light is visible between the end of the spacers and the flat surface. In other words, the spacers should be equal to or slightly higher than the surface of the LCD module. If not, then add washers as necessary. This is important because no pressure Fig.9: the LCD module has eight user-definable characters. Each pixel row translates to one byte, with a total of eight bytes required to define one character. Here we show how a “left arrow” character might be defined. should be applied to the front of the LCD module when the assembly is bolted home. With the assembly complete, you can trial-fit it to the front panel in order to gauge the length of the LED and IR receiver leads. The LED leads need to be long enough so that it protrudes through the panel, but not so long that its shoulder contacts the inside of the panel surface when installed. The IR receiver needs to be bent over at 90°, with its main body mass flush with the inside panel surface. Fig.8 shows how this is done. Take your time with this step, as it’s easy to overstress the leads. The IR lens (the “bump”) should actually slip inside the hole that you’ve drilled in the panel, with plenty of clearance all round. Once you’re satisfied, trim to size and solder to the header pins. Testing the LCD display Hook up the cable to a free serial port on your PC and connect a suitable power source. If you’ve made the cable as per our diagram, then obviously you’ll need access to an unused disk drive power connector from inside the PC case. If all your PC’s power connectors are already in use, you can purchase a “splitter” cable to fix the problem. These are available from DSE (cat X-2604), Jaycar (cat PL-0750) and most other computer suppliers. I’m assuming you’re running Windows 95, 98, ME, NT or 2000, and that The pin header is soldered to the LCD module as shown in the above photograph. The photo at left shows how the LED and IR receiver are mounted on header pins on the main board and plugged into matching header sockets. 30  Silicon Chip www.siliconchip.com.au The completed module is attached to the drive-bay blank using 20mm tapped spacers plus extra M3 nuts and washers as necessary to ensure that the LCD sits flush with the front panel cutout. The drive-bay blanks were resprayed black and the computer case charcoal grey with yellow highlights, to improve the appearance. you have HyperTerminal installed. If you don’t have HyperTerminal installed, then you can install it from the original Windows CD via Control Panel -> Add/Remove Programs -> Windows Setup. You’ll find it in the “Communications” group. When you start HyperTerminal, you’ll be prompted for a name for the new connection. Enter whatever you like and click OK. The Connect to dialog box now appears. Click the down-arrow next to the Connect using box and select the appropriate COM port, then click OK. The COM port settings dialog appears next. The settings you require are as follows: Bits per second: 9600 Data bits: 8 Parity: None Stop bits: 1 Flow control: Hardware Now click on the OK button and you’re ready to go. As soon as power is applied, the start-up message “S ILICON C HIP ” should be displayed and you will be www.siliconchip.com.au able to see the glow of the LED back­ lighting. Characters that you type on the keyboard should appear verbatim on the display. You can also experiment with the various control codes. For example, to clear the display, hold down ‘Ctrl’ and press ‘L’. Testing the IR receiver Before you can test the IR receiver, you need to set up your remote control to suit. Universal remote controls are supplied with a long list of all the brands and types of equipment they support. For our application, you should select only “Philips” as the brand and either “VCR” or “CD” for the equipment type. You’ll probably find that more than one code is listed against each choice, with no further explanation. All you can do is try each code in the list until you find one that works. Following the supplied instructions, lock in the chosen code and then press the appropriate equipment button. For example, if you chose “VCR”, don’t forget to press the VCR button before proceeding! We found that VCR code 278 works well with the Jaycar BC-3000, while for the Remote Master we chose CD code 1065 (use device mode AUX). You’ll know you’ve found a code that works when you point the remote at the IR receiver, press a button (try a digit first) and the LED flashes in response. If you still have the serial connection active, you’ll note that “garbage” characters appear in the HyperTerminal window whenever you press a key on the remote. This is a great sign – it means that all is working to plan! What if it doesn’t work? In all cases, recheck the +5V supply rail. Next, check that the microcontroller’s reset signal on pin 1 is at a logic high (close to 5V) and if you have an oscilloscope, check that the crystal oscillator is oscillating. Does the LCD display a message at power on? If not, check for shorts between pins at CON2 and using the circuit and overlay diagrams as a reference, do a continuity test between the pins on the LCD and the associated pins on the microcontroller. September 2001  31 Listing 1 '{$STAMP BS1} symbol S_IN = 6 'serial data input pin symbol S_OUT = 7 'serial data output pin symbol SYS_CODE = B0 'save system code here symbol CMD_CODE = B1 'save command code here pause 500 'wait for display to initialise ' Clear LCD screen and display message serout S_OUT,N2400,(12,“IR Receive Test”) loop: ' Wait until start of record received ($FE), then save next 2 bytes serin S_IN,N2400,($FE),SYS_CODE,CMD_CODE ' Display the received IR codes on the LCD serout S_OUT,N2400,(12,“Sys Code = ”,#SYS_CODE) serout S_OUT,N2400,(10,13,“Cmd Code = ”,#CMD_CODE) goto loop Listing 2 DEFINT A-Z CLS : PRINT PRINT “Custom character demo for Silicon Chip LCD Display” ' Set up COM port (change COMx number to suit your system). OPEN “COM2:9600,N,8,1,CD0,CS0,DS0,OP0” FOR OUTPUT AS #1 ' Write the bit patterns (from the DATA statements below) ' into the LCD’s CG RAM. FOR Char = 0 TO 2 'define custom chars 0, 1 & 2 CharNum$ = LTRIM$(RTRIM$(STR$(Char))) 'trim off Qbasic’s spaces PRINT #1, CHR$(27); “D”; CharNum$; 'send ESC D and character number FOR Row = 1 TO 8 'each char. consists of 8 rows READ CharBits 'get next bit pattern from data PRINT #1, CHR$(CharBits); 'write to LCD NEXT Row 'do all 8 rows for this character NEXT Char 'do next character PRINT #1, CHR$(12); “NEW CHARACTERS:” PRINT #1, CHR$(16); CHR$(16 + 64); 'cursor to start of second line PRINT #1, CHR$(0 + 128); CHR$(1 + 128); CHR$(2 + 128) 'show custom ' Custom character bit patterns follow. ' OK symbol DATA 8,20,20,8,5,6,5,5 ' locked symbol DATA 14,17,17,31,27,27,31,0 ' unlocked symbol DATA 14,16,16,31,27,27,31,0 If the LCD appears to be working but characters are not displayed when you type in HyperTerminal, then you can do a complete line loopback that will verify your cable as well as the RS232 receiver/transmitter chip (IC4). To do this, remove the LCD, unplug the microcontroller (IC1) and insert a fine wire link between pins 2 & 3 of the microcontroller socket and another link between pins 7 & 10. Leave out the LCD module (and IC1, of course!) and apply power. Now any keys you type should be looped right back and displayed in the HyperTerminal window. So the display and serial input works but the IR receiver doesn’t? First, check that the LED lights when you press the switch (S1). Next, check that you have installed the receiver chip (IC3) correctly, with pin 1 aligned as shown on the circuit and overlay diagrams (and photos). The output from this chip is idle high, going low when infrared light modulated around the 38kHz mark is received. If possible, try a different remote control, set up as detailed above. Got other uses in mind? Although this project is intended for our MP3 Jukebox, it would be equally at home as an extension to just about any computer or microcontroller project that requires an intelligent serial LCD readout and/or an IR receiver. Perhaps an example is in order. Fig.10 shows how to connect up to a Basic Stamp 1. Listing 1 shows just how easy it is to drive, even with the Basic Stamp’s limited resources. This short program waits for a key press on the remote and then writes the received system and command bytes back to the LCD – an easy way to check Fig.10: this project is eminently suitable as an add-on to a variety of other micro projects. Here’s how to wire it up to the Basic Stamp-1C. This model Stamp doesn’t have a true RS232 serial interface, so the resistors are included to provide protection for the I/O port pins. (The Basic Stamp-1C is available from Dick Smith Electronics). 32  Silicon Chip www.siliconchip.com.au The RC5 Remote Control Specification H AVE YOU EVER wondered how it is possible to control multiple pieces of equipment in the same room with just one remote? Well, all remote control systems that we know of use a method of addressing that separates equipment into generic groups. TVs, VCRs and CD players, for example, represent three such groups. In the RC5 specification, there are a total of 32 addressable groups, each with 64 possible commands. If you do the sums, this means that 2048 unique commands (or “messages”) are supported. Each message in the RC5 coding method is composed of a 14-bit serial stream. A message consists of four parts: • Start part – 1.5 bits (2 x logic “1”) • Control part – 1 bit • System part – 5 bits • Command part – 6 bits The start bits give the receiver AGC time to “lock on” to the incoming data. The control bit, also called the toggle bit, is simply a flag to indicate whether the following code is new or repeated. If a new key is pressed, the control bit toggles (changes state) from it’s previous value, otherwise it remains the same. The system bits are the equipment address, as described above. Finally, the command bits are the code for the actual key pressed. Table 3 lists all of the equipment addresses. Table 4 lists just a few of the possible 64 commands and the key functions that they relate to. Determining the code transmitted for any key on your remote is very easy, the codes assigned to each key on the remote. Advanced features The default baud rate is 9600 bits/ sec, but can be changed to either 4800 or 2400 by entering setup mode. To enter setup mode, press and hold down switch S1, then apply power, releasing the switch when the start-up message appears. Immediately the switch is released, a message appears displaying the firmware revision, followed by the www.siliconchip.com.au Table 3: RC5 Equipment Addresses Address 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27-31 Equipment TV1 TV2 Videotext TV1 & TV2 expansion Laser video player VCR1 VCR2 Reserved SAT1 VCR1 & VCR2 expansion SAT2 Reserved CD video Reserved CD photo Reserved Audio preamp 1 Tuner Cassette recorder Audio preamp 2 CD Audio rack Audio satellite receiver DCC recorder Reserved Reserved Writable CD Reserved as we will see in our software examples. On the physical level, data is transmitted using bi-phase (also known as Manchester) encoding. A logic one is represented by a zero-to-one transition at 1/2-bit time, whereas a logic zero is represented by a one-tozero transition. One-bit time is approx. prompt “Set baud rate?”. If you press the switch again within four seconds, the current baud rate is displayed. You can then cycle through all three possible baud rate values in turn, until you find the one that you require. If you don’t press the switch within four seconds, then the display clears and the last value displayed becomes the new baud rate. Don’t worry if you weren’t quick enough the first time; just repeat the procedure! If you don’t press the switch at the Table 4: RC5 Keycodes & Functions Code 0 1 2 3 4 5 6 7 8 9 10 12 13 16 17 32 33 35 39 48 50 52 53 54 55 Function 0 1 2 3 4 5 6 7 8 9 10+ Standby Mute Volume Volume + Ch/prog + Ch/prog 20+ Tint/hue + Pause Rewind Fast-forward Play Stop Record 1.778ms, so a complete message is 24.889ms long, with messages repeated at a minimum of 114ms intervals. To reduce interference from other light sources, data is transmitted on a 36kHz carrier. We found that the Jaycar ZD-1952 infrared receiver IC worked well with a number of different remote controls that we tried, even though its centre frequency is specified as 37.9kHz. “Set baud rate?” prompt, then “Down­ load EEPROM?” appears after a few seconds. If you press the switch at this point, the message changes to “Waiting for data”. As you might have deduced from the message, this feature allows you to update the contents of the microcontroller's EEPROM. In order to make use of this feature, you need at least a little knowledge of microcontroller programming. The AT90S2323 has 128 bytes of EEPROM and our firmware makes use September 2001  33 Parts List For IR Remote Receiver + LCD Display 1 PC board, code 07109011, 115 x 36mm 1 LCD module, 16 character x 2 line with LED backlight* (DSE Cat Z-4172) -OR1 LCD module, 16 character x 2 line (DSE Cat Z-4170). * Note: LCD module with backlighting recommended 1 10-pin dual row header (CON 1) (optional, see text) 1 40-pin single row header socket (CON 2) (Altronics Cat P-5390) 1 40-pin single row header (for LCD module) (Altronics Cat P-5430) 1 90° PC-mount 6-pin header (CON3) (Altronics Cat P-5516) 1 6-pin header socket to suit above (Altronics cat P-5476) 1 SPST tactile membrane switch (S1) (Altronics Cat S-1120) 1 20-pin IC socket (machined pin type) 1 4MHz crystal (HC49 package, parallel resonant) (X1) 1 4-pin disk drive power connector (socket, with male pins) (DSE Cat. P-5120) 1 9-pin female ‘D’ connector with backshell 1 Universal IR Remote Control (eg, Jaycar Cat. AR-1710) Semiconductors 1 AT90S2313-4P microcontroller (IC1), programmed with IRRLCD.HEX & IRRLCD.EEP 1 MC34064P-5 under-voltage sensor (IC2) (Altronics Cat. Z-7252) of a fair slice of this to store parameters such as the baud rate, power-on message and custom LCD characters. If you’re not daunted by the innards of an assembler file, then have a look at the IRREE.ASM file included in the software download – you can open it with any text editor. This file defines the layout of the data stored in the microcontroller's EEPROM. You can make changes to this file, reassemble it (using any Atmel AVR assembler) and download the resultant IRREE.EEP hex file using the above setup mode feature. To do this, enter setup mode, and get the “Waiting for data” message on the 34  Silicon Chip 1 IR receiver (IC3) (Jaycar Cat. ZD-1952; DSE Cat. Z-1955) 1 MAX232 RS232 receiver/driver (IC4) 1 LM7805 5V regulator (REG1) 1 3mm high efficiency red LED (LED1) 1 1N4001 1A diode (D1) Capacitors 1 100µF 25V PC electrolytic 5 10µF 16V PC electrolytic 3 0.1µF 50V monolithic ceramic 2 27pF 50V ceramic disc Resistors (0.25W, 1%) 1 10kΩ 1 4.7kΩ 1 180Ω 1 22Ω 1 10kΩ miniature horizontal trimpot (VR1) Miscellaneous 4 12mm untapped spacers (5mm max. O.D.) 4 M3 x 20mm tapped spacers 4 M2.5 x 20mm screws 4 M2.5 nuts 5 M3 x 6mm c/sunk head screws 4 M3 x 10mm cheese head screws 4 M3 nuts 13 M3 washers 1 TO-220 silicone or mica insulating washer 180mm (approx.) tinned copper wire for links 4-core data cable for serial port connection Light-duty hookup wire display as described above. With the board connected to your PC, open HyperTerminal (configured as described earlier) and send the new IRREE.EEP file out the designated serial port using text only file transfer. If the transfer is successful, then the LCD should display “Download OK!”, otherwise an error message will appear. If nothing happens, then the data was either not received or was garbled. Defining custom characters In addition to the standard character set (see Table 1), the LCD module has eight custom-character slots. These can be really handy, as we found when we needed the classic “play”, “stop” and “pause” symbols for our MP3 Jukebox. LCD characters are composed on a 5 x 8 pixel bitmap. Each character row is defined in one byte, with the upper, unused bits set to zero. Fig.9 gives an example of the values needed to define a single character. Once you know the bit patterns for your new character, send them to the LCD with the following escape sequence: ESC D n B0 B1 B2 B3 B4 B5 B6 B7 where ‘ESC’ identifies the start of a multi-byte instruction, ‘D’ indicates that this is a custom character definition, ‘n’ is the character number (from 0-7), and B0-B7 are the byte patterns that define the custom character. Using the values from our example, the actual string to transmit (in decimal notation) would be: 27 68 00 00 04 08 31 08 04 00 00 The microcontroller maps custom characters to ASCII 128-136, so to display a custom character, use its num­ber (0-7) plus an offset of 128. Listing.2 shows how it all works in a real program. This example, written in QBasic, defines the first three custom character slots and then displays the results. Programming the micro If you purchased this project as a kit, then the microcontroller (IC1) will have been pre-programmed and you can ignore the following information. If not, then we have made provisions for programming the chip in-circuit. In common with many recent microcontrollers, the AT90S2313’s flash program memory and EEPROM data memory can be electrically erased and programmed while in-circuit. Atmel has assigned alternate functions to three port pins for the task, which we’ve routed to CON1, the in-circuit serial programming (ISP) header. To use this feature, you need a free software package from Atmel called AVR ISP. You also need a simple adapter board that connects between your PC’s parallel port and CON1 on our board. We hope to describe this board next month. Finally, the microcontroller program files (including all the source code) are available for free download from the Silicon Chip website at SC www.siliconchip.com.au www.siliconchip.com.au