Professional Documents
Culture Documents
Intro Micro MT August 16 2023
Intro Micro MT August 16 2023
#1)
The following assembly program will be run on PIC16F877 microcontroller system with
Fxtall 8 MHz. Some instructions in the program are shown as Instr_i, i=1,2,..16 symbolically. Those
instructions is either BCF/SF ….., or NOP.
CBLOCK 0X070
CNT_1, CNT_2, CNT_3
ENDC
ORG 0x0000
NOP
Loop: NOP
Instr_1
Instr_2
CALL SUB_1
NOP
NOP
GOTO Loop
;*****************************************************
ORG 0xsayi_1
SUB_1: NOP
MOVLW AAh
Instr_3
Instr_4
MOVWF CNT_1
Loop_1: NOP
Instr_5
Instr_6
CALL SUB_2
NOP
NOP
Instr_7
Instr_8
DECFSZ CNT_1, F
GOTO Loop_1
NOP
ZZ: RETURN
;******************************************************
ORG 0xsayi_2
SUB_2: NOP
MOVLW BBh
Instr_9
Instr_10
MOVWF CNT_2
NOP
Loop_2: NOP
Instr_11
Instr_12
CALL SUB_3
NOP
NOP
Instr_13
Instr_14
DECFSZ CNT_2, F
GOTO Loop_2
RETURN
;*****************************************************
ORG 0x1900
SUB_3: NOP
Instr_15
Instr_16
MOVLW CCh
MOVWF CNT_3
Loop_3: DECF CNT_3, F
MOVLW 20h
XORWF CNT_3, W
BTFSS STATUS, Z
GOTO Loop_3
KK: NOP
YY: RETURN
When the program reaches the line labeled as KK active stack memory portion becomes as follows
Stack memory
Top 110Ah
0909h
Bottom 0005h
Determine
f) Assume that user defined GPRs CNT_1, CNT_2, CNT_3 are redefined as follows.
CBLOCK 0x070
CNT_1
ENDC
;***********************
CBLOCK 0x120
CNT_2
ENDC
;************************
CBLOCK 0x1A0
CNT_3
ENDC
Determine the following symbolic instructions by considering the rules explained in part e.
g) How many memory locations does subroutine SUB_3 occupy in the system memory?
h) Calculate processing time for subroutine SUB_3.
i) If Instr_11 and Instr_12 are erased from the program, determine the instruction to which the
program jumps after execution of CALL SUB_3.
#2)
Consider hex code (machine code) of an assembler program part written for a PIC16F877
microcontroller system.
CBLOCK 0x070
CNT
ENDC
ORG 0x0000
Space characters in 14-bit hex codes are inserted just to increase the readability.
#3) Consider the following hardware and the software associated with it.
CBLOCK 0x070
TMP, CNT0, CNT1, Time
ENDC
ORG 0x0000
NOP
GOTO Main
ORG 0x0004
GOTO ISR
Main: NOP
BANKSEL TRISB
MOVLW F0h
MOVWF TRISB
BCF TRISC, 0
MOVLW b’00000111’
MOVWF OPTION_REG
;**************************************
BANKSEL PORTB
BCF PORTB, 0
BCF PORTC, 0
;**************************************
CLRF INTCON
BSF INTCON, RBIE
BSF INTCON, GIE
;*************************************************
CLRF TMP
CLRF CNT0
AA: CLRF CNT1
CLRF Time
;*************************************************
Loop: NOP
NOP
NOP
GOTO Loop
;*************************************************
ISR: NOP
BTFSC INTCON, RBIF
GOTO Keys
BTFSC INTCON, T0IF
GOTO Measure
GOTO Son
;***************************************************
Keys: BANKSEL PORTB
MOVF PORTB, W
MOVWF TMP
BTFSS TMP, 4
GOTO Key_4
BTFSS TMP, 5
GOTO Key_5
BTFSS TMP, 6
GOTO Key_6
BTFSS TMP, 7
GOTO Key_7
GOTO Son
;************************************************
Key_4: BCF INTCON, RBIE
BANKSEL TMR0
CLRF TMR0
BB: BSF PORTC, 0
BSF INTCON, T0IE
;##################################
MOVLW .5
MOVWF Time
;##################################
GOTO Son
;*******************************************************
Key_5: BCF INTCON, RBIE
BANKSEL TMR0
CLRF TMR0
BSF PORTC, 0
BSF INTCON, T0IE
;##################################
MOVLW .10
MOVWF Time
;##################################
GOTO Son
;*******************************************************
Key_6: BCF INTCON, RBIE
BANKSEL TMR0
CLRF TMR0
BSF PORTC, 0
BSF INTCON, T0IE
;##################################
MOVLW .15
MOVWF Time
;##################################
GOTO Son
;****************************************************
Key_7: BCF INTCON, RBIE
BANKSEL TMR0
CLRF TMR0
BSF PORTC, 0
BSF INTCON, T0IE
;##################################
MOVLW .20
MOVWF Time
;##################################
GOTO Son
;*****************************************************
Measure: NOP
;###########################################
INCFSZ CNT0, F
GOTO Son
INCF CNT1, F
MOVF Time, W
SUBWF CNT1, W
BTFSS STATUS, Z
GOTO Son
BANKSEL PORTC
BCF PORTC, 0
CLRF CNT1
BCF INTCON, T0IE
BSF INTCON, RBIE
;#################################################
Son: BCF INTCON, T0IF
BCF INTCON, RBIF
RETFIE
a) What are the interrupt events that are used in this system?
b) Is any interrupt recognized if no key is pressed initially in this system?
c) If the user pushes Key_4 after power on reset in the system, say at time t=0. What happens?
d) If the user pushes Key_4 after power on reset in the system, say at time t=0. After 1 minute
later, he pushes Key_5. What happens?
e) If the user pushes Key_6 after power on reset in the system, say at time t=0. After 5 minutes
later, he pushes Key_7. What happens?
f) What are the number of active stack locations when the program reaches at point labelled as
AA and BB.