A Tiny 80(C)32 BASIC Board

A tiny but powerful stand alone BASIC microcomputer, not larger than the size of a
package of cigarettes built entirely from salvaged components, just for fun!

Ronald Dekker


Contents:

If you enjoyed this page, then why not also visit:
SC/MP revisited,
A SC/MP micro-computer with NIBL Tiny-BASIC


Introduction

I undoubtedly inherited my passion for electronics from my father, who in his turn inherited it from his father. As far as I can remember I have been playing with electricity and electronics from my earliest childhood. As mentioned, my father played a very crucial role in this. He stimulated me, mainly by giving the right example, but he never over-stimulated me. Whereas I notice in myself that I have the tendency to make things “too easy” for my own son, my father let me fool around, and only helped me on my own request. Anyway, the help he could offer me was limited to radio tubes and transistors because he never was able to make the transition to the digital area. But that was no problem, fortunately he regularly bought the electronics magazine Elektuur, or Elector as it became known to the rest of the world. Already in the end sixties, beginning seventies Elektuur started to publish projects which used these strange bell shaped symbols. In November 1970 Elektuur published a theme number dedicated to the new digital techniques explaining the basics. A few years later – I must have been thirteen - I “discovered” this old number and for the first time acquainted myself with the “0”s, “1”s and the secrets of those mysterious black building blocks. The next few years I played around with 7403 NANDs (an untested dump package bought by postal order – something quite new in Holland at that time - from ORBIT ELECTRONIC). It was wonderful, no bias points or impedance matching, everything worked from the start in a predictable way!

Again a few years later, a new magazine for electronic hobbyists appeared: ETI (Electronica Top Interbational). This magazine opened with a series of articles on the basics of microprocessors. As a fifteen year old, the possibility of building your own computer absolutely fascinated me. In the mean time the price of 8008 processors had dropped to Fl 25.00, and my father bought me one, again from ORBIT ELECTRONIC. The microcomputer I built around it never worked satisfactory. The timing specifications of the 8008 were very strict, and I was lacking the support chips which normally interface the 8008 to its peripherals. When I look back, I cannot help thinking that it was quite remarkable for a fifteen year old in 1976 to be playing around with microprocessors, considering the fact that the 4004 was only introduced by INTEL five years before, and that virtually nobody in Holland had ever heard about this kind of stuff!

In May 1977 Elektuur published its own micro-processor project. It was based on the SC/MP processor from National. It was a simple beginner’s board that was programmed through dip-switches. I didn’t use the dipswitches but instead programmed the memory through the hardware I had already made for my 8008 based system. It was fabulous! I learned everything I know about micro-processors from it, and the endless debugging, error shooting etc. laid the foundation for my professional career as an engineer. Gradually BASIC programmable micro-computers like the infamous PET and the TRS-80 from Radio Shack were introduced on the market. For years, owning a computer like that was my greatest whish, but (looking back fortunately) they were far beyond our financial means.

In 1979 Elektuur published a BASIC programmable system based on the SC/MP processor. In the next few years I built several systems based on this BASIC interpreter. Most notably was a portable system that used sixteen seven segment displays as readout. This laptop “avant la letre” was BASIC programmable with battery backup and capable of programming 2716/2732/2764/27128 EPROMs. At university I had a friend, Peter Faasse, who was mad about micro-controllers from the INTEL 8048 family. Although I did my best to remain a SC/MP enthousiast, I finally capitulated for the beauty and powers of especially the 80(C)32/80(C)52 series of processors. In 1985 Intel released the 8052AH-BASIC microcontroller which basically was a 8052 controller equipped with the powerful MCS 8052AH basic interpreter in ROM. Compared to anything that was available for the SC/MP at that time, this interpreter was incredibly powerful. It had full floating point mathematical functions and lots of extras. Already in 1987 “Elektuur” published a single board BASIC board configured around the 8052AH-BASIC microcontroller (see cover on the right). Very quickly people managed to copy the internal ROM code to an EPROM so that it wasn’t necessary to buy the expensive and difficult to get 8052AH-BASIC. It was possible to built a minimal system using only a processor, an EPROM, some RAM memory and a few TTL logic ICs and … a terminal. And that was exactly what the problem was in those days. I didn’t have a terminal, and PCs running terminal emulator programs didn’t exist yet. Anyway, it was a time in my life when my interests temporarily shifted from electronics to girls, and for quite a number of years there was very little progress as far as micro-electronics was concerned. However, as far as girls were concerned there was considerable progress, and in 1993 I found myself living together with Marie-José to whom I have now been very happily married for more than twelve years. So after having settled down around 1994, I thought it was time to heat up the old soldering iron, and to realize an old dream by building a small and portable system around the MCS-8052AH BASIC interpreter. The system worked like a dream, and I had great fun with it, but I never came round to decently document it. At the writing of this page I am in hospital for the removal of a tumor of the intestines. Obviously this is a pretty nasty affair, but it gives me plenty of time to do some writing-up that was long overdue.
to top of page back to homepage


The circuit of the Tiny 80(C)32 BASIC board

