12.07.2014 Views

Introduction to Microcontrollers

Introduction to Microcontrollers

Introduction to Microcontrollers

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Introduction</strong><br />

<strong>to</strong> <strong>Microcontrollers</strong><br />

Electronics<br />

Club IIT<br />

Kanpur<br />

Computers<br />

and <strong>Microcontrollers</strong><br />

Computers<br />

<strong>Microcontrollers</strong><br />

AtMega 16<br />

Port I/O<br />

Programming<br />

ATmega 16<br />

Applications<br />

<strong>Introduction</strong> <strong>to</strong> <strong>Microcontrollers</strong><br />

Electronics Club IIT Kanpur<br />

Ankit Gupta<br />

March 18, 2010<br />

Electronics Club IIT Kanpur<br />

<strong>Introduction</strong> <strong>to</strong> <strong>Microcontrollers</strong>


Aim of this lecture<br />

<strong>Introduction</strong><br />

<strong>to</strong> <strong>Microcontrollers</strong><br />

Electronics<br />

Club IIT<br />

Kanpur<br />

Computers<br />

and <strong>Microcontrollers</strong><br />

Computers<br />

<strong>Microcontrollers</strong><br />

AtMega 16<br />

Port I/O<br />

Programming<br />

ATmega 16<br />

Applications<br />

What are the <strong>Microcontrollers</strong><br />

Electronics Club IIT Kanpur<br />

<strong>Introduction</strong> <strong>to</strong> <strong>Microcontrollers</strong>


Aim of this lecture<br />

<strong>Introduction</strong><br />

<strong>to</strong> <strong>Microcontrollers</strong><br />

Electronics<br />

Club IIT<br />

Kanpur<br />

Computers<br />

and <strong>Microcontrollers</strong><br />

Computers<br />

<strong>Microcontrollers</strong><br />

AtMega 16<br />

Port I/O<br />

Programming<br />

ATmega 16<br />

Applications<br />

What are the <strong>Microcontrollers</strong><br />

Applications of <strong>Microcontrollers</strong><br />

Electronics Club IIT Kanpur<br />

<strong>Introduction</strong> <strong>to</strong> <strong>Microcontrollers</strong>


Aim of this lecture<br />

<strong>Introduction</strong><br />

<strong>to</strong> <strong>Microcontrollers</strong><br />

Electronics<br />

Club IIT<br />

Kanpur<br />

Computers<br />

and <strong>Microcontrollers</strong><br />

Computers<br />

<strong>Microcontrollers</strong><br />

AtMega 16<br />

Port I/O<br />

Programming<br />

ATmega 16<br />

Applications<br />

What are the <strong>Microcontrollers</strong><br />

Applications of <strong>Microcontrollers</strong><br />

How <strong>to</strong> program a Micocontroller<br />

Electronics Club IIT Kanpur<br />

<strong>Introduction</strong> <strong>to</strong> <strong>Microcontrollers</strong>


Contents<br />

<strong>Introduction</strong><br />

<strong>to</strong> <strong>Microcontrollers</strong><br />

Electronics<br />

Club IIT<br />

Kanpur<br />

Computers<br />

and <strong>Microcontrollers</strong><br />

Computers<br />

<strong>Microcontrollers</strong><br />

AtMega 16<br />

Port I/O<br />

Programming<br />

ATmega 16<br />

Applications<br />

1 Computers and <strong>Microcontrollers</strong><br />

Computers<br />

<strong>Microcontrollers</strong><br />

2 AtMega 16<br />

Port I/O<br />

Programming ATmega 16<br />

Applications<br />

Electronics Club IIT Kanpur<br />

<strong>Introduction</strong> <strong>to</strong> <strong>Microcontrollers</strong>


Computers<br />

<strong>Introduction</strong><br />

<strong>to</strong> <strong>Microcontrollers</strong><br />

Electronics<br />

Club IIT<br />

Kanpur<br />

Computers<br />

and <strong>Microcontrollers</strong><br />

Computers<br />

<strong>Microcontrollers</strong><br />

AtMega 16<br />

Port I/O<br />

Programming<br />

ATmega 16<br />

Applications<br />

Visibly distinguishable parts :<br />

