Tutorial 13 - Multiple Sensors & Timing Diagrems - Past Paper Discussion Part I (LO3 & LO4)
Tutorial 13 - Multiple Sensors & Timing Diagrems - Past Paper Discussion Part I (LO3 & LO4)
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 ;
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
;----------------------------------------------------------------------------
---
; Stack Pointer definition
;----------------------------------------------------------------------------
---
.global __STACK_END
.sect .stack
;----------------------------------------------------------------------------
---
; Interrupt Vectors
;----------------------------------------------------------------------------
---
.sect ".reset" ; MSP430 RESET Vector
.short RESET
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)
;----------------------------------------------------------------------------
---
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 ;
;----------------------------------------------------------------------------
---
; Stack Pointer definition
;----------------------------------------------------------------------------
---
.global __STACK_END
.sect .stack
;----------------------------------------------------------------------------
---
; Interrupt Vectors
;----------------------------------------------------------------------------
---
.sect ".reset" ; MSP430 RESET Vector
.short RESET
.end