As explained, the main purpose of the Tiny BASIC board was not to actually make something useful, but just to play around with the MCS 8052AH BASIC interpreter. Since the whole project had to be realized during a Christmas Holiday period, it had to be a minimum design. Figure 1 shows the circuit diagram of the Tiny 80(C)32 BASIC Board. Although the circuit looks far from minimal, it is actually quite simple. The main components are IC1 an 80C32 processor, IC2 a 27C64 (8 kbytes) or 27C256 (32 kbytes) EPROM containing the MCS-8052AH BASIC interpreter and IC3 a 32 kbytes SRAM. The other components are just some logic ICs to “glue” everything together, and of course a MAX232 for interfacing the board to an RS232 port.

Figure 1. Circuit diagram of the “Tiny 80(C)32 BASIC Board.”
Click here, or on the picture to download the circuit diagram in pdf format.


To review the circuit, let’s first start with the processor. The processor runs on an 11.0592MHz crystal. This rather strange frequency allows the 8032 to accurately generate even the highest baudrates. Besides the 80(C)32, which has no on-board ROM, also an 80(C)52 processor with on-board ROM can be used. This type of processors can often been salvaged from old boards. By tying ^EA (External Address, the ^ denotes active low) to ground, the 80(C)52 fetches instructions from the external memory rather then from the internal memory. Jumper J4 can be used to select the internal memory (low) or the external memory (high). In this way also the pin-compatible processors from the P89C51RB2/RC2/RD2 series, with on-board flash memory can be used. When the external program memory is selected, I/O port 2 is used for address bits A8-A15. The lower address bits A0-A7, and the data bits are in that case multiplexed over I/O port 0. The 8-bit latch IC5 is used to de-multiplex the data and the addresses by latching address bits A0-A7 when ALE (Address Latch Enable) becomes high. Port 1 and four bits from port 3 are available for experimenting. Bits 0 and 1 from port 3 are used for serial communications, and a standard circuit using the MAX232 (IC7) is used to bring the signal levels to RS232 levels.

The next part, the memory organization, is also rather straightforward, but not so easy to explain. First of all it should be understood that the memory mapping of the 80(C)32 family of processors does not follow the more common “von Neumann” structure, where the data and code memories share the same memory, but rather the Harvard mapping structure where the code memory is separated and in parallel to the data memory. Consequently, strobes ^RD and ^WR are used to read and write data to memory or peripherals, while strobe ^PSEN (Program Store Enable) is used to read instructions from the program memory. In this board I used a combination of both in the sense that the data memory fills the complete lower 32k and is accessed by means of the ^RD and ^WE strobes. The program memory also starts at address 0000, but is accessed by the ^PSEN strobe. However, when code memory is accessed beyond the physical EPROM size, the code and data memories are overlaid. This trick allows program extensions to be placed and executed from RAM memory (Fig. 2).

Figure 2. The memory mapping of the Tiny 80(C)32 BASIC board is partly von Neumann, partly Harvard.


To explain how all this works, let’s start with the address decoder IC6. This is a 3 to 8 decoder, meaning that when on the three address inputs a binary address is selected, the corresponding decimal output becomes low. Since the three address inputs of IC6 are connected to the three highest address bits, the entire 64k memory is thus subdivided into eight blocks of 8k each. When addresses in the range 0000-1FFF are selected ^Q0 is low, when addresses in the range 2000-3FFF are selected ^Q1 is low etc (Fig. 2). From Fig.1 it is quite easy to see that the upper 32k of the memory are reserved for the optional 28C64 EEPROM, the 512 kbyte CYM1464 SRAM expansion and the I/O expansion slot. More about these extras later.

Figure 3. The Tiny 80(C)32 BASIC board can easily be built on a piece of breadboard.
Click here, or on the picture to view the backside of the PCB.


The lower 32k of the memory are reserved for the program and data memory. I wanted the board to be suitable for both 8k 27C64 EPROMs, as well as 32k 27C256 EPROMs. By setting jumpers J1 and J2 to their correct positions, either one of these EPROMs is selected. Jumper J1 is trivial, it connects pin 27 either to +5V in case of a 27C64 - where this pin is the program input - or to A14 in case of a 27C256. Jumper J2 connects the ^CS (Chip Select) input of the EPROM to the ^Q0 output of IC6 in case an 8k 27C64 EPROM is used. When a 32k 27C256 EPROM is used, the ^CS input of the EPROM is directly connected to A15, which is obviously low when the lower 32k of memory are addressed. The ^OE (Output Enable) input of the EPROM is directly controlled by the ^PSEN (Program Store ENable) output of the processor.

Writing to the RAM memory (IC3) is also straightforward. The RAM is selected as long as A15 is low (the lower 32k of memory). Since the ^WR strobe of the processor is directly connected to the ^WE input of the RAM, a writing operation in the lower 32k directly results in writing into the RAM. Reading from the RAM is a bit more complicated. Nand gates N1 and N2 form an AND gate, so that when either one of the inputs of N2 becomes low, this will result in a read operation from the RAM. One of the inputs of N2 is connected to the ^RD strobe of the processor so that a data read operation will always result in a read from the RAM. The other input of N2 becomes low when both inputs of N3 are high, or in other words during an instruction read operation (^PSEN=low) when the EPROM is not selected (^CE=high). So when the processor tries to fetch instructions beyond the physical memory size of the EPROM code memory, these instructions are fetched from RAM (Fig. 2).

Figure 4. My “quick reference card,” one of the few pieces of documentation I had so far!


