Copyright © mikroElektronika, June 2013. All rights reserved.
TO OUR VALUED CUSTOMERS I want to express my thanks to you for being interested in our products and for having confidence in MikroElektronika. The primary aim of our company is to design and produce high quality electronic products and to constantly improve the performance thereof in order to better suit your needs. Nebojsa Matic General Manager The Atmel name, logo and products names are trademarks of Atmel in the U.S.A and other countries.
Table of Contents 1. Introduction to mikroPascal PRO for 8051 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 04 2. Hardware Connection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 05 3. Creating a New Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 06 Step 1 - Project Settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1. Introduction to mikroPascal PRO for 8051 mikroPascal PRO for 8051 organizes applications into projects consisting of a single project file (file with the .mpp51 extension) and one or more source files (files with the .mpas extension). The mikroPascal PRO for 8051 compiler allows you to manage several projects at a time. Source files can be compiled only if they are part of the project.
2. Hardware Connection Figure 2-1: Hardware connection schematics Let’s make a simple “Hello world” example for the selected microcontroller. First thing embedded programmers usually write is a simple P0.1 P0.4 R7 4K7 LD0 LED P0.0 R3 4K7 P0.2 LED blinking program. So, let’s do that in a few simple lines of Pascal code. P0.3 LD5 LED P0.4 P0.5 P0.5 R8 4K7 LD1 LED P0.1 R4 4K7 P0.6 LD6 LED P0.7 R1 LED blinking is just turning ON and OFF LEDs that are connected to desired PORT pins.
3. Creating a New Project The process of creating a new project is very simple. Select the New Project option from the Project menu as shown below. The New Project Wizard window appears. It can also be opened by clicking the New Project icon from the Project toolbar. The New Project Wizard (Figure 3-1) will guide you through the process of creating a new project. The introductory window of this application contains a list of actions to be performed when creating a new project.
Step 1 - Project Settings First thing we have to do is to specify the general project information. This is done by selecting the target microcontroller, it’s operating clock frequency, and of course - naming our project. This is an important step, because compiler will adjust the internal settings based on this information. Default configuration is already suggested to us at the begining. We will not change the microcontroller, and we will leave the default AT89S8253 as the choice for this project.
Step 1 - Project Settings If you do not want to use the suggested path for storing your new project, you can change the destination folder. In order to do that, follow a simple procedure: 01 Click the Browse button of the Project Settings window to open the Browse for Folder dialog. 02 Select the desired folder to be the destination path for storing your new project files. 03 Click the OK button to confirm your selection and apply the new path.
Step 1 - Project Settings Once we have selected the destination project folder, let’s do the rest of the project settings: 01 01 Enter the name of your project. Since we are going to blink some LEDs, it’s appropriate to call the project “LedBlinking” 02 02 For this demonstration, we will use the default external crystal 10MHz clock. Clock speed depends on your target hardware. However you configure your hardware, make sure to specify the exact clock (Fosc) that the microcontroller is operating at.
Step 2 - Memory model The memory model determines which default memory type will be used for function arguments, automatic variables, and declarations that include no explicit memory type. 01 Since our project is very simple, we will choose the Small memory model. In this model, all variables, by default, reside in the internal data memory of the 8051 system. Variable access in this memory model is very efficient. 01 Select Small memory model. 02 02 Click Next. Figure 3-5: Choose the memory model.
Step 3 - Add files This step allows you to include additional files that you need in your project: some headers or source files that you already wrote, and that you might need in further development. Since we are building a simple application, we won’t be adding any files at this moment. 01 Click Next.
Step 4 - Include Libraries Following step allows you to quickly set whether you want to include all libraries in your project, or not. Even if all libraries are included, they will not consume any memory unless they are explicitely used from within your code. The main advantage of including all libraries is that you will have over 250 functions available for use in your code right away, and visible from Code Assistant [CTRL+Space].
Step 4 - Finishing After all configuration is done, click “Finish” to complete the New Project wizard. You can still go back and change any settings if necessary. 01 Click Finish. 01 Figure 3-8: Finish the New project wizard, or go back and make some changes.
Blank new project created New project is finally created. A new source file called “LedBlinking.mbas” is created and it contains the main: function, which will hold the program. You may notice that project is configured according to the settings done in the New Project Wizard.
4. Code Example Time has come to do some coding. First thing we need to do is to put PORT0 LEDs into initial state. For example, let’s fill it with logic zeros on every pin: // Turn OFF all LEDs on PORT0 P0 := 0; Finally, in a while loop we will toggle the PORT0 value, and put a 1000 ms delay, so the blinking is not too fast. while TRUE do begin // Toggle LEDs on PORT0 P0 := not P0; // Delay 1000 ms Delay_ms(1000); end; LedBlinking.
Figure 4-2: This is how the code looks written in compiler code editor window Page 16
5. Building the Source When we are done writing our first LedBlinking code, we can now build the project and create a .HEX file which can be loaded into our target microcontroller, so we can test the program on real hardware. “Building” includes compilation, linking and optimization which are done automatically. Build your code by clicking on the icon in the main toolbar, or simply go to Build menu and click Build [CTRL+F9]. Message window will report the details of the building process (Figure 5-1).
6. What’s next? More examples mikroPascal PRO for 8051 comes with over 90 examples which demonstrate a variety of features. They represent the best starting point when developing a new project. You will find projects written for mikroElektronika development boards, additional boards, internal MCU modules and other examples. This gives you a head start in development, and you don’t have to do it all from scratch. In most cases, you can combine different simple projects to create a more complex one.
DISCLAIMER All the products owned by MikroElektronika are protected by copyright law and international copyright treaty. Therefore, this manual is to be treated as any other copyright material. No part of this manual, including product and software described herein, may be reproduced, stored in a retrieval system, translated or transmitted in any form or by any means, without the prior written permission of MikroElektronika.
If you want to learn more about our products, please visit our website at www.mikroe.com. If you are experiencing some problems with any of our products or just need additional information, please place your ticket at www.mikroe.com/support/ If you have any questions, comments or business proposals, do not hesitate to contact us at office@mikroe.com Designed by MikroElektronika, June 2013. Creating the first project in mikroPascal for 8051 ver. 1.