CPU Data Processing, S<strong>to</strong>rage, Power Distribution ,Hard<br />

Disk<br />

I/O Devices Keyboard, Mouse, Moni<strong>to</strong>r, etc<br />

USB/Serial/Parallel Port<br />

Electronics Club IIT Kanpur<br />

<strong>Introduction</strong> <strong>to</strong> <strong>Microcontrollers</strong>


Microprocessor<br />

<strong>Introduction</strong><br />

<strong>to</strong> <strong>Microcontrollers</strong><br />

Electronics<br />

Club IIT<br />

Kanpur<br />

Computers<br />

and <strong>Microcontrollers</strong><br />

Computers<br />

<strong>Microcontrollers</strong><br />

AtMega 16<br />

Port I/O<br />

Programming<br />

ATmega 16<br />

Applications<br />

Figure: Pentium 4<br />

Capable of doing<br />

thousands of<br />

boolean operations<br />

every second<br />

NO STORAGE<br />

MEMORY<br />

NO<br />

INPUT/OUTPUT<br />

DEVICE<br />

Only pins<br />

Present speed ?<br />

Electronics Club IIT Kanpur<br />

<strong>Introduction</strong> <strong>to</strong> <strong>Microcontrollers</strong>


Lets shrink it <strong>to</strong> a chip<br />

<strong>Introduction</strong><br />

<strong>to</strong> <strong>Microcontrollers</strong><br />

Electronics<br />

Club IIT<br />

Kanpur<br />

Computers<br />

and <strong>Microcontrollers</strong><br />

Computers<br />

<strong>Microcontrollers</strong><br />

AtMega 16<br />

Port I/O<br />

Programming<br />

ATmega 16<br />

Applications<br />

Computers <strong>Microcontrollers</strong><br />

RAM Working Registers<br />

Memory<br />

Hard Disk<br />

Kbd/Mouse/Moni<strong>to</strong>r I/O Pins<br />

Serial/Parallel/USB USART/SPI<br />

Read following article on wikipedia<br />

http://en.wikipedia.org/wiki/Microcontroller<br />

Electronics Club IIT Kanpur<br />

<strong>Introduction</strong> <strong>to</strong> <strong>Microcontrollers</strong>


<strong>Microcontrollers</strong><br />

<strong>Introduction</strong><br />

<strong>to</strong> <strong>Microcontrollers</strong><br />

Electronics<br />

Club IIT<br />

Kanpur<br />

What are <strong>Microcontrollers</strong>?<br />

Integrated Circuits (ICs)<br />

Computers<br />

and <strong>Microcontrollers</strong><br />

Computers<br />

<strong>Microcontrollers</strong><br />

AtMega 16<br />

Port I/O<br />

Programming<br />

ATmega 16<br />

Applications<br />

Electronics Club IIT Kanpur<br />

<strong>Introduction</strong> <strong>to</strong> <strong>Microcontrollers</strong>


<strong>Microcontrollers</strong><br />

<strong>Introduction</strong><br />

<strong>to</strong> <strong>Microcontrollers</strong><br />

Electronics<br />

Club IIT<br />

Kanpur<br />

Computers<br />

and <strong>Microcontrollers</strong><br />

Computers<br />

<strong>Microcontrollers</strong><br />

AtMega 16<br />

Port I/O<br />

Programming<br />

ATmega 16<br />

Applications<br />

What are <strong>Microcontrollers</strong>?<br />

Integrated Circuits (ICs)<br />

Programmable You can define what they do.<br />

This is what makes them different from other simpler ICs,<br />

such as AND gates, inverters, etc<br />

Logic tables relating Input and Output can be defined by<br />

you<br />

Electronics Club IIT Kanpur<br />

<strong>Introduction</strong> <strong>to</strong> <strong>Microcontrollers</strong>


<strong>Microcontrollers</strong><br />

<strong>Introduction</strong><br />

<strong>to</strong> <strong>Microcontrollers</strong><br />

Electronics<br />

Club IIT<br />

Kanpur<br />

Computers<br />

and <strong>Microcontrollers</strong><br />

Computers<br />

<strong>Microcontrollers</strong><br />

AtMega 16<br />

Port I/O<br />

Programming<br />

ATmega 16<br />

Applications<br />