The Tiny 80(C)32 BASIC board was built on a piece of breadboard of 10x6.5 cm. I/O expension is available through a connector on the left hand side of the board (Figs. 3 and 4). All I/O extension is mapped into the address space ranging from E000-FFFF (^Q7 from IC7). Since also the ALE strobe is available, it is possible to demultiplex the lowest 8 address bits from the AD0-AD7 lines, resulting in an addressable I/O address space of 256 locations. These locations are addressed as E000-E0FF and then repeat through E100-E1FF etc. etc. The careful reader will have observed that the EEPROM IC4 is not present on the 80(C)32 BASIC board. This is true! IC4 was added at a later stage as a piggy-back option on the SRAM. Read more about the memory options here.
to top of page back to homepage


MCS BASIC-52 Dialects

It is not the purpose of this page to give an in depth discussion of all the ins and outs of MCS BASIC-52 and its dialects. Nevertheless, I would like to give the reader (and myself!) an overview of the most important issues and program versions so that the interested reader can find his way through the available literature. All program versions and relevant literature that I have is available for download.

The original MCS-8052AH BASIC interpreter (the one with the on-board program) was capable of storing a program directly into an EPROM. This was possible because the BASIC interpreter - running in internal ROM memory – could control the I/O ports as required to meet the timing specifications for the programming of the EPROM. With the BASIC interpreter located in external memory, this became impossible, so that the EPROM programming function was lost. However, in version 1.3 this functionality is restored in a very elegant way since this version can program EEPROMs in much the same way as EPROMs

All dialects of MCS BASIC-52 after power up go into into an AUTO-BAUD search routine. By touching the space bar on the terminal (emulator), this routine determines the baud rate and MCS BASIC-52 responds with the sign-on message “MCS-51 BASIC Vx.x*, indicating the version number.

The most important recourse for MCS BASIC-52 is the “MCS BASIC-52 versions 1 & 1.1 OPERATING AND REFERENCE MANUAL” [7]. Although it obviously only covers versions 1.0 and 1.1, it will provide you with 98% of the information you need to work with all versions.

Version 1.0

Version 1.0 of MCS BASIC-52 is very rare. I have never seen it, and I couldn’t find any download version of it on the internet, but I do have a copy of the original V1.0 manual [1]. The frontpage of this manual is dated July 1984, indicating that the writing of MCS BASIC-52 probably covered the best part of 1983 and the first months of 1884.

Version 1.1

Version 1.1 is really the most common version of MCS BASIC-52. It is this version that is described in the “MCS BASIC-52 versions 1 & 1.1 OPERATING AND REFERENCE MANUAL”. According to this manual it is almost completely compatible with version 1.0, apart from some small changes in the handling of the IF_THEN_ELSE statement and the handling of variable names (page 9). Apart from these small changes there are a number of important additions to version 1.1. These additions are extensively listed on pages 10-12. Most important are the addition of six new reset options and the possibility to add user defined commands!

The reset options permit the user to assign the top of memory (MTOP) during reset, and allow the user to write specific RESET programs in assembly. Additionally, they provide an option where the memory will not be cleared during reset (see chapter 11, p145 of the reference manual). Very interestingly, version 1.1 offers the user the possibility to add in a simple but effective way up to sixteen commands and or statements to the ones that are already defined in MCS BASIC-52 (see chapter 12, p152 of the reference manual). For both the reset options, as well as the command extensions the code memory “above” the MCS BASIC-52 interpreter is used starting at 2000H. After start-up MCS BASSIC-52 will check specific memory locations in this area. If it finds specific characters at specific memory locations it knows that certain program extensions have to be activated. If there is no code present in this area, MCS BASIC-52 will execute as version 1.0. All in all these options provide the hobbyist a unique opportunity to interact with the inner workings of the interpreter.

Around 1990 INTEL released the source code of MCS BASIC-52. It consisted of two parts: a package with the floating point routines and the actual interpreter. This source could however not directly be assembled into a hex file. D. Wulf first merged the two parts and provided many relative jumps and calls without label with a suitable label. Also pieces of code which were implemented with data statements were replaced by the appropriate mnemonics [6]. The resulting source file assembles into an INTEL HEX file that one-to-one matches the code in the 8052-AH BASIC.

Figure 5. log-on message of MCS BASIC-52 version 1.1 + “ego-message”


Figure 5 shows the log-on message of version 1.1. Also shown is the so called “ego-message”. A joke of the creator of the program, John Katausky. When on the command line ctrl-W ctrl-C is typed (by Hyperterminal representated by the strange arrow), the name of John is displayed!

Version 1.1+

Already quite early several bugs in version 1.1 were identified. In an article in Elektuur, D. Mudric and Z. Stojsavljevic identified a number of errors in the floating point routines (examples A-E in Appendix B) [5]. For the errors in the substraction routine and in the HEX-to-BCD conversion routines, they published a patch that can be implemented directly by modifying the ROM code (Fig. 6)

Figure 6. Patches proposed by D. Mudric and Z. Stojsavljevic to correct the error in the substraction routine
and to optimize the HEX-to-BCD conversion routine [5].


The patches do not cover the rounding errors in the multiplication routines (examples C-E in Appendix B). I never bothered to implement the patches, but for completeness sake it is mentioned here.

Version 1.2a

