0% found this document useful (0 votes)
19 views

Week3 Microcontroller and Assembly Language

This document provides an overview of microcontrollers and assembly language. It discusses the history of microcontrollers, differences between microprocessors and microcontrollers, common microcontroller hardware such as memory organization and registers. It also covers assembly language fundamentals like opcodes, structure of assembly code, and creating delays. The objectives are to review numbering conversions, microcontroller architecture, assembly language basics, and using opcodes to manipulate data.

Uploaded by

Felipe Teixeira
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Week3 Microcontroller and Assembly Language

This document provides an overview of microcontrollers and assembly language. It discusses the history of microcontrollers, differences between microprocessors and microcontrollers, common microcontroller hardware such as memory organization and registers. It also covers assembly language fundamentals like opcodes, structure of assembly code, and creating delays. The objectives are to review numbering conversions, microcontroller architecture, assembly language basics, and using opcodes to manipulate data.

Uploaded by

Felipe Teixeira
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

ROBO-354

Electric Machinery and


Microcontrollers

School of Engineering Technology & Applied Science


(SETAS)
Advanced Manufacturing and Automation Technology
(AMAT)

Week # 3

Microcontroller and Assembly


Language
Objectives

• Review of numbering conversion


• History of microcontroller
• Microprocessor VS. Microcontroller
• Microcontroller hardware architecture
• Memory organization
• Registers
• TRIS and PORT
• Important facts of assembly language
• Structure of assembly language
• Understanding opcodes (instructions)
• Creating delays

2
Numbering Conversion

• Human prefers decimal (2510)


• Machine prefers binary (11012)
• Programmer prefers hexadecimal (1916)

Decimal

Hexadecimal Binary

3
History

• In the 1940s, US government asked Harvard and Princeton


university to come up with a computer architecture to be
used in computing tables of naval artillery shell distances for
varying elevation and environmental conditions.
• Princeton architecture won the competition because it was
better suited to the technology of the time (before transistors
were even invented)
• Harvard architecture was largely ignore until the late 1970s,
when uC manufacturers realized that the architecture did not
have the instruction/data bottleneck.
• PIC MCU (Micro Computer Unit) is also employed Harvard
architecture.
• PIC : Peripheral Interface Controller
4
Other 8-bit uC

• Microchip: PIC10XXX, PIC12XXX, 14, 16, 18)


– Which one is using in our lab: ???
• Intel: 8051
• Atmel: AVR and 8051
• Philips: 8051
• Zilogs: Z8 and Z80
• Freescale: 68HC11 and 68HC08
• Note:
– PIC16FXXX has on-chip program ROM (Read-Only Memory) in form of
flash memory type EEPROM (Electronically Erasable Programmable
Read-Only Memory), it is great for testing and prototyping.
– PIC16CXXX has program ROM in form of OTP memory (One-Time
Programmable), it is great for mass production (low cost).

5
Microprocessor Versus Microcontroller

6
Choosing Microcontroller

• Meet the computing needs ( Speed, RAM, ROM, I/O…etc)

• Power consumptions

• Availability and accessibility of software and hardware such


as compiler, assembler, debugger, emulator…etc

• Wide variety and reliable sources (Manufacturers)

• Cost per unit

7
PIC Microcontroller

• The PIC uC has a RISC (Reduced Instruction Set Computer)


architecture
• It comes with some standard feature such as
–On-chip program ROM for storing codes or instructions
–RAM for storing data (volatile or temporary)
–EEPROM for storing data (none-volatile or permanent)
–I/O ports for interfacing with outside world
–Timer for creating delays
–Counter for counting events
–ADC (Analog to Digital Converter) for converting continues
variable to binary number
–USART (Universal Synchronous Asynchronous Receiver
Transmitter) for communications
8
Hardware Architecture

9
Feature Comparison

PIC16F747 PIC16F767 PIC18F4580


Program Memory
(ROM)
Data Memory (RAM)
Data Memory
(EEPROM)
I/O

Timer

ADC

Pin

10
Memory Organization, ROM (Read Only Memory)

11
Memory Organization, RAM (Random Access Memory)

