Download as pdf or txt
Download as pdf or txt
You are on page 1of 25

Department of Computer Engineering

Microprocessor and Embedded Systems

Lecture 1
Embedded Systems

Dr. Shubat Owhida

1/5/2023 1
Embedded Systems

Definition: an embedded system is any device that includes a


programmable processor to do dedicated task.
Or: An embedded system is a system whose principal function is
controlled by a microcontroller embedded within it.

Generic Block Diagram of Embedded System 1


The Microcontroller

A microcontroller is a microprocessor designed primarily to


perform simple control functions. Microcontrollers usually have
these features
 Low cost,
 Physically small,
 Input/output intensive, and capable of easy interfacing,
Limited memory capability for program and data,
 Instruction with limited arithmetic capability,
 Ability to operate in a real-time environment.
 In certain applications : Ability to operate in hostile
environment, e.g. high or low temperature, tolerant to
electromagnetic interference are essential

3
Block Diagram of a General-Purpose Controller

Program Further
Power Memory Peripheral

Data Further
Memory Peripheral

Digital
I/0
Mic roproc essor
Reset Core
Interrup t(s) Analog
I/0
Internal Data &
Address Buses
Clock Counters
& Timers

A microcontroller = microprocessor core + memory + peripherals


The Microchip PIC Families

The “PIC” was originally a design of the company General


Instruments. It was intended for simple control applications,
hence the name: Peripheral Interface Controller.

Microcontroller Data width


8-bit Microcontrollers
PIC10, PIC12, PIC14
PIC16, PIC17, PIC18
16-bit Microcontrollers
PIC24F, PIC24H
32-bit Microcontrollers
PIC32
16-bit Digital Signal Controllers
DSP IC30
DSP IC33F
6
PIC 18 Feathers

RISC Architecture
On-chip program, Code, ROM
Data RAM & EEPROM
Timers
ADC
USART
I/O Ports

6
PIC Microcontroller program ROM

It’s used to store Program or code


PIC 18 can support up to 2MB
Generally, they come with 4KB – 128KB
Available in flash, One Time Programmable (OTP), UV-
EPROM, and masked.
Flash memory can be erased in second compared to 20 minute
needed for UV-EPROM
Masked PIC program will be burned into the PIC chip during
the fabrication process
OTP PIC Used for mass production

7
PIC data RAM and EEPROM

Max. 4096 Bytes (4 KB) of data RAM space.

Data RAM space has two components

Varied GPR, General Purpose RAM

 For read/write and data manipulation

 Divided into banks of 256 B


Fixed SFR, Special Function Registers

Some of PICs have a small amount of EEPROM

Used for critical data storing

8
In PIC18, the execution unit takes 4 clock periods

PIC multistage execution pipeline

PIC18 provides 4 addressing modes


Immediate
Direct
Register indirect
Indexed-ROM 9
PIC18 Microcontroller Registers
The Working Register (WREG)
The PIC File Register

The WREG Register (8 bit)


Many registers for arithmetic and logic operation. The WREG
(Working Register) Register is one of the most widely used registers
of the PIC

Example of using WREG


MOVLW
MOVLW k ; Move literal value k into WREG

MOVLW 25H ; 25H → WREG

ADDLW k ; Add literal value k to WREG (k +WREG)


Register File Concept
Register File Concept: Any location in data memory may be operated
on directly, and all peripherals are mapped into data memory as a
series of registers. The PIC18 Family can have a maximum of 4096
Bytes of File Register. Include:

Special Function Registers PIC File Register

Dedicated to specific functions such


General Special Function
as ALU status, timers, serial Purpose RAM Registers

communication, I/O ports, ADC


General Purpose RAM GP RAM EEPROM

Group of RAM locations

The File Register has addresses of 000- FFFH, divided into16 banks
each of size 256 bytes.
Bank switching is a method used to access all the banks. 11
Access bank in the PIC18

Every PIC18 has the access bank


It is 256-Byte bank (default bank).
Divided into equal two discontinuous sections (each 128 B).
GP RAM, from 0 to 7FH
SFR, from F80H to FFFH

Bank switching in the PIC18


Most PIC18 that access the data space in RAM has the ability
to access any bank through setting an optional operand, called A

MOVWF myReg, A
If 0 it access the default bank (default)
If 1, it uses the bank selection register (BSR) to select the bank
12
SFRs of the PIC18 Family

13
The BSR register and bank switching

The BSR is 8-bit register


