' -------------------------------------------------------------------- ' TI LINK ROUTINES for the PICAXE08 SERIES - Benjamin Ryves 29.03.2005 ' -------------------------------------------------------------------- ' These routines are intended for use with a graphical calculator from ' Texas Instruments or compatible device. They implement the basic ' hardware link protocol - to transfer variables between devices you ' will need to implement the software link routines. These have been ' well documented by Romain Liévin and Tim Singer. Visit ticalc.org ' for links to further reading on the subject of linking. It is ' largely due so their documentation that I was able to construct link ' with the calculator at all! ' ' -------------------------------------------------------------------- ' Setting up the link routines ' -------------------------------------------------------------------- ' I was initially put off building a hardware link as I thought I had ' to do all sorts of strange magic with transistors and four IO pins ' on a PIC. How wrong I was! The PICAXE can gracefully switch between ' input/output modes on pins and the behavious here is perfect for the ' needs of the calculator. ' The link cable is made up of 3 leads - two data lines and a common ' grounding. The cable is tipped with 2.5mm stereo jacks. ' If you cut up a TI calc-to-calc cable, you will see that one wire is ' coloured red and the other white. Red is D0 in these routines, white ' is D1. Red is the tip of the stereo jack plug. White is the ring. ' ______ ' __ ___ ________/ / ' / \_/ \_/ | \ ' | D0 | D1 | GROUND | / ' |RED |WHITE| COPPER | \ ' \__/ \___/ \________| / ' \_____\ ' ' You'll need to select two of IO the pins on your PICAXE as pins to ' connect to the data lines of your TI cable. The only requirement is ' that they can switch between input and output modes. Now, you need ' to edit my code a little. You need to edit the "symbol" directives. ' Let's say that you've connected D0 to pin 3, and D1 to pin 4. The ' block would look like this: ' ' |symbol pDATA0 = pin3 ' |symbol pDATA1 = pin4 ' |symbol nDATA0 = 3 ' |symbol nDATA1 = 4 ' ' Sorry about having two "symbol" directives for each data line. I do ' not know of any other way to do it! ' Now, the last thing that needs doing is adjusting the other 3 ' "symbols" (bitCounter, byteToXfer and checkBit) so that they don't ' interfere with your own variables. I gave them the last few, so ' unless you use a lot of variables I hope you don't run into them! ' ' -------------------------------------------------------------------- ' Using the link routines ' -------------------------------------------------------------------- ' This is very simple! ' To send a byte, load the value you want to send into "byteToXfer" ' and call the sub "sendByte" with the "gosub" instruction. ' To receive a byte, just call the sub "getByte" and the value will be ' placed into "byteToXfer". ' A simple program to test that the link works is like this: ' ' |testLoop: ' | gosub getByte ' | gosub sendByte ' | goto testLoop ' ' This will get a byte then spit it right back again! If you use a ' terminal program on your calculator (such as Telnet 83, which I used ' in testing) then you should be able to type in that and watch all ' your letters being echoed back to you. Nifty, huh? ' ' -------------------------------------------------------------------- ' Contacting me ' -------------------------------------------------------------------- ' Shaved off a few bytes? Sped them up? Ported to another chip? Bugs? ' Or just made a really cool TI-connected device? Contact me! ' email: benryves@benryves.com ' web: http://www.benryves.com ' You also can use my email address in MSN if you want. ' --------------------------------------- ' SYMBOLS TO DEFINE IO PINS AND VARIABLES ' --------------------------------------- symbol pDATA0 = pin1 symbol pDATA1 = pin2 symbol nDATA0 = 1 symbol nDATA1 = 2 symbol bitCounter = b11 symbol byteToXfer = b12 symbol checkBit = b13 ' Here's a really bad sample program. It sends the keypress ' kCatalog to the calculator every 10 seconds, making the ' calculator switch to the catalogue of functions. ' I had a really exciting one lined up that sent a variable ' over using the SLP but ran out of EEPROM space. I need a ' PICAXE-08M :( mainLoop: EEPROM 0,(115,135,62,0) for b0 = 0 to 3 read b0,byteToXfer gosub sendByte next for b0 = 0 to 7 gosub getByte next pause 10000 goto mainLoop ' End of really bad sample program ' ---------------------- ' BYTE TRANSFER ROUTINES ' ---------------------- getByte: byteToXfer = 0 for bitCounter = 0 to 7 byteToXfer = byteToXfer / 2 waitGetBit: if pDATA0 = 0 then gotBit0 if pData1 = 0 then gotBit1 goto waitGetBit gotBit0: low nDATA1 if pDATA0 = 0 then gotBit0 input nDATA1 goto gotAndUsedBit gotBit1: low nDATA0 byteToXfer = byteToXfer + 128 if pDATA1 = 0 then gotBit1 input nDATA0 gotAndUsedBit: next return sendByte: for bitCounter = 0 to 7 checkBit = byteToXfer & 1 if checkBit = 1 then sendBit1 sendBit0: setD0L: low nDATA0 waitD1L: if pDATA1 = 1 then waitD1L setD0H: high nDATA0 waitD1H: if pDATA1 = 0 then waitD1H goto sentBit sendBit1: setD1L: low nDATA1 waitD0L: if pDATA0 = 1 then waitD0L setD1H: high nDATA1 waitD0H: if pDATA0 = 0 then waitD0H sentBit: byteToXfer = byteToXfer / 2 input nDATA0 input nDATA1 next return