ECE 354 Introduction to Lab 2. February 23 rd, 2003

Similar documents
ECE 354 Computer Systems Lab II. Interrupts, Strings, and Busses

16.317: Microprocessor-Based Systems I Spring 2012

ECE 354 Introduction to Lab 1. February 5 th, 2003

CENG 336 INT. TO EMBEDDED SYSTEMS DEVELOPMENT. Spring 2006

Interrupts. ELEC 330 Digital Systems Engineering Dr. Ron Hayne. Images Courtesy of Ramesh Gaonkar and Delmar Learning

Assembly Language Instructions

University of Jordan Faculty of Engineering and Technology Department of Computer Engineering Embedded Systems Laboratory

Micro II and Embedded Systems

Experiment 7:The USART

Chapter 5 Sections 1 6 Dr. Iyad Jafar

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

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

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

Outlines. PIC Programming in C and Assembly. Krerk Piromsopa, Ph.D. Department of Computer Engineering Chulalongkorn University

Chapter 4 Sections 1 4, 10 Dr. Iyad Jafar

16.317: Microprocessor-Based Systems I Summer 2012

EE6008-Microcontroller Based System Design Department Of EEE/ DCE

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

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

SOLUTIONS!! DO NOT DISTRIBUTE!!

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

Hardware Interfacing. EE25M Introduction to microprocessors. Part V. 15 Interfacing methods. original author: Feisal Mohammed

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

D:\PICstuff\PartCounter\PartCounter.asm

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

PIC16F87X 13.0 INSTRUCTION SET SUMMARY INSTRUCTIONS DESCRIPTIONS

Chapter 11: Interrupt On Change

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

Performance & Applications

16.317: Microprocessor Systems Design I Fall 2013 Exam 3 Solution

AN587. Interfacing to an LCD Module. Interfacing to an LCD Module INTRODUCTION OPERATION CONTROL SIGNAL FUNCTIONS TABLE 2: CONDITIONAL ASSEMBLY FLAGS

Weekly Report: Interactive Wheel of Fortune Week 4 02/014/07-02/22/07 Written by: Yadverinder Singh

PIC Discussion. By Eng. Tamar Jomaa

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

Learning Objectives:

Section 11. Timer0. Timer0 HIGHLIGHTS. This section of the manual contains the following major topics:

SOLUTIONS!! DO NOT DISTRIBUTE PRIOR TO EXAM!!

PIC 16F84A programming (II)

Midrange 8b PIC Microcontrollers. ECE Senior Design 14 February 2017

Lecture (04) PIC16F84A (3)

Embedded System Design

Application Note - PIC Source Code v1.1.doc

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

Micro-Controller: PIC16C74 < Part 5: Interrupt >

CENG-336 Introduction to Embedded Systems Development. Timers

ME 6405 Introduction to Mechatronics

/* PROGRAM FOR BLINKING LEDs CONEECTED TO PORT-D */

16.317: Microprocessor Systems Design I Spring 2015

Section 14. Timer1 HIGHLIGHTS. Timer1. This section of the manual contains the following major topics:

Microcontrollers. Introduction to the PIC 8-bit Midrange Family. ECE Senior Design 15 February 2017

CHAPTER 4. PIC Microcontrollers. Assembly Language Programming. on-line FREE! Index Development systems Contact us

16.317: Microprocessor Systems Design I Fall Exam 3 December 15, Name: ID #:

EEE111A/B Microprocessors

Chapter 10 Sections 1,2,9,10 Dr. Iyad Jafar

DERTS Design Requirements (1): Microcontroller Architecture & Programming

Instuction set

THE UNIVERSITY OF THE WEST INDIES

These 3 registers contain enable, priority,

PIC Discussion By Eng. Tamar Jomaa

Embedded Systems Design (630470) Lecture 4. Memory Organization. Prof. Kasim M. Al-Aubidy Computer Eng. Dept.

ELCT 912: Advanced Embedded Systems

ECE Test #1: Name

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

The University of Texas at Arlington Lecture 3

Embedded Systems Programming and Architectures

ME 515 Mechatronics. A microprocessor

Section 16. Basic Sychronous Serial Port (BSSP)

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

ECE 354 Computer Systems Lab II. Memory and Indirect Addressing

Mod-5: PIC 18 Introduction 1. Module 5

Section 13. Timer0 HIGHLIGHTS. Timer0. This section of the manual contains the following major topics:

Introduction to Embedded Systems

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING. EE Microcontroller Based System Design

A Better Mouse Trap. Consumer Appliance, Widget, Gadget APPLICATION OPERATION: Ontario, Canada

EE 367 Introduction to Microprocessors Homework 6

Timer2 Interrupts. NDSU Timer2 Interrupts September 20, Background:

