Question 4 (35 marks) A program written in assembly language targeted for PIC18F
ID: 3881793 • Letter: Q
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 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]
Explanation / Answer
Few points about PIC18F4550 :
PIC18F4550 is an 8-bit microcontroller of PIC18 family.
PIC18F family is based on 16-bit instruction set architecture.
PIC18F4550 consists of 32 KB flash memory, 2 KB SRAM and 256 Bytes EEPROM.
a)The output pin used for this program is 40, two rows of pin each of 20 on both the side. It means the input pin used is 20 pins and the number of output pin is 20 pins. PIC Microcontroller is used consisting of 5 I/O ports (PORTA, PORTB, PORTC, PORTD and PORTE).here also it is consist of 5 input/output ports.
In this program PORTB is used. PORTB have 8 pins to receive/transmit 8-bit I/O data. The remaining ports have different numbers of pins for I/O data communications.In PORTB a logic one (1) in the TRISB register configures the appropriate port pin as input and vice versa. Six pins on this port can act as analog inputs (AN).
c)The number of counting performed on loop1 is 255 .
What we have done is first set up our constant COUNT to 255. The next line puts a label, called LABEL next to our decfsz instruction. The decfsz COUNT,1 decreases the value of COUNT by 1, and stores the result back into COUNT. It also checks to see if COUNT has a value of zero. If it doesn’t, it then causes the program to move to the next line. Here we have a ‘goto’ statement which sends us back to our decfsz instruction. If the value of COUNT does equal zero, then the decfsz instruction causes our program to jump two places forward, and goes to where We have said ‘Carry on here’. So, as you can see, we have caused the program to stay in one place for a predetermined time before carrying on. This is called a delay loop. If we need a larger delay, we can follow one loop by another. The more loops, the longer the delay. We are going to need at least two, if we want to see the LED flash.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.