YOU ARE DOWNLOADING DOCUMENT

Please tick the box to continue:

Transcript
Page 1: Programming PIC Microcontrollers

Programming PIC Microcontrollers

Presented by Robert Dyball

Page 2: Programming PIC Microcontrollers

Programming PIC Microcontrollers

Microcontrollers? And why PIC?

Programming PICsElectronics & Interfacing PICs

Putting it all together, where next

What are the alternatives?

Page 3: Programming PIC Microcontrollers

What are Microcontrollers, what can I use them for?

Microcontrollers may be thought of as a complete computer on a single chip.

Page 4: Programming PIC Microcontrollers

What are Microcontrollers, what can I use them for?

Microcontrollers may be thought of as a complete computer on a single chip.

Without a CRT or LCD display (usually)

Page 5: Programming PIC Microcontrollers

Why PIC Microcontrollers?

Page 6: Programming PIC Microcontrollers

Why PIC Microcontrollers? Low cost Few other “glue” components required Low active power use + sleep modes to save power. Many options across hundreds of versions; some

have USB or TCP/IP, differing amounts of RAM, ROM and I/O, flash or one time programmable.

Product families are often code and/or pin compatible

Programmers are very inexpensive Programmable in Assembler or C (free) and a

number of other programming languages including Basic.

Page 7: Programming PIC Microcontrollers

How do I program PIC Microcontrollers

To program a PIC microcontroller:

PIC

In Circuit /ICSP Stand-Alone Manufactured

ProgrammerElectrically Connected to Microcontroller

IDE Compiled / Assembled Program

Usually transferred in “Hex”

Page 8: Programming PIC Microcontrollers

ICSP – In Circuit Serial Programming

Page 9: Programming PIC Microcontrollers

Usually Parallel, RS232 or USB interface

Ideally with ZIF socket(s)

Stand-Alone Programmers

Page 10: Programming PIC Microcontrollers

ICSP – In Circuit Serial Programming

Page 11: Programming PIC Microcontrollers

PIC Architecture – RISC / Harvard RISC (as opposed to CISC)

typically 35, no more than 80 assembler instructions.

Harvard Architecture (not von-Neumann) = separate8 data memory versus 12/14/16 bit program memory.

Page 12: Programming PIC Microcontrollers

PIC Architecture – Clocking / Pipelining Operations execute in one clock cycle (except

branches)

Page 13: Programming PIC Microcontrollers

How do I program PICs - languages Internally PIC executes machine code

You need to compile your code to the correct PIC micro(or near equivalent)

Many different languages are available. Microchip provide with MPLAB IDE their MPASM (assembler), as well as Microchip C, Microchip HiTech C is also available.

Many other 3rd party options including CCS C, CC5X C, GCBasic, Proton Basic, and PIC Basic Pro.

Page 14: Programming PIC Microcontrollers

Programming PICs – Assembler MPLABX for Windows, Mac OS X and Linux

usersor

MPLAB for Windows users

Start simple, use a simpler, low-end PIC

Spacing is important

Page 15: Programming PIC Microcontrollers

Programming PICs – C Use MPLAB or MPLABX

Choose a version of C to suit your target PIC

Page 16: Programming PIC Microcontrollers

Sensors – getting info from the outside Many I/O Port options:

Digital I/O Ports, D to A ports, + specialised ports including:

LIN I2C CAN SPI USB PWM and more …

Page 17: Programming PIC Microcontrollers

I/O ports – the basics Can be configured for input, output or both = “Tristate”

Input ports can detect a digital (on/off) device’s statussuch as a switch.

Output ports can “source” or “sink power”(watch current limitations, check the datasheet)

Some I/O ports have Analog to Digital converter, A to Dcheck datasheet for no. of ports + no. of bits resolution

Page 18: Programming PIC Microcontrollers

LIN – Local Interconnect Network Bus Developed by Freescale along with a number of

automotive companies.

Uses 1 active wire = very simple and inexpensive.

Data is half-duplex (one way at a time).

Speed up to 19.2kbit/s at 40 meter length bus.

Commonly used in motor vehicles.

Page 19: Programming PIC Microcontrollers

I2C – Inter-Integrated Circuit Developed by Philips, uses 2 active wires:

serial data + serial clock= simple and inexpensive.

Data is half-duplex (one way at a time)

10kbit/s, 100kbit/sec, 400kbit/sec, 1Mbit/sec, 3.4Mbit/sechigh speed transfer lowers range to a meters, but using lower speeds, or with buffering can reach 200-1000m

Commonly used in embedded devices, such as mobile phones, to connect the displays, buttons and lights.

Page 20: Programming PIC Microcontrollers

SPI – Serial Peripheral Interface Bus

Developed by Motorola, it’s a “4-wire” bus, comprising serial clock, serial data out, serial data in, chip select.

Full duplex (data can go both ways at once)

Speed can be from 1Mbit/sec to 70Mbit/sec

Used in motherboards, cell phones, embedded devices.

