Presentation is loading. Please wait.

Presentation is loading. Please wait.

EEE527 Embedded Systems Lecture 3: Chapter 1: Using MPLAB (X) + XC32 Ian McCrumRoom 5B18, Tel: 90 366364 voice mail on 6 th ring

Similar presentations


Presentation on theme: "EEE527 Embedded Systems Lecture 3: Chapter 1: Using MPLAB (X) + XC32 Ian McCrumRoom 5B18, Tel: 90 366364 voice mail on 6 th ring"— Presentation transcript:

1 EEE527 Embedded Systems Lecture 3: Chapter 1: Using MPLAB (X) + XC32 Ian McCrumRoom 5B18, Tel: 90 366364 voice mail on 6 th ring Email: IJ.McCrum@Ulster.ac.uk Web site: http://www.eej.ulst.ac.ukIJ.McCrum@Ulster.ac.ukhttp://www.eej.ulst.ac.uk 24/09/13 "Adapted from the text “Programming 32-bit Microcontrollers in C – Exploring the PIC32, © 2008.” Lucio di Jasio www.eej.ulster.ac.uk/~ian/modules/EEE527/files

2 The Plan The first project with MPLAB IDE – The project window – The editor – The output window A first statement A first complete program – Controlling I/Os: Ports and Pins Building the project Using the MPLAB SIM simulator The first debugging experience Hello World!

3 Preparation The following tools will be used in this lesson: MPLAB X IDE, Integrated Development Environment (use version X not v8.xx ) MPLAB SIM, free software simulator (included in MPLAB installation) MPLAB XC32, C compiler (free Student Edition) The following pieces of documentation will be used during this lesson: PIC32MX1XX/2XX datasheet Section 11. I/O Ports – DS61118E You will also need individual sections of the PIC32 Family reference manual Sections 12 i/o ports (DS61120E.pdf) Section 17 ADC (DS61104E.pdf) Make sure they are available and/or installed and ready to use on your computer. You can download them from me or the Microchip web site at: http://www.microchip.com/ http://www.microchip.com/ DESIGN SUPPORT->Reference Manuals, search for “PIC32 Family” DESIGN SUPPORT->Datasheets, search for “PIC32MX250F128B” DESIGN SUPPORT->Compilers tab

4 The New Project Set Up Launch MPLAB IDE Follow the “New Project Set Up” Checklist to create a new project using the Project Wizard

5 The New Project Setup Checklist 1.Select Microchip Embedded – Standalone Project 2.Select the PIC32MX250F128B device and click Next. 3.Select Simulator as the Tool to be used 4.Select the XC32 C-Compiler and click Next 5.Use a Project Name of Hello and click the Browse button and create a new folder named “EEE527” on DRIVE D: 6.Create a folder below this called “Hello” 7.Accept the default project folder “Hello.X”, then click Next. 8.Click on Finish to complete the project set up

