PLZ help with this code for project mplab ASAP :(

Discussion in 'Embedded Systems and Microcontrollers' started by goldfish300, Mar 12, 2009.

  1. goldfish300

    Thread Starter Member

    Mar 12, 2009
    12
    0
    my project is about a game that turn leds on and off . i have 4 leds and 3 button . i need button one when pressed to turn led 1 and 3 on and when button 2 is pressed turn on led 2 and 4 and finally button 3 turn off the leds.

    here i have the code , but when i use it it keep the first the third led on and nothing happen when i press on button 2 or the stop one .

    the code :

    Code ( (Unknown Language)):
    1. #INCLUDE    "P16F84A.INC"
    2.  
    3. #DEFINE     PB1 PORTB, 1
    4. #DEFINE     PB2 PORTB, 2
    5. #DEFINE     PB3 PORTA, 3
    6.  
    7.  
    8. #DEFINE     LEDY        PORTA, 0
    9. #DEFINE     LEDG        PORTA, 1
    10. #DEFINE     LEDR        PORTA, 2
    11. #DEFINE     LEDW        PORTA, 3
    12.  
    13. CBLOCK  0X0C
    14.     A1, A2, A3
    15. ENDC
    16.  
    17. ORG     0X000
    18. GOTO        MAIN
    19.  
    20.  
    21. MAIN
    22.     CALL        SETUP
    23.    
    24.  
    25. FUNCTION   
    26.     BTFSC       PB1
    27.     CALL        GAME1
    28.     BTFSC       PB2
    29.     CALL        GAME2
    30.     BTFSC       PB3
    31.     CALL        STOP
    32.     GOTO        FUNCTION
    33.  
    34. STOP
    35.     BCF     PORTA,0
    36.     BCF     PORTA,1
    37.     BCF     PORTA,2
    38.     BCF     PORTA,3    
    39.  
    40. GAME1
    41.     BSF LEDW
    42.     CALL    DELAY_1S
    43.     BCF LEDW
    44.     BSF LEDG
    45.     CALL    DELAY_1S
    46.     BCF LEDG
    47.     GOTO    GAME1
    48.  
    49. GAME2
    50.     BSF LEDR
    51.     CALL    DELAY_1S
    52.     BCF LEDR
    53.     BSF LEDY
    54.     CALL    DELAY_1S
    55.     BCF LEDY
    56.     GOTO    GAME2
    57.  
    58. DELAY_1S
    59.     MOVLW   D'46'  
    60.     MOVWF   A1
    61.     MOVLW   D'189'
    62.     MOVWF   A2
    63.     MOVLW   D'37'
    64.     MOVWF   A3
    65.     DECFSZ  A3
    66.     GOTO        $-1
    67.     DECFSZ  A2
    68.     GOTO        $-5
    69.     DECFSZ  A1
    70.     GOTO        $-9
    71.     RETURN
    72.  
    73. SETUP
    74.     CLRF        PORTA
    75.     CLRF        PORTB
    76.     BSF     STATUS, RP0
    77.     CLRF        TRISA
    78.     MOVLW   B'00001110'
    79.     MOVWF   TRISB
    80.     BCF     STATUS, RP0
    81.     RETURN
    82.  
    83. END
    and the drawing here :
    [​IMG]

    plz help im having it tomor :confused::confused::confused:
     
  2. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    In GAME1 and GAME2 routines, you end up in an infinite loop.

    You need to check for the button presses in each of the games, on each loop.

    The code is doing exactly what you told it to, unlike object oriented/event oriented programming which runs multiple tasks, assembly is very literal.
     
Loading...