More code examples are in the new 8051 Wiki. You can post your code-snippets there too. Comments can go to the 8051-Guestbook
From the maintainer of the mailing list (Date: Mon, 3 Feb 1997 17:24:04 -0600):
The 8051 Source Code Mailing List is now open for business. To post your 8051 assembly, C, Basic, Forth, PL/M-51, or any other type of source code to this list, send e-mail to 8051code@keil.com. To join the list, send email majordomo@keil.com and subscribe to the 8051code mailing list. Best regards, Jon Ward Keil Software <jonw@keil.com>And pay attention to the message limit of 100kByte:
Hello there, This is just a quick reminder that the maximum message length for the 8051code list server is 100K bytes. Messages longer than this get bounced. If you have messages (code or whatever) that are longer than this, split them into smaller chunks. Thanks, Jon Wardihex.zip dump code in Intel HEX to serial port, A51, by squest@cris.com (Steve J. Quest)
This program will dump a block of program code to the 8051 serial port in Intel HEX format. It was a quick and nasty hack to fulfill a need, however it includes a good checksum calculation routine, which is nice. For simplicity, this program dumps Intel HEX in 16 byte strings only. Usually, this is not a problem, as I used this code typically for dumping HEX to be disassembled. It is assumed that the serial port is preconfigured.iserial.zip interrupt driven serial I/O, Keil C51, by jonw@keil.com (Jon Ward)
This group of functions implements serial I/O that is interrupt-driven. The code was compiled using the Keil C51 compiler but will probably work with any commercial 8051 C compiler. The transmit and receive buffers are 256 bytes long and are stored in XDATA. You must call com_initialize (12000000); to initialize the com routines. The 12000000 specifies the clock frequency of your CPU. This is necessary for baudrate calculations.bin2bcd.zip long to bcd conversion, A51, useable by C51, by fmayr@electronic.tu-graz.ac.at (Friedrich Mayr)
The purpose of the code is to convert a signed long value to BCD - code with leading sign if needed. Values exceeding the range of 6(-:5) Digits should all be displayed by '-'. The usage of memory was critical because no external RAM is present in the system, so only the Accu, B, R1, R2, R3, R4 are used aside of the digit- (and argument-) buffer "U_b".bin2asc.zip converts 4 Bit Binary To ASCII-HEX, Avocet AVA51, by jcwren@atlanta.com (John Wren)
Converts a binary value in Acc to a ASCII printable character, i.e. a bit value 0x00..0x0f, to 0x30..0x39 (0-9), or 0x41..0x4f (A..F).charlcd.zip LCD-driver for Hitachi HD44100/HD44780, Avocet AVA51, by jcwren@atlanta.com (John C. Wren)
Here's an LCD driver package that supports the 1x16 and 2x16 LCDs that use the standard Hitachi HD44100/HD44780 controller series.crc8.zip CCITT-8 CRC, Avocet AVA51, by jcwren@atlanta.com (John C. Wren)
Here's a CCITT-8 CRC calculator. The source contains both the calculated (smaller but slower) version, and the table driven (faster but larger) version.crc16.zip CCITT-16 CRC, Avocet AVA51, by jcwren@atlanta.com (John C. Wren)
Here's a CCITT-16 CRC calculator. The source contains both the calculated (smaller but slower) version, and the table driven (faster but larger) version.autobaud.zip auto baudrate detection, Avocet AVA51, by jcwren@atlanta.com (John C. Wren)
Here's a routine that will autobaud on the serial port. It will handle 150 to 19200 baud, and 38400 can be added easily by modifying the table.cmd.zip command interpreter for the serial port, Keil C51, by jonw@keil.com (Jon Ward)
Here is an example program written in C for the Keil C51 compiler (it probably works with other compilers) that receives variable length strings from the 8051 serial port, compares the string to a list of commands, and performs some action based on the comparison. This works with the interrupt driven serial port code that I sent to the list server earlier this week. There are several sections to this and it's not completely trivial, so I'll dummy up part of a main function to show how it all works.iserial1.zip interrupt driven serial I/O, xdata buffer, 8031, Avocet AVA51, by jcwren@atlanta.com (John C. Wren)
Here's a interrupt driven serial port driver for a generic 8031. It uses external memory for the buffers, which can be up to 255 bytes. The routine assumes that Timer 1 or Timer 2 has already been setup to the appropriate mode and rate. Currently, the serial port is setup for Mode 1, which is what's used for the 8/N/1 format.iserial2.zip interrupt driven serial I/O, COM1, xdata buffer, DS80C320, Avocet AVA51, by jcwren@atlanta.com (John C. Wren)
Here's a interrupt driven serial port driver for a Dallas 80C320 using the second serial port. It uses external memory for the buffers, which can be up to 255 bytes. The routine assumes that Timer 0 or Timer 2 has already been setup to the appropriate mode and rate. Currently, the serial port is setup for Mode 1, which is what's used for the 8/N/1 format.iserial3.zip interrupt driven serial I/O, idata buffer, 8031, Avocet AVA51, by jcwren@atlanta.com (John C. Wren)
Here's a interrupt driven serial port driver for a generic 8031. It uses internal memory for the buffers, which can be up however much space is left over in internal memory after the stack and the remainder of the program. The routine assumes that Timer 1 or Timer 2 has already been setup to the appropriate mode and rate. Currently, the serial port is setup for Mode 1, which is what's used for the 8/N/1 format.iserial4.zip interrupt driven serial I/O, COM1, idata buffer, DS80C320, Avocet AVA51, by jcwren@atlanta.com (John C. Wren)
Here's a interrupt driven serial port driver for a Dallas 80C320 using the second serial port. It uses internal memory for the buffers, which can be up to whatever space is left over after the stack and other internal variables. The routine assumes that Timer 0 or Timer 2 has already been setup to the appropriate mode and rate. Currently, the serial port is setup for Mode 1, which is what's used for the 8/N/1 format.nvm.zip routines for 2 wire NVM using IIC-Bus (I²C-Bus), Avocet AVA51, by jcwren@atlanta.com (John C. Wren)
Here's a group of routines to support a Xicor 24C16 (2Kx8) Serial NVRAM, and compatible parts. The databook says it ought to work with the smaller parts, but I've not tried them.delocal.zip DOS-executable to strip PROCs and local labels from code written by John, by jcwren@atlanta.com (John C. Wren)
Here's a utility I wrote this morning to strip PROCs and local labels from the code I posted earlier this month. Usage help can be displayed with the 'DELOCAL -?' invocationutils01.zip routines, Avocet AVA51, by jcwren@atlanta.com (John C. Wren)
UTIL_ADCAD - Add Acc to DPTR, sets CY UTIL_ADCBAD - Add B/A to DPTR, sets CY UTIL_SUBBAD - Subtracts Acc from DPTR, sets CY UTIL_SUBBBAD - Subtracts B/A from DTPR, sets CY UTIL_INC16 - Increments 16 bit location in IRAM UTIL_UCOMPARE16 - Compares DPTR to 16 bit IRAM value UTIL_UCMPDPTRBA - Compares DPTR to B/A UTIL_SHIFT4L - Shfts a 16 bit IRAM value 4 bits left UTIL_LDDPTRC - Load DPTR from (DPTR) ROM UTIL_LDDPTRD - Load DPTR from (DPTR) XRAM UTIL_STDPTRD - Store R6/7 to (DPTR) XRAM UTIL_DPTRR01 - Exchange R0/1 <-> DPTR UTIL_DPTRR67 - Exchange R6/7 <-> DPTR UTIL_DPTR2C - 2s complelment DPTR UTIL_DPTRDEC - DPTR = DPTR - 1, sets CY UTIL_DPTRASR1 - Arithmetic shift right DPTR UTIL_DPTRSHR1 - Shift DPTR right UTIL_DPTRROL4 - Rotate DPTR left 4 UTIL_DPTRSHL4 - Shift DPTR left UTIL_R3R7RL4 - Shift R3/4/5/6/7 4 bits left UTIL_DPTRX10 - DPTR = DPTR * 10 UTIL_DPTRX100 - DPTR = DPTR * 100 UTIL_DPTRX1000 - DPTR = DPTR * 1000 UTIL_CALLFUNC - Call function DPTR points to UTIL_TOLOWER - Convert Acc to lowercase UTIL_TOUPPER - Convert Acc to uppercase UTIL_HEXTOBIN - Convert ACSII hex to binary UTIL_DECTOBIN - Convert ASCII decimal to binary UTIL_BCDTOBIN - Convert BCD to binary UTIL_ASC36TOBIN - Convert base 36 value to binary UTIL_BINTOASC - Convert binary to ASCII UTIL_BINTOASC36 - Convert binary to ASCII base 36 UTIL_BINTOBCD - Convert 8 bit binary to BCD UTIL_BINTOBCD12 - Convert 12 bit binary to BCD UTIL_BINTODEC - Convert DPTR to signed string UTIL_BINTOUDEC - Convert DPTR to unsigned string UTIL_VALDCDG - Validate Acc for ASCII decimal UTIL_VALHXDG - Validate Acc for ASCII hex UTIL_VALALPHA - Validate Acc for A..Z, a..z, 0..9 UTIL_VALALPHAZ - Validate string for A..Z, a..z, 0..9 UTIL_CNTDG - Count ASCII decimal in string UTIL_UDIV - Unsigned divide UTIL_UMOD - Unsigned mod UTIL_DIV - Signed divide UTIL_MOD - Signed mod UTIL_COPYXTOI - Copy XRAM to IRAM, length UTIL_COPYITOX - Copy IRAM to XRAM, length UTIL_COPYCTODL - Copy ROM to XRAM, length UTIL_COPYCTODZ - Copy ROM to XRAM, string UTIL_COPYDTODL - Copy XRAM to XRAM, length UTIL_COPYDTODZ - Copy XRAM to XRAM, string UTIL_PUT_ETX - Replace 0x00 with ETX in string UTIL_FIND_ETX - Locate ETX in string UTIL_TRIM - Remove trailing spaces UTIL_STRLEN - Return length of stringds1820.zip Simple DS1820 temperature sensor routines, Avocet AVA51, by jcwren@atlanta.com (John C. Wren)
Here's some code to drive the Dallas DS1820 One-wire temperature sensors. It's designed to handle 8 sensors connected to one port. If you only need one sensor, it's pretty easy to carve out the code you need. This code does *not* take advantage of the method Dallas has for putting a number of devices on the same wire. There are several inherent problems with this method, such as enumeration of devices, device location, the fact that the ID number is not printed on the part, heavy recursion is needed to indentify more than a couple of devices, etc.bitstuff.zip Discussion of bitstuffing, ASM, by ccslist@ewol.com (Brent Pollock)
Seeking ASM code for extract 5 bits from 16 bit word.External links refering to this page