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

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

Lecture (04) PIC16F84A (3)

PIC 16F84A programming (II)

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

Flow Charts and Assembler Programs

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

16.317: Microprocessor Systems Design I Fall 2013 Exam 3 Solution

Assembly Language Instructions

ECE Test #1: Name

Embedded System Design

D:\PICstuff\PartCounter\PartCounter.asm

Embedded Systems. PIC16F84A Internal Architecture. Eng. Anis Nazer First Semester

Laboratory Exercise 5 - Analog to Digital Conversion

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

SOLUTIONS!! DO NOT DISTRIBUTE PRIOR TO EXAM!!

CENG 336 INT. TO EMBEDDED SYSTEMS DEVELOPMENT. Spring 2006

Chapter 4 Sections 1 4, 10 Dr. Iyad Jafar

16.317: Microprocessor-Based Systems I Summer 2012

DERTS Design Requirements (1): Microcontroller Architecture & Programming

The University of Texas at Arlington Lecture 5

Timer2 Interrupts. NDSU Timer2 Interrupts September 20, Background:

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

EEE111A/B Microprocessors

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

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

Chapter 5 Sections 1 6 Dr. Iyad Jafar

Application Note - PIC Source Code v1.1.doc

Week1. EEE305 Microcontroller Key Points

16.317: Microprocessor-Based Systems I Spring 2012

CHAPTER 6 CONCLUSION AND SCOPE FOR FUTURE WORK

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

SOLAR TRACKING SYSTEM USING PIC16F84A STEPPER MOTOR AND 555TIMER

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

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

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

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

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.

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

PIC Discussion. By Eng. Tamar Jomaa

ECE Homework #3

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

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)

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

Instuction set

APPLICATION NOTE Wire Communication with a Microchip PICmicro Microcontroller

DESIGN AND FABRICATION OF FARE METER OF TAXICAB USING MICROCONTROLLER

Embedded Systems Programming and Architectures

Chapter 11: Interrupt On Change

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

EECE.3170: Microprocessor Systems Design I Spring 2016

ME 6405 Introduction to Mechatronics

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

UNIVERSITY OF BOLTON SCHOOL OF ENGINEERING B.ENG (HONS) ELECTRICAL AND ELECTRONIC ENGINEERING EXAMINATION SEMESTER /2016

ME 515 Mechatronics. A microprocessor

Binary Outputs and Timing

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

SOLUTIONS!! DO NOT DISTRIBUTE!!

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

EE6008-Microcontroller Based System Design Department Of EEE/ DCE

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

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

PIC16F87X 13.0 INSTRUCTION SET SUMMARY INSTRUCTIONS DESCRIPTIONS

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

Jordan University of Science and Technology Electrical Engineering Department Microcontrollers and Embedded Systems Spring 2011

EECE.3170: Microprocessor Systems Design I Summer 2017

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

CENG-336 Introduction to Embedded Systems Development. Timers

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

Performance & Applications

Chapter 13. PIC Family Microcontroller

Chapter 3: Further Microcontrollers

CONNECT TO THE PIC. A Simple Development Board

Figure 1: Pushbutton without Pull-up.

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.

Micro II and Embedded Systems

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

Hong Kong Institute of Vocational Education Digital Electronics & Microcontroller. 8. Microcontroller

Learning Objectives:

Input/Output Ports and Interfacing

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

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

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

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

S w e d i s h c r. w e e b l y. c o m j a l i l a h m e l i v e. c o m Page 1

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

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

Model Answer Microcontrollers. MCQ Problems Total Q1 Q2

EEE394 Microprocessor and Microcontroller Laboratory Lab #6

1 Introduction to Computers and Computer Terminology Programs Memory Processor Data Sheet Example Application...

Experiment 7:The USART

Lecture (04) PIC 16F84A programming I

1 Introduction to Computers and Computer Terminology Programs Memory Processor Data Sheet... 4

These 3 registers contain enable, priority,

