Docsity

5 Problems on Microcomputers with Solution - Final Exam | ECE 383, Exams of Electrical and Electronics Engineering

Toggle sidebar
bg1
ECE 383 - Microcomputers
Spring 2009 โ€“ Final Exam Solutions
Name:__________________________________________________________________________
Student Number:_________________________________________________________________
Instructions:
1. Print your name and student number above.
2. Indicate your answers clearly in the spaces provided with each problem.
3. You must show work for partial credit. Do all work in the space provided.
4. Open book. Open notes. Open computer. Individual work ONLY.
5. Problem 1 is 35 points. Problem 2 is 35 points. Problem 3 is 15 points. Problem 4 is 15 points.
pf3
pf4
pf5
pf8

Partial preview of the text

Download 5 Problems on Microcomputers with Solution - Final Exam | ECE 383 and more Exams Electrical and Electronics Engineering in PDF only on Docsity!

ECE 383 - Microcomputers

Spring 2009 โ€“ Final Exam Solutions

Name:__________________________________________________________________________

Student Number:_________________________________________________________________

Instructions:

1. Print your name and student number above.

2. Indicate your answers clearly in the spaces provided with each problem.

3. You must show work for partial credit. Do all work in the space provided.

4. Open book. Open notes. Open computer. Individual work ONLY.

5. Problem 1 is 35 points. Problem 2 is 35 points. Problem 3 is 15 points. Problem 4 is 15 points.

[1] Given the following codes, what will the resulting values be at the break points for the memories and

registers?

#include ECE383_Dragon12plus_registers.inc #include ASCII.inc

ORG $

STR DC.B โ€˜CRโ€™, โ€˜LFโ€™ TARGET DC.B 0 DIGIT DC.B 0 THRESHOLD DS.B 1 DIGIT_PATTERN DC.B $3F, $06, $5B, $4F, $66, $6D, $7D, $07, $7F, $6F, $77, $7C, $39, $5E, $79, $

$ $ $ $ $ $

$FF

$4C

$2F

$3E4A $3E4C $

PWM Frequency:

100 (Hz)

ORG $

MAIN: MOVW #ISR1, UserPortH MOVW #TIMER, UserModDwnCtr

MOVB #$FF, DDRB MOVB #$00, DDRH BSET DDRP, #% BSET PORTP, #% BSET PPSH, #% BSET PIFH, #% BSET PIEH, #% BSET TSCR1, #% BSET MCCTL, #% BSET PWME, #% BSET PWMPOL,#% BSET PWMCLK,#% MOVB #$30, PWMPRCLK MOVB #150, PWMSCLB MOVB #100, PWMPER MOVB #0, PWMDTY MOVW #48000,MCCNT CLI

[A BREAK POINT HERE, FILL IN THE VALUES FOR

THE MEMORIES ON THE LEFT ]

INPUT AT SCI0: โ€˜13โ€™

$

$ $

$ A

X

$0D

MAIN_LOOP:

LDX #STR

LOOP1: BRCLR SCI0SR1, SCI_RDRF, LOOP2_END

LDAA SCI0DRL

CMPA #โ€™*โ€™

BEQ END_OF_MAIN

CMPA #CR

BEQ LOOP1_END

STAA 1, X+

BRA LOOP

LOOP1_END:

MOVB #NULL, 0, X

[A BREAK POINT HERE, FILL IN THE VALUES FOR

THE REGISTERS AND MEMORIES ON THE LEFT ]

LDX #STR

LOOP2: LDAB 1, X+

ORG $2F

ISR1: SEI

BRSET PIFH, %00000001, BTN

BRSET PIFH, %00000010, BTN

BRSET PIFH, %00000100, BTN

BTN0: MOVB #5, THRESHOLD

BRA ISR1_DONE

BTN1: MOVB #10, THRESHOLD

BRA ISR1_DONE

BTN2: MOVB #15, THRESHOLD

ISR1_DONE:

BSET PIFH, #$0F

CLI

RTI

WHAT IS THE TIMERโ€™S

FREQUENCY OF GENERATING

INTERRUPTS?

31.25 (Hz)

ORG $

TIMER: SEI

LED0: LDAB PWMDTY

LDX

JSR LED_FLASH

LED1: TFR X, D

LDX

JSR LED_FLASH

MOVB #48000, MCCNT

BSET MCFLG, #%

CLI

RTI

THE PROGRAM STOPS AT THIS

BREAK POINT AT THE FIRST

TIME AFTER INPUTTING โ€˜17โ€™

D X Y

$3F

WHAT IS THE DELAY TIME:

2 (ms)

LED_FLASH:

IDIV

TFR B, Y

LDAA DIGIT_PATTERN, Y

STAA PORTB

BCLR PORTP, #%

JSR DELAY

[A BREAK POINT HERE, FILL IN THE VALUE FOR

THE REGISTERS ON THE LEFT ]

BSET PORTP, %

RTS

DELAY: PSHX

LDX

DBNE X, *

PULX

RTS

[2] Complete the missing parts of the following Assemble code. ADC values will trigger specific PWM

signals, and will be displayed on one-digit 7-segment LED. Pressing key โ€œ1โ€ of the keypad will exit the

