Embedded System
Embedded System
Lecture 1
Embedded Systems
1/5/2023 1
Embedded Systems
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
RISC Architecture
On-chip program, Code, ROM
Data RAM & EEPROM
Timers
ADC
USART
I/O Ports
6
PIC Microcontroller program ROM
7
PIC data RAM and EEPROM
8
In PIC18, the execution unit takes 4 clock periods
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
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
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
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
DECF instruction
Example:
MOVLW 2 Address Data
MOVWF 12H 012H 0
013H
DECF 12H, F 014H
DECF 12H, F 21
MOVF instruction
Example
Write a simple program to get data from the SFRs of Port B and
send it the SFRs of PORT C continuously.
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......
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
NEGF FileReg
Takes the 2’s complement of a file register; Effect all Flags
28