which means that writing to a port implies that the port pins are first read, then this value is modified and then written to the port data latch.

Today's plan: Announcements General Strategy Microcontroller programming concepts/last bits of assembly Activity 2

Discrete Logic Replacement Message Dispatch Engine

Design and Implementation of a FPGA-based Pipelined Microcontroller

APPLICATION NOTE Wire Communication with a Microchip PICmicro Microcontroller

Week1. EEE305 Microcontroller Key Points

Outline. Micriprocessor vs Microcontroller Introduction to PIC MCU PIC16F877 Hardware:

Section 30. In-Circuit Serial Programming (ICSP )

PIC16F8X. 8-Bit CMOS Flash/EEPROM Microcontrollers PIC16F8X PIC16CR8X. Pin Diagram. Devices Included in this Data Sheet:

PIC16F8X 18-pin Flash/EEPROM 8-Bit Microcontrollers

EE 308 Spring Lecture 28 March 30, 2012 Review for Exam 2. Introduction to the MC9S12 Expanded Mode

8051 Microcontrollers

PIC16C432 OTP 8-Bit CMOS MCU with LIN bus Transceiver

Unit wise Question Bank UNIT-II

Flow Charts and Assembler Programs

Chapter 13. PIC Family Microcontroller

CPEG300 Embedded System Design. Lecture 6 Interrupt System

M PIC16F84A. 18-pinEnhanced FLASH/EEPROM 8-Bit Microcontroller. High Performance RISC CPU Features: Pin Diagrams. Peripheral Features:

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

When JP1 is cut, baud rate is Otherwise, baud rate is Factory default is that JP1 is shorted. (JP1 is jumper type in some model)

PIC16F84A 7.0 INSTRUCTION SET SUMMARY INSTRUCTIONS DESCRIPTIONS

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

EEL 4744C: Microprocessor Applications. Lecture 7. Part 2. M68HC12 Interrupt. Dr. Tao Li 1

Microcontroller basics

Transcription:

ECE 354 Introduction to Lab 2 February 23 rd, 2003

Fun Fact Press release from Microchip: Microchip Technology Inc. announced it provides PICmicro field-programmable microcontrollers and system supervisors for the Segway Human Transporter (HT) [ ] The PIC16F87x Flash microcontrollers process sensor data from the inertial monitoring unit and communicate information to the control module. Other PIC16F87x devices located in the battery packs provide monitoring functions. [ ] ECE 354 - Spring 2003 2

Lab 1 Most groups completed Lab 1 good job! Understand how UART works, not just how to use it Lab reports due Wednesday Don t go overboard be concise Questions? Were lab times sufficient? ECE 354 - Spring 2003 3

Overview Lab 2 Interrupts Why we need them How to use them Timer Efficient printing of strings Interfacing PICs and PLDs External bus design READ and WRITE transactions ECE 354 - Spring 2003 4

Lab 2 Interconnect PIC with PLD PLD acts as coprocessor PIC and PLD communicate via bus You have to design bus interface Timer on PIC is used to generate periodic interrupts Will make sure your interface is robust PLD programmed in VHDL Great example of hardware/software co-design! Lab 2 instructions will be available on course web site ECE 354 - Spring 2003 5

Interrupts Lab 1 used polling What is bad about polling? Interrupts Triggered by internal or external events (examples?) Cause program to interrupt and treat interrupt After interrupt processing, processing returns to previous code What is better about interrupts? ECE 354 - Spring 2003 6

Interrupt Example ECE 354 - Spring 2003 7

What Happens During an Interrupt? 1. Interrupts have to be enabled Bits set in INTCON (internal interrupts) or PIE1 (peripheral interrupts) registers 2. Interrupt stimulus Timer/counter overflows, change on external pin 3. Interrupts automatically disabled Bit 7 of INTCON, why? 4. Jump to interrupt vector Address 0x4, typically calls interrupt subroutine 5. Jump to and execute interrupt service routine PIR1 register identifies which interrupt has triggered 6. Return to previous code RETFIE instruction, also enables interrupts ECE 354 - Spring 2003 8

INTCON Register ECE 354 - Spring 2003 9

PIE1 Register ECE 354 - Spring 2003 10

PIR1 Register ECE 354 - Spring 2003 11

RETFIE Instruction ECE 354 - Spring 2003 12

Interrupt Code Sample org H 000 ; Reset vector goto Mainline; Location of start of program Mainline... org H 004 ; Interrupt vector goto IntServ ; Start of int service routine... org H 100 ; put service routing at 0x100 IntServ... ; first inst. of service routine... retfie ; return from interrupt instr. ECE 354 - Spring 2003 13

