SOLUTIONS!! DO NOT DISTRIBUTE PRIOR TO EXAM!!

Similar documents
SOLUTIONS!! DO NOT DISTRIBUTE!!

THE UNIVERSITY OF THE WEST INDIES

Assembly Language Instructions

Performance & Applications

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

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

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

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

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

Flow Charts and Assembler Programs

CENG 336 INT. TO EMBEDDED SYSTEMS DEVELOPMENT. Spring 2006

PIC 16F84A programming (II)

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

Lecture (04) PIC16F84A (3)

Chapter 11: Interrupt On Change

ECE Test #1: Name

EEE111A/B Microprocessors

CENG-336 Introduction to Embedded Systems Development. Timers

D:\PICstuff\PartCounter\PartCounter.asm

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

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

PIC16F87X 13.0 INSTRUCTION SET SUMMARY INSTRUCTIONS DESCRIPTIONS

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

16.317: Microprocessor Systems Design I Fall 2013 Exam 3 Solution

Chapter 5 Sections 1 6 Dr. Iyad Jafar

Instuction set

Chapter 4 Sections 1 4, 10 Dr. Iyad Jafar

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

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

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

APPLICATION NOTE Wire Communication with a Microchip PICmicro Microcontroller

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

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

Week1. EEE305 Microcontroller Key Points

Timer2 Interrupts. NDSU Timer2 Interrupts September 20, Background:

Interfacing PIC Microcontrollers. ADC8BIT2 Schematic. This application demonstrates analogue input sampling

Binary Outputs and Timing

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

movwf prevcod ; a new button is pressed - rcnt=3 movwf (mtx_buffer+1) movlw 3 movwf rcnt

EE6008-Microcontroller Based System Design Department Of EEE/ DCE

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

These 3 registers contain enable, priority,

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

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

ALU and Arithmetic Operations

16.317: Microprocessor-Based Systems I Spring 2012

Micro II and Embedded Systems

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

Embedded System Design

Introduction to PIC Programming

EECE.3170: Microprocessor Systems Design I Summer 2017

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.

16.317: Microprocessor-Based Systems I Summer 2012

Application Note - PIC Source Code v1.1.doc

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

Figure 1: Pushbutton without Pull-up.

PIC PROGRAMMING START. The next stage is always the setting up of the PORTS, the symbol used to indicate this and all Processes is a Rectangle.

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

CONNECT TO THE PIC. A Simple Development Board

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

DERTS Design Requirements (1): Microcontroller Architecture & Programming

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

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

ME 6405 Introduction to Mechatronics

Laboratory Exercise 5 - Analog to Digital Conversion

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

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

Chapter 13. PIC Family Microcontroller

UNIVERSITY OF BOLTON SCHOOL OF ENGINEERING MSC SYSTEMS ENGINEERING AND ENGINEERING MANAGEMENT SEMESTER 2 EXAMINATION 2016/2017

Done 1 NVB THF TLF T/R POL 1SHOT. Figure 1: Status register

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

ECE Homework #3

SOLAR TRACKING SYSTEM USING PIC16F84A STEPPER MOTOR AND 555TIMER

PIC Discussion. By Eng. Tamar Jomaa

Learning Objectives:

Introduction to PIC Programming

Experiment 7:The USART

PIC Discussion By Eng. Tamar Jomaa

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

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

UNIVERSITY OF BOLTON SCHOOL OF ENGINEERING. BEng(Hons) Electrical and Electronics Engineering SEMESTER 1 EXAMINATION 2016/2017

PIC16F84A 7.0 INSTRUCTION SET SUMMARY INSTRUCTIONS DESCRIPTIONS

Application Note One Wire Digital Output. 1 Introduction. 2 Electrical Parameters for One Wire Interface. 3 Start and Data Transmission

16.317: Microprocessor-Based Systems I Fall 2012

Embedded Systems Programming and Architectures

CHAPTER 6 CONCLUSION AND SCOPE FOR FUTURE WORK

Introduction to Embedded Systems

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)

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

16.317: Microprocessor Systems Design I Fall 2014

Chapter 3: Further Microcontrollers

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

EECE.3170: Microprocessor Systems Design I Spring 2016

Input/Output Ports and Interfacing

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

EXPERIMENT 4: Parallel Input/Output. Objectives Introduction to the Parallel Input/Output (I/O) Familiarization to Interfacing

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

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

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

EECS 373 Midterm 2 Fall 2018

Transcription:

