atmel and pic microcontroller

25
ATMEL and PIC Microcontroller Programming using C language Presented by: Engr. Tirso L. Llantada, ECE

Upload: tearsome-llantada

Post on 09-Jul-2015

1.989 views

Category:

Documents


10 download

TRANSCRIPT

Page 1: Atmel and pic microcontroller

ATMEL and PIC MicrocontrollerProgramming

usingC language

Presented by:

Engr. Tirso L. Llantada, ECE

Page 2: Atmel and pic microcontroller

Overview

• Introduction to Microcontrollers

• Hardware Configuration

• Microcontroller Programming

Page 3: Atmel and pic microcontroller

What is a Microcontroller(MCU)

• It is a single chip microprocessor system which contains data and program memory, serial and parallel I/O ports, timers, external and internal interrupts, ALL integrated into a single chip.

Page 4: Atmel and pic microcontroller

Central Processing Unit(CPU)vs

Microprocessor Unit(MPU)vs

Microcontroller Unit(MCU)

Page 5: Atmel and pic microcontroller

Central Processing Unit• this could refer to the actual processor part of a

microcontroller, the microprocessor within a computer, or the processor "box" of a computer system.

Microprocessor Unit• This devices tend to be aimed at computer

applications.

Microcontroller Unit• This devices tend to be aimed at embedded control

applications• They tend to consist of a processor plus a number of

useful peripherals (MMU, Timers, watchdog, A/D, etc, etc, etc).

Page 6: Atmel and pic microcontroller

ALU

Control Unit

Page 7: Atmel and pic microcontroller

ARE WE CLEAR?

Page 8: Atmel and pic microcontroller

Microcontroller Architecture

MicroprocessorSerial

Communications(RS232)

RAM

EEPROM

ROM

Digital I/O

AnalogI/O

Other Peripherals

Page 9: Atmel and pic microcontroller

Microcontroller Architecture

Page 10: Atmel and pic microcontroller

What you need to know!

• Before you can make a working microcontroller project, you should first know the following:

1. Supply Voltage2. Number of I/O3. Special Purpose I/O(Serial Ports, ADC Ports, etc)4. Memory(RAM and ROM) 5. Timers/Counters6. Interrupts7. XTAL Oscillator frequency

Page 11: Atmel and pic microcontroller

INTRODUCINGATMEL 89C2051

Page 12: Atmel and pic microcontroller

Pin Configuration

Supply(VCC,GND)- 2.7V to 6V Operating Range I/0pins:

o Port 1 - The Port 1 is an 8-bit bi-directional I/O port. The Port 1 out-put buffers can sink 20 mA and can drive LED displays directly.

o Port 3 - Port 3 pins P3.0 to P3.5, P3.7 are seven bi-directional I/O pins with internal pull-ups.

Special Purpose I/Oo P3.0 RXD (serial input port)o P3.1 TXD (serial output port)o P3.2 INT0 (external interrupt 0)o P3.3 INT1 (external interrupt 1)o P3.4 T0 (timer 0 external input)o P3.5 T1 (timer 1 external input)

Memory(2Kbytes)

Timers/Counters - 2 16-bit timer/counter Interrupts(6 sources of interrupts)

o Reset, Timer 0 overflow, Timer 1 overflow, External Interrupt 0, External Interrupt 1, Serial Port events (buffer full, buffer empty, etc)

XTAL frequency - 0 Hz to 24 MHz

Page 13: Atmel and pic microcontroller

Hardware Configuration

RS232

Page 14: Atmel and pic microcontroller

Microcontroller Programming

• Traditionally, it can only be programmed using assembly language.

• But due to the complexity of assembly language, high level language were developed such as BASIC and C Programming

Page 15: Atmel and pic microcontroller

Microcontroller Programmingusing C language

Page 16: Atmel and pic microcontroller

Structure of Microcontroller C Programming

Page 17: Atmel and pic microcontroller

Sample Programs

#include<AT892051.h>/*Function to delay about a secondvoid wait_a_sec(){Unsigned int x;for(x=0;x<33000;x++);}/*start of main program*/main(){int LED = 1;

for(;;){

P1=~LED;LED++;wait_a_sec();

}

}

Page 18: Atmel and pic microcontroller

Oops! First we configure!

• Select

Project – Components, Environment, Books

Page 19: Atmel and pic microcontroller

Configuration

• Set the following parameters

Page 20: Atmel and pic microcontroller

Compiling the Project

• SelectProject – Build target

Page 21: Atmel and pic microcontroller

Check Status Window

• There should be 0 errors and

0 warnings

Page 22: Atmel and pic microcontroller

Burn the program

Page 23: Atmel and pic microcontroller

Interrupt Subroutines

1. Interrupt subroutine for timer 1Void timer1() interrupt 3{Interrupt service code goes here}

2. Interrupt subroutine for timer 3Void timer0() interrupt 1{Interrupt service code goes here}

Page 24: Atmel and pic microcontroller

Interrupt Sources

Page 25: Atmel and pic microcontroller

BORING?Lets go with a more interesting one!