An inexperienced programmer has written the code shown below
An inexperienced programmer has written the code shown below for a 16F84A microcontroller, where the interrupt source is Timer O overflow. Identify all errors and rewrite the program fragment correctly.
Solution
; The following line embeds configuration data into the PICmicro LIST P=16F84 __CONFIG H\'3FFA\' ; XTAL mode ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ; using aliases, bit names and conditional loops #DEFINE PAGE0 BCF STATUS,5 #DEFINE PAGE1 BSF STATUS,5 STATUS EQU H\'03\' ; STATUS register TRISB EQU H\'86\' ; Port B direction register PORTB EQU H\'06\' ; Port B data register TRISA EQU H\'85\' ; Port A direction register PORTA EQU H\'05\' ; Port A data register OPSHUN EQU H\'81\' ;OPTION_REGISTER INTCON EQU H\'0B\' ;INTCON REGISTER TMR0 EQU H\'01\' ; TMRCNT EQU H\'20\' ;TMR COUNT d1 EQU H\'22\' ; d2 EQU H\'23\' ; d3 EQU H\'24\' ; ORG 0 ; Reset vector GOTO 5 ; Goto start of program ORG 4 ; Interrupt vector GOTO BUZZ ; Goto BUZZ ORG 5 ; Start of program memory CLRF PORTB ; clear Port B data register CLRF PORTA ; PAGE1 ; PAGE1 MOVLW B\'11000010\' ; MOVWF OPSHUN ;set timer ratio to 1:8 (TMR0 rate) MOVLW B\'11111111\' ; MOVWF TRISA ; Set port A to input CLRF TRISB ; Port B direction register for output PAGE0 MOVLW B\'10100100\' ; MOVWF INTCON CLRF TMR0 MOVLW D\'15\' ; MOVWF TMRCNT ; FORWARD MOVLW D\'80\' MOVWF PORTB ; Set Port B to 80 BTFSC PORTA,0 ; GOTO BACK_R ;BACK RIGHT BTFSC PORTA,1 ; GOTO BACK_L ;BACK LEFT GOTO FORWARD ; BACK_R MOVLW D\'164\' ; MOVWF PORTB ; BCF INTCON,2 ; ENABLE TMR0 INTTERUP CALL DELAY_R ; MOVLW D\'148\' ; MOVWF PORTB ; CALL DELAY_R ; GOTO FORWARD ; BACK_L MOVLW D\'162\' ; MOVWF PORTB ; BCF INTCON,2 ; ENABLE TMR0 INTTERUP CALL DELAY_R ; MOVLW D\'98\' ; MOVWF PORTB ; CALL DELAY_R ; GOTO FORWARD ; BUZZ BSF PORTB,0 DECFSZ TMRCNT ; GOTO BUZZ MOVLW d\'15\' ;RESET THE DELAY COUNTER MOVWF TMRCNT ; BCF PORTB,0 RETFIE DELAY_R movlw 0xFF movwf d1 movlw 0xFF movwf d2 movlw 0x05 movwf d3 goto Delay_0 DELAY_T movlw 0xFF movwf d1 movlw 0xFF movwf d2 movlw 0x05 movwf d3 Delay_0 decfsz d1, f goto Delay_0 decfsz d2, f goto Delay_0 decfsz d3, f goto Delay_0 ;4 cycles return