Version 1.2a is very interesting because if allows MCS BASIC-52 to run on an 8031/8051 processor. The 8031/8051 processor is the smaller version of the 8032/8052 pair; the 8031/8051 only has 128 bytes of internal RAM memory and has two 16-bit timers instead of three. So why bother to put so much effort in making a special 8031/8051 version, when a standard 80(C)32 processor costs less than 2 Euro? Well, that was not always the case. I remember from when I studied that it was much easier to lay my hands on a surplus 8031 processor then on an 8032. Anyway, I do not know what Dan Karmann’s motivation was to create version 1.2a, but he sure did a great job!

Figure 7. Log-on and “ego” messages of version 1.2a


In the program documentation of version 1.2a, Dan Karmann gives a detailed list of all the modifications and improvements he made to MCS BASIC-52 to make it run on a 8051. Most notably all the statements related to timer 2 have been disabled, while timer 1 is time-shared to function as a baud-rate generator, and as the timing device for the PWM statement. Due to the smaller internal RAM in the 8031/8051, the INTERNAL STACK is defaulted to 51 bytes instead of the 179 bytes in the 8052. This may cause some programs to generate an "ERROR: I-STACK". This is typically caused by too many nested levels of parenthesis "()", and can usually be made to work by breaking the expression into several less complex expressions. In addition a number of the “known bugs” in version 1.1 were corrected (Appendix B).

The source code of version 1.2a is not available, but the INTEL hex file can be downloaded here!

Version 1.3

Undoubtedly the best version of MCS BASIC-52 available is version 1.3. It was created by H.-J. Böhling and D. Wulf, and first published in Elektuur in February 2001 [6]. Apart from the article in Elektuur, the website of H.-J. Böhling is a great source of information on version 1.3. and many other useful enhancements and tools! The most important improvements and enhancements of version 1.3 are listed below:

The source code of version 1.3 is a valuable resource on all the modifications and additions that were implemented. H.-J. Böhling was kind enough to offer it to for download on this page. The assembled INTEL hex file of version 1.3 can be downloaded here.

Figure 8. Log-on message of version 1.3. Note that the “ego-message” had to be sacrificed.


H.-J. Böhling also developed several other very useful tools. Very interesting is the terminal emulator Terminal-MCS-51. This terminal emulator not only enables the user to communicate with MCS BASIC-52, but also allows for downloading and uploading of files, and renumber BASIC programs! Terminal-MCS-51 runs under DOS, or in a DOS emulation window under WINDOWS, provided that you have a suitable COM port. Terminal-MCS-51 may be downloaded here or from the website of the author.

Another very useful tool is a set of MCS BASIC-52 command extensions which allow for an easy interfacing of MCS BASIC-52 with I2C bus devices. As explained, the command extansion software is placed in the code memory space immediately above the interpreter starting at 2000H (see chapter 12, p152 of the reference manual). In total six new commands have been added to the MCS BASIC-52 command set: I2CSTART (sends a start condition to the I2C bus), I2CSTOP (sends a stop condition to the I2C bus), I2CPUT(value) (sends a byte to the I2C bus) and I2CGET(variable) (receives a byte from the I2C bus). The last two commands are not related to the I2C bus, but allow for the reading and writing of data from and to arbitrary Special Function Registers. The command extension software is available for download here or from the website of the author.
to top of page back to homepage


3D Integration!

When the Tiny BASIC board first worked I obviously felt very happy, but as soon as the euphoric feeling subsided a bit, I found that the board was a bit too small! The first thing I wanted to add was a X28C64 EEPROM – of course salvaged from an old computer board – to try the EEPROM programming option created by H.-J. Böhling for MCS BASIC-52 V1.3. Since there was no room on the board itself anymore, the only way to go was up! It appeared quite simple to place the X28C64 “piggyback” on the 62256 RAM (Fig. 9D). The ^CE pin was the only one pin that needed an additional connection. This could easily be solved with a wire that is connected to a connector on the board. The same applied to a MK48Z02 “zeropower” SRAM that I found somewhere (Fig. 9C). These “zeropower” SRAMs were popular for a brief period in the eighties. They consist of an SRAM with a piggyback Lithium battery so that the data would be retained even if the supply voltage was switched off. The battery could not be switched off, but a battery life of at least 11 years was guaranteed. When I tested the device some 15 years ago the battery was still ok.

Figure 9. The four 3D memory towers for the Tiny BASIC board. A) the 27C4001 EPROM adapter B) the 62256(32k SRAM)-CYM1664(512k SRAM)-X28C64(8k EEPROM) tower C) the 62256-MZ48Z02 (zeropower)and C) 62256-X28C64 piggybacks.



Slightly more interesting is the memory-tower. It started when I found a discarded video processing board at work which contained a batch of CYM1664 512x8 kbyte multichip SRAM modules. In 1994 a 512 kbyte SRAM was enormous, I just had to try it on the Tiny BASIC board and of course also the EEPROM had to be included as well.

Figure 10. The memory-tower comprising 32 kbyte SRAM working memory (bottom), address latch (on PCB), 512 SRAM extended memory and 8 kbyte EEPROM (top). Click here or on the picture to view more pictures of the memory-tower.



Figure 10 shows how the memories were stacked. The 512k SRAM was subdivided into 64 blocks of 8 Kbyte each. Each block of 8 Kbyte is directly addressable at A000H-BFFFH. A latch holds the 6 bits which are needed to select one of the 64 blocks. The latch is addressed by writing the 6 bits code to an address in the address space C000H-DFFFH.

