Intel MCS-51 SBC on a Cyclone IV FPGA

by mit41301 in Circuits > Computers

53 Views, 0 Favorites, 0 Comments

Intel MCS-51 SBC on a Cyclone IV FPGA

IMG_9516.JPG

For any hobbyist or a student, to learn microcontroller basics and programming requires a demo or developement board. There are many family of devices with different architectures are available. Normally a developement board requires a programmer and a USB-TTL to connect to a PC for downloading and communicating with the target.

This project demonstrates a softcore implemented board. We can see the clear advantages of using a softcore implementation.

We do not have to use the physical CPU, Code ROM and external RAM. All the necessary components can be implemented inside the FPGA using HDL. We can also run the SBC using any desired clock frequency using FPGA's PLL.

Supplies

EP4CE6_Board.JPG

INTEL ALTERA EP4CE6E22C8N FPGA - 1

27MHz oscillator - 1

50MHz oscillator - 1

0603 LED - 8

Switch - 5

EPCS4 Configuration FLASH - 1

CH340C USB-TTL - 1

USB Blaster - 1

Hardware Implementation

50MHz_27MHz.JPG
5_tactile.JPG
AT89S8253_12kB_FLASH.jpg

This project demonstrates the Single Board Computer using 8051 softcore with 12kB ROM and 16kB RAM all implemented inside the Altera Cyclone IV FPGA EP4CE6E22C8N FPGA.

The default program inside the FPGA is BASIC-52 interpreter. It also contains the I2C and SFR extensions which resides above the 8kB. To accomodate the I2C, SFR we have to implement additional 4kB of ROM. This is the reason the SBC having 12kB ROM and not 8kB ROM. The same 12kB FLASH for code is equivalent to using a AT89S8253 microcontroller. AT89S8253 can be operated at a maximum of 6T and still we need external RAM and external Crystal and reset circuits along with external latch to operate as a single board computer.

The board is having 2 oscillators. One at 50 MHz and the other at 27 MHz. We can use either one of them or both of them as we wish. We can operate the Single Board Computer at any desired frequency like 11.059200 MHz, 12MHz, 24MHz,48MHz or 50MHz using available PLL inside the FPGA.

The board also having 5 LEDs, 5 switches, 2 configuration FLASH devices

Software

If we are not going to develop any HDL based projects, then there is no need to download the Intel FPGA Quartus II software. But to program the SOF and JIC files, we need standalone Quartus II programmer. It is better to have the 64 bit supported programmer for windows. Anything above Version 13 will do.

We also need the WCH CH340C driver which can be downloaded from the WCH site.

If we want to use the communication between the PC and SBC, we can install any serial port terminal program such as PuTTy or Tera Term with latest version compatible with our computer.

Application Development

5_LEDs.JPG
janaxelson_idea book.png

For Application program development, we can use any of the Assembler which supports MCS-51 family. We can also use the SDCC compiler using C or Assembly language. There are other C or Assembly language compiler such as Keil, IAR, etc., which may have code size limitation.

ASCIIART.BAS

10 FOR Y=-12 TO 12
20 FOR X=-39 TO 39
30 CA=X*0.0458
40 CB=Y*0.08333
50 A=CA
60 B=CB
70 I=0
80 T=A*A-B*B+CA
90 B=2*A*B+CB
100 A=T
110 IF (A*A+B*B)>4 THEN GOTO 150
120 I=I+1:IF I<=15 THEN GOTO 80
130 PRINT " ",
140 GOTO 170
150 IF I>9 THEN I=I+7
160 PRINT CHR(48+I),
170 NEXT X
180 PRINT
190 NEXT Y

8 running LED (External LEDs)

01 REM 8 LED SHIFT
02 REM SHIFT LEFT AND RIGHT
10 LED = 1
20 IF LED <= 80H THEN PORT1 = 0FFH.XOR.LED ELSE GOTO 1000
30 LED = LED * 2
40 FOR J = 0 TO 999 : NEXT J
50 GOTO 20
900 REM RIGHT SHIFT
1000 LED = 080H
1100 IF LED >= 1 THEN PORT1 = 0FFH.XOR.LED ELSE GOTO 10
1120 LED = LED/2
1130 FOR J = 0 TO 999 : NEXT J
1200 GOTO 1100

5 running LED (Internal LEDs)

