0% found this document useful (0 votes)
25 views15 pages

21L-5720 (Micro - Assignment 2)

This document contains code and explanations for two microprocessor programs. The first program implements an intrusion detection system using a PIC microcontroller. It uses one pin as an input to detect when a switch is closed, signaling intrusion, and another pin to turn on a buzzer. It includes a delay routine to toggle the buzzer on and off. The second program multiplies two variables together using a multiplication loop. It shows the step-by-step working for multiplying 7 * 8 and 2 * 3. It also includes calculations to determine the execution time of the multiplication routines based on the clock speed of the microcontroller.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views15 pages

21L-5720 (Micro - Assignment 2)

This document contains code and explanations for two microprocessor programs. The first program implements an intrusion detection system using a PIC microcontroller. It uses one pin as an input to detect when a switch is closed, signaling intrusion, and another pin to turn on a buzzer. It includes a delay routine to toggle the buzzer on and off. The second program multiplies two variables together using a multiplication loop. It shows the step-by-step working for multiplying 7 * 8 and 2 * 3. It also includes calculations to determine the execution time of the multiplication routines based on the clock speed of the microcontroller.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

MICRO-PROCESSOR (MPI)

ASSIGNMENT # 02

NAME:
Ahmad Sheraz
ROLL NO:
21L-5720
SECTION:
BEE-5A
SUBMITTED TO:
Ma’am Tooba Javed
QUESTION NO:1

CODE 1
#include<p16f877.inc>
;*** VARIABLE DEFINITIONS
VAR1 EQU 0X20
VAR2 EQU 0X21
temp EQU 0X22
temp1 EQU 0X23
temp2 EQU 0X24
temp3 EQU 0X25
;************************
ORG 0x000 ; processor reset vector
clrf PCLATH ; ensure page bits are cleared
goto main ; go to beginning of program
main
BANKSEL TRISB
BSF TRISB,0 ;RB0=INPUT
BCF TRISB,1 ;RB1=OUTPUT
BANKSEL PORTB
INTRUSION:
BTFSC PORTB,0 ;if(RB0==0)
GOTO BUZZEROFF ;if(RB0==VALUE OTHER THAN 0,SAY 1)->BUZZER-OFF
GOTO BUZZERON ;if(RB0==0)->BUZZER-ON
BUZZERON:
BSF PORTB,1 ;SPEAKER-ON
CALL DELAY
GOTO INTRUSION
BUZZEROFF:
BCF PORTB,1 ;SPEAKER-OFF
CALL DELAY
GOTO INTRUSION
DELAY:
MOVLW d'100'
MOVWF temp1
LOOP1:
CALL LOOP2_init
DECFSZ temp1,1
GOTO LOOP1
return
LOOP2_init:
MOVLW d'125'
MOVWF temp2
LOOP2: CALL LOOP3_init
DECFSZ temp2,1
GOTO LOOP2
return
LOOP3_init:
MOVLW d'10'
MOVWF temp3
LOOP3:
DECFSZ temp3,1
GOTO LOOP3
return
END
MP-LAB SOFTWARE(CODE 1):

DELAY-ROUTINE(CALL DELAY):
STIMULUS-CONTROLLER(TOGLLING) AND WATCH WINDOW:
1)RB0==0 TOGGLED->(BUZZER ON):

RB0==0 shows that the switch is closed and connected to the ground. There is intrusion
detection (RB1==1 -> BUZZER ON).
2)RB0==1 TOGGLED->(BUZZER OFF):

RB0==1 shows that the switch is open and not connected to ground. There is no intrusion
detection (RB1==0-> BUZZER OFF)
PROTEUS DESIGN:
1) RB0==0(SWITCH CLOSED(RB1==1) -> BUZZER ON):

Q1(MICRO1-5720).HEX file is included in the PICf16877


2)RB0==1(SWITCH OPEN(RB1==0) -> BUZZER OFF):
QUESTION NO:2

