Over the years I've written and collected some useful subroutines and modules that can be re-used in another project, or stand-alone. Here are the ones I am allowed to share. Some of these I originally found somewhere and modified, and I've tried to give credit where it's due.
Code Disclaimer: All of these code modules are supplied "as-is," with absolutely no warrantees or support, and are to be used at your own risk. There are surely bugs in them somewhere. If you decide to use them in a life-support system or other mission-critical application, you're Krazy!
PIC Assembly Code Routines
Some math routines, serial text handling, and integer-to-ascii display routines. A note about the coding style in these modules: I almost always use little-endian encoding for 16-bit and larger variables, so the first memory slot is the LSB. Also, I frequently only create a label for the first byte. For example, Temp is the first byte. Then, rather than creating 3 more labels like Temp2, Temp3, etc. for the upper bytes, I refer to them as Temp+1, Temp+2, and Temp+3. Some people don't like this notation. Get over it. For me, it makes the declaration section cleaner.
I 2C Master Routines - These routines can be used with a PIC microcontroller to implement an I2C Master. The sample code is for a 20MHz clock, but can easily be adapted to other clock speeds. Note that for communicating with the Gamoto, 100 kHz is the maximum I2C speed that should be used. These routines use the hardware I2C peripheral, as opposed to bit-banging on a GPIO pin.
PIC Macros / Aliases - These are my most frequently used 'additions' or modifications to the MPASM assembly language. They come in handy for switching banks, and testing for positives and negatives, and skipping on borrows, clears, etc.
PIC EEPROM Read - This routine (written here as a macro) will read from the PIC internal EEPROM. It's written for a PIC16F876, but should work for others with small modifications.
PIC EEPROM Write - This routine (written here as a macro) will write to the PIC internal EEPROM. It's written for a PIC16F876, but should work for others with small modifications.
PIC Assembly Multiply - This is a 16-bit x 16-bit multiply with a 32-bit result. One of the multipliers can be negative, but not both. This is what I use in my PID routine to do the filter multiplications.
PIC Interrupt Context Save & Restore - It's a simple thing, but there are so many bugs and ommisions in the Microchip data sheets that I like to keep this chunk of code handy. It saves all context registers going into the interrupt, then recovers them when exiting.
Here's some little scripts I've written for fun, and on the way to learning Python. I keep them handy to refresh my memory on how to do basic tasks like file handling and grabbing web content.
Pente Board Game This program uses PyGame graphical interface to display a pente board game, and it allows you to play against the computer. I'm not releasing the source yet because it's still evolving and I need to clean it up, but I've used Inno Setup to create a windows binary for it. Try it out and let me know if you can beat it! NOTE: The Windows Program Proup is Gamatronix. Here's the windows setup file:Windows Install File: pente_0_01_06_Install_Win32.exe
Table Parser - This accesses a web page and parses the tables for content. The content is stored in a dictionary/list structure that is easy to pass to another module for processing. It's still a work in progress, but works for most cases I've tested.
Get Stocks - This script grabs stock prices, timestamps them, and stores them in a text file, for later trending. It's meant to run as a crontab job once a day, after closing of the market. The stock ticker symbols you want to read need to be in a separate text file.
Opera Link Exporter - This script parses your Opera bookmarks file and outputs a clean HTML file with clickable links. Good way to share your favorite links, without having to write html code. This is link to a text file, so after downloading, rename it to drop the .txt off the end.
Self-Revealing Code - This is a silly little script that outputs itself. There is a name for this kind of program, I just can't remember it.
Visual Basic Code
Just a few handy little functions and routines that I keep re-using over and over. I've also posted the source to a full-blown application, MotoView, which is used to test and configure the Gamoto motor controllers I developed.
MotoView - (40kb zip file) MotoView is basically a serial client to the Gamoto, and is a good illustration of the use of a queue to share the serial port among multiple simultaneous serial clients, in separate windows. It was developed on VB 6.0 sp5, and has been tested with Windows 2000 and XP.
Hex to Decimal - Takes a string representation of a hexadecimal number and returns a long integer.
Decimal to Binary - Takes an integer as input, and returns an 8-character string of 1's and 0's that represents the binary equivalent of the number.
Decimal to Hex Chars - Takes a decimal (long integer) value and returns a string of hex characters, in ascii encoding. For example, if the input is 520 (equal to 0x0208), the output would be = chr(8) & chr(2). This is used to send a hex value in a little-endian serial protocol. This listing includes three variations: 8, 16, and 24-bit conversions, with negative number handling.
C/C++ for Windows
These routines are various little useful routines I've written, mostly in windows in Visual Studio .NET unless noted otherwise.
Windows Serial Library - .zip file. This set of C functions provides easy, native access to the windows serial port. For some reason these kinds of routines are hard to find, so this is the product of many hours of frustrating research. Also included in the zip is a simple demo program in C++ to show by example how it is used.