0% found this document useful (0 votes)
24 views7 pages

Tutorial 13 - Multiple Sensors & Timing Diagrems - Past Paper Discussion Part I (LO3 & LO4)

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views7 pages

Tutorial 13 - Multiple Sensors & Timing Diagrems - Past Paper Discussion Part I (LO3 & LO4)

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Tutorial 13 – Past paper Discussion Part I

EC2031 Final examination 2021

Question 1 (25 marks)

Q1.1
Estimated time to provide answers: 30 min

Figure 1 shows a MSP430 Microcontroller interfaced with buttons and LEDs. A client has
requested to program this microcontroller to toggle LED 1 when SW 1 or SW 2 is pressed. In
addition, for all SW 1 even number of presses, LED 2 should be switched ON. Furthermore,
LED 2 should be switched OFF for all odd number of SW 1 presses. Write the assembly code
with comments to simulate the above request. You are strongly requested to use Interrupts to
receive the switch inputs. Please note that, you are not allowed to distract the operation of the
other pins and ports of the microcontroller. (25 marks)

Figure 1
Solutions – Difficulties in understanding because of no comments will get 0 and that
applies for all the questions

;----------------------------------------------------------------------------
---
; MSP430 Assembler Code Template for use with TI Code Composer Studio
;
;
;----------------------------------------------------------------------------
---
.cdecls C,LIST,"msp430.h" ; Include device header file

;----------------------------------------------------------------------------
---
.def RESET ; Export program entry-point to
; make it known to linker.
;----------------------------------------------------------------------------
---
.text ; Assemble into program memory.
.retain ; Override ELF conditional
linking
; and retain current section.
.retainrefs ; And retain any sections that
have
; references to current section.

;----------------------------------------------------------------------------
---
RESET mov.w #__STACK_END,SP ; Initialize stackpointer
StopWDT mov.w #WDTPW|WDTHOLD,&WDTCTL ; Stop watchdog timer

;----------------------------------------------------------------------------
---
; Main loop here
;----------------------------------------------------------------------------
---

;out config
bis.b #0x08, &P1DIR ;set as output
bic.b #0x08, &P1OUT ;

;out config
bis.b #0x08, &P2DIR ;set as output
bic.b #0x08, &P2OUT ;

bis.b #0x80, &P2DIR ;set as output


bic.b #0x80, &P2OUT ;

;Port1 1st input config interrupt


bic.b #0x01, &P1DIR ; input direction set
bis.b #0x01, &P1REN ; If PxREN is 0, the pull up/down
resistor is disabled. If PxREN is 1, the pull up/down resistor is
enabled.
bis.b #0x01, &P1IE ; enable interrupt
bis.b #0x01, &P1IES ; edge selection
bic.b #0x01, &P1IFG ; flag clear

;Port 1 2nd input


bic.b #0x02, &P1DIR ; input direction set
bis.b #0x02, &P1REN ; If PxREN is 0, the pull up/down
resistor is disabled. If PxREN is 1, the pull up/down resistor is
enabled.
bis.b #0x02, &P1IE ; enable interrupt
bis.b #0x02, &P1IES ; edge selection
bic.b #0x02, &P1IFG ; flag clear

;Port 2 1st input


bic.b #0x40, &P2DIR ; input direction set
bis.b #0x40, &P2REN ; If PxREN is 0, the pull up/down
resistor is disabled. If PxREN is 1, the pull up/down resistor is
enabled.
bis.b #0x40, &P2IE ; enable interrupt
bis.b #0x40, &P2IES ; edge selection
bic.b #0x40, &P2IFG ; flag clear

7 with proper explanation

mainloop:
eint ;enable global, maskable interrupts (set GIE bit)
jmp mainloop
4 -----need explanation else no marks, can be low power moods but
explanation is needed

P1_ISR: mov.b P1IFG, R5 ; port 1.0 intorrupt


and.b #0x01, R5
jnz intrrupt_1

mov.b P1IFG, R5 ; port 1.1 interrupt


9 need explanations else no marks
and.b #0x02, R5
jnz intrrupt_2

mov.b P2IFG, R5 ; Port 2.0 interrupt


and.b #0x40, R5
jnz intrrupt_3
reti ; in case we need this return from
interrupt

intrrupt_1: inc.b R6; testing double press of button


and.b #0x01, R6
jnz press1
bis.b #0x80, &P2OUT
bic.b #0x01, &P1IFG
clr.w R6
reti

