embedded systems lab lab lab 2222 introduction...

8
Introduction To Microcontrollers 0 Lab 2 Mar. /2010 :D Prepared By: Eng.Ola M. Abd El-Latif Islamic University of Gaza Engineering College Computer Department Embedded Systems Lab Lab Lab Lab Lab 2 Introduction to Microcontrollers Introduction to Microcontrollers Introduction to Microcontrollers Introduction to Microcontrollers

Upload: others

Post on 13-Jul-2020

19 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Embedded Systems Lab Lab Lab 2222 Introduction …site.iugaza.edu.ps/olatif/files/2010/02/Lab-2...Introduction To Microcontrollers 2 Lab 2 A microcontroller differs from a microprocessor

Introduction To Microcontrollers

0

Lab 2

Mar. /2010

:D

Prepared By: Eng.Ola M. Abd El-Latif

Islamic University of Gaza

Engineering College

Computer Department

Embedded Systems Lab Lab Lab Lab Lab 2222

Introduction to MicrocontrollersIntroduction to MicrocontrollersIntroduction to MicrocontrollersIntroduction to Microcontrollers

Page 2: Embedded Systems Lab Lab Lab 2222 Introduction …site.iugaza.edu.ps/olatif/files/2010/02/Lab-2...Introduction To Microcontrollers 2 Lab 2 A microcontroller differs from a microprocessor

Introduction To Microcontrollers

1

Lab 2

Lab Lab Lab Lab 2222 Introduction to Introduction to Introduction to Introduction to MMMMicrocontrollersicrocontrollersicrocontrollersicrocontrollers

ObjectivesObjectivesObjectivesObjectives • To be familiar with microcontrollers, PIC18F4550 microcontroller.

Tools

• PIC18F4550 Microcontroller, MPLAB software, Proteus VSM simulation program.

TheoryTheoryTheoryTheory A microcontroller (or MCU) is a computer-on-a-chip. It is a type of microprocessor emphasizing

self-sufficiency and cost-effectiveness, in contrast to a general-purpose microprocessor (the kind

used in a PC).

A microcontroller is a single integrated circuit, commonly with the following features:

• central processing unit - ranging from small and simple 4-bit processors to sophisticated

32- or 64-bit processors

• input/output interfaces such as serial ports (UARTs)

• Other serial communications interfaces like I²C, Serial Peripheral Interface and Controller

Area Network for system interconnect

• Peripherals such as timers and watchdog

• RAM for data storage

• ROM, EPROM, EEPROM or Flash memory for program storage

• clock generator - often an oscillator for a quartz timing crystal, resonator or RC circuit

• many include analog-to-digital converters

� Microcontroller versus Microprocessor

Page 3: Embedded Systems Lab Lab Lab 2222 Introduction …site.iugaza.edu.ps/olatif/files/2010/02/Lab-2...Introduction To Microcontrollers 2 Lab 2 A microcontroller differs from a microprocessor

Introduction To Microcontrollers

2

Lab 2

A microcontroller differs from a microprocessor in many ways. The first and most important

difference is its functionality. In order that the microprocessor may be used, other components

such as memory must be added to it. Even though the microprocessors are considered to be

powerful computing machines, their weak point is that they are not adjusted to

communicating to peripheral equipment.

On the other hand, the microcontroller is designed to be all of that in one. No other specialized

external components are needed for its application because all necessary circuits which

otherwise belong to peripherals are already built into it. It saves the time and space needed to

design a device.

� Input/Output Ports In order to make the microcontroller useful, it

has to be connected to additional electronics,

i.e. peripherals. Each microcontroller has one

or more registers (called a “port”) connected

to the microcontroller pins.

Why input/output? Because you can change the pin’s function as you

wish.

For example, suppose you want your device to turn three signal LEDs and simultaneously

monitor the logic state of five sensors or push buttons. Some of ports need to be configured so

that there are three outputs (connected to the LEDs) and five inputs (connected to sensors).

It is simply performed by software, which means that the pin’s function can be changed

during operation. Usually, each I/O port is under control of another SFR, which means that

each bit of that register determines the state of the corresponding microcontroller pin.

For example, by writing logic one (1) to one bit of that control register SFR, the appropriate

port pin is automatically configured as input. It means that voltage brought to that pin can be

read as logic 0 or 1. Otherwise, by writing zero to the SFR, the appropriate port pin is

configured as an output. Its voltage (0V or 5V) corresponds to the state of the appropriate bit

of the port register.

� Memory Unit

Memory is part of the microcontroller used for

data storage.

Page 4: Embedded Systems Lab Lab Lab 2222 Introduction …site.iugaza.edu.ps/olatif/files/2010/02/Lab-2...Introduction To Microcontrollers 2 Lab 2 A microcontroller differs from a microprocessor

Introduction To Microcontrollers

3

Lab 2 � Read Only Memory (ROM)

ROM (Read Only Memory) is used to permanently save the program being executed. The size

of a program that can be written depends on the size of this memory.

� Flash memory

The contents of this memory can be written and cleared practically an unlimited number of

