You are on page 1of 11
EEEB373, Semester 2, 20162017 QUESTION 1 [20 MARKS] (a) A 2-byte signed number, called NUM2BYTE, is stored at address 0x008-0x009 in the data memory using little endian method. (i) What does it mean by little-endian? [1 marks] Lower byte stored at lowest address (ii) Where is the most significant byte (MSB) of the NUM2BYTE stored? Give the address. [0.5 mark] 0x09 (iii) Where is the least significant byte (LSB) of the NUM2BYTE stored? Give the address. [0.5 mark] 0x08 (iv) Where is the sign of the NUM2BYTE stored? Give the address and its bit number. [1 marks] 0x09 bit 7 (v) How can we determine whether the NUM2BYTE is odd? Describe precisely. [2 marks] hecking bit 0 at Ox8, if bit 0 =1. It’s the odd number (b) Consider the PIC18 assembly code at Figure 1. ORG 0x00 Goro START ORG 0x8 RETEIE ORG 0x18 RETFIE START MOVLW 0X33 MOVWE 0x34,A, XORWE 0X34,W,A END Figure 1 (i) Convert all source codes from label START until before label END only into machine codes. [3 marks] (ii) After the code is executed by the PIC18 MCU, what is the content of data memory at address 0x34 and WREG? [2 marks] Page 2 of 12 EEEB373, Semester 2, 20162017 (©) Consider the following subroutine at Figure 2, Calculate the baud rate if the frequency of the crystal oscillator is 16MHz. (5? marks] USART1_OPEN MOVLW 0x24 MOVE TXSTAL MOVLW D‘103" MOVWF SPBRGI BSF TRISC,RX BCF TRISC,TX BSF RCSTA1, SPEN RETURN Figure 2 SYNC bit BRGH = 0 (low speed) BRGH = 1 (high speed) 0] (Asynchronous) Baud rate = Foge/(64 (X41)) | Baud Rate = Foxc/(16(X+1)) 1} Gynchronous) Baud Rate = Foac/(4(X#1)) N/A sister In asynchronous mode: When BRGH = 1, SPBRG = (F,.-/(1f6 x baud rate))-1 When BRGH = 0, SPBRG = (Fo. /(64 x baud rate)) -1 In synchronous mode ‘SPBRG = (FOSC/(4 x baud rate)) «1 (@ A PIC18 microcontroller has analog to digital converter (ADC) as one of peripheral functions. (i) How many bits ADC able to convert? [1 marks] Gi) Named the registers for ADC’s result stored [2 marks] Gili) Base on (i), Veer =4V and Var. connected to ground. Calculate the ADC conversion results if the corresponding voltage values are 1.341V and 3.718V. For 1.341V ; ADC conversion = 343 For 3.718V ; ADC conversion = 951 Page 3 of 12 ‘EEEB373, Semester 2, 20162017 TT MARI (a) Anarray of 200 values are stored in the program memory. The array of values in the program memory is given a label array_val. You are required to devise an algorithm to count the number of values in the array that is divisible by 2. (i) Draw the flowchart of the algorithm. {6 marks} Rai At Co oa) | No. <-"—- | Yes Cea Result Poked | No _—$__ Page 4 of 12 EEEB373, Semester 2, 20162017 Marks distribution: Setting count and loop count variable (2m) * Read program memory, Andwf with 0x01 and obtaining 0 to get even numbers (2m) * Correct flowchart structure (2m) (ii) Write the instruction sequence for the flowchart in question (i). [6 marks} Page 5 of 12 EEEB373, Semester 2, 20162017 n equ 200° i set 0x00 count set 0x02 mask equ 0x07 cif iA clrf count. movlw upper array_val movwfTBLPTRU,A movlw high array_val movwfTBLPTRH.A. movlw low array_val movwfTBLPTRL,A loop moviwn opfsit. i, A bra exp bra check check movlw mask tbird*+ andwf TABLAT,W,A bnz inc i bra inc_ont inci inet i,RA bra loop inc_cntinef count,F,A, bra inci ex_Ip nop end Marks distribution; * Assigning tbiptr (1m) Loop creation to read arrays (2m) Incrementing count (1m) Reading value into TBLPTR (1m) Andwf with correct mask (1m) Page 6 of 12 EEEB373, Semester 2, 20162017 (b) Write a subroutine to create a time delay of 500ms on a PICI8F4550 controller board. The crystal frequency is 20MHz. Name the subroutine appropriately. [8 marks] ‘Marks distribution: * Delay calculation (2m) * Subroutine name (1m) ‘+ Return statement (1m) ‘+ dup_nop macro & and other applicable loop values and structure (4m) Joop_ent equ 0x00 Joop_entl equ 0x01 dup_nop macro kk variable i i=0 while i < kk nop endw endm delay_halfsec movlw D°s0° movwf, Joop_cntl inner_Ip movlw D’250° movwf loop_ent inner_Ip dup_nop = D'197" decfsz loop_cnt,F,A bra inner_Ip dectsz loop_ent.F.A bra outer_Ip return Page 7 of 12 EEEB373, Semester 2, 20162017 QUESTION 3 [20 marks} (a) Write instruction to configure PORTE bit 1, 2 and 6 as inputs and PORTE bit 0, 3, 4, 5 and 7as outputs. [2 marks] (b) Which registers are involved in the configuration of bidirectional input/output pin for PORTA, and PORTC? [1 marks] (©) Write an instruction sequence to configure INT1 as low priority interrupt and INT3 as high priority interrupt. [6 marks] (@) Write instruction sequence to monitor bit 2 and bit 3 at PORTC. When both bit are HIGH, toggle odd bit at PORTF. When both bit are LOW, complement the PORTD. Otherwise, when one bit HIGH and one bit LOW, send value OxFF to both port; PORTF and PORTD. [11 marks] Page 8 of 12 EEEB373, Semester 2, 20162017 Question 4 [20 marks] (a) Explain what CCP module stands for and describe the usage of each module with an example. [6 marks] Solution: CCP stands for Capture, Compare, and Pulse Width Modulation In capture operation, the CCP module copy the contents of a timer into a capture register on an signal edge. (example: Frequency and duty cycle measurement) In compare operation, the CCP module compares the contents of a CCPR register with that of Timerl (or Timer3) in every clock cycle. When these two registers are equal, the associated pin may be pulled to high, or low, or toggled. (example: Periodic interrupt generation) In PWM mode, the CCP module can be configured to generate a waveform with certain frequency and duty cycle (example: motor speed control) Marks distribution: ‘© Describe each element of CCP with an example (2m each) (b) Write a program to configure Timer® to interrupt every half a second. Configure Timer0 to be low priority. At every interrupt, increment the value of PORTD by one. If the value of the display reaches 15, the next interrupt should reset it to 0. Assume crystal oscillator of 32MHz frequency. [14 marks] Page 9 of 12 EEEB373, Semester 2, 20162017 #include count set 0x00 org 0x00 goto start org 0x08 retfie org 0x18. goto TMROISR: start cif TRISD, A chf PORTD, A bsf — RCON, IPEN, A bef INTCON, TMROIF, A bef — INTCON2, TMROIP, A bsf INTCON, — TMROIE, A bsf INTCON, GIE, A bsf — INTCON, GIEL, A movlw 0x87 movwfTOCON, A movlw OxF6 moywf TMROL, A movlw OxC2 movwf TMROH, A Page 10 of 12 EEEB373, Semester 2, 20162017 Question 5 [20 marks} (a) Refer to Figure 5, consider the following block diagram of an energy management system (EMS) for home owners. The main function of EMS is to record energy usage from appliances in real time. EMS will collect energy usage of connected appliance using digital sensor which provides 2-bits parallel data output. EMS uses the information to calculate energy usage and display updated bill amount every hour, () Sketch schematic connection to EMS hardware implemented using PICI8F4550 and write a pseudocode for the control system. [18 marks] (ii) If we add another digital sensor with 16-bit data output, how best to connect to the EMS? Justify your choice. [2 marks] Refrigerator Lights Ny ENS] Liptay pane Air conditioning | —*] unit Water heater Figure 5 ‘Answer scheme for (a) Timark 2—3 marks 4 marks Program flow Logical program flow Input connection ‘Connect to parallel | 2-bits connected to _| All connected to ilo parallel i/o same parallel i/o Output connection | LED from parallel i7o | Use LCD connected _[ LCD connected to to parallel i/o PORTD Data collection ‘Sequence in main Use timer interrupt process program Bill calculation Sum all input x tariff Display result ‘Use polling to display | Use timer interrupt (letak schematic PICF4550 dari proteus untuk jawapan sketch) Answer scheme for (b) ~ use serial connection to save space/wire Page 11 of 12 EEEB373, Semester 2, 20162017 -END OF QUESTION PAPER- Page 12 of 12

You might also like