What are <strong>Microcontrollers</strong>?<br />

Integrated Circuits (ICs)<br />

Programmable You can define what they do.<br />

This is what makes them different from other simpler ICs,<br />

such as AND gates, inverters, etc<br />

Logic tables relating Input and Output can be defined by<br />

you<br />

Many useful features built in <strong>to</strong> the uC itself<br />

This is what makes them different from the processors on<br />

a computer (called a microprocessor)<br />

Many of the simpler features built in<strong>to</strong> a motherboard are<br />

located in the microcontroller itself, making it<br />

self-sufficient.<br />

Electronics Club IIT Kanpur<br />

<strong>Introduction</strong> <strong>to</strong> <strong>Microcontrollers</strong>


Microcontroller in Everyday Life<br />

<strong>Introduction</strong><br />

<strong>to</strong> <strong>Microcontrollers</strong><br />

Electronics<br />

Club IIT<br />

Kanpur<br />

Computers<br />

and <strong>Microcontrollers</strong><br />

Computers<br />

<strong>Microcontrollers</strong><br />

AtMega 16<br />

Port I/O<br />

Programming<br />

ATmega 16<br />

Applications<br />

Figure: Applications<br />

Electronics Club IIT Kanpur<br />

<strong>Introduction</strong> <strong>to</strong> <strong>Microcontrollers</strong>


Microcontroller in Everyday Life<br />

<strong>Introduction</strong><br />

<strong>to</strong> <strong>Microcontrollers</strong><br />

Electronics<br />

Club IIT<br />

Kanpur<br />

Computers<br />

and <strong>Microcontrollers</strong><br />

Computers<br />

<strong>Microcontrollers</strong><br />

AtMega 16<br />

Port I/O<br />

Programming<br />

ATmega 16<br />

Applications<br />

Figure: Application of Microcontroller in Au<strong>to</strong>mobile<br />

Electronics Club IIT Kanpur<br />

<strong>Introduction</strong> <strong>to</strong> <strong>Microcontrollers</strong>


Microcontroller in Everyday Life<br />

<strong>Introduction</strong><br />

<strong>to</strong> <strong>Microcontrollers</strong><br />

Electronics<br />

Club IIT<br />

Kanpur<br />

Computers<br />

and <strong>Microcontrollers</strong><br />

Computers<br />

<strong>Microcontrollers</strong><br />

AtMega 16<br />

Port I/O<br />

Programming<br />

ATmega 16<br />

Applications<br />

Figure: Example of Microwave oven<br />

Electronics Club IIT Kanpur<br />

<strong>Introduction</strong> <strong>to</strong> <strong>Microcontrollers</strong>


Microcontroller in Everyday Life<br />

<strong>Introduction</strong><br />

<strong>to</strong> <strong>Microcontrollers</strong><br />

Electronics<br />

Club IIT<br />

Kanpur<br />

Computers<br />

and <strong>Microcontrollers</strong><br />

Computers<br />

<strong>Microcontrollers</strong><br />

AtMega 16<br />

Port I/O<br />

Programming<br />

ATmega 16<br />

Applications<br />

Doesn’t need a monster with 3.2 GHz Intel Core 2 Quad<br />

extreme processor with 2 GB Dual channed DDR3 RAM,<br />

320 GB HDD and Dedicated nVIDIA GEFORCE graphics<br />

!!!.<br />

What is of main concern is cost and size.<br />

What it will be running through out its life is a simple<br />

program that is hardly more than 4KB in size, requiring<br />

less than 128 Bytes of RAM <strong>to</strong> s<strong>to</strong>re few varriables<br />

Electronics Club IIT Kanpur<br />

<strong>Introduction</strong> <strong>to</strong> <strong>Microcontrollers</strong>


AtMega 16<br />

<strong>Introduction</strong><br />

<strong>to</strong> <strong>Microcontrollers</strong><br />

Electronics<br />

Club IIT<br />

Kanpur<br />

Computers<br />

and <strong>Microcontrollers</strong><br />

Computers<br />

<strong>Microcontrollers</strong><br />

AtMega 16<br />

Port I/O<br />

Programming<br />

ATmega 16<br />

Applications<br />

40 Pins<br />

4 PORTs<br />