press1: xor.b #0x08, &P1OUT ; toggle LED


bic.b #0x80, &P2OUT
bic.b #0x01, &P1IFG ; clear flag
reti ; return from interrupt

intrrupt_2: xor.b #0x08, &P1OUT ; toggle LED


bic.b #0x02, &P1IFG ; clear flag
reti ; return from interrupt

intrrupt_3: xor.b #0x08, &P2OUT ; toggle LED


bic.b #0x40, &P2IFG ; clear flag
;bic.b #0xff, &P1IFG ; clear flag
reti ; return from interrupt

;----------------------------------------------------------------------------
---
; Stack Pointer definition
;----------------------------------------------------------------------------
---
.global __STACK_END
.sect .stack

;----------------------------------------------------------------------------
---
; Interrupt Vectors
;----------------------------------------------------------------------------
---
.sect ".reset" ; MSP430 RESET Vector
.short RESET

; port 1 interrupt vector selection


5 need explanations and the body of the
code to get this mark, else no marks given
.sect ".int02" ; GPIO port 1 selected
.short P1_ISR
.sect ".int03" ; GPIO port 2 selected
.short P1_ISR
.end
Question 2 (25 marks)

Q 2.1
Estimated time to provide answers: 30 min

A dot matrix LED driver chip needs three control lines such as chip select ( CS ), clock (CLK)
and data-in (DIN) to control the operation. The DIN line holds 4 bits of data that should be
clocked-in to the chip as shown in Figure 2. Please note that the DIN data has to be available at
the rising edge of the CLK to accept the data by the chip. CS has to take logic low before
clocking any data. After clocking bits starting from D3 to D0, CS line should go to logic high as
shown in Figure 2.

Figure 2

Write the assembler code (with comments) compatible with MSP430 microcontroller to clock
the given 4 bits of data 1010. You are strongly requested to use left/right shift operations
associated with any logic function to get this work done (maximum 5 marks will be given to
those who do not use left/right shift operations). (25 Marks)

Solutions – done for 8 cycles, question is for 4 cycles


;----------------------------------------------------------------------------
---
; MSP430 Assembler Code Template for use with TI Code Composer Studio
;
;
;----------------------------------------------------------------------------
---
.cdecls C,LIST,"msp430.h" ; Include device header file
;----------------------------------------------------------------------------
---
.def RESET ; Export program entry-point to
; make it known to linker.
;----------------------------------------------------------------------------
---
.text ; Assemble into program memory.
.retain ; Override ELF conditional
linking
; and retain current section.
.retainrefs ; And retain any sections that
have
; references to current section.

;----------------------------------------------------------------------------
---
RESET mov.w #__STACK_END,SP ; Initialize stackpointer
StopWDT mov.w #WDTPW|WDTHOLD,&WDTCTL ; Stop watchdog timer

;----------------------------------------------------------------------------
---
; Main loop here
;----------------------------------------------------------------------------
---
bis.b #0x0f, &P2DIR ;set as output
mov.b #0x09, R8; CS low for 8 cycles
;out config
5 bis.b #0xff, &P1DIR ;set as output
bic.b #0xff, &P1OUT ;

mov.w #0x80, R5; multiplier


mov.w #0xa4, R6; data
mov.w #0xa4, R7; data

start: bic.b #0x10, &P1OUT; CLK logic low


dec.b R8 ; check 8 bits for cs
jnz mainloop

bis.b #0x0f, &P2OUT ;cs high after 8 clock cycles


6 nop
nop
mov.b #0x09, R8; load CS low for 8 cycles
dec.b R8

mainloop: bic.b #0x0f, &P2OUT ;cs low


and.b R5, R6
jnz notzero

bic.b #0x20, &P1OUT ; data line low


rlc.b R7
9 mov.b R7, R6
bis.b #0x10, &P1OUT; CLK triggerd logic high
jmp start

notzero: bis.b #0x20, &P1OUT ; data line high


rlc.b R7
mov.b R7, R6
5 bis.b #0x10, &P1OUT; CLK triggerd logic high
jmp start

;----------------------------------------------------------------------------
---
; Stack Pointer definition
;----------------------------------------------------------------------------
---
.global __STACK_END
.sect .stack

;----------------------------------------------------------------------------
---
; Interrupt Vectors
;----------------------------------------------------------------------------
---
.sect ".reset" ; MSP430 RESET Vector
.short RESET

; port 1 interrupt vector selection

.end

You might also like