Copyright mikroElektronika January 2012 All rights

Copyright Mikroelektronika January 2012 All Rights-Free PDF

  • Date:27 Jul 2020
  • Views:10
  • Downloads:0
  • Pages:20
  • Size:2.71 MB

Share Pdf : Copyright Mikroelektronika January 2012 All Rights

Download and Preview : Copyright Mikroelektronika January 2012 All Rights


Report CopyRight/DMCA Form For : Copyright Mikroelektronika January 2012 All Rights


Transcription:

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 Microchip name logo and products names are trademarks of Microchip Technology in the U S A and other countries. Table of Contents,1 Introduction to mikroC PRO for PIC 04. 2 Hardware Connection 05,3 Creating a New Project 06.
Step 1 Project Settings 07,Step 2 Add files 10,Step 3 Include Libraries 11. Step 4 Finishing 12,Blank new project created 13,4 Code Example 14. 5 Building the Source 16,6 Changing Project Settings 17. 7 What s next 18,1 Introduction to mikroC PRO for PIC. mikroC PRO for PIC organizes applications 01,into projects consisting of a single project file.
file with the mcppi extension and one or,more source files files with the c extension 06. The mikroC PRO for PIC compiler allows you 02,to manage several projects at a time Source. files can be compiled only if they are part of,the project. A project file contains,Project name and optional description 05. Target device in use,Device clock,List of the project source files.
Binary files mcl and,Other files,In this reference guide we will create a new. project write code compile it and test the, results The purpose of this project is to make 01 Main Toolbar 04 Messages 07 Project Manger. microcontroller PORTB LEDs blink which will, 02 Code Explorer 05 Code Editor 08 Library Manager. be easy to test,03 Project Settings 06 Image Preview. 2 Hardware Connection Figure 2 1,Hardware connection schematics.
Let s make a simple Hello world example for the, selected microcontroller First thing embedded MCLR RE3 RB7. RA0 RB6 RB4 RB0, programmers usually write is a simple LED blinking RA1 RB5. RA2 RB4 LD5 LD1, program So let s do that in a few simple lines of C RA3 RB3. PIC18F45K22,RB0 LD6 LD2,8MHz SEC RE0 RB0 LED LED,RE1 VCC VCC MCU 4K7 4K7. LED blinking is just turning ON and OFF LEDs that C22 C21 VCC MCU VCC RD7. 22pF 22pF GND RD6 LED, are connected to desired PORT pins In order to see.
RA7 RD5 4K7 4K7, the example in action it is necessary to connect RC0 RC7. the target microcontroller according to schematics RC1. shown on Figure 2 1 In the project we are about, to write we will use only PORTB so you should RD1 RD2. connect the LEDs to PORTB only, Prior to creating a new project it is necessary to do the following. Step 1 Install the compiler Step 2 Start up the compiler. Install the mikroC PRO for PIC compiler from the Product DVD or Double click on the compiler icon in the Start menu or on your desktop. download it from the MikroElektronika website to Start up the mikroC PRO for PIC compiler The mikroC PRO for PIC. IDE Integrated Development Environment will appear on the screen. http www mikroe com eng products view 7 mikroc pro for pic Now you are ready to start creating a new project. 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. Figure 3 1 Introductory window of the New Project Wizard. 01 Click Next,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 PIC18F45K22 as the choice for.
this project, Figure 3 2 You can specify project name path device and clock in the first step. 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 03. selection and apply the new path, Figure 3 3 Change the destination folder using Browse For Folder dialog. Step 1 Project Settings,Once we have selected the destination. project folder let s do the rest of the project,01 Enter the name of your project Since.
we are going to blink some LEDs,it s appropriate to call the project. LedBlinking,02 For this demonstration we will use,the default external crystal 8MHz. clock Clock speed depends on your,target hardware and whether you. are using PLL or not But however you,configure your hardware make sure to 03. specify the exact clock Fosc that the,microcontroller is operating at.
Figure 3 4 Enter project name and change device clock speed if necessary. 03 Click the OK button to proceed,Step 2 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, Figure 3 5 Add existing headers sources or other files if necessary.
Step 3 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 500. functions available for use in your code,right away and visible from Code Assistant.
CTRL Space We will leave this in default,configuration. 01 Make sure to leave Include All,02 Click Next, Figure 3 6 Include all libraries in the project which is a default configuration. Step 4 Finishing,After all configuration is done final step. allows you to do just a bit more,01 There is a check box called Open Edit 01. Project window to set Configuration,bits at the final step Edit Project is.
a specialized window which allows you,to do all the necessary oscillator and. PLL settings as well as to set other,configuration bits We made sure that. everything is described in plain English,so you will be able to do the settings. without having to open the datasheet,Anyway since we are only building a. simple application we will leave it at 02,default configuration HS oscillator with.
PLL disabled Therefore leave the,checkbox unchecked. Figure 3 7 Choose whether to open Edit Project window after dialog closes. 02 Click Finish,Blank new project created,New project is finally created A new source. file called LedBlinking c is created and it,contains the void main function which. will hold the program You may notice that,project is configured according to the settings. done in the New Project Wizard, Figure 3 8 New blank project is created with your configuration.
4 Code Example,Time has come to do some coding First thing. we need to do is to initialize the PORTB to act,LedBlinking c source code. as digital output TRISB register associated,1 void main. with PORTB is used to set whether each pin,2 set PORTB to be digital output. acts as input or output,set PORTB to be digital output 4.
5 Turn OFF LEDs on PORTB,LATB register is used instead of PORTB for. digital output We can now initialize it with,logic zeros on every pin. 9 Toggle LEDs on PORTB,Turn OFF LEDs on PORTB 10 LATB LATB. 12 Delay 1000 ms,Finally in a while loop we will toggle the. 13 Delay ms 1000,PORTB value and put a 1000 ms delay so.
the blinking is not too fast,while 1 16,Toggle LEDs on PORTB. Delay 1000 ms,Delay ms 1000, Figure 4 1 Complete source code of the PORTB LED blinking. Figure 4 2 This is how the code looks,written in compiler code editor window. In this reference guide we will create a new project write code compile it and test the results The purpose of this project is to make microcontroller PORTB LEDs blink which will be easy to test A project file contains Project name and optional description Target device in use Device clock List of the project source files Binary files mcl and Other files

Related Books