PIC16F84A - MPLAB PROGRAMMING

Thread Starter

EDSON ONCEBAY

Joined Mar 31, 2015
4
Hi there, I'm working on a project for school and it is kinda confusing so I'm here desperately for help.
Assignment: " Connect PORTB to the 8 LEDs and PORTA to switches S10 to S14, with S14 the MSB. Write a program to add or subtract two Hex numbers (NUM1 + NUM2 or NUM1-NUM2) depending on the value of S10 (PORTA bit 0). If S10 is logic “0” the program will add the two numbers or if S10 is logic “1” the program will subtract them "

I came up with my code and this is what I have so far:

Code:
        #include <GENERAL.H>
; =======================================================================
 NUM1        EQU        0x5A   
 NUM2        EQU        0x39

 REG1       EQU     0x40
 REG2       EQU     0x41
; =======================================================================               

        __CONFIG    0X3FF2       
        ORG            0X0000       
        GOTO        START
        ORG            0X0004       
        RETFIE


                     
START   BSF      STATUS,RP0
        MOVWF    TRISB
        BCF      STATUS,RP0 
        MOVWF    PORTB

       
                BTFSC    PORTA,0            ;skip next instruction if RA0 = 1 and go to SUM
        GOTO     SUM

        MOVLW    NUM2                ;put NUM2 in W
        SUBLW    NUM1                ;subtract NUM2 in W from NUM1  
        MOVWF    REG1                ;save the result in REG1
        MOVF     STATUS,W            ;copy the STATUS register value to W
        MOVWF    REG2                ;and then to REG2
        GOTO     DONE

SUM        MOVLW    NUM1                ;put NUM1 in W
        ADDLW    NUM2                ;add NUM2 with the result in W
        MOVWF    REG1                ;save the result in REG1
        MOVF     STATUS,W            ;copy the STATUS register value to W
        MOVWF    REG2                ;and then to REG2

DONE
        END
I would appreciate your feedback. Thanks!!!
 
Top