EEEB373 Final Exam Sem3 1819 Set 1 2apr
EEEB373 Final Exam Sem3 1819 Set 1 2apr
EEEB373 Final Exam Sem3 1819 Set 1 2apr
PUTRAJAYA CAMPUS
FINAL EXAMINATION
DURATION : 3 Hours
INSTRUCTIONS TO CANDIDATES:
3. Write all answers in the answer booklet provided. Write answer to different question
on a new page.
4. The PIC18 instruction set is provided. DO NOT write anything on it. Kindly return
the instruction set when the exam is over.
(a) Consider a hypothetical 16-bit PIC microcontroller with the following design:
• Data memory of up to 16 KB
• Program memory of up to 8 MB
• Instructions of 32 bits
• File registers of 16 bits
• Same STATUS register as PIC18 family
Draw the block diagram of this PIC chip showing only the following elements:
(i) The PC, WREG and STATUS registers inside the CPU. Show the width of each
register.
[3 marks]
(ii) The data memory and program memory blocks. Show the first address and the
last address of each memory block.
[3 marks]
(iii) The address bus between the CPU and the data memory. Show the bus width
(number of bits).
[1 mark]
(iv) The address bus between the CPU and the program memory. Show the bus width
(number of bits).
[1 mark]
(v) The data bus between the CPU and the data memory. Show the bus width (number
of bits).
[1 mark]
(vi) The instruction bus between the CPU and the program memory. Show the bus
width (number of bits).
[1 mark]
Page 2 of 8
EEEB373, Special Semester, 2018/2019
(a) A list of 32 bytes is stored in program memory. Write a program to count the numbers
that are multiples of 4 in the list. Store the count in a file register labelled as mul4.
Assume the list of numbers are stored at address 0x000050 that is named array.
[14 marks]
(b) Study the flowchart shown in Figure 1 then convert the algorithm to a PIC18 assembly
program.
Figure 1
[6 marks]
Page 3 of 8
EEEB373, Special Semester, 2018/2019
(a) Refer to the pin diagram of the PIC 18 in Figure 2 and identify the available PORTs
and the number of bits in each PORT.
[2 marks]
Figure 2
(b) In Figure 3, RB3 is an input bit that represents the condition of a door alarm. If it goes
LOW, that means that the door is open. The program in Figure 4 monitors the bit
continuously and whenever it goes LOW it sends a HIGH-to-LOW pulse to turn on a
buzzer at RC5. The program contains TWO (2) errors; identify and correct them.
[4 marks]
Line#
1 BSF TRISB, 3
2 BSF TRISC, 5
3 HERE BTFSS PORTB, 3
4 BRA HERE
5 BSF PORTC, 5
6 BCF PORTC, 5
7 BRA HERE
Figure 3 Figure 4
Page 4 of 8
EEEB373, Special Semester, 2018/2019
(c) Write a program to simulate a traffic light controller for two traffic lights. The traffic
light patterns and durations are shown in Table 1. Assume the following:
(i) Pins RD5, RD4 and RD3 are assigned to drive the green, yellow and red lights of
the first traffic light (respectively) and pins RD2, RD1 and RD0 to derive the
same lights of the second traffic light.
(i) You have a subroutine (delay5s) which you can call for a 5-second delay.
(ii) The traffic light LEDs require low voltage to turn on.
[8 marks]
Traffic light 1 Traffic light 2
Green Yellow Red Green Yellow Red Durations
1 0 0 0 0 1 25
0 1 0 0 0 1 5
0 0 1 1 0 0 20
0 0 1 0 1 0 5
Table 1
(d) Write a program that creates a square wave of 75% duty cycle on bit 3 of PORTC. Refer
to Figure 5. Assume you are given a subroutine called DELAY of any arbitrary delay
and use this subroutine to produce the required signal.
[6 marks]
PIC18F
RC3
Figure 5
Page 5 of 8
EEEB373, Special Semester, 2018/2019
(a) Refer to the schematic diagram in Figure 6 and answer the following questions:
(i) Use S1 and S2 as low and high priority interrupt sources, respectively. Write a
program that sends TWO (2) to the 7-segment display if S2 is pressed and send
FOUR (4) to the 7-segment display if S1 is pressed.
[8 marks]
(ii) If both interrupt sources in the figure are to be set to low priority, what changes
need to be made to the circuit and program?
[6 marks]
Figure 6
(b) Write an instruction sequence to configure Timer 2 interrupt to high priority and enable
the interrupt.
[4 marks]
(c) Show how to mask (disable) all the interrupts with a single instruction.
[2 marks]
Page 6 of 8
EEEB373, Special Semester, 2018/2019
(b) Calculate the value of SPBRG so that baud rate of USART communication is
19,200kbps when fXTAL is 20MHz.
[3 marks]
(c) PIC18 uses 10-bit ADC. Calculate the content of ADRES register (in Hex) given that
analog input voltage is 2.25V, Vref+ = 4.5V and Vref- = 1.5V.
[5 marks]
(d) Consider the schematic in Figure 7 for a generic zebra crossing traffic light.
Figure 7
(i) Use TIMER0 to create a subroutine that can produce a delay of 0.5 second.
Assume oscillator frequency is 20MHz.
[5 marks]
Page 7 of 8
EEEB373, Special Semester, 2018/2019
(ii) Sketch a flowchart for the main program and interrupt service routine of the traffic
light according to these operating principles:
1. It is always GREEN light until pedestrian requested to cross by pressing S1
(triggered the interrupt).
2. Light turns YELLOW five (5) seconds after crossing request.
3. Light turns RED after ten (10) seconds of yellow.
4. BLUE blinks every 1/2 second while SSD display counts down from 9 – 0
sec.
5. Repeat (1) until there is another pedestrian request.
[15 marks]
Page 8 of 8