Saving State Some state of PIC is not preserved during interrupt What is state? What is preserved? What can get lost? How to avoid problems: Preserve state (w, STATUS) before interrupt processing or Do not change state during interrupt processing (difficult) See section 12.11 of data sheet and Peatman section 4.5 Note: use of swapf instruction instead of movf ECE 354 - Spring 2003 14

Interrupt Limitations What happens if interrupt is too long? Other critical interrupts cannot be handled or Livelock (not on PIC due to lack of recursion) Beware of function calls in interrupt service routine Stack overflow could happen max nesting of program + max nesting of ISR + 1 = 8 ECE 354 - Spring 2003 15

Timer Interrupts The PIC has several built-in timers timer0 is a simple 8-bit counter External or internal clock Prescaler possible See Peatman pp.100 103, data sheet pp.47 49 ECE 354 - Spring 2003 16

String Printing Printing strings on terminal can be awkward Example: print Hello call wait ; subroutine which checks PIR bit 4. movlw H ; send ASCII w char. to W movwf TXREG ; send w char. to UART trans. buffer call wait ; subroutine which checks PIR bit 4. movlw e ; send ASCII o char. to W movwf TXREG ; send o char. to UART trans. buffer call wait ; subroutine which checks PIR bit 4. movlw movwf... Any ideas? l ; send ASCII w char. to W TXREG ; send w char. to UART trans. Buffer ECE 354 - Spring 2003 17

Advanced String Handling (1) Store text into memory Process one character a time Consider: ORG 0x0 goto Start ; jump to the start of the program ORG 0x5 sub1 nop ; start of a subroutine... return ; return from subroutine ORG 0x30 Start... call sub1 ; call the routine nop ; first instr. after return ECE 354 - Spring 2003 18

Advanced String Handling (2) call instruction: return instruction ECE 354 - Spring 2003 19

Advanced String Handling (3) retlw instruction returns and puts value into w Call subroutine for each character Use retlw to return each character and place into w Send w to UART ECE 354 - Spring 2003 20

String Handling Code (1) BANKORAM EQU H 20 ; equate a constant to hex 20. ORG BANKORAM ; reserve space in DATA MEMORY cblock ; create a pointer in bank 0 at 0x20 POINTER ; name of value endc ORG 0x0 goto Start ; jump to the start of the program ORG 0x5 sub1 movf POINTER, W ; move value in POINTER to W addwf PCL, F ; add value to PC retlw A H retlw A e retlw A l retlw A l retlw A o retlw 0 RETURN ; shouldn t get here ECE 354 - Spring 2003 21

String Handling Code (2) ORG 0x30 Start clrf POINTER Loop call sub1... ; check if return value is 0 btfsc status, z ; branch if not 0 goto Done ; else done... ; check bit 4 in PIR movwf TXREG... ; increment POINTER goto Loop ; print another character ORG 0x60 Done nop goto Done ECE 354 - Spring 2003 22

String Handling A bit complex Simplified by dt assembler directive dt Hello translates into retlw A H retlw A e retlw A l retlw A l retlw A o Note: does not terminate string (with A 0 )! Saves memory space More easily modifiable You need to understand how it works, but you don t need to use it. ECE 354 - Spring 2003 23

OK, Who s Confused? See Peatman Section 8.6, pp.154 157 ECE 354 - Spring 2003 24

Data Exchange Via Bus Multiple devices can be connected through a bus We connect PIC to PLD PIC should be able to read from and write to PLD PLD acts as coprocessor For example: write value to 0x1 and 0x2 and read f(0x1, 0x2) from 0x3 ECE 354 - Spring 2003 25

Bus Interface A bus needs: Address, data, control signals For Lab 2: Port A: four bit address value Port B: four bit data input Port D: four bit data output Port C: up to six control signals Build read and write transactions Need to be robust and reliable (interrupts!) ECE 354 - Spring 2003 26

Bus Issues Control signals indicate valid address/data PIC and PLD use same clock (synchronous) Interrupts on PIC can cause delays! Transactions needs to be acknowledged (why?) PLD acks when WRITE result was received PIC acks when READ result was received The logic analyzer is your best friend ECE 354 - Spring 2003 27

Example WRITE ECE 354 - Spring 2003 28

Example READ ECE 354 - Spring 2003 29

Bus Implementation Need signal to distinguish READ and WRITE There are better, simpler ways Consider using control bits for multiple purposes Use PLD state machines One for address One for read One for write Implement on PLD using VHDL Basically what you have done in ECE 353 ECE 354 - Spring 2003 30

Lab 2 BEFORE YOU START: READ! Lab Assignment PIC data sheet section 12.10 12.11 (interrupts) Peatman, chapter 4 (timer and interrupts) Think about how you want to split work If you separate PIC and PLD design, make sure you have a good bus interface! Think about steps to take to get it working Start working early! You will need more time than for Lab 1 Lab due March 12 th ECE 354 - Spring 2003 31