THE UNIVERSITY OF THE WEST INDIES EXAMINATIONS OF APRIL MID-TERM 2005 Code and Name of Course: EE25M Introduction to Microprocessors Paper: MidTerm Date and Time: Thursday April 14th 2005 8AM Duration: One Hour INSTRUCTIONS TO CANDIDATES: This paper has 9 pages and 19 questions Answer ALL questions in Sections A and B. Marks for each question are given in the margin. Approved calculators may be used. SOLUTIONS!! DO NOT DISTRIBUTE PRIOR TO EXAM!! Section A (15 marks) contains 15 multiple-choice questions. Questions in Section A should be answered on this exam script. Choose the most appropriate answer for each question, and circle the letter for your choice. You should spend about 20 minutes on Section A. Section B (30 marks) contains 4 questions. Questions in Section B should be answered on this exam script. Any code written for Section B should be appropriately commented for clarity. You should spend about 40 minutes on Section B. The following datasheets/information are attached to/distributed with this exam paper. PIC16F87x instruction set summary Data sheet for Timer0 Please write your ID# on the front cover and on each page in the spaces provided. c The University of the West Indies

page 2. Section A Questions Q1, Q2, and Q3 refer to the following piece of code for the PIC16F877, to multiply two numbers M1 and M2. mul clrw loop addwf M2,W btfsc incf decfsz goto movwf STATUS,C R_hi,F M1,F loop R_lo Q1. The code will perform multiplication of the initial values in M1 and M2 using: (a) partial sums; result in R_hi and R_lo. (b) partial sums; result in M2, M1. (c) repeated addition; result in M2, M1. (d) repeated addition; result in R_hi and R_lo. (e) repeated addition; result in the working register. Q2. To use this code eectively, we MUST: Q2-I ensure that M1 is unsigned Q2-II ensure that M2 is unsigned Q2-III initialize R_hi to zero Q2-IV initialise R_lo to zero Choose the most appropriate combination: (a) Q2-I and Q2-II only (b) Q2-I and Q2-III only (c) Q2-I and Q2-IV only (d) Q2-II and Q2-III only (e) Q2-II and Q2-IV only Q3. How many machine cycles will this routine take to run (ignoring the cycles for the call)? (a) 1 + 5 (M1 1) + 6 (b) 1 + 5 (M1 1) + 7 (c) 1 + 5 (M2 1) + 6 (d) 1 + 6 (M1 1) + 8 (e) 1 + 6 (M2 1) + 8

page 3. Q4. Three sets of C code have been written to perform the multiplication of 255 and 27 using repeated addition. Q4-I Q4-II Q4-III void main() int k,m1,m2; long int R; void main() int k,m1,m2; long int R; void main() int k,m1,m2; long int R; R=0; M2=27; M1=255; for (k=0;k<=m1;k++) R=R+M2; R=0; M2=27; M1=255; for (k=m1;k>0;k++) R=R+M2; R=M2=27; M1=254; for (k=0;k<=m1;k++) R=R+M2; For the compiler used, integers are represented using 8 bits, and long integers are represented using 16 bits. When run, Program Q4-I never stops. Programs Q4-II and Q4-III, however, run as expected. The MOST PLAUSIBLE explanation for the failure of Program Q4-I is that: (a) R is not big enough to hold the result of the operation. (b) R should also be declared as an integer. (c) the number 255 cannot be represented using 8 bits. (d) the termination test requires representing the number 256 in 8 bits. (e) there is a aw in the compiler it generates bad code sometimes. Q5. A normally-closed push button switch needs to be interfaced to the PIC16F877, so that we can determine if it is pressed or not by checking the state of the input pin. Which of the following connections are viable alternatives? Q5-I tie the switch between PORTB pin and ground with internal pull-ups enabled Q5-II tie the switch between PORTB pin and ground with an external pull-up resistor Q5-III tie the switch between PORTB pin and V DD with internal pull-ups enabled Q5-IV tie the switch between PORTB pin and V DD with an external pull-down resistor (a) none of these are viable alternatives (b) Q5-I and Q5-IV only (c) Q5-I, Q5-II, and Q5-III only (d) Q5-I, Q5-II, and Q5-IV only (e) Q5-I, Q5-II, Q5-III, and Q5-IV

