RSS Feed Email Facebook Twitter Stumbleupon Google Bookmark

Compilers For 8051 Microcontrollers

By Igor Funa

8051 Microcontrollers: An Applications Based Introduction

Most computers in use today are embedded in some electronic device, from appliances to mobile devices. Such computers are called embedded systems. A key component in embedded system is a microcontroller. This is a microprocessor with emphasis on I/O operations. The role of microcontroller is to control electronic devices providing all necessary switching, measurements and communication with the world. Microcontroller is the brain of the device.

The first microcontrollers emerged in 1970s. They were 8-bit devices capable of running a program from internal ROM or external EEPROM memory. One of the popular microcontrollers was Intel 8051. Intel developed a family of microcontrollers named MCS-51, where 8051 was probably the most popular member. It is amazing that this architecture is still popular today. There are many manufacturers like Atmel, Silicon Labs and NXP that still use the 8051 core for their microcontrollers. This means that all the tools that were developed thirty years ago can, at least in theory, be still used today to develop programs for 8051-compatible microcontrollers.

The 8051 family of microcontrollers is special because it has many types of memory that need special instructions to access it. The basic memory is located in the DATA segment and most instructions can access it. The size of this memory segment is 256 bytes. The upper 128 bytes are reserved for Special Function Registers, memory mapped registers that control functions of the microcontroller. The lower half is divided into three parts. Addresses from 0 to 31 are memory addresses for registers R0 to R7 in 4 register banks (0 to 3). Addresses from 32 to 127 are general purpose memory locations with additional function of addresses from 32 to 47 which are also bit-addressable. Most 8051 microcontrollers (except the original 8051 microcontroller) have also additional 128 bytes of IDATA memory which is similar to DATA memory but can only be accessed indirectly. It is located at addresses from 128 to 255. Special instructions are needed for this type of memory. 8051 microcontrollers support also external memory located at XDATA segment. Its size is 64kB and can be accessed only indirectly with few special instructions. There is also a special bit-addressable memory where you can access individual bits (256 bits in total). The first half of this bit-addressable memory is general purpose memory while the upper half maps to bit-addressable special function registers.

This complicated memory model makes compiler construction a complicated task. But because the 8051 microcontrollers were well accepted in industry and they are also present in many hobby projects, quite a lot of companies decided to develop their own 8051 compiler. There are many commercial C compilers for 8051 microcontrollers available. Most of them are part of some commercial package together with integrated development environment (IDE), debugger and simulator. Among those the Keil IDE/compiler is probably the most popular. There is also one popular and free C compiler SDCC (Small Device C Compiler). SDCC is a retargettable, optimizing ANSI - C compiler that targets the Intel 8051, Maxim 80DS390, Zilog Z80 and the Motorola 68HC08 based microcontrollers. SDCC is Free Open Source Software, distributed under GNU General Public License (GPL).

The other hemisphere in 8051 programming is Pascal. Pascal programming language was designed by Niklaus Wirth in late 1960s. Its main purpose was to teach programming. The language itself is focused on structured programming and has many constructs for data structures. Borland Turbo Pascal was probably one of the most successful Pascal compilers around. It was very popular in 1980s and early 1990s. Its successor was Borland Delphi which is a visual rapid application development tool still in use today. Pascal is rarely used in embedded programming although there are compilers available also for AVR, ARM and PIC microcontrollers.

There is probably only one commercial Pascal compiler for 8051 microcontrollers, the KSC Pascal51. This clearly shows the market of C and Pascal compilers. However, there is also Turbo51, a free Pascal compiler for 8051 microcontrollers. Turbo51 is a fast single pass optimizing compiler with Borland Turbo Pascal 7 syntax and advanced multi-pass optimizer.

Similar situation is also with other popular microcontroller families like AVR, ARM and PIC. A plethora of C compilers are available and only a few Pascal or Basic compilers. Of course, we should not count assembly language compilers. These are the basic compilers for every processor or microcontroller. The most important thing with compilers is the code they generate. This should be highly optimized for size and speed. Comparing the code size of a program written for the same task in SDCC and in Turbo51 we can conclude that the result is not dependent on programming language. Either C or Pascal can be used to create a compact and optimized code. It is just the personal preference of the programmer what language he will use.

It is very interesting to compare generated code for some particular C or Pascal instruction, e.g. for 8051 microcontroller. We get practically the same microcontroller instructions. This is another confirmation that high level language is only a tool to describe the algorithm. It is the task of an optimizing compiler to generate individual microcontroller instructions that do what is needed.

Microcontroller market will continue to grow. One of the most important markets for microcontrollers is the automotive industry. It is the a driving force in the microcontroller market, especially at it's high end. Many microcontrollers were developed specifically for automotive applications. On the other hand almost every electrical device from toys to appliances uses some form of embedded system. The conclusion is that with microcontroller market growing also the need for high-quality embedded compilers will grow. This will lead to better compilers that will generate faster and more optimized code.

About The Author
Igor Funa is a hobby programmer interested in computers, Pascal programming language, broadcasting, transmitting sites, DVB-T, and physics in general. If you are programming for 8051 microcontrollers and like Pascal programming language then you should check Pascal compiler for 8051 microcontrollers. Article Source: EzineArticles.com.

See Also:


blog comments powered by Disqus