CODE 2:
list p=16f877
#include<p16f877.inc>
;*** VARIABLE DEFINITIONS
VAR1 EQU 0X20
VAR2 EQU 0X21
temp EQU 0X22
;************************
ORG 0x000 ; processor reset vector
clrf PCLATH ; ensure page bits are cleared
goto main ; go to beginning of program
main
MOVLW b'00000111'
MOVWF VAR1 ;VAR1=7
MOVLW b'00001000'
MOVWF VAR2 ;VAR2=8
MOVF VAR1,0 ;W-REGSITER=VAR1=7
MULTIPLICATION:
DECFSZ VAR2 ; LOOP WILL RUN VAR2 TIMES ( AS VAR1 * VAR2)

GOTO ADD
GOTO STOP ;(VAR2=0)
ADD:
ADDWF VAR1,0 ;(W=VAR1+W) -> STORING IN W-REG
GOTO MULTIPLICATION
STOP:
END
MP-LAB SOFTWARE(CODE 2)
MULTIPLICATION OF ( VAR1==00000111 * VAR2==00001000 ):

VAR1=7 * VAR2=8
1) 7+7=14 -> 0E HEX
2) 14+7=21 ->15 HEX
3) 21+7=28 ->1C HEX
4) 28+7=35 ->23 HEX
5) 35 +7=42 ->2A HEX
6) 42+7=49 ->31 HEX
7) 49 +7=56 ->38 HEX
The multiplication loop run(VAR2 TIME’S for the value ( 7,,6,5,4,3,2,1 ) and for 0th time
it skips the goto add instruction and jumps to goto stop.
MULTIPLICATION OF ( VAR1==00000010 * VAR2==00000011 ):

VAR1=2 * VAR2=3
1) 2+2=4
2) 4+2=6 ; The multiplication loop run (VAR 2 TIME’S) for the value (
VAR2==2,1 ) and for 0th time it skips the goto add instruction and jumps to goto stop
STOPWATCH ( TIME IN MICRO SECONDS) FOR VAR1=7 * VAR2=8
MULTIPLICATION:

STOPWATCH ( TIME IN MICRO SECONDS) FOR VAR1=2* VAR2=3


MULTIPLICATION:
CALCULATING TOTAL TIME (EXECUTION TIME):
STATEMENTS(INSTRUCTION’S) CYCLES
MOVLW b’00000111’ 1
MOVWF VAR1 ; VAR1=7 1
MOVLW b’00001000’ 1
MOVWF VAR2 ; VAR2=8 1
MOVF VAR2,0 1
DECFSZ 1 (VAR2-1) TIMES
+
GOTO ADD 2
GOTO STOP 2
ADDWF 1 (VAR2-1) TIMES
+
GOTO MULTIPLICATION 2

IF FOSc=4MHZ:
T=1/F
T=1/4*10^6
T=0.25 *10^-6 seconds
4 CLOCK CYCLES = 4 * ( 0.25 *10^-6 )
4 CLOCK CYCLES= 1*10^-6 sec

TOTAL CYCLES:
1) VAR2==8
T=1 + 1 + 1 +1 + 1 + ( DECFSZ cycles + GOTO ADD cycles )* (VAR2 -1) + ( DECFSZ
CYCLE, WHEN VAR2 ==0) + ( GOTO STOP CYCLES ) + (ADDWF + GOTO
MULTIPLICATION ) * (VAR2 -1)
T= 5 + (1+2) *( 8-1) + 2 + 2 + (1+2)* ( 8-1)
T=9 + 3 (n-1) + 3(n-1)
T=9 +3n -3 +3n -3
T=9+6n
T= 9 + 6 *(8)
T= 51 CYCLES
EXECUTION TIME
T= 51 * ( 1 * 10^-6 seconds)
T= 51 *10^-6 seconds

2) VAR2==3
T=1 + 1 + 1 +1 + 1 + ( DECFSZ cycles + GOTO ADD cycles )* (VAR2 -1) + (
DECFSZ CYCLE, WHEN VAR2 ==0) + ( GOTO STOP CYCLES ) + (ADDWF +
GOTO MULTIPLICATION ) * (VAR2 -1)

T= 5 + (1+2) *( 3-1) + 2 + 2 + (1+2)* ( 3-1)


T=9 + 3 (n-1) + 3(n-1)
T=9 +3n -3 +3n -3
T=9+6n
T= 9 + 6 *(3)
T= 27 CYCLES

EXECUTION TIME
T=27 *(1 * 10^-6 seconds)
T=27*10^-6 seconds

You might also like