The University of Texas at Arlington Lecture 7

Similar documents
Arithmetic,logic Instruction and Programs

Arithmetic and Logic Instructions. Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan

The University of Texas at Arlington Lecture 5

The University of Texas at Arlington Lecture 3

PIC Architecture & Assembly Language Programming. Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan

Chapter 4 Sections 1 4, 10 Dr. Iyad Jafar

ECE Test #1: Name

Section 31. Instruction Set

Assembly Language Instructions

PIC 16F84A programming (II)

CENG 336 INT. TO EMBEDDED SYSTEMS DEVELOPMENT. Spring 2006

Lecture (04) PIC16F84A (3)

16.317: Microprocessor-Based Systems I Summer 2012

Chapter 5. Problems All programming problems should include design pseudo code either as a separate design document on embedded comments in the code.

SOLUTIONS!! DO NOT DISTRIBUTE!!

TOPIC 3 INTRODUCTION TO PIC ASSEMBLY LANGUAGE. E4160 Microprocessor & Microcontroller System. Prepared by : Puziah Yahaya JKE, POLISAS / DEC 2010

DERTS Design Requirements (1): Microcontroller Architecture & Programming

16.317: Microprocessor-Based Systems I Spring 2012

Lesson 14. Title of the Experiment: Introduction to Microcontroller (Activity number of the GCE Advanced Level practical Guide 27)

LAB WORK 2. 1) Debugger-Select Tool-MPLAB SIM View-Program Memory Trace the program by F7 button. Lab Work

EEE111A/B Microprocessors

CHAPTER 6 ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS

4.5.1) The Label Field ) The Mnemonic Field. 4.5) Assembly Language Program Structure A PIC18 ALP consists of 3 type of statements:

/ 40 Q3: Writing PIC / 40 assembly language TOTAL SCORE / 100 EXTRA CREDIT / 10

Input/Output Ports and Interfacing

ENE 334 Microprocessors

16.317: Microprocessor-Based Systems I Fall 2012

PIC16F87X 13.0 INSTRUCTION SET SUMMARY INSTRUCTIONS DESCRIPTIONS

16.317: Microprocessor Systems Design I Fall 2013 Exam 3 Solution

Instuction set

ALU and Arithmetic Operations


EEE3410 Microcontroller Applications Department of Electrical Engineering Lecture 4 The 8051 Architecture

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING. EE6008 Microcontroller based system design

Chapter 6. Problems All programming problems should include design pseudo code either as a separate design document on embedded comments in the code.

Embedded Systems. PIC16F84A Sample Programs. Eng. Anis Nazer First Semester

EECE.3170: Microprocessor Systems Design I Summer 2017 Homework 5 Solution

ET355 Microprocessors Thursday 6:00 pm 10:20 pm

PIC Discussion. By Eng. Tamar Jomaa

Hi Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan

16.317: Microprocessor Systems Design I Spring 2015

Mod-5: PIC 18 Introduction 1. Module 5

ME 515 Mechatronics. A microprocessor

APPLICATION NOTE 2361 Interfacing an SPI-Interface RTC with a PIC Microcontroller

Week1. EEE305 Microcontroller Key Points

Flow Charts and Assembler Programs

UNIVERSITY OF ULSTER UNIVERSITY EXAMINATIONS : 2001/2002. Semester 2. Year 2 MICROCONTROLLER SYSTEMS. Module Code: EEE305J2. Time allowed: 3 Hours

APPLICATION NOTE Wire Communication with a Microchip PICmicro Microcontroller

ELEG3923 Microprocessor Ch.6 Arithmetic and Logics

DS2401 Silicon Serial Number

UNIVERSITY OF ULSTER UNIVERSITY EXAMINATIONS : 2001/2002 RESIT. Year 2 MICROCONTROLLER SYSTEMS. Module Code: EEE305J1. Time allowed: 3 Hours

THE UNIVERSITY OF THE WEST INDIES

NH-67, TRICHY MAIN ROAD, PULIYUR, C.F , KARUR DT. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING COURSE MATERIAL

Mechatronics and Measurement. Lecturer:Dung-An Wang Lecture 6

DS1306. Serial Alarm Real Time Clock (RTC)

More (up a level)... Connecting the Nokia 3510i LCD to a Microchip PIC16F84 microcontroller

PTK8756B 8 Bit Micro-controller Data Sheet

ECE Homework #3

DS1302. Trickle Charge Timekeeping Chip FEATURES PIN ASSIGNMENT PIN DESCRIPTION

ELEG3923 Microprocessor Ch.2 Assembly Language Programming

