- Discrete LEDs
- Dot/Bar LEDs
- Matrix LEDs
- 7-Seg LEDs
- Serial -- Software
- Serial -- Hardware
- RS-232 via the MAX3232
- I2C -- EEPROM
- I2C -- DS1307 Real Time Clock
- 1-Wire -- DS18B20, Powered, Single-Drop
- 1-Wire -- DS18B20, Powered, Multi-Drop
- 1-Wire -- DS18B20, Parasitic, Multi-Drop
- TI Link Protocol -- Calculator Demo
- Infrared Communication
- MIDI -- Output Demo
- MIDI -- Input Demo
- MIDI to Analog Synth
Serial -- Software
With this exercise we now begin to look into the business of communications. For starters, let's see how the serial (RS-232) mode works, using a software driver. What this means is that we can employ any pins we want, and furthermore may use the technique with any PIC. (Although just about every microcontroller nowadays has the internal circuitry to do serial communications.) All of the details are handled by the PIC Micro Pascal library unit "SSerial.pas." Let's get a few of the requirements for the project out of the way first.
To run this exercise, you'll connect the circuit up to a laptop or other suitable computer running terminal software. On my workbench, I'm using an old Gateway laptop. Since it is sufficiently new enough not to have a COM port, though, I fitted it up with a COM-to-USB adapter. I got this dirt cheap from Amazon several years ago (no doubt a Chinese import), but it works just fine. To use it with Windows, you'll want a Prolific PL-2303 driver. Here's what she looks like:
Other than that, to complete the hook-up, you'll require the usual RS-232 type cable. I bought a heavy-duty one, surplus, from All Electronics for a dollar or two way back when.
Next, you'll need some terminal software running on the laptop. If you're a glutton for punishment, you could try the old HyperTerminal program which used to be supplied with Windows. It's a real stinkbomb, though, so I use something called "Br@y's Terminal." (That's not a typo). This is a really slick package and free of charge. You can find it at:
I've found it so useful, that I put it in my PIC Micro Pascal IDE menu for ready access:
Another cool option to consider should you own an Android device is the app, "Serial USB Terminal." It's available for free in the Play Store. I just tried it out on a Simbans tablet and it works very well. This could really be convenient for some portable gear! Here's a snapshot:
And with that, we're ready for the circuit:
The transistors take care of the needed signal inversion, while D1 dumps any incoming negative voltages to ground. (Genuine RS-232 swings between -12V and +12V, though your laptop probably just goes 0V to +5V. In any event, the transistor along with the diode guard against the worst case scenario).
Here's what happens when you run the exercise. The terminal will print a message, asking which LED you wish to illuminate. So, type in a number from 1 to 8 to do so. If you enter a number out of range, the PIC sends a message back to the terminal so indicating. Here's a screen shot of it in action; click on it to enlarge:
It's not a bad little exercise. It demonstrates communication in both directions, and moreover does something halfway useful. Obviously, it's only a simple step forward to switch some opto-couplers and relays to control real-life devices.
Click to get the source code.
Click to get the schematic PDF.
Next Project: Serial -- Hardware