6 The Windows (note the tabs as well! Familiarize yourself with the Windows (Tile) layout of MPLAB X.

7 You can reset to this view using the Windows top-level menu (Alt-W)

8 To add a new file to your project Do one of the following; Go to the Projects tab (top RHS of screen) and rightclick on “Source Files” Click on the New File ICON (1 st on icon toolbar) Use the main FILE ->New File menu Use the shortcut.

9 Choose a C main file

10 Name it main.c

11 Make sure you have main.c in these two places

12 Add the line #include below the other #includes. Find this file and open it using F)ile->Open File… (c:\Program Files\Microchip\xc32\pic32-libs\include) It refers to./proc/p32mx250f128b.h open it as well You will need to refer to this file, and to the datasheet to resolve exact names of registers and bits.

13 I/O PINS I/O pins can be configured as: – Digital Inputs – Digital Ouputs (Push Pull) – Digital Outputs (Open Drain) – Analog Inputs – Dedicated inputs or outputs for a number of peripherals – Pins to interface to programmers (PICKIT or JTAG)

14

15 PORTA and PORTB Different PORTs group pins with different functions PORTB for example contains a number of pins that can be configured as analog inputs to the Analog to Digital Converter (ADC). PORTA contains a number of pins that can be used for the JTAG interface, TRACE function, and the I2C interface Refer to the specific device datasheet for a detailed list of each PORT/pin capabilities

16

17 TRIS registers TRIS registers control the direction of each pin (Input/Output) TRISA, TRISB… each port has a corresponding tris register – Setting a bit to 1 configures a pin as Input – Clearing a bit to 0 configure the corresponding pin as an output

18

19

20 Microchip have renamed ANSEL to ADxPCFG in some CPUs

21 Therefore to use PORT B for simple I/O we must disable the ANALOG functions available on those pins. Similarly to use PORT A for simple I/O we must disable JTAG functionality There are other subtle points such as using the CHANGE registers associated with I/O pins – but the powerup defaults are ok in this case. Also a lot of peripherals can be switched to (almost) any PINs so we will need to look at “PERIPHERAL PIN SELECT” (PPS) at some stage, but, for now, the defaults are ok.

22 /* * File: main.c * Author: ian * * Created on 24 September 2013, 10:02 */ #include /* * */ int main(int argc, char** argv) { TRISB = 0; // all PORTB as output AD1PCFG = 0x0000; // all PORTB as digital PORTB = 0xff; return (EXIT_SUCCESS); } Edit your main.c to…

23 The Watch Window  Once a debugging tool (MPLAB SIM) is selected  Open the Watch Window  To inspect the content of a variable (symbol) or any of the special function registers (SFR)  Select the desired output format(s) The “NEW WATCH” under “DEBUG” top menu

24 Compiling and Linking A compiler transforms the C source code (.c) and all included (.h) files into a relocatable code object (.o) The linker takes all the relocatable code objects (.o) and libraries (.lib) and assembles them into an executable (.hex) file BUILD PROJECT to compile >>

25 Using the Simulator Learn the basic debugging options offered by the Simulator – Reset – Single Step (Over/In) – Animation – Running – Halting

26 Debugging: Hello World Set Watchpoints on PORTA and PORTB, set breakpoints on the pink lines and use DEBUG to singlestep and observe the ports change Lookup JTAGEN and AD1PCFG in both xc.h and the datasheets. Note in some pics AD1PCFG is changed to ANSELB

27 Analog Pin Functions Multiplexing The Analog Pins control: AD1PCFG

28 Summary In this lesson we learned: How to create a new project How to create our first C source file How to build a project using the MPLAB C32 compiler About PINs and PORTs How to configure and control simple digital output pins How to configure and use the MPLAB SIM simulator

29 Advanced Material

30 The Disassembly Window If you want to see what happens at the machine instruction level: – Open the disassembly window

31 The Memory Gauge If you want to see how much memory RAM and FLASH is being used by the project Look at the memory guage in the dashboard

32 Notes for the PIC MCU Experts The PIC32 PORTS are not necessarily 32-bit large. In fact most PORTS are 16-bit at the most. The PIC32 PORTS are designed to be compatible with the 8-bit and 16-bit PIC PORTS I/O PORT control in C is easy Use the LATx registers to control directly the output latches

33 Tips and Tricks Interfacing to 5V input and output signals is possible with some caution: – Digital Input pins are 5V tolerant – Digital Output pins can be configured as Open Drain – Use the ODCx registers to configure an output pin for Open Drain mode. – Watch Out! Pins that are multiplexed with analog functions are NOT 5V tolerant!

34 Suggested Excercises If you have the Explorer16 board and an in circuit debugger: – Use the MPLAB REAL ICE Debugging or the MPLAB ICD2 Debugging checklists to help you prepare the project for debugging. – Insert the instructions required to disable the JTAG port. – Test the PortA example, connecting the Explorer16 board and checking the visual output on LED0-7. If you have the PIC32 Starter Kit: – Use the PIC32 Starter Kit Debugging checklist to help you prepare the project for debugging. – Modify the code to operate on PortD, but do NOT disable the JTAG port. – Test the code by checking the visual output on LED0-2 on the PIC32 Starter Kit itself. In both cases you can: – Test the PortB example by connecting a voltmeter (or DMM) to pin RB0, if you can identify it on your board, and watching the needle move, between 0 and 3.3V, as you single step through the code.

35 Recommended Readings Kernighan, B. & Ritchie, D. The C Programming Language Prentice-Hall, Englewood Cliffs, NJ When you read or hear a programmer talk about the “K&R” … they mean this book! Also known as “the white book”, the C language has evolved quite a bit since the first edition was published in 1978! The second edition (1988) includes the more recent ANSI C standard definitions of the language The MPLAB C32 compiler adheres to the ISO/IEC 9899:1990 (also known as C90) standard

36 Online Resources http://en.wikibooks.org/wiki/C_Programming This is a Wiki-book on C programming and as such it is a bit of a work in progress. It’s convenient if you don’t mind doing all your reading online. Hint: look for the chapter called “A taste of C” to find the omnipresent “Hello World!” example.


Download ppt "EEE527 Embedded Systems Lecture 3: Chapter 1: Using MPLAB (X) + XC32 Ian McCrumRoom 5B18, Tel: 90 366364 voice mail on 6 th ring"

Similar presentations


Ads by Google