EE 361L Digital Systems and Computer Design Laboratory

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

THE UNIVERSITY OF THE WEST INDIES

Introduction. Embedded system functionality aspects. Processing. Storage. Communication. Transformation of data Implemented using processors

PIC16C84. 8-bit CMOS EEPROM Microcontroller PIC16C84. Pin Diagram. High Performance RISC CPU Features: CMOS Technology: Peripheral Features:

PIC Discussion By Eng. Tamar Jomaa

Transcription:

Philadelphia University Faculty of Engineering Course Title: Embedded Systems (630414) Instructor: Eng. Anis Nazer Dept. of Computer Engineering Final Exam, First Semester: 2016/2017 Student Name: Student Number Date: 6/1/2017, No. of Pages: 3 Time Allowed: 2 hours Instructions: ALLOWED: Non-programmable calculator, pens and drawing tools (no red colour). NOT ALLOWED: Papers, literatures and any handouts. Otherwise, it will lead to the non-approval of your examination. Shut down Telephones, and other communication devices. Please note: Write your name and your ID number on every page of the solution sheets. All solutions together with solution methods (explanatory statement) must be inserted in the labeled position on the solution sheets. Support your answer with diagrams, equations and examples when possible You can submit your exam after the first hour. ASSUME THAT THE PIC16F84A MICROCONTROLLER IS USED IN ALL QUESTIONS UNLESS SPECIFIED OTHERWISE Question 1 (4 marks) Answer the following questions briefly: a) What is the name of your project in the course? b) Name one of the configuration bits and explain its purpose CP: code protect, to prevent read/write of program memory after downloading code FOSC1, FOSC0 : to select oscillator type and frequency WTDE: to enable the watchdog timer PWRTE: to enable the power up timer c) What is the purpose of the stack memory in the PIC microcontroller To hold the return address after a call or interrupt d) Draw a proper connection for a button connected to the MCLR input of the PIC16F84A

Question 2 (11 marks) It is required to design the controller for a washing machine. The system is composed of the following components: PIC16F84A microcontroller A DC motor, and an H bridge An electronic valve to control the flow of water A switch to select the washing cycle type, we have a cycle for white clothes and a cycle for colored clothes A push button to start the washing cycle A heating element to heat the water The washing machine operates as follows: 1) The system waits for the start button to be pushed 2) The heater is turned on for a period of time: 30 seconds for colored clothes and 60 seconds for white clothes 3) The water valve is turned on for 60 seconds 4) Motor is rotated clockwise for 10 seconds 5) Motor is rotated counter clockwise for 10 seconds. 6) Repeat steps (4) and (5) for a period of time: 30 minutes for colored clothes, and 60 minutes for white clothes Answer the following questions and state any assumptions you make: a) Specify the inputs and outputs of the microcontroller Inputs: switch to select the washing cycle, button to start the washing Outputs: DC Motor, Heater, Water valve b) Draw a simplified block diagram of the system, showing the components as blocks (2 marks) PIC16F84A Switch: 0: closed, white 1: open, colored RA0 RB0 Water valve Button: 0: pushed, start 1: open RA1 RB1 RB2 H bridge Motor RB3 Heater

c) Draw a flow chart of the program to control the system (3 marks) Start Is button pushed no Heater ON delay 30s White? delay 30s no Heater OFF OPEN Water valve delay 60s CLOSE Water valve T = 90 no White? T = 180 Rotate Motor clockwise delay 10s Rotate Motor counter clockwise delay 10s T = T-1 Motor OFF no T > 0

