You are on page 1of 21

Introduction to Microcontrollers

By Mr Gregory. K. Mavhunga

Outline

What is a microcontroller Why we use microcontrollers PIC microcontrollers Architecture Programming a PIC [16F628A] Example application Summary

Microcontroller samples

What is a microcontroller
A microcontroller is a stand alone, self contained system with peripherals, memory, and a processor. Unlike microprocessor systems, which typically have RAM, ROM and other peripheral devices as standalone ICs or modules Contains all these items on one IC

Advantages of microcontrollers
Ease of use and accessibility Low cost with optimal performance Low power requirements, typical of embedded devices Easily replaceable or re-purposed/ reprogrammed

Typical components of microcontroller

Fig 01. Components of a microcontroller Address bus carries address from CPU to select a particular location in memory or I/O interface. Data bus carries data read/written between CPU & memory or I/O interface. Control bus carries timing signals such as READ & WRITE.

Uses of microcontrollers
Electrical appliances Automobile applications Toys Calculators Industrial process control

PIC Microcontrollers
Peripheral Interface Controller (PIC) was originally designed by General Instruments In the late 1970s, GI introduced PIC 1650 and 1655 RISC with 30 instructions. PIC was sold to Microchip Incorporated Features: low-cost, self-contained, 8-bit, Harvard structure, pipelined, RISC, single accumulator, with fixed reset and interrupt vectors.

PIC Architecture

Fig 02 Havard architecture used In PIC MCus

Address bus carries address from CPU to select a particular location in memory or I/O interface. Data bus carries data read/written between CPU & memory or I/O interface. Control bus carries timing signals such as READ & WRITE.

PIC Families

C implies CMOS technology; Complementary Metal Oxide Semiconductor

F insert indicates incorporation of Flash memory technology


Example: 16C84 was the first of its kind. It was later reissued as the 16F84, incorporating Flash memory technology. It was then reissued as 16F84A.

Programming a PIC
Components required - PIC, 16F628A , or any PIC microcontroller - MPLAB IDE (with C compiler HTC) - Programmer ( ICD2, PicKit 2, etc)

Fig 6 Basic setup of programmer

Programming languages
Machine code prone to error and time consuming virtually non existent Assembly small code size, efficient memory use hence excellent good for time critical routines and applications High Level languages fast product development, easier to debug and maintain C Basic Pascal

Programming example 16F628A


35 instructions RISC RAM 224 bytes EEPROM 128 bytes Flash 2048 words ( 2 bytes per word) Vcc +2.0V to +5V DC Output - +5V, 25mA current Cost - less than ZAR40

PIC 16F628A

Fig 4 Pin out of PIC 16F628A

PIC 16F628A internal structure


Fig 03 Simplified block diagram

PIC 16F628A features

Fig 5 Program and data memory and peripherals of PIC 16F628A

35 instruction RISC controller Cheap and low power requirements Flash based as opposed to CMOS parts (reprogrammable multiple times)

PIC 16F series assembly instruction set

Basic Setup

Fig 6 ICD2 and Pickit 2

Circuit diagram

Reset

Fig 7 PIC 16F887 blink LED example circuit

Sample program code


Assembly program /* Blinks an LED connected to port B*/ BCF TRISB,0 BCF PORTB,0 LOOP: pausems .1000 BSF PORTB, 0 pausems .1000 BSF PORTB, 0 GOTO LOOP END ;control never reaches here } C program void main(void) { TRISB0 = 0;// Make RB0 output PORTB.RB0 = 0; // Make RB0 low while(1) //loop forever { __delay_ms(500); // 1s delay PORTB.RB0 = 1; // LED on __delay_ms(500); // 1s delay PORTB.RB0 = 0; // LED off }

Summary

Microcontrollers are essentially micro-computers, with all the necessary components on one IC, (i.e. microprocessor core, memory and peripherals) Microchip offers plethora of devices, with varying capabilities and cost A lot of documentation and resources available Easy to use, inexpensive and are easily repurposed. Low power consumption and high reliability