# Homework Solution: Question 4 (35 marks)…

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]

Few points about PIC18F4550 : PIC18F4550 is an 8-bit microcontroller of PIC18 family.

Question 4 (35 marks)

A program written in galaxy dialect targeted ce PIC18F4550 microcontroller is listed as below:

ORG   0000H

;*****Fixed up the Trues****

STATUS equ 03h     ;Address of the STATUS record

COUNT1 equ 08h     ;Primitive contrary ce our relapse loops

COUNT2 equ 09h     ;Second contrary ce our relapse loops

;****Fixed up the mien****

bsf STATUS,5       ;Switch to Bank 1

movlw 00h          ;Fixed the Mien B buttons

movwf TRISB ;to output.

bcf STATUS,5       ;Switch tail to Bank 0

;****Rotate the LED on****

Start       movlw 02h          ;Rotate the LED on by primitive putting it

movwf PORTB ;into the w record and then on the mien

;****Set-out of the relapse loop 1****

Loop1 decfsz COUNT1,1    ;Subtrstrike 1 from 255

goto Loop1    ;If COUNT is naught, convey on.

decfsz COUNT2,1      ;Subtrstrike 1 from 255

goto Loop1    ;Go tail to the fixed-out of Loop 1.

;****Relapse refined, now rotate the LED impromptu****

movlw 00h            ;Rotate the LED impromptu by primitive putting

movwf PORTB ;it into the w record and then on the mien

Loop2       decfsz COUNT1,1

goto Loop2

decfsz COUNT2,1

goto Loop2

;****Now go tail to the fixed-out of the program

goto Fixed-out          ;go tail to Fixed-out and rotate LED on again

;****End of the program****

END                      ; End of program

Program 2

Given that the crystal abundance is 1MHz and each adbadness takes 4 cycles to execute:

(a)          Identify the output button used ce this program.                                                         [2 marks]

(b)          Draw the circumference selfsame to this program.                                                        [5 marks]

(c)          Determine the calculate of counting manufactured by Loop1 and Loop2.        [5 marks]

(d)         Explain why span relapse loops, Loop1 and Loop2 are deficiencyed ce the program aloft.                                                                                                                                                                     [5 marks]

(e)          Explain the drawtail of using span relapse loops ce the program aloft.                   [3 marks]

(f)          Rewrite the aloft program using barely individual relapse loop (Loop1).                              [15 marks]

## Expert Exculpation

PIC18F4550 is an 8-bit microcontroller of PIC18 sequenceage.