page 4. Q6. Select the most appropriate combination of words to complete the sentence. A programmer used the Q6-I instruction instead of the Q6-II instruction at the end of an Interrupt Service Routine for the PIC16F877. The program failed to work because Q6-III. (a) Q6-I: retfie; Q6-II:; Q6-III: interrupts were not re-enabled. (b) Q6-I: retfie; Q6-II:; Q6-III: PCL was not restored. (c) Q6-I: retfie; Q6-II:; Q6-III: the stack overowed. (d) Q6-I: ; Q6-II:retfie; Q6-III: interrupts were not re-enabled. (e) Q6-I: ; Q6-II:retfie; Q6-III: the stack overowed. Q7. A 4 bit timer/counter module is connected so that one of its inputs is a 100Hz signal, and the other is a signal whose frequency is to be determined. The frequency ranges which can be measured in counter mode are: (a) min: 0Hz; max: 1.5kHz; resolution ±100Hz (b) min: 0Hz; max: 1.6kHz; resolution ±50Hz (c) min: 100Hz; max: 1.5kHz; resolution ±100Hz (d) min: 100Hz; max: 1.5kHz; resolution ±50Hz (e) min: 100Hz; max: 1.6kHz; resolution ±100Hz Q8. You have a circuit in which the timer/counter module inside the PIC16F877 is used to count each falling edge from an externally supplied signal. You notice that the module counts twice on each falling edge. In order to discover the cause of the problem, the MOST appropriate action is to: (a) check the supply voltage for noise using a multimeter. (b) replace the PIC16F877 and see if the problem disappears. (c) use a pull-down resistor on the input pin and see if the problem disappears. (d) increase the frequency of the external signal and see if the problem disappears. (e) visually inspect for loose wires. Q9. Timer0 (8-bit timer) of the PIC16F877 is congured to increment on the rising edge of the internal machine cycle clock (CLKOUT) with a pre-scaler value of 1:64. What is the interval between successive overows of Timer0 if the PIC16F877 is clocked using a 10M Hz oscillator? (a) 64µs (b) 102.4µs (c) 256µs (d) 6553.6µs (e) 16384µs

page 5. The following information is to be used for questions Q10 to Q12. A rotary optical incremental encoder (rotary pulse generator) has two outputs, channel A and channel B. Channel A is used to generate external interrupts on a PIC16F877 at each rising edge. Channel B is connected to another pin on the PIC16F877. An Interrupt Service Routine (ISR) is used to determine the direction of rotation clockwise (rising edge of A coincides with a low on B) or anticlockwise (rising edge of A coincides with a high on B) and the distance turned (counting number of pulses on Channel A). Several "strange behaviours" may be observed with this system: P-I : counting less than the actual number pulses P-II : counting more than the actual number of pulses P-III : deducing the wrong direction of motion Q10. Which of the "strange behaviours" listed can occur if interrupts occur before the previous interrupt is handled? (a) P-III only (b) P-I and P-II only (c) P-I and P-III only (d) P-II and P-III only (e) P-I, P-II, and P-III Q11. Which of the "strange behaviours" listed can occur if the encoder output does not rise quickly enough? (a) P-III only (b) P-I and P-II only (c) P-I and P-III only (d) P-II and P-III only (e) P-I, P-II, and P-III Q12. Which of the "strange behaviours" listed can occur if the voltage supplying the PIC16F877 and the encoder uctuates? (a) P-III only (b) P-I and P-II only (c) P-I and P-III only (d) P-II and P-III only (e) P-I, P-II, and P-III

page 6. Q13. You are told that the 80C51 and PIC16F877 both have data transfer instructions. The 80C51 can move a literal to any register using one instruction: MOV Reg, #6. The PIC16F877 can move a literal to the working register, and subsequently to any register using two instructions: movlw 6 followed by movwf Reg. Based on this information ONLY, we can assume that an 80C51 program involving several literalto-register data transfers will probably: Q13-I have less lines of code Q13-II require less program storage space Q13-III run faster Which combination of stated assumptions is appropriate? (a) none of the above assumptions are appropriate. (b) Q13-I only (c) Q13-I and Q13-II only (d) Q13-I and Q13-III only (e) Q13-I, Q13-II and Q13-III Q14. Select the most appropriate combination of words to complete the sentence. The design of an embedded system starts with the Q14-I, which is followed by the Q14-II and then the Q14-III. (a) Q14-I: conceptual design; Q14-II: function statement; Q14-III: requirements list (b) Q14-I: conceptual design; Q14-II: requirements list; Q14-III: function statement (c) Q14-I: function statement; Q14-II: conceptual design; Q14-III: requirements list (d) Q14-I: function statement; Q14-II: requirements list; Q14-III: conceptual design (e) Q14-I: requirements list; Q14-II: function statement; Q14-III: conceptual design Q15. When writing routines for a microprocessor, you have been advised to always initialize your registers, even if the power-on-default value is the value you want. Which of the following statements is an INVALID reason for this guideline? (a) The microprocessor may be reset without re-powering up. (b) The microprocessor may power-up incorrectly. (c) The routine may run after the value was changed by another routine. (d) The routine may be interrupted while it is running. (e) The routine may work incorrectly if the register has a non-default value.