8051 Overview and Instruction Set

EE 367 Introduction to Microprocessors Homework 6

DS2401 Silicon Serial Number

Chapter 13. PIC Family Microcontroller

CONNECT TO THE PIC. A Simple Development Board

Fortune. Semiconductor Corporation 富晶半導體股份有限公司. 8-bit MCU with 1k program ROM, 64-byte RAM, 1 R2F module and 3 13 LCD driver. TD Rev. 1.

Microcontroller. Instruction set of 8051

Q1: Multiple choice / 20 Q2: Protected mode memory accesses. / 40 Q3: Reading PIC. / 40 assembly language TOTAL SCORE / 100

FIFTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLOGY-MARCH 2014 EMBEDDED SYSTEMS (Common for CT,CM) [Time: 3 hours] (Maximum marks : 100)

ELEG3924 Microprocessor

DS2405. Addressable Switch PIN ASSIGNMENT

e-pg Pathshala Subject : Computer Science Paper: Embedded System Module: 8051 Architecture Module No: CS/ES/5 Quadrant 1 e-text

ME 6405 Introduction to Mechatronics

Digital Arithmetic. Digital Arithmetic: Operations and Circuits Dr. Farahmand

PIC18F452 Timer adjustment

TUTORIAL Assembly Language programming (2)

DS2401. Silicon Serial Number FEATURES PIN ASSIGNMENT

Principle and Interface Techniques of Microcontroller

PIC16F84A 7.0 INSTRUCTION SET SUMMARY INSTRUCTIONS DESCRIPTIONS

DS1305. Serial Alarm Real Time Clock (RTC) FEATURES PIN ASSIGNMENT ORDERING INFORMATION

Microcontroller systems Lec 2 PIC18LF8722 Microcontroller s s core

C and Embedded Systems. So Why Learn Assembly Language? C Compilation. PICC Lite C Compiler. PICC Lite C Optimization Results (Lab #13)

/ 28 HLL assembly Q4: Conditional instructions / 40 TOTAL SCORE / 100 EXTRA CREDIT / 10

SOLAR TRACKING SYSTEM USING PIC16F84A STEPPER MOTOR AND 555TIMER

DS2430A 256-Bit 1-Wire EEPROM

BINARY SYSTEM. Binary system is used in digital systems because it is:

Lecture Topics. Announcements. Today: Integer Arithmetic (P&H ) Next: continued. Consulting hours. Introduction to Sim. Milestone #1 (due 1/26)

DS1305 Serial Alarm Real Time Clock (RTC)

ME 475 Lab2 Introduction of PIC and Programming. Instructor: Zhen Wang

Controller Provides Display of Monitored Process Deviation

8051 Programming: Arithmetic and Logic

8051 Microcontrollers

Chapter 2 Number System

Assembly Language Design

DS1306 Serial Alarm Real-Time Clock

Programming of 8085 microprocessor and 8051 micro controller Study material

DS2223/DS2224. EconoRAM FEATURES PACKAGE OUTLINE. PIN CONNECTIONS Pin 1 GND Ground Pin 2 DQ Data In/Out Pin 3 V CC Supply Pin 4 GND Ground

Micro II and Embedded Systems

8051 Microcontrollers

Dept. of Computer Engineering Final Exam, First Semester: 2016/2017

Transcription:

The University of Texas at Arlington Lecture 7 CSE 3442/5442

Agenda HW 2 due today Begin Chapter 5 In class assignment. Reading Assignment for Tuesday, Continue Reading Chapter 6. Assignment 3 and 4 due Tuesday (September17) 2

Example of Interfacing PIC to LED/Switches on QwikFlash Potentiometer 1 k pull up resistor on OPEN DRAIN Push Button Switch 3

Use of RA4 on QuickFlash- (Open Drain pin) see http://en.wikipedia.org/wiki/open_drain An open drain terminal is connected to ground in the low voltage (logic 0) state, but has high impedance in the logic 1 state. This prohibits current flow, but as a result, such a device requires an external pull-up resistor which is also connected to the positive voltage 4

Open-Drain Discussion- Cont. When a device is in the high-impedance state, the pull-up resistor keeps the line at logic 1. The line stays there until the device goes into the logic 0 state, and begins to sink current. This current flow creates a voltage drop across the pull-up resistor, and the line drops to the logic 0 voltage. 5

Open-Drain Discussion- Cont. Open-drain devices are commonly used to connect multiple devices to a bus.this enables one device to drive the bus without interference from the other inactive devices - if open-drain devices are not used, then the outputs of the inactive devices would attempt to hold the bus voltage high, resulting in unpredictable output. 6

Consider the One-Transistor Inverter Figure C-2 in the Appendix illustrates the simple transistor inverter. 7

Some Logic Family Specifications 8

Drive and Fan Out Capabilities of Different Semiconductor Families 9

Computing The Fan-Out 10

STD TTL Low I OL /I IL = 16/1.6 = 10 High I OH /I Ih = 0.4/.04 = 10 11

Computing Pull Up Value for Open Collector 12

Consider Pull up for the One- Transistor Inverter Assume R C in figure below, is an external pull up resistor V OL = V CC - V IL v OH ~ V IH(max) I PU I PU IOH(Leakage) I OL I IL I PU = I OL + I IL I IH I PU = I OH - I IH 13

Driving Multiple Devices For driving multiple (N) similar modules, use R Max = ()V CC - V O )/(I PU ) where: V O set to 0 I PU = I OL - N*I IL R Min = (V CC - V IH )/(I PU ) where: V IH I PU = I OH + N*I IH Also See: http://www.interfacebus.com/ic_open_collector_output _pins.html 14