A,B,C,D<br />

4X8 I/O pins<br />

Electronics Club IIT Kanpur<br />

<strong>Introduction</strong> <strong>to</strong> <strong>Microcontrollers</strong>


Ports<br />

<strong>Introduction</strong><br />

<strong>to</strong> <strong>Microcontrollers</strong><br />

Electronics<br />

Club IIT<br />

Kanpur<br />

Computers<br />

and <strong>Microcontrollers</strong><br />

Computers<br />

<strong>Microcontrollers</strong><br />

AtMega 16<br />

Port I/O<br />

Programming<br />

ATmega 16<br />

Applications<br />

Electronics Club IIT Kanpur<br />

<strong>Introduction</strong> <strong>to</strong> <strong>Microcontrollers</strong>


Registers<br />

<strong>Introduction</strong><br />

<strong>to</strong> <strong>Microcontrollers</strong><br />

Electronics<br />

Club IIT<br />

Kanpur<br />

Computers<br />

and <strong>Microcontrollers</strong><br />

Computers<br />

<strong>Microcontrollers</strong><br />

AtMega 16<br />

Port I/O<br />

Programming<br />

ATmega 16<br />

Applications<br />

The ports are bi-directional: Each pin can be individually<br />

configured for input or output.<br />

For each port (x = A, B, C or D), there are three relevant<br />

registers.<br />

DDRx<br />

set a specific port pin <strong>to</strong> output (1) or input (0)<br />

PINx<br />

<strong>to</strong> read input data from port<br />

PORTx<br />

<strong>to</strong> write output data <strong>to</strong> port<br />

Electronics Club IIT Kanpur<br />

<strong>Introduction</strong> <strong>to</strong> <strong>Microcontrollers</strong>


Examples<br />

<strong>Introduction</strong><br />

<strong>to</strong> <strong>Microcontrollers</strong><br />

Electronics<br />

Club IIT<br />

Kanpur<br />

Computers<br />

and <strong>Microcontrollers</strong><br />

Computers<br />

<strong>Microcontrollers</strong><br />

AtMega 16<br />

Port I/O<br />

Programming<br />

ATmega 16<br />

Applications<br />

x=A,B,C,D<br />

DDRx<br />

DDRA=00001111; or DDRA=0x0F;<br />

Pin 0,1,2,3 PORTA assigned as output and pin 4,5,6,7 as<br />

output<br />

PINx<br />

DDRB.0=0;<br />

first assign Pin o of port B as input a=PINB.0;<br />

a will s<strong>to</strong>re the current value of Pin 0 of port B<br />

PORTx<br />

DDRA=0xFF or DDRA=11111111;<br />

first assign Port A as output PORTA=0xD7; or<br />

PORTA=11010111;<br />

pin 0,1,2,4,6,7<br />

Electronics Club<br />

willIIThave Kanpuroutput <strong>Introduction</strong><br />

high<br />

<strong>to</strong>and <strong>Microcontrollers</strong><br />

pin 3 and 5 will have


Let’s write a code<br />

<strong>Introduction</strong><br />

<strong>to</strong> <strong>Microcontrollers</strong><br />

Electronics<br />

Club IIT<br />

Kanpur<br />

Computers<br />

and <strong>Microcontrollers</strong><br />

Computers<br />

<strong>Microcontrollers</strong><br />

AtMega 16<br />

Port I/O<br />

Programming<br />

ATmega 16<br />

Applications<br />

Problem:<br />

Suppose we want <strong>to</strong> this led glow for 500 ms and remain off for<br />

500 ms and repeat and assume led is connected <strong>to</strong> PORTA.0<br />

Electronics Club IIT Kanpur<br />

<strong>Introduction</strong> <strong>to</strong> <strong>Microcontrollers</strong>


<strong>Introduction</strong><br />

<strong>to</strong> <strong>Microcontrollers</strong><br />

Electronics<br />

Club IIT<br />

Kanpur<br />

Computers<br />

and <strong>Microcontrollers</strong><br />

Computers<br />

<strong>Microcontrollers</strong><br />

AtMega 16<br />

Port I/O<br />

Programming<br />

ATmega 16<br />

Applications<br />

Code<br />

void main()<br />