page 7. Section B The following information should be used for all questions in Section B. You are a member of a development team which is working on a new microprocessor-controlled refrigerator, using a PIC16F877 with a 700 Hz clock. The refrigerator consists of a cooling unit, a defrost unit, and a thermostat, which are connected to PORTD pins <2>, <1> and <0> respectively. loop: The cooling unit is switched on when PORTD<2> is high. The defrost unit is switched on when PORTD<1> is low. PORTD<0> has an external pull-up resistor. The thermostat pulls PORTD<0> low when the fridge temperature is above c + 2 degrees Celsius, and keeps the line low until the fridge temperature drops below c 2 degrees Celsius; where c is the temperature setting for the fridge. The defrost unit is activated for approximately 6 minutes each day. The main program algorithm is: configure pins if defrost unit is on else if defrost-time over turn off defrost unit start timing defrost-delay (239) if defrost-delay over else turn on defrost unit start timing defrost-time (1) if thermostat line active else turn on cooling unit turn off cooling unit Q1. Write a routine named Init which will congure PORTD<2>, PORTD<1> as outputs and PORTD<0> as an input. Your routine should NOT aect the conguration state of the other PORTD pins. You should at the end of your routine. label/; 3 marks correct conguration of TRISD register (lose each if wrong register/bank, if bad bits or if alters other bits). Sample answers: 4 marks Init BANKSEL TRISD bsf TRISD,0 bcf TRISD,1 bcf TRISD,2 BANKSEL PORTD Init BANKSEL TRISD movlw 0x01 iorwf TRISD,F movlw 0xF9 andwf TRISD,F BANKSEL PORTD

page 8. Q2. Write an interrupt handler for Timer0 named TmrHndler which clears the Timer0 ag, decrements the value in Cnt, and disables the Timer0 interrupt if Cnt is 0. You should at the end of your interrupt handler. label/; clear ag; disable timer interrupt only if Cnt is 0; decrement Cnt (with correct destination)) Sample answer: 4 marks TmrHndlr bcf decfsz bcf INTCON, T0IF Cnt,F INTCON, T0IE Q3. Write a routine named StrtTimer which takes the value in the working register, places it in a register called Cnt, clears the Timer0 register, congures Timer0 for 1:256 pre-scaler, and internal clock, (i.e. 700Hz clock signal; timer expires every 6.24 minutes) enables the Timer0 interrupt, and global interrupts You should at the end of your routine. move W into Cnt; appropriate banking for OPTION_REG and TMR0; 2 marks appropriate bits set in OPTION_REG (1:64 pre-scaler, CLKOUT) clear timer 0, 2 marks appropriate bits in INTCON (GIE, T0IF, and T0IE) Sample answer: 7 marks StrtTimer movwf Cnt BANKSEL OPTION_REG movlw B'xx0x0111' movwf OPTION_REG BANKSEL TMR0 clrf TMR0 movlw B'1x1xx0xx' movwf INTCON

page 9. Q4. Write an assembly language main program for the PIC16F877 which performs the algorithm provided. Your main program should indicate where the preceding routines Init and StrtTimer, the Interrupt Service Routine and handlers are to be placed, but you do NOT need to rewrite them. Your main program should use appropriate preprocessor directives. Max. 15 marks. use of directives LIST, INCLUDE. use of sleep or END directive. choice of data location for Cnt. 2 marks choice of program location & use of reset/interrupt vector. 2 marks place value (1 or 239) in W prior to call of delay routine. 2 marks use of call for routines, and goto for loops/vectors. 4 marks correct ow for each of the decision-statements. 2 marks turn on/o cooling and defrost units. 2 marks identify & correct aw in algorithm (cool/defrost simultaneously). 15 marks LIST p=16f877 INCLUDE <p16f877.inc> Cnt EQU 0x20 ORG 0x00 goto start ORG 0x04 goto ISR ORG 0x10 start call Init bcf PORTD,2 ; turn o cooling unit bsf PORTD,1 ; turn o defrost unit loop btfsc PORTD,1 ; if defrost unit is o goto dfsto dfston movf Cnt,F ; if defrost-time not over keep looping btfss STATUS,Z bsf PORTD,1 ; otherwise turn o defrost unit movlw D'239' ; and start timing defrost-delay call StrtTimer dfsto movf Cnt,F ; if defrost-delay not over check thermostat btfss STATUS,Z goto chkthm bcf PORTD,1 ; otherwise turn on defrost unit bcf PORTD,2 ; turn o cooling unit movlw D'1' ; and start timing defrost-time call StrtTimer chkthm btfss PORTD,0 ; if thermostat line is active bsf PORTD,2 ; turn on cooling unit btfsc PORTD,0 ; if thermostat line is not-active bcf PORTD,2 ; turn o cooling unit sleep ; put the two routines: Init and StrtTimer followed by the ISR and handlers here!! END