atmel and pic microcontroller
TRANSCRIPT
ATMEL and PIC MicrocontrollerProgramming
usingC language
Presented by:
Engr. Tirso L. Llantada, ECE
Overview
• Introduction to Microcontrollers
• Hardware Configuration
• Microcontroller Programming
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.
Central Processing Unit(CPU)vs
Microprocessor Unit(MPU)vs
Microcontroller Unit(MCU)
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).
ALU
Control Unit
ARE WE CLEAR?
Microcontroller Architecture
MicroprocessorSerial
Communications(RS232)
RAM
EEPROM
ROM
Digital I/O
AnalogI/O
Other Peripherals
Microcontroller Architecture
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
INTRODUCINGATMEL 89C2051
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
Hardware Configuration
RS232
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
Microcontroller Programmingusing C language
Structure of Microcontroller C Programming
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();
}
}
Oops! First we configure!
• Select
Project – Components, Environment, Books
Configuration
• Set the following parameters
Compiling the Project
• SelectProject – Build target
Check Status Window
• There should be 0 errors and
0 warnings
Burn the program
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}
Interrupt Sources
BORING?Lets go with a more interesting one!