{<br />

DDRA=0x00;// or DDRA.0=0<br />

}<br />

{<br />

PORTA=0b00000001;<br />

delay_ms(500);<br />

PORTA=0b00000000;<br />

delay_ms(500);<br />

}<br />

SetPortDirection();<br />

will it blink once ?<br />

Electronics Club IIT Kanpur<br />

<strong>Introduction</strong> <strong>to</strong> <strong>Microcontrollers</strong>


<strong>Introduction</strong><br />

<strong>to</strong> <strong>Microcontrollers</strong><br />

Electronics<br />

Club IIT<br />

Kanpur<br />

Computers<br />

and <strong>Microcontrollers</strong><br />

Computers<br />

<strong>Microcontrollers</strong><br />

AtMega 16<br />

Port I/O<br />

Programming<br />

ATmega 16<br />

Applications<br />

Introduce a while loop<br />

void main()<br />

{<br />

DDRA=0x00;// or DDRA.0=0<br />

while(1)<br />

{<br />

PORTA=0b00000001;<br />

delay_ms(500);<br />

PORTA=0b00000000;<br />

delay_ms(500);<br />

}<br />

}<br />

SetPortDirection();<br />

Electronics Club IIT Kanpur<br />

<strong>Introduction</strong> <strong>to</strong> <strong>Microcontrollers</strong>


More coding<br />

<strong>Introduction</strong><br />

<strong>to</strong> <strong>Microcontrollers</strong><br />

1.Binary number display<br />

Electronics<br />

Club IIT<br />

Kanpur<br />

Computers<br />

and <strong>Microcontrollers</strong><br />

Computers<br />

<strong>Microcontrollers</strong><br />

AtMega 16<br />

Port I/O<br />

Programming<br />

ATmega 16<br />

Applications<br />

Electronics Club IIT Kanpur<br />

<strong>Introduction</strong> <strong>to</strong> <strong>Microcontrollers</strong>


More coding<br />

<strong>Introduction</strong><br />

<strong>to</strong> <strong>Microcontrollers</strong><br />

2.Moving train pattern<br />

Electronics<br />

Club IIT<br />

Kanpur<br />

Computers<br />

and <strong>Microcontrollers</strong><br />

Computers<br />

<strong>Microcontrollers</strong><br />

AtMega 16<br />

Port I/O<br />

Programming<br />

ATmega 16<br />

Applications<br />

Electronics Club IIT Kanpur<br />

<strong>Introduction</strong> <strong>to</strong> <strong>Microcontrollers</strong>


How <strong>to</strong> Program a Microcontroller<br />

<strong>Introduction</strong><br />

<strong>to</strong> <strong>Microcontrollers</strong><br />

Electronics<br />

Club IIT<br />

Kanpur<br />

Computers<br />

and <strong>Microcontrollers</strong><br />

Computers<br />

<strong>Microcontrollers</strong><br />

AtMega 16<br />

Port I/O<br />

Programming<br />

ATmega 16<br />

Applications<br />

Steps are<br />

1 Create a project in CVAVR and writing a program in<br />

C<br />

CVAVR<br />

2 Convert/compile it in<strong>to</strong> machine language (.hex<br />

format)<br />

CVAVR<br />

3 Download the hex file in ATMega 16<br />

AVR Studio<br />

For uploading ,we need a programmer<br />

Electronics Club IIT Kanpur<br />

<strong>Introduction</strong> <strong>to</strong> <strong>Microcontrollers</strong>


More ..<br />

<strong>Introduction</strong><br />

<strong>to</strong> <strong>Microcontrollers</strong><br />

Electronics<br />

Club IIT<br />

Kanpur<br />

Computers<br />

and <strong>Microcontrollers</strong><br />

Computers<br />

<strong>Microcontrollers</strong><br />

AtMega 16<br />

Port I/O<br />

Programming<br />

ATmega 16<br />

Applications<br />

Timers<br />

ADC<br />

LCD(Character/Graphical/Mobile lcd)<br />

Mo<strong>to</strong>rs<br />

UART/SPI/I2c/PS2)<br />

EEPROM,MMC<br />

Electronics Club IIT Kanpur<br />

<strong>Introduction</strong> <strong>to</strong> <strong>Microcontrollers</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!