Embed
Email

FINE392 Technology Art Studio

Document Sample

Shared by: ewghwehws
Categories
Tags
Stats
views:
0
posted:
1/18/2012
language:
pages:
14
FINE392

Technology Art Studio





Introduction to Microcontrollers

Outline

What is a microcontroller?

Digital representation of information

The PIC 16F84

Programming your microcontroller

Sample interface circuits

Sample software

BREAK

Hands-on fiddling

Demystifying the “micro”

A small, inexpensive, specialized (or, “limited”)

computer

Used by the millions annually: cars (engine, ABS,

many others), toasters, VCRs, fridges, microwaves,

DVD players, cameras, etc.

Each of us probably comes into contact with a dozen

microcontrollers daily.

Remember: you use a lot of technology daily with no

consideration at all for how it works…this is no

different.

What is a microcontroller?



power logic

serial output

timer(s)

timing

memory

PWM outputs

digital I/O microcontroller



analog LCD driver

analog inputs to digital

Digital representation of I/O

Internally, computers represent things using

bits, having a value of either 0 or 1.

For each digital I/O pin, there is a single bit

value stored in memory:

read 0 if pin voltage is “low”, 1 if “high”

write 0 sets pin voltage “low”, 1 sets “high”

Memory is generally organized in bytes, which

are groupings of 8 bits. However, the tools

we’ll be using allow bit-level access, which

simplifies things for us.

The PIC 16F84-10/P

Very popular, lots and lots of info

on the internet

Pin 18 Pin 10

5V supply

Ext. CLK  10MHz Pin 1

Pin 9

13 bidirectional I/O pins

PORTA: RA0-RA4 Pin 1 Pin 18



PORTB: RB0-RB7

1 internal timer

TTL input levels

“high” is anything from 2.4V to 5V

“low” is anything from 0V to 0.8V

Pin 9 Pin 10

5V power supply

wall-wart, 3AAs, DC P/S,

9V + voltage regulator

7805 family of regulators Pin 1 Pin 3

7-20VDC (+) 5VDC (+)

drops 7-20VDC to 5VDC Pin 2

GND (-)

apply Vin between pin 1 (+)

and pin 2 (-)

5V is output between pin 3

(+) and pin 2 (-)

7805 can supply up to 1A

with proper heat sinking

External timing

Pin 7

GND (-)

PICs have ability to use many

timing sources Pin 1 Pin 1 Pin 8

CLK out

marked NC

The most “self-contained” is by sharp

corner Pin 14

an oscillator 5VDC (+)



Pin 1 Pin 14

Pin 1 is marked by a pointed

corner; the others are

rounded. Pin 8

Pin 7









to PIC

13 bi-directional I/O pins

two ports: PORTA (5 bits) and RA2 RA1

RA3 RA0

PORTB (8 bits) RA4



the value of bit i on PORTx is stored

in variable Rxi RB0 RB7

RB1 RB6

E.g., set bit 3 of PORTB low: RB3 = 0 RB2 RB5

RB3 RB4

the direction of bit i on PORTx is set

with variable TRISxi

0 = output, 1 = input

E.g., set bit 2 of PORTA as input:

TRISA2 = 1

NOTE: RA4 is special

Reading a switch 5V (+)



All the PIC can tell you is if the

to PIC switch

pin is “high” or “low”. input pin



We need to find a way to make 1kW – 100kW

“pull-down”

resistor

the switch action change the GND (-)

pin from high to low.

When the switch is open, input internal

“pull-up”

“floats” unless you have a if RBPU=0



“pull-down” resistor.

PORTB has internal “pull- input circuitry

ups”, which can be used by

setting RBPU=0 in your code

GND (-)

Lighting a LED

All the PIC can do is output “high”

(~5V) or “low” (~0V)

We need to somehow make that

light (or not light) the LED.

If the anode (+) of the LED is at a from PIC

output pin

higher voltage than the cathode (-),

current will flow through it and it LED

will light.

Too much current will burn out the 100W – 1kW

current-limiting

resistor

LED, so always use a current- GND (-)

limiting resistor.

Sample software

LED on RB0

Switch on RB5



Flash LED on for 100ms, then off



Use RB5 to control the frequency of flashing

if RB5 is high, flash twice/second

if RB5 is low, flash once/second

Sample software

Initialization Loop

TRISB5 = 1; if (RB5==1)

TRISB0 = 0; RB0 = 1;

delay_ms(100);

RB0 = 0;

RBPU = 0;

delay_ms(400);

else

RB0 = 1;

delay_ms(100);

RB0 = 0;

delay_ms(900);

Break…

Breadboard the following circuit

Get the sample code sample1.c and sample2.c

After the break, we’ll look at how to create a code

project and program the PIC

LED on pin 6 switch from pin 11

power timing (RB0), with resistor PIC16F84 (RB5) to GND (-)



 5V (+)

 GND (-)









GND (-)

 5V (+)



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

You are almost ready to download!

You are almost ready to download!