Figure 11. The EPROM adapter. A rotary BCD encoder selects one out of sixteen 32 Kbyte blocks from a 27C4001 EPROM.



To be able to play with the different versions of MCS BASIC-52, I first had a set of EPROMs each one with a different version, or different set of command extensions. After a while however, I got tired of replacing the EPROMs every time and I constructed the EPROM adapter depicted in Fig. 11. The 27C4001 is a 512 Kbyte EPROM which is subdivided into sixteen blocks of 32 Kbytes each. Every block contains a different BASIC version or a different command extension set. A miniature rotary BCD encoder is used to select one of the blocks. The BCD encoder is constructed in such a way that the switches are all closed when it is set to zero. A block is selected by setting the rotary encoder in the proper position while pressing the reset button.
to top of page back to homepage


IO expansion board

The purpose of the IO expansion board was mainly to play around with the I2C command extensions designed by H.-J. Böhling (also see the section on version 1.3), and to do some simple communication with port 1. Figure 12 depicts the circuit diagram of the IO expansion board.

Figure 12. Click here or on the picture to download a circuit diagram in pdf format.


Resistors R22-R29 pull-up port 1 to a high level when it is used as input. Resistors R1-R8 are low enough to pull an input of port 1 to a low level when one of the switches SW0-SW7 is closed, but high enough not to seriously load the port when the port is used as output. For both sets of resistors a SIL (Single In Line) resistor array was used. Both in input mode, as well as in output mode the status of port 1 is monitored by eight LEDs which are buffered by a 74HCT540. The sound which can be generated with the PWM statement in MCS BASIC-52 can be made audible by a small piezo beeper connected to port 1.2.

Figure 13. Front- and Backside of the IO expansion board.



The basic I2C interface only limits the voltages on the I2C lines to the supply voltage of +5V. The PCF8583 (yes, again salvaged from an old circuit board) which is included on the board, is a real time clock with alarm and 240 bytes of RAM. An interesting device, which is ideal for experimenting with the I2C bus. A lithium battery is used to power the PCF8583 when the supply voltage is disconnected.

Figure 14. This simple program illustrates the use of the I2C command extensions.
The program writes 064H to memory location 040H in a PCF8583, and then reads this location.

There are plenty of sites that give a good explanation of the I2C protocol. The datasheet of the PCF8583 also gives a good overview of the I2C protocol. Interfacing MCS BASIC-52 with the I2C bus using the command extension module that was developed by H.-J. Böhling, is very easy. The command extension module adds four new commands to the MCS BASIC-52 instruction set: I2CSTART, I2CSTOP, I2CPUT(), I2CGET . Figure 14 shows the use of these commands in a very simple program. The program writes the value 064H (decimal 100) to RAM location 040H, and then reads this location again. Writing data to the PCF8583 starts by issuing a start condition (line 10). Next the master (the processor) transmits the I2C address of the PCF8583 which is 0A0H. Bit 0 of this address always indicates whether the next byte is going to be written to (bit0=0 so address becomes 0A0H), or read from (bit=1 so address becomes 0A1H) the slave device (the PCF8583 in this case). In this case we write, so the address becomes 0A0H. After the address, the memory location, and the data are written to the PCF8583 an I2CSTOP terminates the writing operation. Reading from the PCF8583 again starts by issuing the device address. Since we first have to write the memory location to the PCF8583, we specify the “write address” 0A0H (line 90). By issuing a second I2CSTART condition and the “read address” 0A1H, the PCF8583 is switched to read mode. The byte is read in line 130. An I2CSTOP command again terminates the read sequence.

Figure 15. The 80(C)32 Tiny BASIC board with all bells and whistles mounted.

to top of page back to homepage


Appendix A: Setting-up “Hyperterminal” for MCS BASIC-52

There are many terminal emulators that are suitable for communicating with the BASIC board, however, since “Hyperterminal” is supplied with WINDOWS it is a first obvious choice. As with all Microsoft stuff I had some difficulty to get it working, so to save you – and myself in the future – the trouble, here are some directions to get it working.

Figure A1. Setting-up Hyperterminal for communication with the BASIC board.


The Hyperterminal program can be found under: Programs > Accessories > Communications > Hyperterminal
After starting the program, it will first ask for a “Connection Description” (Fig. A1-A). Enter a suitable name like “8032” and select an appropriate icon and then click OK. Next the “Connect To” windows pops up (Fig. A1-B). Select either the COM1 or the COM3 port depending on which port you are using or have installed. After clicking OK, the “COM1 Properties” window pops up (Fig. A1-C). The highest baudrate that my COM port could handle was 115200 baud, and even at this baud rate there was a flawless communication between the PC and the BASIC board. However, I would recommend that at a first try a safer baudrate of 19200 is used. Select the other properties as shown in Fig. A1-C. Especially make sure to select Flow control “None”. I have no idea what this does, but selecting one of the other options does not work. By clicking OK the link is established.

Figure A2. In the File>Properties>Settings window it is possible to select what character(s)
Hyperterminal will send when the Backspace key is pressed.


The line editor functions of MCS BASIC-52 are very minimal and basically limited to back-spacing. As backspace character, MCS BASIC-52 expects a RUBOUT or DELETE character (7FH). This is not Hyperterminal’s default character. To select the proper backspace code, open the properties window by clicking: File > Properties >Settings. When this window has opened (Fig. A2) select “Backspace key sends”: Del. Click ok, and save the configuration.
to top of page back to homepage