d) Write a program in C or assembly to operate the system, Assume a delay of 10 seconds is available (5 marks) Assembly: #include "p16f84a.inc" c EQU 0x0C ; counter for motor ; select inputs and outputs BSF STATUS, RP0 CLRF TRISB MOVLW 0x03 MOVWF TRISA BCF STATUS, RP0 CLRF PORTB ; wait for start start BTFSC PORTA, RA1 GOTO start ; heater BSF PORTB, 3 ; heater on CALL delay_30s BTFSC PORTA, 0 CALL delay_30s BCF PORTB, 3 ; heater off ; water BSF PORTB, 0 CALL delay_60s BCF PORTB, 0 ; motor BTFSC PORTA, 0 MOVLW D'90' BTFSS PORTA, 0 MOVLW D'180' MOVWF C loop BSF PORTB, 1 ; clockwise BCF PORTB, 2 BCF PORTB, 1 ; counterclockwise BSF PORTB, 2 DECFSZ T, 1 GOTO loop C #include "p16f84a.inc" void main() int c = 0; TRISB = 0; // output TRISA = 3; // input while ( 1 ) // wait for start while ( PORTA.F1 == 1 ) ; // heater PORTB.F3 = 1; if ( PORTA.F0 == 1 ) Delay_ms(30000); else Delay_ms(60000); PORTB.F3 = 0; // water PORTB.F0 = 1; Delay_ms(60000); PORTB.F0 = 0; // motor if ( PORTA.F0 == 1 ) c = 90; else c = 180; do PORTB = 0x02; Delay_ms(10000); PORTB = 0x04; Delay_ms(10000); c = c-1; while ( c > 0 ) ; PORTB = 0; CLRF PORTB GOTO start ; motor off ; repeat cycle delay_30s RETURN delay_60s CALL delay_30s CALL delay_30s RETURN END

Question 3 (8 marks) You need to design an electronic die نرد) (حجر. The system is composed of a common anode 7 segment display and a switch. When the switch is closed the 7 segment display shows a number between 1 and 6. The flow chart of the program is shown. a) Draw a circuit diagram showing the detailed connection for the PIC Start microcontroller, the switch, and the 7 segment display N = 1 display N Is switch closed No Increment N No N = 7? N = 1 b) Write the lookup table in assembly language for the numbers from 1 to 6 N RB6 g RB5 f RB4 e 1 1 1 1 1 0 0 1 2 0 1 0 0 1 0 0 3 0 1 1 0 0 0 0 4 0 0 1 1 0 0 1 5 0 0 1 0 0 1 0 6 0 0 0 0 0 1 0 RB3 d RB2 c RB1 b RB0 a (2 mark) table ADDWF PCL,1 RETLW 0xFF ; this entry is because N starts from 1 RETLW 0x79 RETLW 0x24 RETLW 0x30 RETLW 0x19 RETLW 0x12 RETLW 0x02

c) Write a complete program in assembly language that will implement the required program. (4 marks) #include "p16f84a.inc" N EQU 0x0C ; counter ; select inputs and outputs BSF STATUS, RP0 CLRF TRISB BSF TRISA, 0 BCF STATUS, RP0 CLRF PORTB MOVLW 1 MOVWF N main MOVF N, 0 CALL table MOVWF PORTB BTFSS PORTA, 0 INCF N, 1 MOVLW D'7' XORWF N, 0 BTFSC STATUS, Z CALL reset reset MOVLW 1 MOVWF N RETURN table ADDWF PCL,1 RETLW 0xFF ; This entry is because N starts from 1 RETLW 0x79 RETLW 0x24 RETLW 0x30 RETLW 0x19 RETLW 0x12 RETLW 0x02 END

Question 4 (8 marks) I always hit the wall when parking my car :( I need your help in designing a system that will solve this problem. You proposed to use the following components: An analog sensor to measures the distance between the car and the wall. The sensor gives a voltage between 1V and 5V that is proportional to the distance. If the distance is 10cm, the sensor gives 1V, if the distance is 50cm the sensor gives 5V Three LEDs: green, orange, and red PIC16F877 microcontroller which has a 10 bit ADC converter. The green LED is on if the distance is larger than 40cm, the orange LED is on if the distance is between 20cm and 40cm, and the red LED is on if the distance is less than 20cm a) What is the output voltage of the sensor if the distance is 40cm? 10cm 1V 50cm 5V so, 40cm 4V b) What is output of the ADC if the input voltage is 4V? step size = (5-1) / 1023 = 4/1023 = 0.00391 Output = (4-1) / 0.00391 = 767.25 => output = 767 = 0b1011111111 or 768 = 0b1100000000 c) What input voltage of the ADC would result in an output of 0b1000000000? if ADC output = 0b1000000000 = 512 Input = 1 + 512*0.00391 = 3V d) What values should be stored in ADCON0 and ADCON1 to operate the ADC? ADCON0 = 0bxx0000x1 ADCON1 = 0bxxxx1000 or 0bxxxx1011 or 0bxxxx1100 or 0bxxxx1101 or 0bxxxx1111 (2 marks)

