PIC16F84A - MPLAB PROGRAMMING

Discussion in 'Homework Help' started by EDSON ONCEBAY, Mar 31, 2015.

  1. EDSON ONCEBAY

    Thread Starter New Member

    Mar 31, 2015
    4
    0
    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 (Text):
    1.  
    2.         #include <GENERAL.H>
    3. ; =======================================================================
    4.  NUM1        EQU        0x5A  
    5.  NUM2        EQU        0x39
    6.  
    7.  REG1       EQU     0x40
    8.  REG2       EQU     0x41
    9. ; =======================================================================              
    10.  
    11.         __CONFIG    0X3FF2      
    12.         ORG            0X0000      
    13.         GOTO        START
    14.         ORG            0X0004      
    15.         RETFIE
    16.  
    17.  
    18.                      
    19. START   BSF      STATUS,RP0
    20.         MOVWF    TRISB
    21.         BCF      STATUS,RP0
    22.         MOVWF    PORTB
    23.  
    24.        
    25.                 BTFSC    PORTA,0            ;skip next instruction if RA0 = 1 and go to SUM
    26.         GOTO     SUM
    27.  
    28.         MOVLW    NUM2                ;put NUM2 in W
    29.         SUBLW    NUM1                ;subtract NUM2 in W from NUM1  
    30.         MOVWF    REG1                ;save the result in REG1
    31.         MOVF     STATUS,W            ;copy the STATUS register value to W
    32.         MOVWF    REG2                ;and then to REG2
    33.         GOTO     DONE
    34.  
    35. SUM        MOVLW    NUM1                ;put NUM1 in W
    36.         ADDLW    NUM2                ;add NUM2 with the result in W
    37.         MOVWF    REG1                ;save the result in REG1
    38.         MOVF     STATUS,W            ;copy the STATUS register value to W
    39.         MOVWF    REG2                ;and then to REG2
    40.  
    41. DONE
    42.         END
    43.              
    I would appreciate your feedback. Thanks!!!
     
Loading...