Appendix B: Bugs in MCS BASIC-52

The original MCS BASIC-52 has quite a few bugs. A number of these bugs are related to the possibility to extend the program code of MCS BASIC-52 with additional commands and data. An extensive list of these bugs and their solutions can be found in the documentation of version 1.2a by Dan Karmann and in the assembly listing of version 1.3 by H.-J. Böhling and D. Wulf. In an article in Elektuur in 1992 D. Mudric and Z. Stojsavljevic described a number of imperfections in the mathematical routines of MCS BASIC-52, along with some simple test programs to illustrate these imperfections[5]. In this section the examples given in Elektuur have been repeated.

The small errors in the examples above originate from an bug in the substraction routine. In [5] a simple bug-fix is suggested that can be implemented by simply changing some bytes in the original version 1.1 code (version 1.1+).


The result of all three program examples above should have been the error message: ERROR: ARITH. UNDERFLOW – IN LINE 30. For example D and E version 1.3 indeed produces this error message. Example C however, even fails in this latest version.


The next bug is a curious one. In the original version the interpreter deleted the f from any variable name ending by an f, fp, fpr, fpro that was followed by a space. Example F illustrates this bug. The operator asc() should return the ASCII value of that character. For characters a-z,0-9 this operator functions perfectly, however, for characters +,-,*,/,<,=,>, and ? the operator asc() returns not the ASCII value, but the value of the TOKEN which represents the symbol internally. A simple test is PRINT CHR(ASC(“character”)) which should return the character itself (Example G).


In the original version of MCS BASIC-52 it was not possible to reset the value of the variable TIME. The small program in Example H illustrates this problem. In the program, we want to measure (in 5 milliseconds increments) the execution time of the FOR-NEXT loop in line 40. In the two examples given in Example H the program is executed directly after a power-up. First variable TIME is reset to zero. In both versions it is indeed zero, but this is not due to the statement in line 10, but because the variable is cleared on power-up. Next we start incrementing TIME every 5 ms in line 30, and we stop incrementing it in line 50. We see that the execution of the FOR-NEXT loop takes about 0.1 sec. Observe next that in the original version it is not possible to reset TIME! Even a new RUN command will not clear TIME.


In the table the performance of the four MCS BASIC-52 versions discussed on this page is compared.
to top of page back to homepage


Appendix C: Running MCS BASIC-52 on a P89C51RB2/P89C51RC2/P89C51RD2 processor

At some point I salvaged some P89C51RD2 processors from Philips Semiconductors (now NXP) from some discarded circuit boards. The P89C51RB2/P89C51RC2/P89C51RD2 line of processors is fantastic. The largest member of the family has no less than 64 Kbytes of on-board flash memory and 1 Kbyte of Extended RAM. It appeared quite simple to run MCS BASCI-52 from the internal flash memory. The programming of the P89C51RD2 processor is reasonably straight forward, but it does involve sending some awkward strings of symbols to the processor since the programming commands are based on an extension of the INTEL hex format. On my page In Circuit Programming for the P89C51Rx2 you can read all the details of programming these processors, here I will limit myself to a step-by-step instruction of how to load MCS BASIC-52 into the flash memory, mainly to document the process for myself.

Figure C1. The Tiny BASIC board in program mode.



Jumper J3 and J4 (Fig. 1) were not part of the original Tiny BASIC board, but were added later to facilitate on-board programming of the P89C51RD2+. During normal operation with a standard 80(C)32 with external memory, jumper J3 is not placed and jumper J4 is placed in the external memory position. To bring a P89C51RD2+ in the programming mode certain conditions on certain pins have to be satisfied. The process of bringing the processor in the program mode starts by pushing the reset button. While holding the reset button pressed (!) ^PSEN is forced to 0V (by placing J3), and jumper J4 is removed so that ^EA can be tied directly to +12V (Fig. C1)! After these operations the reset button can be released. The P89C51RD2+ is now in program mode.

Figure C2. The isp command window.



The details of programming the P89C51RD2+ can be found in In-circuit and in-application programming of the 89C51Rx+/Rx2/66x Processors. Although programming the P89C51RD2+ is really rather straight forward, it does involve sending some INTEL hex like string commands including the check sum. Especially the checksum makes it difficult to improvise these strings. That is the reason why I wrote the small terminal emulator program “isp”. A detailed description of “isp” can be found on my page about isp. The only thing that I can add here is that, although the isp tool was developed in QBASIC on an old DOS system, it also worked perfectly on my new DELL Laptop!

Careful reading of the datasheet of the P89C51RD2+ revealed that by default, the processor uses the internal extended RAM memory instead of any externally added RAM. To force the processor to use the external RAM memory, it is necessary to set bit “EXTRAM” in the “AUXR#” registed (direct address 8EH). To do this we make use of one of the reset options of MCS BASIC-52 V1.1. Immediately after startup MCS BASIC-52 will examine code memory location 2001H. When it finds character 0AAH in that location, MCS BASIC-52 will first call external code memory location 2090H where the user may place special routine which needs to be executed on startup (p. 147 of the reference manual). In this case a small piece of code (“89C51.hex”) which just sets bit EXTRAM. This patch, as well as all the other software needed to load MCS BASIC-52 V1.3 into the P89C51RD2 can be downloaded here.

