Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
COE 115
Lecture 1
UP EEEI CoE 115 Lecture 1 2
Coverage
• Programming structures and techniques.
• Conditional branching. Subroutines. Generating time delays and intervals.
Look-up tables. Indirect addressing.
• Digital interfacing.
• Analog sensing and A/D conversion. D/A conversion and PWM. Frequency
measurement.
• Communication.
• Bit banging, synchronous, asynchronous, SPI, I2C, USART, USB, CAN
• High-speed techniques and considerations
UP EEEI CoE 115 Lecture 1 5
Grading
• Lab Grade
• 65%
• Lecture Grade
• 35%
• Short Quizzes / Attendance / Etc 10%
• Long Quizzes (3) 90%
• LONG QUIZ
• September 21, 2019 (Saturday) 10-11:30 Lectures 1 -6
• October 10, 2019 (Monday) 10 -11 :30 Lectures 7-10
• November 15, 2019 (Saturday) 10 – 11:30 Lectures 10-14
• December 7, 2019 (Saturday) 10 -11:30 Lectures 14- 18
UP EEEI CoE 115 Lecture 1 6
Agenda
• Embedded Systems
• Microcontrollers
• Embedded applications using MCUs
• Basics of architecture
• PIC Microcontrollers
• PIC microcontrollers (Architecture)
• Memory organization and addressing modes
UP EEEI CoE 115 Lecture 1 7
Embedded Systems
• An embedded system is a special
purpose system that is used to
perform a dedicated function Home
Appliance
• Embedded systems encompass a
broad range of computational
power Printers
• Embedded systems seems
synonymous to “invisible” A/V Devices
UP EEEI CoE 115 Lecture 1 9
Domestic Refrigerator
UP EEEI CoE 115 Lecture 1 10
Serial Data
PIC Compass
Power 5V
Microcontroller Serial
Regulation & Clock
Management
Serial Extension Bus
9V
Alkaline Pulse Width Modulation
Stream x2
9V Motor Drive
Interface
Motor Motor
Left Right
UP EEEI CoE 115 Lecture 1 11
Dash Climate
window motor Board Control
lock control
lock actuator open door sensor
Driver's
Steering Seat
Central
Control Air Radio
Bag & CD
CAN Bus
Left
Door
UP EEEI CoE 115 Lecture 1 12
Embedded systems
• Cars
8
UP EEEI CoE 115 Lecture 1 13
Embedded systems
• Examples
• Digital and analog televisions
• Set-top boxes (DVDs, VCRs, Cable boxes)
• Personal digital assistants PDAs
• MP3 Players and iPods
• Kitchen appliances ( refrigerators, microwave ovens)
• Telephones, cell phones
• Cameras
• GPS receivers
• … and many others
UP EEEI CoE 115 Lecture 1 14
Embedded Computer
Conditioning
Conversion
Signal
Input
Output
Drive
EmbeddedSoftware
Computer Output
Conditioning
Data
Conversion
Variables Variables
Signal
Input
Output
Drive
Output
Data
Variables Software Variables
Hardware
Hardware
lens
• • Single-functioned
Single-functioned -- always a--digital
always a digital camera
camera
• Tightly-constrained -- Low cost, low power, small, fast
• Tightly constrained – Low cost, low power, small, fast
• Reactive and real-time -- only to a small extent
• Reactive and real-time – only to a small extent
13
UP EEEI CoE 115 Lecture 1 19
Analog
Electronics Computer Architecture
Embedded Systems
Sensors and Software Engineering
Measurements
Data
Electric Motors & Communications
Actuators Control
Engineering
UP EEEI CoE 115 Lecture 1 23
What is a Microcontroller?
The Microcontroller
• A microcontroller is a microprocessor designed primarily to perform
simple control functions.
• Usually have these features
• low cost,
• physically small,
• input/output intensive, and capable of easy interfacing,
• limited memory capability for program and data,
• instruction set leading to compact code, with limited arithmetic capability, •
ability to operate in a real-time environment.
• For some applications, these features may also be needed:
• ability to operate in hostile environment, e.g. high or low temperature,
tolerant to electromagnetic interference, low power, with features adapted
to battery power.
UP EEEI CoE 115 Lecture 1 25
What is a Microcontroller?
• Difference between microcontroller and a microprocessor
system.
UP EEEI CoE 115 Lecture 1 26
The Microcontroller
UP EEEI CoE 115 Lecture 1 27
What is a Microcontroller?
• A microcontroller has a processor and many peripherals integrated
with it on the same chip, like a flash memory, RAM, I/O ports, serial
communication ports, ADC …Etc.
UP EEEI CoE 115 Lecture 1 28
What is a Microcontroller?
• A timer module to allow the MCU to perform tasks for certain time
periods.
• A serial I/O port to allow data to flow between the MCU and other
devices such as a PC or another MCU
A Typical Microcontroller
• Central processing unit
• Arithmetic logic unit (ALU), which performs computation.
• Registers needed for the basic operation of the CPU, such as the program
counter (PC), stack pointer (SP), and status register (SR). or Special
function registers (SFR)
• Further registers to hold temporary results.
• Instruction decoder and other logic to control the CPU, handle resets,
and interrupts, and so on.
UP EEEI CoE 115 Lecture 1 30
What is a Microcontroller?
• A microprocessor can’t do all the functions of a computer system
on its own, and needs another circuits or devices to support it.
• I/O devices, RAM, ROM, DMA controllers, Timers, ADC, LCD driver.. Etc.
UP EEEI CoE 115 Lecture 1 31
A Typical Microcontroller
• Memory for the program: Nonvolatile (read-only memory, ROM),
meaning that it retains its contents when power is removed.
• Memory for data: Known as random- access memory (RAM) and
usually volatile.
• Input and output ports: To provide digital communication with the
outside world.
• Address and data buses: To link these subsystems to transfer data
and instructions.
• Clock: To keep the whole system synchronized.
UP EEEI CoE 115 Lecture 1 32
Comparison
UP EEEI CoE 115 Lecture 1 35
Motorola 68000
PIC 12F508
UP EEEI CoE 115 Lecture 1 37
memory), and EEPROM (for constants).1 The resulting board layout is depicted in Figure 1.1; as you
can see, there are a lot of chips on the board, which take up most of the space (euro format, 10 ⇥ 16
cm).
• Using Zilog Z80
Figure 1.1: Z80 board layout for 32 I/O pins and Flash, EEPROM, SRAM.
Incidentally, we could also solve the problem with the ATmega16 board we use in the Microcon-
troller lab. In Figure 1.2, you can see the corresponding part of this board superposed on the Z80
PCB. The reduction in size is about a factor 5-6, and the ATmega16 board has even more features
than the Z80 board (for example an analog converter)! The reason why we do not need much space
UP EEEI CoE 115 Lecture 1 38
Microcontroller Solution
Using
•1.1. An Atmega 16 board
INTRODUCTION 3
Figure 1.3: Pinouts of the Z80 processor (left) and the ATmega16 controller (right).
PC0-PC7, PD0-PD7, which can be used for different functions. For example, PD0 and PD1 can be
used as the receive and transmit lines of the built-in serial interface. Apart from the power supply,
the only dedicated pins on the ATmega16 are RESET, external crystal/oscillator XTAL1 and XTAL2,
and analog voltage reference AREF.
UP EEEI CoE 115 Lecture 1 40
Popular microcontrollers
• 8051 (Intel and others)
• 80286 EX (Intel)
• PIC (Microchip)
• 68HC05 (Motorola)
• Z8 (Zilog)
• MSP430 (TI)
UP EEEI CoE 115 Lecture 1 41
Agenda
• What are embedded systems? How do we implement them?
• What is a microcontroller
• Developing embedded applications using MCUs
• Basics of architecture
• PIC Microcontrollers
• Basics of PIC micro devices architecture
• Memory organization and addressing modes
• C Programming language
UP EEEI CoE 115 Lecture 1 42
Hardware Development
• This includes choosing the right MCU for your application so that it
can satisfy the required applications.
Which Microcontroller ?
• Which one for a given application
• Cost is important.
• Cheapest device that matches the application needs
• Microcontrollers are generally tailored for specific applications.
• Wide variety to choose from
UP EEEI CoE 115 Lecture 1 45
Which Microcontroller ?
• Controller family
• Defines the controller architecture
• Microcontrollers of same family will contain same processor core
• Code compatible
• Differ in additional components:
• amount of memory, number of timers, a different peripherals
• INTEL 8051, HC, PIC, ATMEL, TI
• Even in a single family there will be different controllers
UP EEEI CoE 115 Lecture 1 46
A Manufacturer’s Microcontroller Portfolio
Memory Memory
Core P Core Q Core R
Peripherals Peripherals Memory
Peripherals
Core P Memory Core Q Memory
Peripherals Peripherals
Core R Memory
Peripherals Peripherals
Memory
Core R
Memory Memory
Core Q
Core P
Peripherals Peripherals
Peripherals
UP EEEI CoE 115 Lecture 1 47
Software Development
UP EEEI CoE 115 Lecture 1 48
Software Development
UP EEEI CoE 115 Lecture 1 49
Software Development
• Using assembly language involves learning the microcontroller’s
specific instruction set and may result in more compact and faster
codes
C vs Assembly language
Linker
• The linker’s function is to link code modules saved in different files
together into a single final program .
Debugger
• Common debugging features include:
Software Development
• An Integrated Development Environment (IDE) puts all of the
previously discussed software components under one common
unified user interface
• MPLAB / MPLAB X ( Proprietary to Microchip)
• TI Code composer Studio ( Proprietary to TI)
• IAR Systems (3rd Party)
• KEIL (3rd Party)
Agenda
• What are embedded systems? How do we implement them?
• What is a microcontroller
• Developing embedded applications using MCUs
• Basics of architecture
• PIC Microcontrollers
• Basics of PIC micro devices architecture
• Memory organization and addressing modes
• C Programming language
UP EEEI CoE 115 Lecture 1 55
21
UP EEEI CoE 115 Lecture 1 57
Architecture (Instructions)
UP EEEI CoE 115 Lecture 1 58
Pipelining
Pipelining
Classic 5-stage RISC pipeline
Agenda
• What are embedded systems? How do we implement them?
• What is a microcontroller
• Developing embedded applications using MCUs
• Basics of architecture
• PIC Microcontrollers
• Basics of PIC micro devices architecture
• Memory organization and addressing modes
• C Programming language
UP EEEI CoE 115 Lecture 1 63
PIC microcontrollers
• One of the leading architectures
for low end applications (
applications requiring 4,8,16-bit
processors)
• Easier implementation to
pipelining without having a
complex hardware, less silicon
area and less power consumption
UP EEEI CoE 115 Lecture 1 64
PIC Microcontrollers
• PICmicro devices architecture
• Harvard, RISC architecture
• Instruction Pipelining
• An instruction is fetched and another instruction is executed at the same time
every single TCY
UP EEEI CoE 115 Lecture 1 65
Agenda
• What are embedded systems? How do we implement them?
• What is a microcontroller
• Developing embedded applications using MCUs
• Basics of architecture
• PIC Microcontrollers
• Basics of PIC micro devices architecture
• Memory organization and addressing modes
• C Programming language
UP EEEI CoE 115 Lecture 1 67
Oscillator
• Choice of suitable oscillator mode in the applications according to:
Oscillator
UP EEEI CoE 115 Lecture 1 69
Oscillator
UP EEEI CoE 115 Lecture 1 70
Instruction Cycle
• Time of fetching, decoding and executing an instruction is
the instruction cycle.
• For PICmicro devices:
UP EEEI CoE 115 Lecture 1 71
Instruction Cycle
• The instruction fetch begins with the program counter incrementing
Q1
• In the execution cycle, the fetched instruction is latched in the
“Instruction Register (IR) in cycle Q1. This instruction is then
decoded and executed during the Q2, Q3 and Q4 cycles. Data
memory is read during Q2 (operand read) and written during Q4
(destination write)
UP EEEI CoE 115 Lecture 1 72
Instruction Cycle
• Each instruction is fetched in one instruction cycle, and
then decoded and executed in another instruction cycle
Instruction cycle
• Ex. If you use a 4 MHz oscillator, the MCU will execute 1 Million
instruction per second (1 MIPS)
Agenda
• What are embedded systems? How do we implement them?
• What is a microcontroller
• Developing embedded applications using MCUs
• Basics of architecture
• PIC Microcontrollers
• Basics of PIC micro devices architecture
• Memory organization and addressing modes
• C Programming language
UP EEEI CoE 115 Lecture 1 75
Memory Organization
UP EEEI CoE 115 Lecture 1 76
UP EEEI CoE 115 Lecture 1 77
Memory organization
UP EEEI CoE 115 Lecture 1 78
Memory Organization
UP EEEI CoE 115 Lecture 1 79
Memory Organization
UP EEEI CoE 115 Lecture 1 80
Memory Organization
UP EEEI CoE 115 Lecture 1 81
Agenda
• What are embedded systems? How do we implement them?
• What is a microcontroller
• Developing embedded applications using MCUs
• Basics of architecture
• PIC Microcontrollers
• Basics of PIC micro devices architecture
• Memory organization and addressing modes
• C Programming language
UP EEEI CoE 115 Lecture 1 82
C Programming Language
• Features of C
• Extensive use of function calls
• Low level (Bitwise) programming readily available
• Pointer implementation- extensive user of pointers for memory and
arrays
• Structures and functions
• Can handle low-level activities
• Produces efficient programs
• Fast
• It can be compiled on a variety of computers
UP EEEI CoE 115 Lecture 1 83
C Programming Language
UP EEEI CoE 115 Lecture 1 84
Data Types
UP EEEI CoE 115 Lecture 1 85
Operators
UP EEEI CoE 115 Lecture 1 86
Operators
UP EEEI CoE 115 Lecture 1 87
Conditional Statements
UP EEEI CoE 115 Lecture 1 88
Switch Statements
UP EEEI CoE 115 Lecture 1 89
For loop
UP EEEI CoE 115 Lecture 1 90
Arrays
UP EEEI CoE 115 Lecture 1 92
Functions
UP EEEI CoE 115 Lecture 1 93
Agenda
• Embedded Systems
• Microcontrollers
• Embedded applications using MCUs
• Basics of architecture
• PIC Microcontrollers
• PIC microcontrollers (Architecture)
• Memory organization and addressing modes
UP EEEI CoE 115 Lecture 1 95
Summary