program. Pressing keys โ€œ4โ€ and โ€œ7โ€ will change the ADC threshold value.

#include ECE383_Dragon12plus_registers.inc

ORG $ DIGIT_PATTERN DC.B $3F, $06, $5B, $4F, $66, $6D, $7D, $07, $7F, $6F, $77, $7C, $39, $5E, $79, $ ADC_VALUE DC.W 0 ADC_CHANNEL DS.B 1 ADC_THRESHOLD DS.W 1

ORG $ MAIN: BSET PUCR, PUCR_PUPAE MOVW #$2F00, $3E4C ;PUSHBUTTON INITIALIZATION WITH BUTTON0~ MOVB #$00 , DDRH ; BCLR PPSH , #%00000011 ; BSET PIFH , #%00000011 ; BSET PIEH , #%00000011 ; MOVW #$3000 , $3E4A ;MODULUS TIMER INITIALIZATION WITH A 32MS BSET TSCR1 , #%10000000 ;INTERRUPT PERIOD BSET MCCTL , #% MOVW #48000 , MCCNT CLI MOVB #$0F , DDRA ;KEY_PAD INITIALIZATION MOVB #$FF , DDRB ;FOR CHECKING KEY โ€˜1โ€™ BSET DDRP, #$0F ;LED INITIALIZATION BSET PORTP, #$ BSET ATD0CTL2, #$80 ;ADC0 INITIALIZATION BSET ATD0CTL3, #%00100000 ;4-STAGE SUCCESSIVE APPROXIMATION BSET ATD0CTL4, #$00 ;10-BIT SAMPLING RESOLUTION CHECK_KEY: MOVB #$0F , PORTA ;CHECK KEY โ€˜1โ€™, โ€˜4โ€™, โ€˜7โ€™ ONCE; BCLR PORTA , #%00000001 ;IF NONE PRESSED, NOP ;GO TO NEXT BRSET PORTA, #%01110000,NEXT ;IF KEY โ€˜1โ€™ PRESSED, LDAA PORTA ;GO TO END_OF_MAIN CMPA #$EE ;IF KEY โ€˜4โ€™ PRESSED BEQ END_OF_MAIN ;SET ADC_THRESHOLD AS 500 CMPA #$DE ;IF KEY โ€˜7โ€™ PRESSED BEQ MOV1 ;SET ADC_THRESHOLD AS 0 MOV2: MOVW #0, ADC_THRESHOLD BRA NEXT MOV1: MOVW #500, ADC_THRESHOLD NEXT: LDD ADC_VALUE CPD ADC_THRESHOLD BGE PWM

PWM1: BSET PWMCTL,#%01000000 ;GENERATE A WAVEFORM WITH 0.02Hz BSET PWME, #%00110000 ;AND %10 ACTIVE HIGH DUTY CYCLE BSET PWMPOL,#%00110000 ;USING PWM CHANNELS 4 & 5 BSET PWMCLK,#% MOVB #$07 , PWMPRCLK MOVB #250 , PWMSCLA MOVW #18750, PWMPER MOVW #1875 , PWMDTY BRA CHECK_KEY

[3] Correct the following interrupt service subroutine code that displays the values of PWM duty cycle

period (0~100) on one of the three-digit 7-Segment LEDs.

(Correcting any 5 of 7 mistakes will get the full points)

ORG $

DIGIT_PATTERN DC.B $3F, $06, $5B, $4F, $66, $6D, $7D, $07,

$7F, $6F, $77, $7C, $39, $5E, $79, $

STR DS.B 3

ORG $

... MOVW #$3000, $3E4C

BSET PPSH, #$

BSET PIEH, #$

BSET PIFH, #$

ORG $

ISR1: SEI

LDY #STR

LDAB PWMDTY

LDAA

LOOP: LDX

IDIV

STAB 1, Y+

TFR X, D

CPD #NULL

BNE LOOP

LOOP_END: BRSET PIFH, #$01, BTN

BRSET PIFH, #$02, BTN

BRSET PIFH, #$04, BTN

BTN0: MOVB #$FE, PORTP

LDAA STR+

BRA ISR1_DONE

BTN1: MOVB #$FD, PORTP

LDAA STR+

BRA ISR1_DONE

BTN2: MOVB #$FB, PORTP

LDAA STR

ISR1_DONE: TFR A, Y

LDAA DIGIT_PATTERN, Y

STAA PORTB

JSR DELAY_100MS

BSET PIFH, #$

CLI

RTI

DELAY_100MS: LDY

LOOP1: LDX

DBNE X, *

DBNE Y, LOOP

RTS

[4] Design an embedded system capable of adaptive cooling. Specifically, (i) the system is equipped with

one temperature sensor and one PWM signal channel; (ii) most of the time, the sensor monitors the

environment temperature, and PWM signal duty cycle is set as zero; (iii) if the sensor detects a

temperature higher than a threshold, PWM signal duty cycle will be set as 70%; (iv) if the sensor detects a

temperature lower than the threshold, PWM signal duty cycle will be set as zero again.

( Hint: use ADC, PWM and Timer )

(1) Draw a flow chart of the system operation;

(2) Highlight the used registers and variables at each step.