Question: Question 4 (35 marks) A program written in assembly language targeted for PIC18F4550 microcontroller is listed as below: ORG 0000H ;*****Set up the Constants**** STATUS
Question 4 (35 marks)
A program written in assembly language targeted for PIC18F4550 microcontroller is listed as below:
ORG 0000H
;*****Set up the Constants****
STATUS equ 03h ;Address of the STATUS register
COUNT1 equ 08h ;First counter for our delay loops
COUNT2 equ 09h ;Second counter for our delay loops
;****Set up the port****
bsf STATUS,5 ;Switch to Bank 1
movlw 00h ;Set the Port B pins
movwf TRISB ;to output.
bcf STATUS,5 ;Switch back to Bank 0
;****Turn the LED on****
Start movlw 02h ;Turn the LED on by first putting it
movwf PORTB ;into the w register and then on the port
;****Start of the delay loop 1****
Loop1 decfsz COUNT1,1 ;Subtract 1 from 255
goto Loop1 ;If COUNT is zero, carry on.
decfsz COUNT2,1 ;Subtract 1 from 255
goto Loop1 ;Go back to the start of Loop 1.
;****Delay finished, now turn the LED off****
movlw 00h ;Turn the LED off by first putting
movwf PORTB ;it into the w register and then on the port
;****Add another delay****
Loop2 decfsz COUNT1,1
goto Loop2
decfsz COUNT2,1
goto Loop2
;****Now go back to the start of the program
goto Start ;go back to Start and turn LED on again
;****End of the program****
END ; End of program
Program 2
Given that the crystal frequency is 1MHz and each instruction takes 4 cycles to execute:
(a) Identify the output pin used for this program. [2 marks]
(b) Draw the circuit corresponding to this program. [5 marks]
(c) Determine the number of counting performed by Loop1 and Loop2. [5 marks]
(d) Explain why two delay loops, Loop1 and Loop2 are needed for the program above. [5 marks]
(e) Explain the drawback of using two delay loops for the program above. [3 marks]
(f) Rewrite the above program using only one delay loop (Loop1). [15 marks]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
