Advanced Microcontrollers and Interfacing
Advanced Microcontrollers and Interfacing
DEE722 (v1)
Advanced Microcontrollers and
Interfacing
TOTAL = 120
Final % = %
Please Note:
1. This closed-book Test is a part of the final mark of this paper. Student must complete
this closed-book test if you wish to be eligible to pass this paper.
2. ENSURE THAT THIS COVER SHEET IS FILLED IN AND ATTACHED TO YOUR COMPLETED CLOSED-BOOK TEST.
3. You are required to answer ALL questions in this closed-book Test.
4. Write your answers on answer sheets attached with this test. Any extra sheet, you
need will be provided by the examiner during exam.
5. Your handwriting must be neat and legible; otherwise you will not receive the marks
allocated for the question(s) which are not legible.
6. Cheating. Students caught cheating during the exam will receive ZERO marks with no
possibility for re-sits.
7. Appeal. If you are not satisfied with the marks received for this Assessment, you may
appeal for reconsideration by completing the ASSESSMENT APPEAL form (Form 7.3).
All Appeals must be submitted through your lecturer WITHIN 3 DAYS from the receipt
of your assessment result.
8. Refer to your student Handbook for regulations relating To
Resubmission/Reassessment/Retest. These must be applied for WITHIN 3 DAYS from the date
Assessment Feedback is provided by the lecturer. All applications are to be submitted to your
lecturer.
Assessment Instructions:
7. Ms. Karrie would like to store some temporary data values in microcontroller. Which memory
can she prefer? RAM/ROM?
8. Ms. Tessa would like to store program instructions in microcontroller. Which memory can she
prefer? RAM/ROM?
Microcontroller Basics:
15. Explain the use of three buses with the diagram below.
17. Ms. Lim’s computer (CPU) has a 16-bit data bus, where as Mr. Lee’s computer (CPU) has a 32-bit
data bus.
a. Which CPU is better/faster in transferring the data? Why?
PIC16F887
Pin configuration Sheet
19. Consider that a LED is connected to pin 19. What are the SFRs that need to be configured? Provide
their required value.
20. Consider that a LED is connected to pin 34. What are the SFRs that need to be configured? Provide
their required value.
21. If two push buttons bt1 and bt2 are connected to pin number 5 and 8 respectively, which other
SFRs need to be configured? Provide their required value.
22. Consider that three analog temperature and humidity sensors are connected to pin 3, 4, and 38.
In this case which other SFRs are required to be configured? Provide their value as well.
23. Consider that a LED is connected to pin 31. Write the SFR and its value to make the LED glow.
24. Consider that a LED is connected to pin 40. Write the SFR and its value to make the LED glow.
25. How many interfaces are available in PIC16F887 for PORTA, PORTB, PORTC, PORTD, PORTE. Name
them and its corresponding pins.
Circuit Design
27. Draw a design circuit diagram with PIC16F887 microcontroller which glows 4 LEDs when the push
button is pressed. Note: PIC16F887 pin diagram is shown below.
28. Write the MPLABX XC8 program to glow 4 LEDs when the push button is pressed.
29. Draw a design circuit diagram with PIC16F887 microcontroller with 2 LED (L1, L2) and 2 push
buttons (P1, P2). If P1 is pressed, L1 should glow. If P2 is pressed, L2 should grow. If both are not
pressed, no LED should glow.
30. Write the MPLABX XC8 program to accomplish the task given in Q29.
Write a brief explanation of uses of the following modules present in the microcontroller.
31. Timer
38. Draw a design circuit diagram which rotates the DC motor in one direction when a push button is
pressed. Use PIC16F887 microcontroller for this purpose.
Programming basics:
43. Instead of assigning values to each of the SFRs RB0 to RB7, how would you specify using PORTB
SFR?
1
1.5
2
2.5
3
3.5
4
46. Write MPLABX XC8 program to print the first 10 integers in 8 LEDs connected to PORTD. Note:
Use ‘for’ loop.
47. List atleast 5 SFRs you have come across in programming the microcontroller.
PIC16F887 Timers
50. How many bits are there in each timer register in PIC16F887?
51. What is the maximum value that can be represented in the timer register? Explain.
52. What is the frequency of oscillator if the frequency of the timer is 4 MHz?
53. Mr. Rob wants to increase the timer values, but he did not want to compromise/decrease the
frequency of the oscillator. What should he do?
54. Mr. Sam wants to configure his microcontroller as timer instead of counter. How does he do it in
the MPLAB C program?
55. How do you configure the prescalars to be assigned either to ‘TMR0’ or ‘WDT’?
56. What are the possible values that can be chosen as prescalars? What is the maximum value?
57. How does one represent the prescalar value, say 8 in programming the PIC16F887 using Hi-Tech
C Code?
59. What is the elapsed time when the start of the timer register is 123 with the oscillator
frequency as 16 MHz (no prescalars)?
60. What is the start value of the register when the FOSC is 8 MHz and the elapsed time is 10 μs (no
prescalars)?
61. Ms. Sim wants to measure the elapsed time of 10 ms with the microcontroller oscillator
frequency 12 MHz. What is the prescalar value that needs to be used?
62. Find the start value of the timer register with the following information. Prescalar (N) = 128,
elapsed time = 13 ms, frequency of oscillator = 10 MHz.
63. Consider the case in which your microcontroller is connected to 10MHz external oscillator. Design
a digital counter that should count from 0 to 60 in 1 min, i.e. every increment should be after 1
second, using PIC16F887 and timer0 module for this purpose. Use a push button to start this
counter and show the values of 0 to 60 by use of 8 LEDs connected to PORT D.
f. The prescalar value from the previous question is clearly above 256. What is required to
avoid inaccuracy in the code?
h. What is the name of the input and output port from the above question?
k. How do you represent the start of the timer in the XC8 code?
𝑓𝑜𝑠𝑐
𝑓𝑡𝑖𝑚𝑒𝑟 = 4
1
𝑇𝑡𝑖𝑚𝑒𝑟 =
𝑓𝑡𝑖𝑚𝑒𝑟
Elapsed time would be given in the question. The value of A is 0 and the value of B is 255.
𝑂𝑟𝑖𝑔𝑖𝑛𝑎𝑙 𝑁 𝑣𝑎𝑙𝑢𝑒
𝐸𝑥𝑡𝑟𝑎 𝑐𝑜𝑢𝑛𝑡𝑒𝑟 =
256
(B) If there are extra counters, use the following formula to find A.
Basic Information:
Timer Timer
0 0
PSA T0CS
1 WDT 1 Counter
65. What is the value of PS0, PS1, PS2 if the value of N=35?
66. How do you assign prescalar to timer rather than watch dog timer? (Note: Use ‘PSA’)
67. How do you choose timer in the circuit rather than a counter? (Note: Use ‘T0CS’)
69. How do you represent the start value of the timer? What value is assigned to it? A or B?
70. How do you choose counter in the circuit rather than a timer? (Note: Use ‘T0CS’)
71. How do you assign prescalar to watch dog timer rather than timer? (Note: Use ‘PSA’)
Write a MPLAB Hi-Tech C Program to show the pattern of “OFF OFF OFF OFF OFF OFF OFF OFF” on 8
LEDs connected to PORTC which gets reverse every 13ms. The frequency of the oscillator is 10 MHz.
(Note: Use Timer. Don’t use __delay_ms)
Solution:
fosc= 10 MHz
Prescaler= 126.95 => Prescaler values are discrete values therefore we can select 128
If we want to tune the timer and make it even more accurate we can change the initial value so
that:
13ms=TMR0 x 128 x 0.4us => TMR0= 253.9 => if we choose the initial value of 256-254=2 then
timer would work even more accurate. The last part regarding the accurate calculation is not
expected from the students, however if it is done, shows their better understanding.
Write a MPLAB Hi-Tech C Program to show the pattern of “ON ON ON ON ON ON ON ON” on 8 LEDs
connected to PORTD which gets reverse every 1 second. The frequency of the oscillator is 10 MHz.
(Note: Use Timer. Don’t use __delay_ms)
Solution:
The next step is configuring the Timer0 so that it can signal the elapsed time of 1sec. As known
Timer0 works on fosc/4 resulting in
fosc= 10 MHz
Prescaler= 9765.625 => Prescaler values are discrete values and the maximum is 256 therefore
we can select 256 for the prescaler and we need extra counter as well;
If we want to tune the timer and make it even more accurate we can change the initial value so
that:
1sec=(B – A + 1) * 256 * 38 * 0.4us => (B – A + 1) = 256.99 => if we choose the initial value of
0 then timer would work accurate enough.
Timer Exercises
72. Write a MPLABX XC8 program to show the pattern of “ON OFF ON OFF ON OFF ON OFF” on 8
LEDs connected to PORT C which gets reverse every 250ms. In other words after each 250ms, the
LEDs which were on should get off and vice versa. The frequency of the oscillator is 8 MHz. Show
all the calculations. (Note: Use Timer. Don’t use __delay_ms)
73. Write a MPLABX XC8 program to show the pattern of “ON OFF OFF OFF ON OFF OFF OFF” on 8
LEDs connected to PORT C which gets reverse every 40ms. In other words after each 40ms, the
LEDs which were on should get off and vice versa. The frequency of the oscillator is 8 MHz. Show
all the calculations. (Note: Use Timer. Don’t use __delay_ms)
74. Draw a circuit diagram with PIC16F887 to accomplish the following task: 8 LEDs show the pattern
of “ON OFF OFF OFF ON OFF OFF OFF” connected to PORT C which gets reverse every 40ms.
Preview Questions:
76. What is the length (in bits) of the output of analog to digital conversion?
79. What is the value of ADCS1, ADCS0, if the clock frequency is Fosc/32?
80. What is the value of CHS3 – CHS0 if the analog channel 7 is used?
81. What is the value of CHS3 – CHS0 if the analog channel 12 is used?
83. What is the value of ANSEL, ANSELH if the ADC uses analog channel 10?
84. What is the value of ANSEL, ANSELH if the ADC uses analog channel 13?
86. What is the value of ADCON0 register if the clock frequency is Fosc/32 and uses analog channel 9?
87. What is the value of ADCON0 register if the clock frequency is Fosc/8 and uses analog channel 6?
88. What is the value of ADCON1 register if the conversion result is right justified?
89. What is the value of ADCON1 register if the conversion result is left justified?
90. The output of my ADC is 0b1101100010. What is the value of ADRESH and ADRESL, if the values
are right justified?
91. The output of my ADC is 0b1100111011. What is the value of ADRESH and ADRESL, if the values
are left justified?
#include <htc.h>
__CONFIG(WDTE_OFF & CP_OFF & MCLRE_OFF & LVP_OFF);
#define _XTAL_FREQ 10000000
void main()
{
ANSEL = 0b00000001;
ANSELH = 0;
TRISA=0x1;
TRISB = 0x0;
TRISC = 0x0;
ADCON0=0b10000001; //ADON=1, CH=0
ADCON1=0b10000000; //ADFM=1, VCFG0=0, VCFG1=0
ADIE = 1;
ADIF = 0;
PEIE = 1;
GIE = 1;
while(1)
{
__delay_us(20);
GODONE=1;
}
}
Notes:
102. What is the name of the module used to convert the digital to analog signal?
103. List the bits of INTCON register in PIC16F887 and its uses.
105. What are the 8 modes in which the Oscillator be configured to?
106. Explain the differences between TMR0 and TMR1 interms of bits, prescalar, clock source,
etc.
TMR0 TMR1
107. Explain the differences between TMR0 and TMR2 interms of bits, prescalar, clock source,
etc.
TMR0 TMR2
108. Compare RISC and CISC along with an example for each.
RISC CISC
109. Please find below two CPU architectures, ‘a’ and ‘b’. Please specify the advantages and its
disadvantages.
Advantages: Advantages:
Disadvantages: Disadvantages:
111. Explain the difference between pipelined and non-pipelined instruction based on the figure
shown below.
114. Compare the following three communication modules: parallel ports, serial synchronous and
asynchronous modules in PIC16F887 and PIC16F877
115. Compare the following three special function modules: serial peripheral ports, CAN interface
and Ethernet interface module in PIC16F887 and PIC16F877
Intake Month
Paper
and Year
Assessor Comments
I understand that I have three working days from the date I sign this form to apply to my lecturer
/ assessor for a recount/reconsideration OR a resit / resubmission, and that my eligibility to apply
for this is subject to the regulations of the programme / paper / unit standard I am enrolled into.
(Refer to relevant Course Outline and student handbook).
I understand that I am not entitled to a resit for a Final Exam.
I understand that I may be contacted in relation to this assessment, and that this assessment may
be used for external post-assessment moderation purposes.
I understand that my results are not final until post-assessment moderation and ratification
processes are completed.