Intel 8051 Microcontroller
The basic Intel 8051 Microcontroller consist of 4 Kilobytes of ROM(factory mask programmed), 128 bytes of RAM, Four 8 bit Input/Output ports, two 16 bit timer/counter, Serial interface, 64 Kilobytes external code memory space, 64 Kilobytes external data memory space, Boolean processor (operates on single bits), 210 bit addresable locations. Several companies outsource 8051 and now includes larger memories, Analog to Digital converter, faster clock, lots of I/O, more timer/counters, flash memories, CAN, I2C, special functions, and so on.
When I started programming for the 8051, I use purely assembler and the 8031 version which uses EPROM. I have a IBM XT and an EPROM programmer. I created the file and assemble the file, if there is no error, I burn the hex code in the EPROM (mostly 2764 8 Kilobytes). After burning the EPROM, I plug the EPROM to the socket board, if there is a mistake, I have to erase the EPROM with an ultraviolet lamp then repeat the cycle (edit, assemble, burn, plugged, erase EPROM). Needless to say the EPROM socket on the target PCB starts wearing out very fast. I have several PCB versions of the 8031 from different manufacturers.
I saw a circuit that can overlap the external code and data space by ANDing the RD and PSEN signal. This opens a tremendous opportunity, I no longer burn/erase EPROM and wear out the socket. I can program an EPROM one time to receive data over the serial RS-232 line, write the data to the target board as a data then execute that data as a code. This added only a static RAM to the address map. Now I can easily assemble a program, upload the code to the SRAM, execute and if there is a problem, just reset the board then start over again, no more pulling EPROM from the socket to erase. The monitor program on the 8031 can communicate any Windows terminal program (Procomm, Hyperterminal, etc.)
One of my first board to take advantage of this overlapping code/data space is my own gadget board, this board I wire-wrapped by myself and consist of several IC chips. The SRAM is battery back and when P1.0 bit is grounded, any reset or power cycle, the code in SRAM will execute. Here is the bottom and top view of the board. The CPU is a Philips 80C552, 2x40 memory mapped LCD, 16 keys decoded by a 74C922, relay I/O through ULN2803, stepper motor control through UCN 4202, 32 Kilobytes battery backed Static RAM, DS1287 Dallas Real Time Clock, TIL 311 hexadecimal decoder display, self-oscillator buzzer, 8155 I/O timer chip, 8255 I/O chip, MAX 232 level converter chip. The monitor routine is programmed in assembly including LCD routines (init, clear, jump to 2nd line), acquiring keypress from the 74C922. I later on bought a 'C' compiler from Dunfield and that makes the development even faster. Here is the code to display Hello world to the LCD. You can easily access all I/O peripheral including the clock, stepper motor interface, keypad. I still use this board today for experimenting.
The overlapping code/data space is so successful that I made another wire-wrap board and here is the picture top and bottom. I also modified several commercial board that I bought to accomodate the code/data overlap and here are some of the pictures. The basics of overlapping code/data is here. Eventually I switch to Atmel AVR microcontroller, with flash memory, in-circuit programming, one instruction per cycle.
Picture and source code to drive a Hyundai 256 x 128 dot lcd, includes graphics and text demo. Source code has more documentation and pin-out assignments. Here is the source code in 'C' and here is the picture. Assumes an 8155 Peripheral Input/Output chip is memory mapped to an 8031 microcontroller.
Sony Playstation memory card is normally 1 Mb or 128 Kilobyte of memory, interface is similar to an SPI. Pin assignments are:
- Pin 1 data from memory card
- Pin 2 command data to memory card
- Pin 4 ground
- Pin 5 3.6 volts (use a couple of small diode from 5 volts to drop the voltage down)
- Pin 6 select for memory card active low
- Pin 7 clock
- Pin 9 acknowledge from memory card
Pin 1 orientation is from 2 contacts, 3 contacts, 3 contacts, pin 1 is the 1st of the 2 contacts. Memory organization is 15 block, 64 frame per block, 128 byte per frame. XOR flag includes address pointer, if there is error in write, end flag 0x4E did not write.
Format for write command is:
- Command header 4 bytes (0x81, 0x57 'W', 0x00, 0x00) card responds (don't care 1st byte, 0x00, 0x5A, 0x5D)
- Address pointer for frame 2 bytes (high address, low address) you must include this to the XOR flag plus all data, card responds (0x00, high address)
- Data block 128 bytes, card responds (low addres, data 1 thru 127)
- XOR flag 1 byte, card responds data 128
- End status 2 bytes (0x00, 0x00), card responds (0x5C, 0x5D)
- End flag 1 byte (0x00, 0x00) if data is successfully written card responds (0x47)
- End flag if error 1 byte (0x00) if data is not written card responds (0x4E)
Check the respond from the memory card after end flag to make sure the data is written successfully. Format for read command is :
- Command header 4 bytes (0x81, 0x52 'R', 0x00, 0x00) card responds (don't care 1st byte, 0x00, 0x5A, 0x5D)
- Address pointer for frame 2 bytes (high address, low address) card responds (0x00, 0x00)
- Command response 1 byte (0x00) card responds (0x5C)
- Data header 1 byte (0x00) card responds (0x5D)
- Data address 2 bytes (high address, low address) card responds (high address, low address)
- Data block 128 bytes (0x00 128 times) card responds actual data 1 thru 128
- XOR flag 1 byte (0x00) card responds XOR data
- End flag 1 byte (0x00) card responds 0x47
Here is the code for an 8051 bit bang SPI, tested OK with MadCatz and Sony memory card. Here is the write code and read code. The code is in 'C' with mixture of assembly.
Siteplayer connected to an 80552 microcontroller collecting data for windows and door openings, more information in Java section under languages, here is the code to send UDP packet from site player initiated by the 80552. Data is sent to a Linux box running a UDP server, data collected is added to a database (MySQL) using JDBC with a date time stamp.
One of my 8031 projects is operating a Teac 100 Compact Disc changer through the computer, I opened the front casing of the cd changer and solder wire wrap to each function buttons. I bought a bunch of miniature 5 volt relay from Digi-key and solder the wire wrap from the 100 disc changer. The relay is controlled by a ULN2803 driver chip through a shift register 74LS165. The 74LS165 is controlled by PORT 0 of the 8031, the serial port of the 8031 (UART) is hooked-up to a MAX232 level converter. The serial port is connected to a serial port of a computer and I use Turbo C for the user interface and command. The PC sends command like, CD number and song number, then the 8031 decodes the received character from the serial port, it then translates this character to which relay to trigger. Because the CD changer is operating linearly, the 8031 has to account for time delay from releasing the current disc, the laser head traveling to the new disc and playing the new disc and skipping track to the wanted song. If you are currently playing disc 2 and decided to move to disc 65 then there is quite a bit of time involved.
In 1987 while visiting Children's museum in Boston, I observed a device outside the museum. There is a painted footprint in the walkway and if you step on the painted footprint, a device speaks " You are five feet and eight inches tall ". I was so amazed and tried to find the facts. I ordered a Polaroid ultrasonic and a National Semiconductor Digi-talker. I hooked-up the ultrasonic vertically and when you press a button, the 8031 initiate a pulse and wait for the echo from the transducer. Based on the speed of sound divided by two for round trip pulse I can guess a person's height and use the Digi-talker to say the height in feet and inches. Everybody at work is pretty amazed at this gadget. I found out the measurement is temperature dependent and I added a semi-calibration routine to the device before I used the device for demontration purposes. Here is the picture for the speech synthesizer and sonar range finder.
While stationed at Cape Cod Canal, Sandwich Mass. I designed and implemented a computerized visual Nautical chart. This is featured in the U.S. Coast Guard nationwide magazine "Commandant's Bulletin" September 1991 issue. I wired over 300 LED's over the nautical chart of Cape Cod. The LED's are hooked-up to 8255 I/O chips controlled by an 8031. The board is connected to a computer running a Pascal program.
I experiment a lot with the 8051 device including stepper motors, led, LCD, H-bridge motor controller, Nintendo game pad, Nintendo power glove, Polaroid ultrasonics, line following robot, infrared transmitter/receiver. I also built the kit from Circuit Cellar Inc. gray scale video digitizer transmitter/receiver and the trainable infrared master controller which later on I modify to run the overlap code/data memory configuration. I also experiment with 8751 One time programmable and 8751 EPROM. Most of my experimentation, I ported to the Atmel AVR which is faster and has flash memory and in-circuit program capable.