Silicon ChipThe PICAXE, Pt.9: Keyboards 101 - December 2003 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Publisher's Letter: Australian power stations should be solar or gas-fired
  4. Feature: What You Need To Receiver Weather Satellite Images by Jim Rowe
  5. Feature: A Self-Diagnostics Plug For Your Car by Julian Edgar
  6. Project: VHF Receiver For Weather Satellites by Jim Rowe
  7. Order Form
  8. Project: Linear Supply For Luxeon 1W Star LEDs by Peter Smith
  9. Product Showcase
  10. Weblink
  11. Feature: PC Board Design Tutorial, Pt.3 by David L. Jones
  12. Feature: SPLat Controls microPLCs by Peter Smith
  13. Project: MiniCal 5V Meter Calibration Standard by Barry Hubble
  14. Project: PIC-Based Car Battery Monitor by Alan Bonnard
  15. Project: The PICAXE, Pt.9: Keyboards 101 by Stan Swan
  16. Vintage Radio: The AWA PF car radio & the Ferrite Tranimate by Rodney Champness
  17. Book Store
  18. Back Issues
  19. Notes & Errata
  20. Market Centre
  21. Advertising Index
  22. Outer Back Cover

This is only a preview of the December 2003 issue of Silicon Chip.

You can view 30 of the 96 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 "What You Need To Receiver Weather Satellite Images":
  • VHF Receiver for Weather Satellites PCB [06112031] (AUD $15.00)
Articles in this series:
  • What You Need To Receiver Weather Satellite Images (December 2003)
  • VHF Receiver For Weather Satellites (December 2003)
  • What You Need To Receiver Weather Satellite Images (December 2003)
  • VHF Receiver For Weather Satellites (December 2003)
  • Antenna & RF Preamp For Weather Satellites (January 2004)
  • Antenna & RF Preamp For Weather Satellites (January 2004)
Items relevant to "VHF Receiver For Weather Satellites":
  • VHF Receiver for Weather Satellites PCB [06112031] (AUD $15.00)
  • VHF Receiver for Weather Satellites PCB pattern (PDF download) [06112031] (Free)
  • Panel artwork for the VHF Receiver for Weather Satellites (PDF download) (Free)
Articles in this series:
  • What You Need To Receiver Weather Satellite Images (December 2003)
  • VHF Receiver For Weather Satellites (December 2003)
  • What You Need To Receiver Weather Satellite Images (December 2003)
  • VHF Receiver For Weather Satellites (December 2003)
  • Antenna & RF Preamp For Weather Satellites (January 2004)
  • Antenna & RF Preamp For Weather Satellites (January 2004)
Items relevant to "Linear Supply For Luxeon 1W Star LEDs":
  • Luxeon 1W Linear Power Supply PCB pattern (PDF download) [11112031/2] (Free)
Articles in this series:
  • PC Board Design Tutorial, Pt.1 (October 2003)
  • PC Board Design Tutorial, Pt.1 (October 2003)
  • PC Board Design Tutorial, Pt.2 (November 2003)
  • PC Board Design Tutorial, Pt.2 (November 2003)
  • PC Board Design Tutorial, Pt.3 (December 2003)
  • PC Board Design Tutorial, Pt.3 (December 2003)
Items relevant to "MiniCal 5V Meter Calibration Standard":
  • MiniCal PCB pattern (PDF download) [04112031] (Free)
Articles in this series:
  • PICAXE: The New Millennium 555? (February 2003)
  • PICAXE: The New Millennium 555? (February 2003)
  • The PICAXE: Pt.2: A Shop Door Minder (March 2003)
  • The PICAXE: Pt.2: A Shop Door Minder (March 2003)
  • The PICAXE, Pt.3: Heartbeat Simulator (April 2003)
  • The PICAXE, Pt.3: Heartbeat Simulator (April 2003)
  • The PICAXE, Pt.4: Motor Controller (May 2003)
  • The PICAXE, Pt.4: Motor Controller (May 2003)
  • The PICAXE, Pt.5: A Chookhouse Door Controller (June 2003)
  • The PICAXE, Pt.5: A Chookhouse Door Controller (June 2003)
  • The PICAXE, Pt.6: Data Communications (July 2003)
  • The PICAXE, Pt.6: Data Communications (July 2003)
  • The PICAXE, Pt.7: Get That Clever Code Purring (August 2003)
  • The PICAXE, Pt.7: Get That Clever Code Purring (August 2003)
  • The PICAXE, Pt.8: A Datalogger & Sending It To Sleep (September 2003)
  • The PICAXE, Pt.8: A Datalogger & Sending It To Sleep (September 2003)
  • The PICAXE, Pt.8: The 18X Series (November 2003)
  • The PICAXE, Pt.8: The 18X Series (November 2003)
  • The PICAXE, Pt.9: Keyboards 101 (December 2003)
  • The PICAXE, Pt.9: Keyboards 101 (December 2003)