Computing Pull-Up Resistor TPS62067 into TPS62067 From Referenced TI Application Note: SLVA485-Oct 2011 See Link http://www.ti.com/lit/an/slva485/slva485.pdf 15

Open Drain Example - TI Application SLVA485) 16

TI Application SLVA485 pp. 2 SVS Supply Voltage Supervisor PG - power good and LBI - Low battery 17

Open Drain High 18

Computing R pull-up Max And I pullup 19

I OL 20

Open Drain Low V PG = 0 for Lower R 21

Computing R pull-up Min And I pullup V PG = 0 for Lower R, or use Vout 22

R pull-up 1.8 kω R Pull-up 727.3 k Ω 23

Chapter 5 ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS 24

Chapter 5 Instructions ADDWF filereg d add contents of working register to filereg result in filereg or WREG ADDWFC same as first instruction but adds previous carry bit to result (multibyte instructions) C = 1 3C E7 + 3B 8D -------------- = 78 74 25

ADDWFC ; Loc 6 = (8D) ; Loc 7 = (3B) MOVLW 0xE7 ;Load WREG with E7H ADDWF 0x6,F ;F = W + F C=1 MOVLW 0x3C ; WREG 3CH ADDWFC 0x7,F ; F = W + F + carry 26

BCD/DAW Unpacked BCD lower bits number in BCD upper 4 bits zero Packed BCD both lower 4 and upper 4 bits BCD number DAW, decimal adjust MOVLW 0X47 ADDLW 0X25 DAW ; ADJUST FOR BCD (WREG = 72H) 27

Multiplication of unsigned numbers MULLW K ;PRODH = high byte, SFR and PRODL = low byte Byte x Byte WREG K SFR One byte must be in WREG and second - Literal 28

Division of Unsigned Numbers No single instruction for division of byte/byte numbers in PIC18. Must use repeated subtraction see Example 5-8 pp164 29

Signed Numbers Positive numbers +127 to -128 Overflows indicated by flag in Status Register (See examples pp 169-170) If result of an operation on signed numbers too large for the register 30

OV flag The Overflow flag is set when 1. carry from D6 to D7 but no carry out (C=0) 2. carry from D7 our (C=1) but no carry from D6 to D7 31

Example 5-14 Example: -128 1000 0000 + -2 1111 1110-130 0111 1110 N=0, C=1 No carry from D6 to D7 32

Logic Instructions AND OR XORLW K (exclusive of two operands) COMF (complement filereg) (1 s Complement) NEG (negate filereg) (2 s Complement) 33

Compare Instructions CPFSGT Skip if FileREG > WREG CPFSEQ Skip if FileREG = WREG CPFSLT Skip if FileREG < WREG 34

Rotate and Swap Nibbles RRNCF(RLNCF) filereg,d ; rotate right/left RRCF(RLCF) filereg,d ; rotate right/left through carry SWAPF filereg,d ; swaps upper and lower nibbles (4bits) 35

36

Embedded Design with the PIC18F452 Microcontroller Prentice Hall, 2003 Peatman 37

Work the following Examples in Class 1a. Find the C,Z, and DC flags for: MOVLW 0x3F ADDLW 0X45 1b. MOVLW 0xEF MOVWF MYREG BSF STATUS,C MOVLW 0 ADDWFC MYREG,F 38

In Class Example - CONT 2. True or False The DAW instruction only works with the WREG register 3. Which register holds the OV flag 4. True or False In using the CPFSEQ instruction, we must use WREG as one of the registers. 39