Page 21: Programming PIC Microcontrollers

CAN – Controller Area Network

Started as a message based Vehicle Bus standard for automotive applications.

Very high noise immunity

40 metres at 1Mbits/sec or 500m at 125kbits/sec

Now also used for industrial automation and medical equipment , as well as some trucks, tractors, aircraft etc.

Page 22: Programming PIC Microcontrollers

PWM – Pulse Width Modulation

Commonly used for DC motor control, aircraft servos,can also control brightness of lights

Page 23: Programming PIC Microcontrollers

USB – Universal Serial Bus

Page 24: Programming PIC Microcontrollers

What Electronics knowledge do I need?

As little or as much as you want

vs

Page 25: Programming PIC Microcontrollers

Basic PIC circuit – RC clock

Page 26: Programming PIC Microcontrollers

Basic PIC circuit – ceramic resonator

Page 27: Programming PIC Microcontrollers

Basic PIC circuit – ceramic resonator

Page 28: Programming PIC Microcontrollers

Interfacing PICs - A to D inputs

Page 29: Programming PIC Microcontrollers

Interfacing PICs to sensors, switches … PIC can see a single push of a switch as

multiple presses this is known as “key bounce”, may need to de-bounce

Page 30: Programming PIC Microcontrollers

Interfacing PICs to PCs, Phones … Many ways to interface to PC

- USB is one of the easiest- RS232 relatively easy to use, but voltages can be an issue

Phones often have RS232

Page 31: Programming PIC Microcontrollers

Putting it all together - project ideas, tips

Is your project idea is possible?

Try the same principles as we do in Agile software development:

- break it down into small do-able pieces- do a research “Spike”, pick a small task- try to create a “Sashimi slice” – a small vertical layer

Page 32: Programming PIC Microcontrollers

Putting it all together - project ideas, tips Breadboard

Page 33: Programming PIC Microcontrollers

Putting it all together - project ideas, tips

Page 34: Programming PIC Microcontrollers

Putting it all together - project ideas, tips Packaging: DIP, DIL, SMD, SOIC …

Page 35: Programming PIC Microcontrollers

Putting it all together - project ideas, tips Packaging: DIP, DIL, SMD, SOIC …

Page 36: Programming PIC Microcontrollers

Putting it all together - project ideas, tips Ready-made Development Boards:

Page 37: Programming PIC Microcontrollers

Putting it all together - project ideas, tips Breadboard + Development Board:

Page 38: Programming PIC Microcontrollers

Putting it all together - project ideas, tips Development Boards with Breadboard

Page 39: Programming PIC Microcontrollers

Putting it all together - project ideas, tips

Look at projects people have already done, it may not be as much fun, but is it simpler to buy something close?

Page 40: Programming PIC Microcontrollers

Putting it all together - project ideas, tips Vehicle OBD-II diagnostics

OBD-II connectors on all new cars, these communicate using CAN protocol …

Page 41: Programming PIC Microcontrollers

Vehicle OBD-II diagnostics

See: http://sourceforge.net/projects/priidash/

Page 42: Programming PIC Microcontrollers

Vehicle OBD-II diagnostics

See: http://sourceforge.net/projects/priidash/

Page 43: Programming PIC Microcontrollers

Tired of phones not doing enough?

See: http://wiki.openmoko.org/wiki/I2C_Pressure_Sensor

Add a sensor that reads temperature and pressure

Page 44: Programming PIC Microcontrollers

So … Make your phone work harder!

See: http://wiki.openmoko.org/wiki/I2C_Pressure_Sensor

Add code with some maths + air pressure readings, and get an altimeter as well …

Page 45: Programming PIC Microcontrollers

DIY Protection:An Ultrasonic Nerf-Missile launcher.

See: http://www.steffenschuette.de/steffenschuette/elektronik/us2bRadar/

One PIC18F4550, an ultrasonic ranging module and a recycled stepper motor…

Page 46: Programming PIC Microcontrollers

DIY Protection:An Ultrasonic Nerf-Missile launcher.

See: http://www.steffenschuette.de/steffenschuette/elektronik/us2bRadar/

Page 47: Programming PIC Microcontrollers

DIY CNC Router

See: http://erik-pic-microcontroller.blogspot.com/2010/02/cnc-router-project.html

A PIC microcontroller, open source design, home built hardware

Page 48: Programming PIC Microcontrollers

Security – Key Logger

There are numerous projects that might be possible, thoughthe use of them might best beconsidered very carefully!

eg. A key logger with just 3 chipsthat can secretly log keys andthen later retrieve them witha special combination of keys.

Page 49: Programming PIC Microcontrollers

Where next

Breadboard + a few components + programmer

or

Pre-made development board

Page 50: Programming PIC Microcontrollers

What are the alternatives?

Page 51: Programming PIC Microcontrollers

More Information

Go to

http://www.coastnerds.info

for links to this presentation

Join the Coastnerds Facebook group.


Related Documents