You are on page 1of 25

ATMEL and PIC Microcontroller Programming using C 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)

this could refer to the actual processor part of a microcontroller, the microprocessor within a computer, or the processor "box" of a computer system. This devices tend to be aimed at computer applications.
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).

Central Processing Unit

Microprocessor Unit Microcontroller Unit

ALU
Control Unit

ARE WE CLEAR?

Microcontroller Architecture
EEPROM

RAM
ROM

Other Peripherals

Microprocessor

Serial Communications (RS232)

Analog I/O

Digital I/O

Microcontroller Architecture

What you need to know!


Before you can make a working microcontroller project, you should first know the following: 1. 2. 3. 4. 5. 6. 7. Supply Voltage Number of I/O Special Purpose I/O(Serial Ports, ADC Ports, etc) Memory(RAM and ROM) Timers/Counters Interrupts XTAL Oscillator frequency

INTRODUCING ATMEL 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 bidirectional I/O pins with internal pull-ups.

Special Purpose I/O


o o o o o o

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


o

P3.0 RXD (serial input port) P3.1 TXD (serial output port) P3.2 INT0 (external interrupt 0) P3.3 INT1 (external interrupt 1) P3.4 T0 (timer 0 external input) P3.5 T1 (timer 1 external input)

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 Programming using C language

Structure of Microcontroller C Programming

Sample Programs
#include<AT892051.h> /*Function to delay about a second void 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


Select
Project Build target

Check Status Window


There should be 0 errors and 0 warnings

Burn the program

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

Interrupt Sources

BORING? Lets go with a more interesting one!

You might also like