Parity and Check Sum Parity and Check Sum: Parity and checksum are used to help insure data is transmitted from one module to another without loss of bits or data. Your text discusses check sum in Chapter 5. Neither method will guarantee signal integrity, but are simple methods often used for aiding loss of information in communications. 40

Parity and Check Sum Check Sum: 1. Add the bytes and ignore the carries 2. The 2 s complement of the result in 1. forms the check sum. Parity: For odd carry, count the number of ones in each column. Make the carry bit for that column one if there is an even number of ones. If an odd number the carry bit should be zero. 41

Parity and Check Sum cont. Parity Example Check Sum Example 1001 40 0110 20 1101 31 1111 91 = 1001 0001 0010 Or 2 s Comp. 0110 1111 42

43

44

45

Parity and Checksum Additional Examples: The (vertical) parity and checksum bytes for the following four hex bytes are 35 (0011 0101) and E8 respectively. 23 (0010 0011) 23 + A2 + 8F + C4 = 218h A2 (1010 0010) 0001 1000 = 1110 0111 = 8F (1000 1111) E7 + 1 = E8 C4 (1100 0100) 0011 0101 35 Parity (odd) 46

In Class Assignment #2 cont. The Hex files generated by Microchip s assembler uses a check sum with each load file. Additional information can be found on the web at the following two links: http://en.wikipedia.org/wiki/parity_bit http://en.wikipedia.org/wiki/checksum 47

Parity and Checksum cont. Compute first the odd (vertical) parity byte and then checksum for the following bytes: 1. 0010 1001 29 1101 0111 D7 1000 1010 8A 1100 1001 C9 48

In Class Assignment - Answers 1. a. Find the C,Z, and DC flags for: MOVLW 0x3F ADDLW 0X45 3 F +4 5 -------------- = 8 4 C = 0, Z=0, DC = 1 49

Answers - Continued b. MOVLW 0xEF MOVWF MYREG BSF STATUS,C MOVLW 0 ADDWFC MYREG,F 1 + E F + 0 0 -------------- = (0) F 0 C = 0, Z=0, DC = 1 50

Answers - Continued 2. True or False The DAW instruction only works with the WREG register - TRUE 3. Which register holds the OV flag - STATUS 4. True or False In using the CPFSEQ instruction, we must use WREG as one of the registers. - TRUE 51

Parity and Checksum cont. Compute first the odd (vertical) parity byte and then checksum for the following bytes: 1. 0010 1001 29 1101 0111 D7 1000 1010 8A 1100 1001 C9 0100 0010 ODD Parity AD Check Sum 52

Chapter 6 Addressing 53

Addressing Methods Immediate Addressing Operand part of the instruction Direct Addressing Instruction has the operand address and thus can be directly addressed Register Indirect Addressing Instructions specifies a register that has the address of the operand (pointer to the operand). 54

Addressing Methods - cont Immediate Addressing operand is part of the instruction, thus immediately available when instruction is fetched. MOVLW 0X25 ; 25H WREG ANDLW B 01000000 ;AND WREG with 40H Using EQU COUNT EQU 0x30 MOVLW COUNT ; 30H WREG ; Assembler insures 30H placed in the second byte of the instruction 55

Addressing Methods- cont. Direct Addressing operand is obtained from file register. MOVLW 0X25 ; 25H WREG MOVFW 0x45 ; MOVE CONTENTS OF FILE ; REGISTER 45H TO WREG, ; (0x45) WREG MOVFF 0x40, 0x50 ; (40H) (50H) Note the MOVWF only access the current bank while the MOVFF instruction can access all of the 4K RAM address space File register (RAM) arranged into 16 Banks of 256 bytes. 56

Data RAM Registers 16 Banks of 256 Bytes 57

Bank Addressing Direct Addressing Instructions take 2 bytes, one for the operation and the other for an 8 bit 256 byte Access Bank address. Thus need way to access the other Banks. 58

Direct Addressing cont. When using direct addressing recall the result of the operation can be saved in either the file register ( F ) or WREG ( W ) Example: INCF 0x20,W ;(0x20) + 1 (WREG) INCF 0X20,F ;(0x20) + 1 (0x20) or INCF 0X20 ;(0x20) + 1 (0x20) (Default ; File Register 59

SFR Note: The Special Function Registers or SFR can be directly accessed by their names. (For C, see header file, e.g.. MPLAB-Cxx PIC18F452 processor header) MOVWF PORTB BSF register STATUS,C ; set c bit of status 60