My very first first 8052 BASIC Project

PIC is a nice little chip, but it does have it's limitations. However, there is a relatively cheap way to have a BASIC programmable microcontroller system. Some time in early 80-ies Intel produced a mask-prgrammed 8052 MCU which contained a floating-point Basic interpreter with lots of interesting features, including built-in support for EPROM storage of BASIC programs. There is a plethora of information scattered on the web about this chip, but no one place provides a complete set of instructions to get you started. This project is my attempt to provide just that.

So, first of all, you need a 80C52 or compatible microcontroller. There are several producers, I used Atmel's AT89C52 which is FLASH based, so it can be reprogrammed (as opposed to 80C52 which is OTP part). Any 89C52 or 87C52 part will do fine for experimenting, but if you do not have a programmer for 8051 family of MCU-s, Atmel also has a AT89S8252 (8052 compatible chip with 2K of EEPROM built in) with a serial programming interface which makes building a programmer much easier.

Once you have the controller, you need a board to stick it in. I built mine from scavanged parts and it has serial port, full data and address bus buffering, 32K static RAM and 8K or 16K of EPROM on board. I'm feeding this beast from standard PC power supply, using 12V for EPROM programming directly. National Semiconductor's 12.5V VPP parts seem to program just fine at 12V. Click here to see the schematics.

Bear in mind that this was my first 8052-BASIC project, so the hardware is quite a bit overengineered on some parts while it misses some stuff that should be implemented in other parts. A better, lower chip count and fully implemented 8052-BASIC core is available here.

Just a few short remarks:

Now, once you have the board download the interpreter source and binary code, program the MCU, stick it into socket on your board, hook up the PC with straight modem cable, and power on. Wait a second or two, then press space on the keyboard. If you have everything right, the interpreter will detect the baud rate you are using and output

*MCS-51(tm) BASIC V1.1*

When you get this far, things are looking good. Enter PRINT MTOP at prompt, you should get 32767 if you used 32K RAM. To verify EPROM cicruit, try entering PROG1 at prompt, if you do not get a programming error then you just wrote the baud rate to use into EPROM, and BASIC will not wait for keypress next time you start it. Before going on to literature and references, here are two programs that I wrote, the first of them has proved very valuable.

You will usually work in RAM, but when you try to make a more permanent copy of your code, you enter PROG (or FPROG) at prompt to transfer the code into EPROM. BASIC will give you a sequence number of the program just stored and this number is the only way to refer to the stored program. To improve things, I always write this program into EPROM first:

10     REM Basic ROM directory
20    ADR=8010H : PN=1
30     IF XBY(ADR)<>55H THEN  END
40    ADR=ADR+1 : BA=ADR
50     IF XBY(ADR)=1 THEN  GOTO 80
80     GOSUB 100: PRINT : PN=PN+1 : ADR=ADR+1:   GOTO 30
100    PRINT "PRG",PN,"from ", :  PH1. BA, :  PRINT " to ", :  PH1. ADR,
110    PRINT " (",ADR-BA,"bytes)",

When run, this program lists all programs stored into EPROM by giving code start and end address, length of the code, and most importantly, if the first program line is a comment, it will print out the text after REM keyword. The example output might look something like that:

PRG 1 from  8011H to  8134H (291 bytes) Basic ROM directory
PRG 2 from  8136H to  81CDH (151 bytes) ROM dump

Now, when I power the board on, I just enter RROM 1 and I have a complete listing of all stored programs. Much better. The second useful piece of code is memory dump program:

10 REM ROM dump
20   ADR=8000H
30    PRINT  :  GOSUB 70: PRINT  :  PRINT "More?",
40   A=GET :  IF A=0 THEN  GOTO 40
50    IF A<>27 THEN  GOTO 30
60    END
70    FOR XA=ADR TO ADR+255:  X=XA.AND.0FH:  IF X<>0 THEN  GOTO 90
80    PRINT  :  PH1. XA,
90    PH0. XBY(XA),:  NEXT :  ADR=XA:  RETURN

It starts at 8000H and dumps pages until you press ESC at the prompt. The data is taken from external data memory space, you need to change XBY() to CBY() to read internal ROM, or DBY() to read internal register space.

IDE Interface

While 16K of EPROM is a lot compared to PIC memory space, it is nothing in todays information overload. For serious data logging, and just for fun, here is a schematic drawing for IDE drive interface. If you are willing to waste 50% of the disk space, and stretch the IDE interface specs a bit, you can leave out all IC-s except IC1, and connect LED directly to /DASP line. You will be able to read and write only lower 8 bits of the data words, but otherwise it will work just fine, because all control registers are 8-bit.However, I wanted to access all bytes, so I built extra register to capture high byte of the data word. IC1 decodes IDE command block registers at 0E000H-0E007H, IDE control block registers at 0E008H-0E00FH, and the extra data register at 0E010H.

I am tinkering with a software now, so far I have

As usual, once I got the hardware working and concept proven I lost interest in the project so this is what I have and there is but a very little hope that there will be something more coming under this project..


8052 reference sites

Useful literature

Copyright © Madis Kaal 2000-