Logic analyser/ Digital storage oscilloscope with the 89S8252

A series on the 8051 microcontroller family is starting with this month's section. Specifically, the 89S8252 will be used, whose main attraction is the on-chip 1,000 times serially reprogrammable flash memory (8 kbytes). Other features include a 57,600 bps UART, 3 sixteen bit timers, 9 interrupts, dual data pointer, 2k of EEPROM, watchdog timer, code protection (read is prohibited) and low power mode.

The chip provides 0.5 MIPS of processing power and a maximum rate of 57,600 bps for the UART in mode 1 if an 11.059 MHz crystal is connected to it. There are four 8-bit ports, but 2.25 are taken up by the external memory interface. In fact, all pins but power, and the crystal connections serve a dual purpose. The site can think of many applications which will only require sequential access to the external RAM, therefore freeing one of the ports. However, I must confess I have never needed more than two ports for any project so far.

There are several application boards, and you can get one ready made, too, but details of the development system actually built are here: A 6264 8kbyte memory was used instead of the 62256 (they are pin compatible for the signals required by the former) and the LCD was omitted, but otherwise it is much the same board.

The board did not present any difficulties: If you omit some of the connectors, and assuming you did not get a plated through pcb, you still need to fit some vias so that the corresponding connections are made. Moreover, an external device cannot be driving the P1 port during flash programming, can it? Ergo, the project should work first time.

Simple logic analyser/ DSO

A simple logic analyser project (or digital storage oscilloscope), the site thinks, will show most 8051 features. That includes ports, timers, the UART, interrupts, external RAM and data pointer. A port pin is configured as an input by writing a logic 1 to it- and this is the default state at power-on. (There is a short delay between writing the value and the corresponding voltage actually appearing on the pin). The external interrupt, Int0, is triggered by a negative edge at P3.2; the port value is captured, stored into external memory and the data pointer advanced until the memory is filled. It is very easy to modify the program so the last 8,192 samples prior to some event are recorded, which will more likely be useful for faultfinding.

The data is then moved to the computer by the serial link at 57,600 bps, after you press the P3.3 push button. Why should you have to do this? Sampling may take place a long way from the computer, and therefore a long serial cable is unnecessary. Alternatively, you could wait for the PC to send a serial message, before transmission of data commences. Here are all the programs for this project.

The PC will abort reception on getting a Control-Z character (26 decimal), and there are two ways around this: You either transmit data as two hex digits, which doubles the time, or replace number 26 by a 6 byte sequence which is unlikely to appear naturally. This has worked so far, and if occasionally the computer does not close the serially received file, the DOS console window is closed, and the file seems to be in place afterwards.

For some projects, the design time can be a few minutes, with a microcontroller (unlike procuring a PCB). The result is cheaper than a commercial device, and the microcontroller flash can be reprogrammed for many projects. Alternatively, a one-time programmable device may be obtained at a lower cost. However, the maximum speed is disappointing at about 100,000 samples per second for the 11 MHz crystal. The memory available will be filled very soon at that rate.

Some people say they are using the 89S8252 at 24 MHz, though reliable operation may only be available for a short time, and not under general conditions. In any case, the DS89C420 provides 33 Mips- and then some. Some care is needed though, since the devices are backwards compatible with the 8051 (obviously excluding the timing of commands), but not entirely between themselves. If you are concerned your code should be immediately portable to another 8051 variant, you must not exploit the special features of later chips.

The memory should really have been driven by two 8-bit counters, like the 74LS393, and then a (much simpler) microcontroller is only needed for control and communications with the PC. Actually, if your code can cope with the different versions of parallel ports available, you don't need a microcontroller at all. The site will get back to this project.

A possible testing circuit

If you are in for debugging delights, the test programs included in the file to download should help: Port test provides audible frequencies of 14 kHz at P0.0 and P1.0 and P2.0 and P3.0, 7 kHz at P0.1 and so on, assuming an 11 MHz crystal. You can listen to them on a high impedance earphone, in series with a 470 Ohm safety resistor. ( As P0 is open collector, a 4.7k resistor connected to power will also be needed for this one). A test of the serial flash programming interface is therefore provided by this program, as well as some confidence the 89S8252 is functional. If it fails, you will want to check that power is supplied to the chip, the crystal is properly connected, and the serial interface. It is not necessary to fit the latch and memory for this test.

A memory test is implemented (for A8 to A14) by producing audible frequencies of 220 Hz at P1.0, 110 Hz at P1.1 and so on, as the memory is filled with an incremental pattern. For A0 to A7 the frequencies are 2.5 kHz at P1.0, 1.25 kHz at P1.1 and so forth. If you miss one of the tones, the corresponding address line is suspected, while both tones missing probably point to the datapath around the latch or memory. For example, at my first try I did not get the 2.5 kHz tone, revealing a cold joint at A0.

The last test is for the user (not flash programming) serial port: The personal computer is set at 57,600 bps, eight data bits and no parity, while the DSR and CTS sensitivity must be defeated (see the capture.bat file). A text file is sent from the PC, which is longer than 8,192 bytes, and you get just those bytes back after you press the P3.3 pushbutton.

You will need microflash.exe for serially reprogramming the flash memory. (It is rather discomforting that there is no obvious verification message, but the board certainly seems to be doing what it is told). While the package includes Tasm, the table driven assembler, it seems to be shareware. On the other hand, here is a freeware 8051 compiler (alternate ftp site). You can go a long way simply by cutting and pasting other programmers' code, but if you are developing anything substantial, you will find a free 8051 simulator useful. (It also needs 8051.dll). If you want to know more about the 89S8252, you will need a datasheet. Some of the material (like timers and the UART) is omitted, being virtually unchanged from the 8051 datasheet.

External links were checked at the time of writing, but the site assumes no responsibility for them in the future.

For my own code: Valid XHTML 1.0!
1