Text: Question 1 (20 marks)
(a)
List 3 differences between a microprocessor and microcontroller.
[6 marks]
(b)
A program written in assembly language targeted for PIC18F microcontroller is listed as below:
ORG 0000H
CNT EQU 0x70
CLRF TRISB,1
CLRF PORTB
MOVLW 0x64
MOVWF CNT
; 0x70 is the location for CNT
; Set Port B to output
; Clear Port B
LOOP1:
MOVLW 0xFF
; Put 0xFF into W register
; Toggle Port B
XORWF PORTB,1,0
DECF CNT,1,0
BNZ LOOP2
; Jump to LOOP2 if not zero
BRA LOOP1
; Jump to LOOP1
END:
LOOP2:
Given that the crystal frequency is 16MHz and each instruction takes 4 cycles to execute.
(i) Briefly explain how the XORWF is able to toggle Port B
[3 marks]
(ii) Calculate the duration of the output pulse of Port B based on LOOP2
[5 marks]
(iii) Rewrite the program above in C language. Show only the main function. Use the library function Delay10TCY(x) to generate the desired delay.
[6 marks]