To conclude (and mainly for myself) a recapitulation of all the steps to go through to load the P89C51RD2 with the BASIC interpreter:

The P89C51RD2 has now successfully entered the program mode and is ready to accept the program:

Next the patch can be loaded:

To remove the processor from program mode and to test the program:

If everything if ok, MCS BASIC-52 will log-on as normal (Fig. C3)

Figure C3. MCS BASIC V1p3 successfully loaded into the P89C51RD2

to top of page back to homepage


Appendic D:Emulating MCS BASIC-52!

If you are not a hardware oriented person, or just only want to play around with the MCS BASIC-52 interpreter without having to build the hardware, there is a solution! In 1992 Werner Hennig-Roleff wrote SIM51D, a simulator for the 8051/8052 line of processors. This simulator is actually very extensive and I used it myself in the past to debug pieces of assembler when I got absolutely stuck. It has one major drawback, the program and the documentation are in German! Living in Holland I fortunately know enough German to be able to work with it, but I can imagine that this is a bit more complicated for the rest of the world.

As a demonstration of the power of his simulator, Werner included a demonstration how his SIM51D is able to completely emulate MCS BASIC-52 including an emulation of a terminal. The program runs under DOS, but can also be started from a Command Prompt Window under Windows. The shareware version of SIM51D and several other necessary files can be downloaded here.

Figure D1. Starting SIM51D from the Command Prompt


To run SIM51D create a directory SIM51D in the root of your hard-disk (this saves you a lot of time navigating through directory structures from the command prompt). Unpack the SIM51D_BASIC.zip in this directory. Open a Command Prompt window and navigate the prompt into the directory. To start SIM51D, and at the same time automatically execute the commands to load the BASIC interpreter (BASIC51.ABS) and to select the proper simulation environment settings, it is sufficient to issue the command: SIM51D @BASIC52.KEY (Fig. D1). Note the space in between SIM51D and @BASIC52.KEY!

Figure D2. SIM51D in action simulating MCS BASIC-52


For the shareware version of SIM51D you have to press return a number of times and watch the commercials in between before the program starts. When it starts it automatically initializes the simulation environment end loads MCS BASIC-52 (version 1.1). By hitting the terminal emulator in SIM51D displays the familiar log-on message (Fig. D2). Just as with the real MCS BASIC-52 it is now possible to enter a program and run it. Surprisingly the emulator running on a modern laptop is just a fragment slower than the interpreter running on a 11.0592MHz 80(C)32 processor! The program window of SIM52 displays the part of the program that is being executed and some of the most important registers. In this simulation mode the program window is not continuously updated. Continuous updating of the program window is possible by starting the program with: SIM51D @BASIC52F.KEY. Arend Postma brought the latest version of SIM51D to my attention. It is Freeware and does not contain the annoying delays. I did not personally test it yet.
to top of page back to homepage


Appendix E: Interfacing with an LCD display

It is absolutely not the intention to give a complete overview of all the ins and outs of LCD displays. There are plenty of excellent sites which deal with this topic extensively [10]. In this section I will limit myself to those details which are relevant for this project. First a bit on the basics of LCD displays. Most LCD displays are based on the HD44780 LCD controller from Hitachi and therefore more or less operate in the same way. The display has an eight bit databus (four bits is also supported) and uses three control signals R/W, RS and E. A low on R/W indicates a write operation while a high indicates a read operation. A low on RS indicates a character data read/write operation, while a high signals the writing or reading of a command. The actual read/write operation is performed during E=1. Beware that the HD44780 is quite slow, so be sure to follow the timing specifications given in the datasheet.

Figure E1. This simple board interfaces the Tiny BASIC board
to an DMC20434 OPTREX display.


A small interface board to connect the LCD display to the port1/port3 expansion slot was made. The board was designed to interface to a DMC20434 OPTREX display. The interface board additionally contains three LEDs which signal the status of the three control lines. Note that the enable line E is inverted. The reason for this is simple. When the processor is initialized, all ports are configured as inputs. Since we use pull-up resistors, this means that all the pins, including E, would become “1”, so that the display would be activated. By inverting E this is prevented. Obviously E now becomes and “active low” signal.

Figure E2. Example showing how AND and OR operations are used to modify
only certain bits of port3 to issue a “write data command” to the display.


The BASIC program LCD.LIS was written to test the LCD display. It was written for MCS BASIC-52 V1.3 and uses the command extensions module written by H.-J. Böhling. The program itself is pretty straightforward and consists of three parts. In the first part (lines 10-170) the display is initialized. This part of the program is messy. Many of the lines are not required but are just there to allow for experimenting. Most important is the initialization code 030H which defines the data bus as eight bits. The second part (lines 180-1310) generates a menu that allows the user to enter directly LCD commands. The final part consists of a set of subroutines which actually communicate with the display: 9000-9060 write a command, 9100-9160 read a command, 9200-9260 write data, 9300-9350 read data, 9405-9440 wait until busy flag is clear, 10000-10010 wait loop. The LCD display is controlled by the bits of port3. Since some of the other bits of port3 are used for other purposes (e.g. serial communications) we have to be a bit carful with writing to port3 from the BASIC program. Figure E2 illustrates how AND and OR commands are used to issue a write data command to the display without modifying the other bits.

