Web server on a 8051 microcontroller

December 26, 2011

Release    hardware www    Reading time: 3 minutes

A couple of years ago it was rather fashionable to create a web server in a microcontroller, most often in a Microchip PIC 16F84 microcontroller. The latter has been chosen because of easy programmability, I surmise. But each implementation had at least one thing about it I disliked: one used a preprocessor to translate web page contents to TCP/IP packet payloads, which required one additional step before compiling, another one used an external EEPROM for storage of the said contents; a third one did not have an external EEPROM, but had much less than 1 kb for web page data storage. Besides, almost all of them had been written in assembler. These implementations impressed me, but they did not have enough appeal for being rebuilt.

All of a sudden, seeing easily programmable 8051 clones from Atmel, which had between 16 and 64 kb flash memory and (as all 8051-based microcontrollers have) a hardware UART, I decided to implement a minimal web server by myself, choosing C as the appropriate programming language. This can be seen as an experiment in compatiblity, both in hardware, because the resulting web server runs on any 8051 clone with enough program memory and in software, because it might be ported to any architecture, for which a C compiler exists. The first of the mentioned implementations, Miniweb, appeared to be a good starting point before the discovery that fixed TCP/IP packets made it somewhat inflexible. Another implementation, phpstack, by the same author, came as the main inspiration instead. The results are packed into  this repository.

Much information about the development, as well as the BSD license, under which this web server implementation is published, reside in the file Readme.txt. Working with the 8051 architecture meant to stick with SDCC. The development was conducted under Windows; instead of using a building utility such as make, two DOS batch files were used, c.bat for compilation and conversion of the resulting file to the programmable Intel HEX format and c-clean.bat for cleaning the directory.

The server communicates over a SLIP connexion (therefore you will need a serial port), using the address, communicating with 2400 bps at clock frequency of 12 MHz, or 4800 bps at 24 MHz. Internally, the server uses the standard 8051 UART and Timer1 to generate correct timings for the UART. The most basic, characters only, connexion, resides in the file pingpong.c. It answers the input ping with pong (it just translates an i to o, echoing all other characters back), hence the naming of all source files, as all implementations are expected to answer reactively to the input.

Next higher implementation, SLIP only, is implemented in the file slippong.c. An implementation using IP is in the file ippong.c. It also implements ICMP, so from this implementation on, you may ping the server and receive answers. TCP is added in the file tcppong.c. The final implementation is in the file httppong.c. The file httppong.hex contains ready-to-flash firmware, working at the aforementioned IP address with the aforementioned parameters. The implementation uses 76 bytes of RAM and (with current HTML data) 2950 bytes of ROM. To reduce usage of RAM, banking techniques of the 8051 were employed.

Useful data is in the array welcomepage, which was placed in ROM. Update this array with new data. Recompile. Flash. Use.

comments powered by Disqus