• RAM
– SFR (Special Function Register)
– GPR (General Purpose Register)
• SFRs are dedicated to specific functions such as ALU Status, Port,
Timer, ADC …etc. It has a fixed hardware address.
Ex: STATUS 03h
PORTA ?
TRISA ?
• GPRs are used for data storage and scratch pad, 8 bits of data can
be stored in each location or address.

12
• RAM StructureOrganization,
Memory of RAM (Random Access Memory)
PIC16F747 divided
into 4 Banks
• Each bank consists of
SFR and GPR
• Bank changing request
must be performed prior
to access its contents

13
Registers

• CPU uses many register to store data temporarily

• WREG (Working Register) is the most important one, which plays


role in processing data for Assembly language

• WREG is used for all arithmetic and logic operations

• WREG can only store 8 bits of data

• Note: Any data larger than 8 bits must be broken into 8-bit chunks
or byte side before it is able to process

14
Working Register (WREG)

SETAS - AMAT: EET-323 Week #1 15


STATUS Register

• The Status register contains the arithmetic status of the ALU, the
Reset status and the bank select bits for data memory
• Because of data memory (RAM) is partitioned into multiple banks,
Bits RP1 (Status<6>) and RP0 (Status<5>) are used to access
desired bank select

16
TRIS and PORT Register

17
TRIS and PORT Register

• PORT is an I/O point which allows microcontroller to interact with


outside world

• Some pins for these I/O Ports are multiplexed with an alternate
function for the peripheral features on the device.

• TRIS determines PORT’s direction, as input or output

• Set TRIS bit (=1) will make PORT’s pin input

• Clear TRIS bit (=0) will make PORT’s pin output

• Ex: TRISA = 0xFF PORTA input

TRISB = 0 PORTB output

18
Programming in Assembly Language

• All CPUs are able to work only in binary (0 and 1) but at a


very high speed pace
• Program that consist of 0 and 1 is called machine language
• Hexadecimal numbering system is used to represent binary
numbers because it is more efficient and less cumbersome
• Assembly language were developed, which provided
mnemonics for the machine code instructions, plus other
features that made programming faster and less prone to
error
• Assembly codes are translated into machine codes by a
program called Assembler
• Assembly language is referred to as a low-level language
because it deals directly with the internal structure of the
CPU
19
Structure of Assembly Language

• An Assembly Language consists of four fields


#1 #2 #3 #4
[Label] Mnemonic [Operand] [; Comment]

Note: Brackets indicate that a field is optional and not all lines
have them

• Mnemonic = Opcode = Instruction


• ORG and END are directive to Assembler while Opcodes are
directive to CPU

20
Structure of Assembly Language

21
Opcodes (Instructions)

• MOVLW K : moves literal value K into WREG


8-bit value (00 to FF)
Working register
Literal (Constant)
Move (Copy)
Ex. MOVLW 0xA0

22
Opcodes (Instructions)

• ADDLW K : ??

• Ex: Write codes to add decimal number 50 to 100

23
Opcodes (Instructions)

• Write codes to move value 0xAA to PORTB register

• Write codes to flash all bits of PORTB on and off

24
Creating Delays

• Short delay sub-routine


DELAY MOVLW 0xC8
MOVWF COUNT1
LOOP DECFSZ COUNT1, 1
GOTO LOOP
RETURN

1- Calculate total machine cycle of the delay sub-routine?


2- Calculate total time delay if oscillator’s frequency is 1MHz?

25
Programming Microcontroller

• ICSP (In-Circuit Serial Programmer) is an interface used to program


PIC uC
• PICkit 2/3 is used as Programmer and Debugger
• Programming pin configurations

26
Review Questions

1. What is MCU and PIC stand for?


2. What architecture does PIC adopted? (Harvard/Princeton)
3. Microcontroller is an integration of microprocessor and other
peripherals. (T/F)
4. Which of the components below is used to provide clock signal to
CPU? (ROM, RAM, Timer, Oscillator)
5. Instruction codes are stored in ROM, while data are stored in
RAM. (T/F)
6. The stored contains in ROM and RAM will be lost when supplied
power is removed. (T/F)
7. 8-bit microcontroller can only process 8 bits of data or less. (T/F)
8. It is highly recommended to store temporary processing data in
one of these: ROM, SFR, GPR, Does not really matter.

27

You might also like