International Carpathian Control Conference ICCC’ 2002 MALENOVICE, CZECH REPUBLIC May 27-30, 2002
IMPLEMENTATION OF USER-FRIENDLY PROGRAMMING ENVIRONMENT FOR STANDALONE MICRO-CONTROLLERS Marek BABIUCH Department of Control Systems and Instrumentation, VSB - Technical University of Ostrava, Ostrava, Czech Republic,
[email protected] Abstract: The contribution is dealing with design, developing and implementation of userfriendly environment for standalone micro-controllers especially for Risc PIC family of Microchip micro-controllers. The Reason of decision of this implementation is easy. Users can use for programming micro-controllers only difficult language Assembler or some expensive supporting C compilers. This paper offers solving of this problem. Here is described possibility of user-friendly programming at easier way. There is shown created windows application in this paper. User can use this application for creating assembler source code by simply set up options and mouse clicking on easy understanding offering commands. Key words: micro-controller, PIC, Assembler, programming.
1 Introduction: Properties of stand-alone micro-controllers Microchip is a leading supplier of 8-bit micro-controllers, with one of the broadest product offerings. Products range from 8-pin, 12 bit instruction word to 68-pin, 16-bit instruction word devices. Fast operation, low power and low cost combine to make the Microchip PIC-micro family one of the most popular product lines in the world PIC microcontrollers PIC are suitable for all embedded applications, real time applications, for flexible control, evaluation, peripheral construction, intelligent decoders, drivers, practically. High performance enables their applications in the areas, where they were recently impossible as qualitatively higher replacement of parallel connection, e.g. standard circuits, TTL or small signal box fields. Typical micro-controller family includes wide range of chips with common properties. Advanced (but not especially) chip is an EPROM-based micro-controller with an integrated Analog-to-Digital Converter. This easy to program (only 35 single word instructions) device contains 4096x14 words of program memory, 192 bytes of user RAM and 5 MIPS 471
performance 20MHz. In addition to the 8-channel 8-bit A/D converter, this peripheral-rich device includes Brown-Out-Reset (BOR), Power-On-Reset (POR), three timer/counters, two Capture/Compare/PWM modules and two serial ports. The synchronous Serial Port can be configured as either a 3-wire Serial Peripheral Interface (SPI™) or the 2-wire InterIntegrated Circuit (I2C™) bus. This device also features a Universal Synchronous Asynchronous Receiver Transmitter (USART), which is also known as a Serial Communications Interface (SCI). For example type PIC16C74A has 33 I/O pins with 25mA source/sink per I/O. PIC16C74A fits perfectly in applications from security and remote sensors to appliance control and automotive. Besides the main technical parameters another aspects are essential: • Low cost, market availability. • Quality, cheap and easy design and development means, extensive function libraries and typical application. • Technical and application supports are provided.
2 Micro-controllers Programming Programming micro-controllers is done only in Assembler language by instructions in instruction set. It is necessary to comply with valid rules and programming process. Symbols and variables, space in memory, where the program will be stored, end of the program etc. are defined for an application. Source code will be compiled into hexadecimal form in MPLAB environment and further PICSTART programmer connected to serial port will transfer it into memory of micro-controller. Programming environment enables simulation of the written program in three windows. First window is a Program Memory Window which enables debugging the entire program step by step and at the same time in the other two windows - Special Function Register Window and File Register Window enable monitoring the status of system registers and the status of user defined registers and variables as well. Resulting programmed source code will be compiled into hexadecimal form and with the help of PICSTART PLUS programmer or its equivalent instrument connected to the serial port it will be transferred into memory of standalone micro-controller. Before its execution the type of oscillator must be set (RC,LS,HS, XT), watchdog enabled or disabled, and protected mode for reading selected, etc. Major problem is a fact that we must teach and use relatively difficult Assembler language for any howbeit-easy application. Of course we can use some C compiler available on the market, but those compilers is usually expensive and in additional programming of micro-controller become no way easier.
3 Design and Developing User-friendly environment At the first stage of design is important to summarize all requirements for program generating. User should be led at the same way, as he would proceed with standard programming procedure. But difference must be unique: The program should be generated quickly, simply and easy to understand. User shouldn’t know about some important adjustment, which application generated automatically and which standard assembler programmator solves using by product specification and this also takes a lot of time. 472
Following procedures summarized major sequences for implementation of assembler code generator: • Initial program set-up. • Initial options set-up for chosen micro-controller. • Frame program code generating. • Variables, constant and register declaration. • Interrupt handling ensuring. • Standard command construction generating. • Special command construction generating.
4 Implementation of Assembler Code Generator First step of user work at the application is micro-controller selection. This operation takes only few seconds. But at standard assembler programming user must locate interrupt vector, reset vector, start of the program, allocation of free memory banks and several other steps. User neither knows about these operations in this application. Particular micro-controllers are different exactly in these options.
Fig.1 Initial windows for micro-controllers source code options
473
Another step is setting up the configuration bits, oscillator selection, watchdog options etc. Every procedures are similar with standard way of programming, here is clicked by mouse. Next steps are for programme information: number of version, name of author and typical source code commentary. This information are required together with offering of include file and path selection for generated source code. After these steps we have enough information for generating first code frame. At now we have actual CPU options, reset, interrupt vectors, system registers and user space allocation and other information prepared for another programming. Program variables, which user wants to declare, are stored at free memory space into user memory banks. It is ensured automatically by applications. Different microcontrollers have different memory bank and system registers area. But user shouldn’t worry about this; it’s not his job as special assembler programmator. At figure 1 you can see windows for initial setting of stand-alone micro-controller programming. After generating all procedures describes above we continually stand before mainly source code creating. All is also presented at visual form and we can generate all instructions of micro-controllers. We should only use mouse clicking and variable and register filling. We have possibility to see these instructions at easy understanding form as we know from higher programming languages than assembler.
Fig.2 Application for assembler code generating
474
At the figure 2 you can see window for generating standard instructions of microcontrollers as: arithmetical, logical, byte instruction, rotation, moving registers, conditions and cycles and other routines. At the left text box we you see generated assembler source code. Implemented application also has another windows for source code generating, especially for generating advanced procedures as serial communication, pwm outputs, analogue to digital conversion etc. These operations are based and generated on the similar principle as you can see by standard operations at figure 2.
5 Conclusion Standalone micro-controllers PIC are suitable for all control real-time applications and they've many implementations in equipment, which is able to work by beforehand written program. Wide spectrum of Microchip's micro-controllers enables an easy choice of a concrete type for our requested application. But particular micro-controller families are different from the point of view hardware structures and their programming. In additional user must know assembler language for programming whatever application. This paper describes one way to make it easy. User-friendly environment is one of the most demanding requirements for successfully micro-controller using.
References BABIUCH, M. 2000. Programové vybavení jednočipových mikropočítačů v řídicích systémech. Sborník Workshop ‘2000’ Fakulty strojní, Ostrava, VŠB-TU Ostrava, pp. 7-10. ISBN 80-7078-745-7. MICROCHIP 1999. MPASM USER’S GUIDE, MPLAB USER’S GUIDE, MPSIM USER’S GUIDE. Microchip Technology, 1999. MICROCHIP 2001. Pic Micro Devices. – PIC16C7X Family Datasheets. 2001. Available from: PEROUTKA, O. 1998. Mikrokontroléry PIC 16C7X. Praha, BEN-technická literatura, 1998, ISBN 80 86056-41-4.
475