times, the microcontrollers with Flash ROM are ideal for learning, experimentation and small-

scale manufacture. Because of its popularity, the most microcontrollers are manufactured in

flash versions today. So, if you are going to buy a microcontroller, the type to look for is

definitely flash.

� Random Access Memory (RAM) Once the power supply is off the contents of RAM (Random Access Memory) is cleared.

It is used for temporary storing data and intermediate results created and used during the

operation of the microcontroller.

Special Function Register

In addition to the registers which do not have any

special and predetermined function, every

microcontroller has a number of registers whose

function is predetermined by the manufacturer.

Their bits are connected (literally) to internal

circuits such as timers, A/D converter, oscillators

and others, which means that they are directly in

command of the operation of the microcontroller.

Page 5: Embedded Systems Lab Lab Lab 2222 Introduction …site.iugaza.edu.ps/olatif/files/2010/02/Lab-2...Introduction To Microcontrollers 2 Lab 2 A microcontroller differs from a microprocessor

Introduction To Microcontrollers

4

Lab 2 � Electrically Erasable Programmable ROM (EEPROM)

The contents of the EEPROM may be changed during operation (similar to RAM), but

remains permanently saved even upon the power supply goes off (similar to ROM).

Accordingly, an EEPROM is often used to store values, created during operation, which must

be permanently saved. For example, if you design an electronic lock or an alarm, it would

be great to enable the user to create and enter a password, but useless if it is lost every time

the power supply goes off. The ideal solution is the microcontroller with an embedded

EEPROM.

� Central Processor Unit (CPU)

As its name suggests, this is a unit which

monitors and controls all processes inside the

microcontroller. It consists of several smaller

subunits like Instruction Decoder, Arithmetical

Logical Unit (ALU) and Accumulator.

� PIC microcontrollers

PIC microcontrollers designed by Microchip Technology are likely the right choice for you if

you are the beginner. Here is why... The real name of this microcontroller is PICmicro

(Peripheral Interface Controller), but it is better known as PIC. Its first ancestor was designed

in 1975 by General Instruments.

This chip called PIC1650 was meant for totally different purposes. About ten years later, by

adding EEPROM memory, this circuit was transformed into a real PIC microcontroller.

Page 6: Embedded Systems Lab Lab Lab 2222 Introduction …site.iugaza.edu.ps/olatif/files/2010/02/Lab-2...Introduction To Microcontrollers 2 Lab 2 A microcontroller differs from a microprocessor

Introduction To Microcontrollers

5

Lab 2

PICPICPICPIC18181818FFFF4550455045504550 Microcontroller Microcontroller Microcontroller Microcontroller

• High Performance RISC CPU.

• Operating Frequency: DC – 48 MHz.

• Linear program memory addressing to 32 Kbytes.

• Can store up to 16,384 single-word instructions.

• Linear data memory addressing to 2 Kbytes.

• 256 bytes EEPROM memory.

• Five bidirectional I/O Ports: A, B, C, D, E.

• Three independent Timers/Counters & Watch-dog timer.

• Serial Communications:

o Enhanced USART Module, Supports RS-485, RS-232.

o Master Synchronous Serial Port (MSSP): supports SPI and I2C mode.

• Streaming Parallel Port (SPP).

• Incorporate a fully featured Universal Serial Bus communications module that is

compliant with the USB Specification Revision 2.0.

• Compatible 10-bit Analog-to-Digital Converter: 13 input channels.

Pin DiagramPin DiagramPin DiagramPin Diagram

Page 7: Embedded Systems Lab Lab Lab 2222 Introduction …site.iugaza.edu.ps/olatif/files/2010/02/Lab-2...Introduction To Microcontrollers 2 Lab 2 A microcontroller differs from a microprocessor

Introduction To Microcontrollers

6

Lab 2

Lab Exercises…Lab Exercises…Lab Exercises…Lab Exercises…

You took enough instructions for using MPLAB & Proteus ISIS programs in the lab. These

instructions should make you able to accomplish the following procedure:

Part 1

• Connect the circuit shown in the Figure_1 below on Proteus ISIS program.

• Write an assembly language program that send 0x8a to port B.

• Load the(.hex) file to PIC18f4550 microcontroller.

• Configure PIC18f4550 parameters needed for the simulation by putting Processor clock

frequency 8MHz.

• Simulate the circuit using Proteus ISIS program.

Figure_1

Page 8: Embedded Systems Lab Lab Lab 2222 Introduction …site.iugaza.edu.ps/olatif/files/2010/02/Lab-2...Introduction To Microcontrollers 2 Lab 2 A microcontroller differs from a microprocessor

Introduction To Microcontrollers

7

Lab 2

Part 2

• Connect the circuit shown in the Figure_2 below on Proteus ISIS program.

• Write an assembly language program that inputs data from port D and sends it to port B.

• Load the(.hex) file to PIC18f4550 microcontroller.

• Configure PIC18f4550 parameters needed for the simulation by putting Processor clock

frequency 8MHz.

• Simulate the circuit using Proteus ISIS program.

Figure_2