Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Q4(a) Construct the initialization code needed for the PIC16F877A to set Timer T

ID: 2291957 • Letter: Q

Question

Q4(a) Construct the initialization code needed for the PIC16F877A to set Timer TMRO to generate an interrupt after 10 extenal pulses. The register INTCON and OPTION REG are shown in appendix. You need to write the code needed to initialize the three register properly (6 marks) (b) Construct a proper interrupt service routine for a PIC16F877A microcontroller that has its Port B interrupt on change enabled. On interrupt, this routine should read the content of Port A, multiply it by 2 and save the result in memory location 0x30 (7 marks) (c) Explain the steps that should be followed for an analog to digital conversiorn (7 marks) using 16F877A.

Explanation / Answer

Answer :- 4)a) The assembly code for TMR0 initialization is written below-
INIT:
MOVLW 0xC0 ;W = 1100_0000
MOVWF OPTION_REG ;use 1:1 pre-scalar
MOVLW 0xF5 ;W = 0xF5
MOWF TMR0 ;make timer to count 10 pulses only
MOVLW 0xE0 ;W = 1110_0000
MOVWF INTCON ;enable interrupt for timer zero

Answer :- 4)b) The ISR has been written below-
INT_VECT ISR 0x0004 ;interrupt vector table address for port B change interrupt
GOTO ISR_PORTB ;goto label name ISR_PORTB

ISR_PORTB:
BCF INTCON, GIE ;disable all interrupt
MOVLW 0x30 ;W=0x30
MOVWF FSR0L ;FSR0L = 0x30
CLRF FSR0H ;FSR0H = 0x00
BCF STATUS, C ;clear the carry flag bit
RLF PORTA, 0 ;do portA*2 and keep in W register
MOVWF INDF0 ;write the result at address 0x30
RETFIE ;return from interrupt

Answer :-4)c) The steps for ADC has been written below-

1. Initialize the ADC Module
2. Select the analog channel
3. Start ADC by making Go/Done bit high
4. Wait for the Go/DONE bit to get low
5. Get the ADC result from ADRESH and ADRESL register