8051 Code Repository

From Wiki
Jump to: navigation, search

These are routines I've written over the years. My programming philosophy is to create as many reusable components as possible. Anyone who has written assembly code for the 8031 family knows it doesn't have a huge stack area. In spite of that, almost all of these routines are written as sub-routines, and try to save registers that are used whenever possible. While this may seem contrary to some 8031 programmers way of thinking, stack space is one of the few things I've never really run out of on an 8031 project. And in all seriousness, if space has gotten that tight, you either abandon modular programming methods, or you switch to a larger part.

That being said, I've tried to comment these routines with register usage, stack usage, philosophy behind what they do, etc. I won't by any means say it's great code, but it's worked for me. Also, some of these routines may seem pretty simple, or somewhat trivial. I've found that by having all these available, large or small, I avoid having to go back into older projects to cut and paste code.

If you find a bug, or have questions or comments about the code, or you use it in a project, I'd like to hear from you. I can be reached here, and will usually respond within a day or so, assuming I'm not out of town. Please don't write me asking me to write code for a student project (this happens, really). I will be happy to try to point you in the right direction, or provide advice, but I will not do your project for you! I will write code for money, however (I'm a consultant, so this shouldn't be surprising).

All routines are freeware. Please respect my copyright, and leave any copyright information in the source code. There are no warranties, express or implied, with regard to this. While I cannot control how the code is used, I would prefer that it not be used in situations where the failure of the code may lead to injury or death of people or animals in the event of failure (this primarily means life support equipment and primary avionics equipment). If you desire to use the code in such a purpose, please contact me first. If you feel compelled to send me a gratuity for the use of this code, by all means, feel free!

One final note: All this code was written using the Avocet AVCASE51 macro assembler and linker. While it's not the best package available (one day I want to write my own, but that's GUP fodder), and has a few quirks, it does support procedures and local labels. I've provided a utility in both source and executable format for removing the PROC headers and local labels, for those assemblers that don't support them.

The sources can be retrieved from the Subversion repository.

Subversion Repository (username 'guest', password is empty)

Utilities

delocal.exe is a utility converts local labels to the routine name plus a sequential number. It also removes all PROC/ENDPROC pairs from the source. Unfortunately, I seem to have lost the source for it, so it's provided as a .EXE only.

Subversion Repository (username 'guest', password is empty)

Descriptions

ADCAD.ASM This adds the accumulator to DPTR, leaving the result in DPTR, and CY set if the result overflows 16 bits. Used by CCITT16.ASM, CRC16.ASM, SP0_X.ASM, and SP1_X.ASM.
AUTOBAUD.ASM Allows automatic baud rate detection on the standard serial port. Uses timer 1, and assumes a 11.0592Mhz crystal. Also presumes 8 bit word length, no parity, and 1 stop/start bit from the host. Supports all standard rates from 150 to 19200 baud. Higher rates or non-standard rates can be easily added.
CCITT16.ASM Calculates a 16 bit CRC, using the CCITT polynomial of X^16 + X^12 + X^5 + 1. PPP uses this method. Also needs ADCAD.ASM (included in ZIP file).
CRC16.ASM Calculates a 16 bit CRC using the CCITT polynomial of X^16 + X^12 + X^5 + 1, but does it "backwards" from CCITT. XMODEM, YMODEM and ZMODEM protocols use this method. Also needs ADCAD.ASM (included in ZIP file).
CRC8.ASM Calculates a 8 bit CRC, using the CCITT polnomial of X^8 + X^5 + X^4 + 1. Used by Dallas Semiconductor for the 1-wire bus devices.
DS1820.ASM These routines manage up to 8 DS1820 temperature sensors on a port, one DS1820 per port pin. Checks for presense, etc. See code for comments. Also needs MACROS.INC (included in ZIP file).
LCD.ASM General purpose routines for controlling a Hitachi 44100 based LCD (typical 2x16, 2x20, etc). Cursor management, text out from code or data space, etc. Requires LCD_IO.ASM and MACROS.INC (included in ZIP file).
LCD_IO.ASM I/O module for LCD.ASM. Allows easier portability between a debugging and production platform, if different.
MACROS.INC General purpose macro library. Contains compare and jump less than (<), greater than (>), less than or equal (<=), greater than or equal (>=), etc.
SP0_I.ASM This is an interrupt driven serial input and output routine that uses IDATA space for it's buffers. Uses 6 bytes of IDATA for pointers, and 1 BIT variable, plus however many IDATA bytes for the buffer space. Presumes that whichever timer is used for the serial port is already setup.
SP0_X.ASM This is an interrupt driven serial input and output routine that uses XDATA space for it's buffers. Uses 6 bytes of IDATA for pointers, and 1 BIT variable. Requires the ADCAD.ASM file. Presumes that whichever timer is used for the serial port is already setup. Also needs ADCAD.ASM (included in ZIP file).
SP1_I.ASM Same as SP0_I.ASM, except supports the second serial port on the Dallas 80C320 family.
SP1_X.ASM Same as SP0_X.ASM, except supports the second serial port on the Dallas 80C320 family. Also needs ADCAD.ASM (included in ZIP file).
UTIL.ASM A collection of assorted utility routines, including 16-bit math and arithmetic operations, copy function, character validation, etc.