Embed
Email

PIC programming1 MPLAB PICs

Document Sample
PIC programming1 MPLAB PICs
Shared by: HC120209144639
Categories
Tags
Stats
views:
1
posted:
2/9/2012
language:
pages:
15
PIC course

1) Program design - Assignment hand-out

2) Microchip – PICs and MPLAB

3) Input and Output – Digital and serial I/O

4) Debugging – using MPLAB simulator

5) Lab session

6) Analogue input

7) Interrupt programming – external and timers

8) Simulator - stimulus and DCMI

9) Test 2 – Assignment hand-in

1

PIC course – PICs and MPLAB

Programmable Interface Controllers (PICs)

Why PICs ?

Cheap, programmable devices

Large variety I/O options.

- Plus advanced I/O - USB, Ethernet,

Manufactured by Microchip,

www.microchip.com







2

PIC course – PICs and MPLAB

A few flavours:

Low-end devices: (12-bit instruction size) –

e.g. PIC16C5X

Mid-range devices (14-bit instruction size)

High(er)-end devices: (16-bit instruction size)

– PIC18 range – we’ll use the PIC18C452

Top-end devices: (16-bit instruction and data

word) – PIC24





3

PIC course – PICs and MPLAB

18C452 Features:

Operating voltage Standard: 4.5 - 5.5V, L parts: 2 – 6V

Frequency DC – 40MHz

Oscillator Crystal, external RC

Program memory (bytes) 32K

Data Memory (Bytes) 1536

I/O Ports 5 – Ports A, B, C, D, E

Timers 4

Capture/Compare/PWM 2

Serial Communications MSSP, USART

Parallel Communications PSP

10-bit Analog-to-Digital Module 8 input channels

Programming In-circuit serial, or programmer







4

PIC course – PICs and MPLAB

Pin-out – note multi-function pins









5

PIC course – PICs and MPLAB

Circuit – simple – Clock: RC or crystal









6

PIC course – PICs and MPLAB

PIC registers

PIC is controlled by Special Function Registers (SFR)





I/O ports: TRIS (tri-state control register)

– TRISA for PORTA, TRISB for PORTB etc.

A ‘0’ sets pin as output - a ‘1’ sets it as input.



Other SFRs, e.g:

Analogue, timer, control and capture register

Programming: SFRs defined in .H header file.

7

PIC course – PICs and MPLAB

PIC configuration register

Holds design set-up

e.g oscillator type (RC, crystal) and speed,

watch dog timer, brown out & low voltage detect

levels etc.

Is controlled by a fuse, set when PIC

programmed



If relevant, have to set in code – e.g:

#pragma config WDT = OFF

8

PIC course – PICs and MPLAB

C Programming

ANSI – slightly different from C#

(no Console reads or write)

- No Op Sys or pre-written I/O with embedded

systems



Microchip MCC18 compiler

MPLAB program debugger environment

Free from Microchip – see notes

9

PIC course – PICs and MPLAB

Program is compiled, linked (with other

programs) and run under MPLAB.



MPLAB does have serial output emulator



This week’s task

First program writes to this.







10

PIC course – PICs and MPLAB

First program:

//

// Hello.c - prints Hello world ! - jba 6/09

//



#include // includes the printf definition

#pragma config WDT = OFF

// command to C18 - turn off the watch-dog timer - later



void main (void) // main program starts here

{

printf ("Hello World !"); // print to MPLAB output window

while (1) ; // permanent loop to end prog.

}





11

PIC course – PICs and MPLAB

Other embedded processors

ARM processors

The ARM (Advanced RISC Machine)

32-bit architecture

Used in PDAs, iPODs and mobile phones.

There are many variants but they all use the

same processor core.

C compilers are available for these.





12

PIC course – PICs and MPLAB

Other embedded processors

Arduino board

Uses Atmel ATMega 32 bit processor

Programmed via USB port

Expanded using plug-in modules









13

PIC course – PICs and MPLAB

Summary

• PIC devices

• Features

• Pin-out

• Hardware design

• SFRs

• MCC18 & MPLAB

• First program

• Other embedded processors





14

PIC course – PICs and MPLAB

This week’s task

• Type in ‘Hello World’ program

• Run MPLAB – set up environment (PIC, add C

program and link to PIC library and header files, set

Memory model)

• Set output window to simulate serial I/O

• Run program

• Output:









15


Related docs
Other docs by HC120209144639
By registering with docstoc.com you agree to our
privacy policy

You are almost ready to download!

You are almost ready to download!