01 REM 5 LED SHIFT
02 REM SHIFT LEFT AND RIGHT
10 LED = 1
20 IF LED <= 10H THEN PORT1 = 0FFH.XOR.LED ELSE GOTO 1000
30 LED = LED * 2
40 FOR J = 0 TO 999*3 : NEXT J
50 GOTO 20
900 REM RIGHT SHIFT
1000 LED = 010H
1100 IF LED >= 1 THEN PORT1 = 0FFH.XOR.LED ELSE GOTO 10
1120 LED = LED/2
1130 FOR J = 0 TO 999*3 : NEXT J
1200 GOTO 1100

LED Blink

10 CLOCK 1
20 PORT1=255
30 TIME=0
40 ONTIME 1,100
50 GOTO 50
100 REM TIMER INTERRUPT
110 PORT1=PORT1.XOR.255
120 ONTIME TIME+1,100
130 RETI

The board have 5 LEDs as shown in the above picture. We can either have 8 External LEDs or Internal 5 LEDs. The pin assignments are different and we need to load the corresponding configuration file.

RUN LED

05 N = 1
10 DO
15 REM XBY(8000H)=N
20 PORT1 = N
30 N = N*2
35 GOSUB 60
40 UNTIL N>255
50 GOTO 5
60 FOR I=1 TO 100*10
65 NEXT I
70 RETURN

If we want to learn more about BASIC-52, we should start with the book "The Microcontroller Idea Book"

Circuits, Programs, & Applications featuring the 8052-BASIC Microcontroller by Jan Axelson

There is a free PDF version of the book available from the Jan Axelson author site

There are many example programs available in the book which will give the user insight into power of BASIC-52.

All the programs listed in the book is available for download as a single .ZIP file. We can easily edit and modify and send the file to the microcontroller running BASIC-52 through serial terminal program like PuTTY or Tera Term. We can also find the MCS-51 BASIC-52 user manual and original Ver.1.1 source code at HERE


SOF or JIC File

IMG_9502.JPG

We can load the ready to use configuration files into FPGA. If we load the SOF, the configuration data will be lost or corrupted after power OFF. So if we want a persistent configuration, we should use the JIC file.

The board is having to FLASH devices to store the configuration or data. The EPCS4 is the actual device connected to the FPGA's dedicated pins for automatically load the configuration during powerup. 25Q64 also connected to FPGA I/O pins. To use this we need to write our own program to access the FLASH or we have to use the inbuilt IP for EPCS controller.

The SOF and JIC files can be found HERE

Communication

CH340C.JPG
ON_OFF.JPG

The board has onboard CH340C chip which acts like a USB-TTL bridge. In the HDL coding we just need to assign the Tx and Rx pins to use this IC. After mapping the Rx, Tx we can connect the Type-C cable to PC. Both power and communication are available through the Type-C connector. There is a addition On/Off switch on the board to control the power of the board.

After the configuration is successful, we can establish communication with the SBC using serial port through any serial terminal app similar to PuTTy or Tera Term

In-System Memory Content Editor

The advantage with the Softcore processor is we don't need any programmer to program the application HEX file into the softcore processor. We can use the In-System Memory Content Editor feature of Quartus II to view, monitor the status or change the program using JTAG mode. We can also use the SignalTap for debugging.

Keil C51 and SDCC

The scope of application is not restricted only to BASIC-52. We can also develop using any assembler, Keil C51, SDCC for 8051 etc.,

Just download the HEX file using In-System Memory Content Editor. We have access to both the Program memory and external memory.

Keil C51 LED Flasher

/* BLINKY.C - LED Flasher for the Keil MCBx51 Evaluation Board with 80C51 device*/
#include <REG51F.H>

// When you have enabled the option Stop Program Execution with Serial
// Interrupt, the Monitor-51 uses the serial interrupt of the UART.
// It is therefore required to reserve the memory locations for the interrupt
// vector. You can do this by adding one of the following code lines:

// char code reserve [3] _at_ 0x23; // when using on-chip UART for communication
// char code reserve [3] _at_ 0x3; // when using off-chip UART for communication

void wait (void) { /* wait function */
; /* only to delay for LED flashes */
}

void main (void) {
unsigned int i; /* Delay var */
unsigned char j; /* LED var */

while (1) { /* Loop forever */
for (j=0x01; j< 0x80; j<<=1) { /* Blink LED 0, 1, 2, 3, 4, 5, 6 */
P1 = j; /* Output to LED Port */
for (i = 0; i < 10000; i++) { /* Delay for 10000 Counts */
wait (); /* call wait function */
}
}

for (j=0x80; j> 0x01; j>>=1) { /* Blink LED 6, 5, 4, 3, 2, 1 */
P1 = j; /* Output to LED Port */
for (i = 0; i < 10000; i++) { /* Delay for 10000 Counts */
wait (); /* call wait function */
}
}
}
}