Purchase a printed copy of this issue for $10.00.

A NEW “CLASS“ OF PICAXE Keyboards 101 by Stan Swan New PC on the Christmas wish list? Kids getting your old PC (again)? Maybe they’ve already got your previous cast offs!? Can’t bear to just throw out that new millenium keyboard you lovingly crafted prose and caressed spreadsheets with? Consider our PICAXE-18 (A or X) “PS/2 to RS-232” converter that creates a versatile 2-wire serial data sender, suitable linking to a remote terminal or LCD display. W ith flair, the entire circuit and 3xAA battery power supply may even be able to be housed inside the keyboard – suiting perhaps a serial “computerless” keyboard able to send data for many kilometres along a simple two-wire link (refer “Damp String” Datacomms, July 2003 SILICON CHIP). In spite of its recent multimedia and Internet variations, the PC’s humble QWERTY keyboard surely is the industry’s bargain workhorse, with a service life extending often well beyond its companion PC. It is debatable in a commercial sense if it’s worth cleaning spills and dirty finger marks off them, since in spite of their electronic and mechanical sophistication, new (barebones) keyboards sell for under twenty dollars – often well under. But if you’re prepared to spend a few minutes wash & brush up time, you’ll no doubt be able to lay your hands on plenty of working ones (maybe even more after office Christmas parties!). For this project however it’s suggested you stick with relatively recent PS/2 models, since the original 1980s XT design is not PICAXE-18A/X friendly. In addition, even early 1990s AT types, especially those with the larger 5-pin 76  Silicon Chip DIN socket, may be power hungry. Tests on assorted six-pin miniDIN PS/2 keyboards showed most were delightfully tolerant of lower supply voltages but some drew up to 70mA. Since the aim is to run the entire setup off the usual PICAXE 3xAA (4.5V) supply, it’s best to use such a battery busting keyboard just for initial testing and keep your eyes peeled for one of the “smell of an oily rag” ones. If you don’t have a DMM to check working current, then open up the keyboard itself (mind the cockroaches!) and check the dates on the keyboard’s inbuilt control electronic ICs. www.siliconchip.com.au We found an early 90s era HP had “9315” ( = 1993 15th week ) on its 40pin Motorola controller and predictably drew a greedy 60mA even at 3V. The Y2K-era discard settled on finally drew just 2mA at voltages anywhere from 3 - 5.5V (thus matching a PICAXE needs well) and seemed typical of many such now available. Some PDA thin and “rollup” keyboards look even more frugal. Use of such interfacing keyboards has been a popular PIC16F834 or Atmel AVR micro controller project for some years but coding has been a challenge to say the least! PC keyboards operate via weird hex “scan codes” that follow no logical layout and are easiest dealt with via a lookup table. Thankfully both the 18A and X PICAXES offer a convenient key-press keyin reading (which detects the key press at inputs 6 and 7) for keyvalue to lookup the associated “scan code” which can be neatly grouped for reading under the Picaxe EEPROM command. These codes are seamlessly converted to ASCII, then further sent out as 2400bps serial RS232 data for terminal or LCD display (refer July and August 2003 SILICON CHIP articles). Given the 256-byte non-volatile RAM of both the 18A and X, it proved feasible to use half of this (bytes 0-127 are of course used by the EEPROM) as a keystroke memory buffer – these are displayed (and then overwritten) at next switch on. This buffer could instead be used to send a prepared message(s) when certain keys were pushed, and feasibly could again hold temperature values from our November DS1B20 data logger as well. Classic ASCII codes (pronounced “ass-key” = American Standard Code for Information Interchange) began use with the IBM PC in 1981 (but date in fact from 1963!), and represent one of the few forty-years-old computer technologies still thriving. The first 128 numbers (256 = 28 for extended ASCII) are grouped into 31 non printing functions, such as 8 = BackSpace (BS) and 13 = Carriage Return (CR), while 32 – 128 represent normal alphanumeric characters (65= A, 66 = B etc). Only CAPITALS are used in this program incidentally (these should be sufficient for messages such as www.siliconchip.com.au +3-5V IC1 PICAXE-18 4.7k DB9 1 IN 2 22k 3 5 4.7k IN 1 18 2 SER OUT IN 0 17 2 (TO PC SERIAL PORT) 4.7k 10k 3 SER IN IN 7 16 4 RESET IN 6 15 5 0V RESET 4 +V 4-WIRE RIBBON CONNECTOR FOR PS/2 5 CLOCK MINI DIN - EX PC KEYBOARD 1 DATA SUPPLY 14 6 OUT 0 OUT 7 13 3 0V PIEZO LEDS 7 OUT 1 OUT 6 12 K SERIAL OUTPUT TO TERMINAL PROGRAM OR LCD A 8 OUT 2 OUT 5 11 PICAXE18A RED LED λ 9 OUT 3 OUT 4 10 9 18 SC  2003 Picaxe-18a - “KEYBOARDS 101” Circuit and protoboard layout, using the same overall scheme as last month. Pinouts for the keyboard socket (corresponding to the “keyboard” output numbers at right) are shown below. 1 +V KEYBOARD 4 1 5 3 2x 3x 4.7kΩ OUTPUTS 3-5V PICAXE-18A 0 1 2 3 4 5 6 7 22kΩ A 10kΩ LED 5 3 2 (RS232) K 0V RESET SWITCH SERIAL (LCD) OUTPUT PIEZO This PICNIK box and proto-board layout is a bit simpler than the layout diagram above because we’ve removed all of the nonessential wires and links. The two pins painted white on the miniDIN (keyboard) socket have no connection. December 2003  77 KEYB18XA.BAS (Also downloadable from: http://picaxe.orconhosting.net.nz/keyb18xa.bas) ‘KEYB1XA.BAS - for Dec 03 “Silicon Chip” PICAXE-18X/A article.Ver 1.02 2/11/03 ‘Converts attached PS/2 PC computer keyboard codes for ASCII display.NB-NOT the ‘normal Prog.Editor PC kbd but an “old PC” one - selected for low power demands. ‘EEPROM command preloads ASCII values into 18X/A data memory for lookup table. ‘When key pressed,it’s “value” used as the data memory address via the read cmd. ‘The correct ASCII value is then shifted from the data memory into variable b1 ‘For PICAXE-18X/A or 28X only - will NOT work PICAXE-08 (since no “key” cmds). ‘Refer article & schematic for kbd V & I findings + 18X/A connection details. ‘Via Stan.SWAN =>s.t.swan<at>massey.ac.nz. Comment lines (starting ‘)can be ignored. ‘-------------------------------------------------------------------------------‘ INPUTS 3-5V +supply OUTPUTS PS/2 (5)(3)(1)(4) ‘+ + + + + + + + + + + + + + + + + + + + + + + keyboard G S ‘| ,------------| -typically C R U ‘o o o o------- | | SEROUT _Piezo a recent L O D P ‘KBd.| | | --------| | one takes O U A P ‘ | 0 1 2 6 7 =| PICAXE |=0 1 2 3 4 5 6 7 just 2mA C N T L ‘ | =| 18X(A) |= L <at> 3V-5V ! K D A Y ‘ |_0V --------- E ========== ‘ (SERTXD) |* | D ** =wire to 4.7k | | | | ‘ |||----------------/ * | | | | | | | | | pullup R & reset | | | | ‘Prog. - - - - - - - - - - - - - - - - - Ch OV Ch +5V ‘input Common gnd for serial,kbd,piezo & supply PICAXE-18X/A => 6 7 ‘--------------------------------------------------------------------------------serout 2,n2400,(12,”PC keyboard + PICAXE-18X/A terminal”) ‘Power switch on title wait 1: serout 2,n2400,(12) ‘1 sec.title display then FF(12=FormFeed) = new page for b0=128 to 255 ‘sweep thru’ all upper 128 non volatile RAM locations read b0,b1 ‘stored data values readout to terminal/ LCD at switch on serout 2,n2400,(b1) ‘EEPROM occupies first 128 bytes of course,so just 128 ch. next b0 ‘~20 spaced words,buffer stored for next power on display serout 2,n2400,(32) ‘space indictes end of buffered text & fresh display start ‘--------------------------------------------------------------------------------reset: b0=127 ‘reset for RAM storage -first 128(0-127) used EEPROM “keyvalues” kbd: ‘decoding/display routine. SERTXD cmd ideal initial 18X tweaking for b0=128 to 255 ’increment for last 128 keystrokes capture.NB-overwrites earlier keyin ‘Get the keyboard press.NB-all processing stops until received! read keyvalue,b1 ‘convert key value from keyin cmd into an ASCII character as b1 if keyvalue=$5A then crlf ‘Carriage Return & Line feed routine for Enter key ($5A) if keyvalue=$66 then bksp ‘backspace key routine for BkSp key ($66) ‘sertxd (b1) ‘pulsout 2,500 ‘display <at>4800bps ASCII ch.(via inbuilt F8 ?)NB:SERTXD 18X only! ‘LED flash output 2 confirms key push. SEROUT flashes LED also serout 2,n2400,(b1) ’pin 2 2400 bps serial output for terminal/LCD display. 18A/X sound 7,(100,5) ‘key push sound- alter to suit (usual syntax).Remove if tedious ! pause 100 ‘may be needed to prevent double ch. sending-alter to suit ~150 ? write b0,b1 ‘stores last 128 raw keystrokes (less CRLF & BS) non volatile RAM if b0=255 then reset ‘ allow for overwriting initial stored keystroke buffer next b0 ‘increment RAM storage location until 128 ch. buffer is full goto kbd ‘NB:18X SERTXD ideal tweaking- maybe ‘rem out finally (as here)? ‘---------------------------------------------------------------------------------crlf: ‘CR & LF routine to action ‘Enter’ key press.(ASCII values) serout 2,n2400,(13,10) ‘force a CR(=13) & LF(=10) for new line display on terminal sound 7,(80,20) ‘old typewriter CR sound (!?)-alerts to different key press pause 200 ‘”typomatic” delay to prevent double action- alter to suit goto kbd ‘loop back to main key decoding routine ‘---------------------------------------------------------------------------------bksp: ‘BackSpace routine to action ‘BkSp’ keypress.(ASCII values) serout 2,n2400,(8) ‘force a BS(=8)on terminal.NB Some term. progs.may ‘ignore’ sound 7,(50,20) ‘raspberry sound (!?)- alerts to different key press pause 10 ‘short delay prevents double BS keypress- alter to suit goto kbd ‘loop back to main key decoding routine ‘---------------------------------------------------------------------------------‘Keyvalue data via Picaxe Editor:->file ->open ->samples ->keyin.bas CAPITALS only! EEPROM $00,(“?9?5312C?A864?’?”) EEPROM $10,(“?????Q1???ZSAW2?”) EEPROM $20,(“?CXDE43?? VFTR5?”) EEPROM $30,(“?NBHGY6???MJU78?”) EEPROM $40,(“?,KIO09??./L;P-?”) EEPROM $50,(“??’?[=?????]????”) EEPROM $60,(“?????????1?47???”) EEPROM $70,(“0.2568??B+3-*9??”) 78  Silicon Chip ‘FN KEYS-all EEPROM values are hexadecimal(base 16) ‘MAIN KBD.Keyvalues run $10-$1F. So $1C=A,$1D=W etc ‘NB “gap” before the “V” =SPACE BAR (keyvalue $29) ‘Refer keyvalue list =>Help- Picaxe-18 -Basic cmds ‘Use “If keyvalue =$xx then action” for ‘capture’ ‘further specific keys.Thus if keyvalue=$76 (= Esc) ‘force term.’Escape’ action -> serout 2,n2400,(12) ‘NUMERIC KEYPAD.where 12=FF (ASCII) to clear screen TABLE 8 – SORRY - YOUR TURKEY IS BURNT) but with the huge (600 code lines) memory of the 18X, code can be extended to action further keys as required. The circuit has again been built onto breadboard PICNIK-18 style (refer November SILICON CHIP), for clarity stripped to just those few wires actually needed. Old PC motherboards should supply a (de soldered) PS/2 socket, so that a convenient four-wire ribbon cable – PCB header pin adaptor can be used. If you are sacrificing the keyboard however, just cut its fiddly PS/2 plug off to access and strengthen (perhaps with IC socket leads) these four wires for direct connection. Don’t forget the two 4.7k pullup resistors to Picaxe inputs 6 and 7, and also a similar 4.7k at the “18” reset pin (4). A reset push switch (to ground) may be useful here, if only to ensure just the Picaxe is reset and thus give cleaner output than a power off (which also switches the keyboard). Remote display (from output 2) can be via any terminal program, such as Hyperterminal, Bananacom or even the convenient Picaxe editor’s “F8”. The Rev. Ed. AXE033 serial LCD, although only a 16 x 2 display (and References and parts suppliers (also refer to previous months articles) 1. www.asciitable.com lists a lucid (extended) ASCII table. 2. www.beyondlogic.org/keyboard/ keybrd.htm covers classic AT keyboard interfacing 3. www.picaxe.co.uk (Revolution Education) – generously provided 18X & A insights and graphics. 4. www.picaxe.com (MicroZed) – Australian master distributor for all Picaxes and accessories 5. http://www.picaxe.orconhosting. net.nz/ Authors Picaxe resource site with program listings and numerous links. www.siliconchip.com.au In Australia and New Zealand Scan codes for a standard keyboard. Using the code opposite, the PICAXE will decode these for further use. needing a good 5V supply), works well too and naturally removes the need for a display computer. Don’t neglect old but reliable DOS notebooks and mono organisers (perhaps with damaged keyboards!) – most have terminal ability too and some (such as the Sharp OZ/ZQ Wizards or Casio PV organisers) draw only tiny currents. The “18X” can valuably have its baud rate wound up from 2400bps to suit these. Although the program runs on either the 18A or 18X, the latter controller offers a handy SERTXD “tweaking” feature over its programming cable, much as does the baby “08”via serout 0 . It’s actioned on an 18X by pushing F8, and directs serial output data (suitably SERTXD instructed) back to the editing PC (at 4800 bps as well). Naturally this saves the inconvenience of both program and D9 cable swapping if you’ve only a single PC. It’s tempting to feed the serial data to a low power 433.92MHz LIPD transmitter (such as the cheap TWS/RWS pair) for wireless use, with a perhaps a decoding “08” at the far end. Tests with these devices, with ranges enhanced by a 4 element Yagi gave useful signals at several km (see http://www.picaxe.orconhosting.net.nz/ yagi433.jpg). We might have a more detailed look at these sometime in the future, depending on interest. But, as confirmed in both my “08” articles and the November Silicon Chip “Mr. Vineyard” modem, slower data rates (300 bps?) and “massaging” seem inevitable, since useful may not mean reliable… We’ll cover simple wireless workarounds, using interrupts and infrared, as part of our next article early next year. Happy QWERTYmas ! SC TAKE YOUR PIC Picaxe.com.au DISTRIBUTOR MicroZed.com.au PHONE (02) 6772 2777 9-5 FAX (02) 6772 8987 24 Hours ALL PICAXE ITEMS ON OUR SHELVES! NEXT MONTH: We're starting a new series of PICAXE projects from the makers of the chips, Rev-Ed in the UK. But fans of Stan Swan need not be too concerned: Stan's unique PICAXE column will return shortly! Developed for students, & professional performance makes PICAXE the most easy-to-use micro ever: PICAXE "programmer" is two resistors and a 4.5V battery! STOCKISTS In AUSTRALIA: altronics.com.au School Electronic Supplies (John - 03 8802 0628) In NEW ZEALAND (South Island): sicom.co.nz In NEW ZEALAND (North Island): surplustronics.co.nz And for chips in Australia: oatleyelectronics.com www.siliconchip.com.au December 2003  79