Embedded system (Chapter 2) part A

33
MICROCONTROLLER ARCHITECTURE & ASSEMBLY LANGUAGE PROGRAMMING DEPARTMENT OF ELECTRICAL ENGINEERING POLITEKNIK SULTAN HAJI AHMAD SHAH CHAPTER 2 Part 1 EC501 EMBEDDED SYSTEM APPLICATIONS

Transcript of Embedded system (Chapter 2) part A

Page 1: Embedded system (Chapter 2) part A

MICROCONTROLLER

ARCHITECTURE &

ASSEMBLY LANGUAGE

PROGRAMMING

DEPARTMENT OF ELECTRICAL ENGINEERING

POLITEKNIK SULTAN HAJI AHMAD SHAH

CHAPTER 2 – Part 1

EC501 EMBEDDED SYSTEM APPLICATIONS

Page 2: Embedded system (Chapter 2) part A

LEARNING OUTCOMES

Part 1: Understand the PIC18 Architecture

Part 2:

Know PIC Assembly Language

fundamental

Page 3: Embedded system (Chapter 2) part A

Part 1 : PIC18 Microcontroller Architecture

At the end of this session you should be able to

explain:

PIC18 Microcontroller families

PIC18 architecture

Data RAM file Register

Page 4: Embedded system (Chapter 2) part A

Overview

Page 5: Embedded system (Chapter 2) part A

INTRODUCTION

PIC is a family of modified Harvard

architecture microcontrollers made by Microchip

Technology, derived from the PIC1650 originally

developed by General Instrument's

Microelectronics Division.

The name PIC initially referred to "Peripheral

Interface Controller”

Page 6: Embedded system (Chapter 2) part A

PICs are popular with both industrial developers and hobbyists alike due to their:

1. low cost,

2. wide availability,

3. large user base,

4. extensive collection of application notes,

5. availability of low cost or free development tools,

6. serial programming (and re-programming with flash memory) capability.

Page 7: Embedded system (Chapter 2) part A

PIC Families

Page 8: Embedded system (Chapter 2) part A

PIC18 PIC® Microcontrollers

The PIC18 family use an 8-bit architecture.

With up to 16 MIPS of processing power, PIC18

Microcontrollers feature advanced peripherals, such as CAN,

USB, Ethernet, LCD and CTMU.

Page 9: Embedded system (Chapter 2) part A

29 March, 2013 mfauzi 9

Basic Upgrade

USB CAN

Page 10: Embedded system (Chapter 2) part A

PIC18 Architecture

PIC microcontrollers are based on advanced RISC

architecture.

RISC stands for Reduced Instruction Set Computing. In

this architecture, the instruction set of hardware gets

reduced which increases the execution rate (speed) of

system.

PIC microcontrollers follow Harvard architecture for

internal data transfer

Page 11: Embedded system (Chapter 2) part A

RISC vs CISC

Reduced instruction set computing, or RISCis

a CPU design strategy based on the insight that

simplified instructions can provide higher

performance if this simplicity enables much faster

execution of each instruction.

A complex instruction set computer (CISC), is

a computer where single instructions can execute

several low-level operations

Page 12: Embedded system (Chapter 2) part A

PIC18 Architecture (cont’d)

PIC microcontrollers are designed using the

Harvard Architecture which includes:

Microprocessor unit (MPU)

Program memory for instructions

Data memory for data

I/O ports

Support devices such as timers

Page 13: Embedded system (Chapter 2) part A

Harvard Architecture vs Von Neumann

Architecture • Von Neumann

Architecture:

– Used single memory space

for program and data.

– Limits operating bandwidth

• Harvard Architecture:

– Uses two separate memory

spaces for program

instructions and data

– Improved operating

bandwidth

– Allows for different bus

widths

Von Neumann

Architecture

8-bit Bus

CPU

Program

& Data

Memory

CPU

Harvard

Architecture

Data

Memory

Program

Memory

8-bit Bus

16-bit Bus

Page 14: Embedded system (Chapter 2) part A

PIC18 Architecture

PIC18 Architecture Block Diagram

Page 15: Embedded system (Chapter 2) part A

PIC18 Features:

CPU core

The function of the CPU is to execute (process)

information stored in memory.

Program ROM

The ROM use to store program.

Page 16: Embedded system (Chapter 2) part A

PIC18 Features (cont’d)

Data Memory

The data memory is SRAM and EEPROM.

provides a place to store data as application executes

and is lost when power is removed from the system.

EEPROM

also a nonvolatile memory which is used to store

data like values of certain variables. PIC18F4550 has

256 Bytes of EEPROM.