Figure E3. The Tiny BASIC board interfaced to a DMC20434 OPTREX display.


When the display is first turned on, it should display alternating black and blank lines. Starting LCD.LIS should clear the display. Text can now be entered. By pressing the “Escape” key, the program displays a simple menu. From this menu a command code can be entered directly.
to top of page back to homepage


Appendix F: The EPROM switch

This is the strangest tool that was made for the Tiny BASIC board. It was designed to ease the development and testing of command extensions. By activating the EPROM switch, we can make the Tiny BASIC board think that instead of a 32k EPROM, a 8K EPROM is used. The idea is that during command code programming special instructions can be used which reside in the 32k EPROM. The command extensions are then programmed in the upper 24k of the RAM with address starting from 2000H. When the switch is activated the upper 24k of EPROM code memory are replaced by RAM. In that way the new command extensions can be tested.

Figure F1. Circuit diagram of the EPROM switch.


The circuit of the EPROM switch is quite simple. FF1 is used as a simple set-reset flip-flop to debounce the push-button S1. So every time S1 is pressed there is one nice clean 0->1 transistion on the Q output of FF1. FF2 is used as a toggle flip-flop. So on every 0->1 transition FF2 toggles. C1, D1 and R5 take care that FF2 is reset (Q=0) on power-up. LED D2 lights up to indicate that the EPROM switch is active (8k EPROM space selected).

Figure F2. The EPROM switch connected to the Tiny BASIC board. Note that normally the EPROM switched would be used in combination with a 32k EPROM!


The output of N3 is connected to the ^CE input of the EPROM, and subsequently to the circuit around N1-N4 (on the Tiny BASIC board) that activates the RAM when the code memory is accessed. The output of N3 becomes low when either input of N3 becomes 1. N2 makes sure that the EPROM is always selected when the lower 8k of code space is addressed. N1 additionally selects the EPROM for the complete lower 32k of code space, but only if output Q of FF2 is low. To activate the EPROM switch it is not necessary to press the reset button.
to top of page back to homepage


Download Summary

The unofficial history of the 8051 by Jan Waclawek
The MCS BASIC52 Operating and Reference manual
Elektuur February 2001 “MCS BASIC-52 V1.3” (Dutch)
Elektuur November 1992 “Upgrade for MCS BASIC V1.1” (Dutch)
Elektuur May 1987 “Controlling LCD displays” (Dutch)
In-circuit, In-application programming of the 89C51Rx+ microcontrollers.
PCF8583 Real time clock/calendar + RAM with I2C interface datasheet
The circuit diagram of the 80(C)32 Tiny BASIC board
The circuit diagram of the IOadapter
MCS BASIC-52 V1.1 Original assembler file as released by INTEL
MCS BASIC-52 V1.1 Assembler file edited by H.-J. Böhling and D. Wulf
MCS BASIC-52 V1.1 INTEL HEX file.
Documentation of MCS BASIC-52 V1.2
MCS BASIC-52 V1.2 For 8031 processors INTEL HEX file.
MCS BASIC-52 V1.3 Assembler code written by H.-J. Böhling and D. Wulf
MCS BASIC-52 V1.3 INTEL Hex file
LCD.LIS, a small BASIC program that can be used to test an LCD display.
All the stuff you need to program MCS BASIC-52 in a 89C51Rx+.
I2C command extension module written by H.-J. Böhling
Terminal emulator written by H.-J. Böhling. Allows for uploading and downloading of BASIC files!
8051/8052 simulator written by Werner Hennig-Roleff. Runs MCS BASIC-52 on a PC!
8051/8052 simulator written by Werner Hennig-Roleff. Runs MCS BASIC-52 on a PC! Latest and Free version.
to top of page back to homepage


Acknowledgements

I would like to thank Peter Faasse, Hans-Jürgen Böhling, D. Wulf, Arend Postma and Werner Hennig-Roleff for their highly valued contributions.



References and web-links


[1] John Katausky, “MCS BASIC-52 USERS MANUAL,” INTEL Corporation 1984, Order Number: 270010-001
[2] ”8052-BASIC Computerboard,” Elektuur, november 1987, pp. 38-44
[3] “BASIC-Computerboard in CMOS,” januari 1990, pp. 76-79
[4] E. Vermeulen, “ROM-copy,” Elektuur, september 1990, pp. 8081
[5] D. Mudric and Z. Stojsavljevic, “Verbeteringen in MCS-51 BASIC V.1.1,” Elektuur, februari 1992, pp. 74-77
[6] H.-J. Böhling and D. Wulf, “MCS BASIC-52 V1.3,” Elektuur februari 2001, pp.28-31.
[7] John Katausky, “MCS BASIC-52 versions 1 & 1.1 OPERATING AND REFERENCE MANUAL,” INTEL Corporation 1986.
[8] Website of H.-J. Böhling: http://home.arcor.de/h.boehling/80c32.htm
[9] A useful site on the I2C interface: http://www.esacademy.com/faq/i2c/general/i2cproto.htm
[10] A useful site on the interfacing of LCD displays to microcontrollers: http://www.8051projects.net/lcd-interfacing/


to top of page back to homepage


In Conclusion

I immensely enjoyed writing this page. It was an old project, and it was great fun to discover what I had been up to more than a decade ago. It helped me through a difficult period.

The complete family!