Slides created by: - PowerPoint PPT Presentation

1 / 11
About This Presentation
Title:

Slides created by:

Description:

We need a C cross-compiler, ... hooking up real hardware Simulation is not perfectly accurate No understanding of analog effects Debugger Select Tool MPLAB Sim ... – PowerPoint PPT presentation

Number of Views:52
Avg rating:3.0/5.0
Slides: 12
Provided by: Tria587
Learn more at: https://ics.uci.edu
Category:

less

Transcript and Presenter's Notes

Title: Slides created by:


1
PIC Development Environment
MPLAB IDE integrates all of the tools that we
will use
  • Project Manager -Groups together all files and
    data related to a project
  • Editor Standard text editor to write code with
  • Assembler and Linker Stand-alone or to group
    several sources/libraries
  • Debugger Standard debugger, used with simulator
    or in-circuit emulator
  • Execution Engines Instruction-level simulators
    for PIC devices
  • Programmer Transfers the executable to the PIC
    part

Cross-Compiler generates PIC machine code from a
high-level language We need a C cross-compiler,
will use HI-TECH C for PIC10/12/16
2
Downloading/Installing Tools
  • PICKit 1 comes with CDs but you should download
    the newest versions
  • MPLAB IDE
  • Go to www.microchip.com, select MPLAB IDE link
  • Select MPLAB IDE v8.50 Full Release Zipped
    Installation link
  • Unzip and install
  • During the installation you will be prompted to
    download/install Hi-Tech C Compiler
  • HI-TECH C Compiler
  • You may need to install this directly
  • Go to www.htsoft.com
  • Select PIC10/12/16 MCUs
  • Download lite mode v9.70
  • Include PICC path in your path when prompted

3
Development Example
How to Make a Project 1. Write some C code using
an editor, save it in a directory Try
blinking-LED code on course webpage 2. Create a
new project using Project gt Project Wizard 3.
Select device PIC16F684 4. Prompt Select a
language toolsuite, choose HI-TECH Universal
Toolsuite 4. Choose a name and directory for your
project 5. Prompt Add Existing Files, add your C
source file Select the C source file on the
left, click Add button 6. Select Finish if
everything looks OK
4
Compiling and Programming
  • 1. Select Project gt Build to compile the project
  • - You should see a window and eventually a
    Build Successful msg
  • 2. Plug in the PICKit 1
  • 3. Choose board with Select Programmer gt PICKit 1
  • 4. Program the PIC with Programmer gt Program
    Device
  • The program should run after a few seconds.

5
Simulation with MPLAB
  • Simulation is useful to try before hooking up
    real hardware
  • Simulation is not perfectly accurate
  • No understanding of analog effects
  • Debugger gt Select Tool gt MPLAB Sim to start
    simulator
  • Basic Debugger Operations (via new buttons)
  • Run
  • Pause
  • Animate run slowly
  • Step In step to next line
  • Step Over step past a function
  • Step Out complete current function
  • Reset start simulation at beginning

6
Breakpoints, Timing, Watching
  • Breakpoints
  • Set breakpoints by double-clicking on the line of
    code
  • Manage breakpoints using Debugger gt Breakpoints
  • Stopwatch
  • Debugger gt Stopwatch shows cycle count and time
  • Useful to make delays with loops
  • Watch Window
  • Watch window shows register and variable contents
  • Add SFR to add a register, Add Symbol to add a
    variable

7
(No Transcript)
8
Blinking LED Code
include ltpic.hgt __CONFIG (FCMDIS IESODIS
BORDIS UNPROTECT MCLRDIS PWRTEN WDTDIS
INTIO) main () int i PORTA 0 TRISA4
0 TRISA5 0 while (1 1) for(i0 i lt
25000 i) RA4 RA4 gt 1
9
Blinking Light Code Components
  • Include required libraries
  • includeltpic.hgt defines the memory mapping of all
    special registers
  • Set the Configuration Bits of the microcontroller
  • These bits control processor functions (clock
    source, watchdog, etc.
  • Use __CONFIG macro to set them in C
  • Be careful with these
  • Initialize I/O pins input or output? Initialize
    values
  • Infinite while loop Common in embedded systems
  • Delay loop Needed to slow system to match human
    perception

10
Controlling Digital I/O Pins
  • PORTA is a 6 bit bi-directional port
  • TRISA is the corresponding direction register
  • Setting a TRISA pin 1 makes the corresponding
    PORTA pin an input
  • Clearing a TRISA pin makes the corresponding
    PORTA pin an output
  • Reading the PORTA register shows the status of
    the pins
  • Writing to PORTA writes to the pins (if they are
    outputs)
  • Can refer to individual bits in the PORTA and
    TRISA registers
  • TRISA0 0
  • RA0 1

11
Length of Delay Loop
for (i0 ilt25000 i)
Clock freq 4MHz, Period 250 ns
  • How long is this loop?
  • 25000 clocks?
  • Loop needs to compare i to 25000 and to increment
    i.
  • 25000 is larger than 8 bits.
  • Need to see the assembly code to know for sure.
Write a Comment
User Comments (0)
About PowerShow.com