Page 17: Embedded system (Chapter 2) part A

PIC18 Features (cont’d)

I/O Ports: The I/O ports are used to interface the microprocessor

to the outside world.

PIC18F4550 pin diagram.

Page 18: Embedded system (Chapter 2) part A

Other internal Devices

Oscillator

8x8 Multiplier

ADC Interface

Timers/Counters

USB

Page 19: Embedded system (Chapter 2) part A

PIC18 Registers

CPUs use many registers to store data

temporarily.

To program in assembly language, we must

understand the registers and architecture of

given CPU and the role they play in processing

data.

Page 20: Embedded system (Chapter 2) part A

PIC18 Registers

PIC microcontroller contains an 8-bit ALU (Arithmetic

Logic Unit) and an 8-bit Working Register (WREG).

There are different GPRs (General Purpose

Registers) and SFRs (Special Function Registers) in

a PIC microcontroller.

The overall system performs 8-bit arithmetic and logic

functions.

Page 21: Embedded system (Chapter 2) part A

PIC registers

Page 22: Embedded system (Chapter 2) part A

WREG Register

Stand for Working register

8-bit register

Use for all arithmetic and logic instructions.

used by many instructions as:

the source of an operand.

the destination for the result of the instruction

execution.

Page 23: Embedded system (Chapter 2) part A

PIC File Register

The file register is read/write memory used by

CPU for data storage, scratch pad, and

register for internal use and functions.

Divided into two sections:

a) Special Function Registers (SFR)

b) General Purpose Registers (GPR)

Page 24: Embedded system (Chapter 2) part A

General Purpose Register (GPR)

8-bit registers

are a group of RAM locations in the file

register that are used for data storage and

scratch pad.

the space that is not allocated to the SFRs

typically used for general-purpose registers.

Page 25: Embedded system (Chapter 2) part A

Special Function Register (SFR)

SFR are dedicated to specific functions such

as ALU status, timers, serial communication,

I/O ports, ADC and so on.

The function of each SFR is fixed by the CPU

designer at the time of design.

8-bit registers

Page 26: Embedded system (Chapter 2) part A

Special

Function

Register

of PIC18

family

Page 27: Embedded system (Chapter 2) part A

SFR (cont’d) Examples of SFR register:

1. PORTx

2. LATx

3. TRISx

4. TIMER0

5. ADCON0, ADCON1

6. ADRESH

7. INTCON

8. etc

Page 28: Embedded system (Chapter 2) part A

Review Questions

1. What do RISC an CISC stand for?

2. True or false. Harvard architecture uses the same address and data busses to fetch both code and data.

3. Register WREG is ____ -bit wide.

4. True or false. Data space is SRAM memory, whereas program (code) space is of the ROM type.

5. The general-purpose RAM and SFRs together are called __________.

6. The SFR registers in PIC are ___-bit.

Page 29: Embedded system (Chapter 2) part A

STATUS Register

8-bit register

referred to as the flag register.

only 5 bits of it are used by the PIC18.

called conditional flags

The three unused bits are unimplemented and

read as 0.

Page 30: Embedded system (Chapter 2) part A

STATUS Register (cont’d) Flags in Status Register

b7 b6 b5 b4 b3 b2 b1 b0

Negative Overflow Zero Digit Carry Carry

C (Carry/Borrow Flag) set when an addition generates a carry and a

subtraction generates a borrow.

DC(Digit Carry Flag):also called Half Carry flag;set when carry generated

from Bit3 to Bit4 an arithmetic operatio.n

Z(Zero Flag):set when result of an operation is zero.

OV(Overflow Flag):set when result of an operation of signed numbers goes

beyond seven bits-if the results fall outside 127(0x7F)and -128(0x80).

N(Negative Flag):set when bit B7 is one of the result of an arithmetic/logic

operation.

- - - N OV Z DC C

Page 31: Embedded system (Chapter 2) part A

Example 1

Show the status of the C, DC and Z flag after the addition of 38H and 2FH.

Solution: 38H 00111000

+ 2FH + 00101111

67H 01100111

C = 0

DC = 1

Z = 0

Page 32: Embedded system (Chapter 2) part A

Review Questions

1. The flag register in PIC is called the _______.

2. What is the size of the flag register in PIC?

3. Which bits of the status register are unused?

4. Which bits of the status register are used for the C and DC flag bit respectively?

5. Show the status of the C, DC and Z flag after the addition of 9CH and 64FH.

Page 33: Embedded system (Chapter 2) part A

References

Microchip.com

Wikipedia, the free encyclopedia

http://www.engineersgarage.com