4 bits are used  16 banks
Banks 0 (from 00 to FF)
Banks 1 (from 100 to 1FF)
Banks 2 (from 200 to 2FF)
.....
Banks F (from F00 to FFF) (includes SFR)

Upon power-on reset, BSR is equal to 0 (default value)

A: Bit in the Instruction Field for INCF F, D, A


Two thing must be done
Load BSR with desired bank by making A = 1 in the instruction
D : destination address (File REG or WREG)
14
Example of using BSR

Write a program to copy the value 55H into RAM memory locations
340H to 342H

Solution
MOVLB 03 ; Bank 3
MOVLW 55 ; WREG = 55H
MOVWF 40, 1 ; Copy WREG to RAM location 340H
MOVWF 41, 1 ; Copy WREG to RAM location 340H
MOVWF 42, 1 ; Copy WREG to RAM location 340H

15
Instruction with the default access bank

MOVWF instruction
MOVWF Address ; F indicates for a file register
;Copy WREG, to a destination in the file register.
Example:
MOVLW 99H
MOVWF 12H
It cannot move literal values directly into the general purpose RAM
location in the PIC18

Address Data
012H 99
99 H → WREG
013H
014H
16
ADDWF Instruction

ADDWF File Reg. Address, D ; Adds together the content of


WREG and a file register location
If D=0 or D=W (Destination WREG)
If D=1 or D=F (Destination File register)

Example
State the content of file register location and WREG after the
following program:

MOVLW 0
MOVWF 12H
MOVLW 22H
ADDWF 12H, F 99 H → WREG
Address Data
ADDWF 12H, F 012H 44
013H
17
COMF instruction

Complement the content of File Register and places the results


in WREG or in File Register.
Example Address Data
MOVLW 55H F81H AAH
F82H
MOVWF PORTB F83H
B1 COMF PORTB, F
GOTO B1

DECF instruction
Example:
MOVLW 2 Address Data
MOVWF 12H 012H 0
013H
DECF 12H, F 014H
DECF 12H, F 21
MOVF instruction

MOVF File Reg. Address, D


If D=0 or D=W
; Copies the content of File Register (from I/O pin) to WREG
If D=1 or D=F
; The content of the File Register is copied to itself.
Example:
Write a simple program to get data from the SFRs of Port B and send
it the SFRs of PORT C continuously. Address Data
AGAIN MOVF PORTB, W F81H XX
F82H
MOVWF PORTC F83H

GOTO AGAIN Address Data


F81H XX
F82H XX
F83H 22
MOVFF instruction

MOVFF Source FileReg, Destination FileReg

Example
Write a simple program to get data from the SFRs of Port B and
send it the SFRs of PORT C continuously.

AGAIN MOVFF PORTB, PORTC


GOTO AGAIN

20
Arithmetic Instructions

ADDLW k
ADDWF FileReg, D
ADDWFC ;With carry (adding two 16-bit numbers)

Example
MOVLW F5 ; WREG = F5
ADDLW 0B ; WREG= F5 + 0B = 00 C=1

Example
MOVLW E7 ; WREG = E7
ADDWF 06, F ; F = W + F = E7 + 8D = 74 and C=1
MOVLW 3C ; WREG = 3C
ADDWFC 07, F ;F=W+F+C

21
Instructions cont......

DAW, Decimal Adjust WREG

SUBLW k ; (WREG= k- WREG)


SUBWF F, D ; ( destination = fileReg – WREG)
SUBWFB ; (subtract with borrow )
SUBFWB ; (subtract with borrow )

Example
MOVLW 23 ; WREG=23
SUBLW 3F ; WREG = 3F - WREG

22
MUL Instruction

Example
MOVLW 25 ; WREG=25
MULLW 65 ; WREG=25 * 65

Logical instructions

ANDLW k
ANDFW FileReg, D
IORLW k
IORFW FileReg, D
XORLW k
XORFW FileReg, D

Effect only Z and N Flags


23
Compare Instructions
CPFSGT ; Skip if FileReg > WREG
CPFSEG ; Skip if FileReg = WREG
CPFSLT ; Skip if FileReg < WREG

NEGF FileReg
Takes the 2’s complement of a file register; Effect all Flags

PIC Status Register (8 bit)


Five bits are used
D0: C Carry Flag
D1: DC Digital Carry Flag
D2: Z Zero Flag
D3: OV Overflow Flag
D4: N Negative Flag
27
Instruction That affect flag Bits

28

You might also like