e) Write a program in C or assembly to operate the system as described. (3 marks) #include "P16F877.inc" BSF STATUS, RP0 CLRF TRISB BSF TRISA, 0 BSF TRISA, 2 BSF TRISA, 3 MOVLW 0x88 MOVWF ADCON1 BCF STATUS, RP0 MOVLW 0x01 MOVWF ADCON0 void main() unsigned int N=0; TRISB = 0; TRISA = 0x0D; ADCON1 = 0x88; ADCON0 = 0x01; while (1) ADCON0.GO_DONE = 1; while ( ADCON0.GO_DONE == 1) ; main BSF ADCON0, GO_DONE wait BTFSC ADCON0, GO_DONE GOTO wait MOVLW 0 XORWF ADRESH, 0 BTFSC STATUS, Z GOTO RED MOVLW 0x03 XORWF ADRESH, 0 BTFSC STATUS, Z GOTO GREEN N = ADRESH; N = N << 8; N = N + ADRESL; if ( N < 256 ) PORTB = 0x04; else if ( N < 768 ) PORTB = 0x02; else PORTB = 0x01; GOTO ORANGE RED MOVLW 0x04 MOVWF PORTB ORANGE MOVLW 0x02 MOVWF PORTB GREEN MOVLW 0x01 MOVWF PORTB END

Question 5 (9 marks) Choose the most correct answer: Question 1) Which of the following is true? be honest :) A) I LOVE the course B) I HATE the course C) I have mixed feelings?!? D) I don't know how I feel!!!???? 2) The maximum size of a lookup table in the PIC16F84A is : A) 1000 value B) 100 value C) a) 2000 value D) 256 value Answer A D 3) Assume RA2 is configured as output, and the PIC executed the instruction BSF PORTA, 2 which of the following is true? A) The pull up transistor is ON B) The pull down transistor is ON C) Both pull up and pull down transistors are ON D) Both pull up and pull down transistors are OFF 4) Which of the following is true about the PIC microcontroller? (I) It has a CISC instruction set (II) It is a Harvard architecture A) (I) only B) (II) only C) (I) and (II) D) Both are false 5) Assume an 8MHz clock is used, what is the approximate delay of the following code? L1 MOVLW D'200' MOVWF counter NOP NOP DECFSZ counter, 1 GOTO L1 A B C A) 1000s B) 125 s C) 0.5ms D) 1s 6) Which of the following INTCON values will enable the external and timer interrupts of the PIC16F84A? A) 0xB0 B) 0x30 C) 0x86 D) 0x36 7) Which of the following interrupt sources cannot be disabled? A) external interrupt B) timer interrupt C) PORTB interrupt D) None of the choices 8) Assume a 10MHz oscillator is connected to the PIC16F84A, how long would it take for the timer0 to overflow if you store the value of 0xC3 in the OPTION register and start the timer from 0 A) 1.6384ms B) 3.2768ms C) 0.1024ms D) 12.8 s 9) Assume a 10MHz oscillator is connected to the PIC16F84A and only the timer0 interrupt is enabled. What is the maximum possible time between interrupts generated by the timer0 interrupt? A) 1 s B) 0.5 s C) 26.2 ms D) 6.55 ms A D A C Lcd_Out(1,1," GOOD LUCK :) ");