PLZ HELP AS SOON AS POSSIBLE :( :(

Discussion in 'Embedded Systems and Microcontrollers' started by goldfish300, Apr 29, 2009.

  1. goldfish300

    Thread Starter Member

    Mar 12, 2009
    12
    0
    well im working on a project for the p16f628A and the program should do the followeing

    if pb1(puch button) =1 > left

    if pb2 =1>right

    if pb3 =1 > Motor goes in full speed
    =0 > motor goes in half speed
    i have just wrote the code but can't get it right so plz who can help me i will post the code (.asm) and the picture with the files needed

    Code ( (Unknown Language)):
    1. #INCLUDE    "P16F628A.INC"
    2.  
    3. #DEFINE PB1 PORTA,0
    4. #DEFINE PB2 PORTA,1
    5. #DEFINE PB3 PORTA,2
    6. #DEFINE SW  PORTA,3
    7.    
    8.     ORG     0X000
    9.     GOTO    MAIN
    10.  
    11. MAIN
    12.     CALL    SETUP
    13.     CALL    SETUP_PWM_1
    14.     GOTO    LOOP
    15.  
    16.                  
    17.  
    18. LOOP   
    19.     BTFSC   PB1
    20.     CALL           MOTOR_STOP
    21.     BTFSC   PB2
    22.     CALL            MOTOR_LEFT
    23.     BTFSC   PB3
    24.     CALL    MOTOR_RIGHT
    25.     BTFSC   SW
    26.     CALL            HIGH_SPEED 
    27.     BTFSC   SW
    28.     CALL          HALF_SPEED
    29.     GOTO    LOOP
    30.  
    31. MOTOR_STOP
    32.     CLRF    CCPR1L
    33.     BCF     PB1
    34.     BCF     PB2
    35.     RETURN
    36.  
    37. MOTOR_LEFT
    38.     BSF     PB1
    39.     BCF     PB2
    40.     RETURN
    41.  
    42. MOTOR_RIGHT
    43.     BCF     PB1
    44.     BSF     PB2
    45.     RETURN
    46.  
    47. HALF_SPEED
    48.     MOVLW   D'125'
    49.     MOVWF   CCPR1L
    50.     RETURN 
    51.  
    52. HIGH_SPEED
    53.     MOVLW   D'255'
    54.     MOVWF   CCPR1L
    55.     RETURN
    56.  
    57. SETUP_PWM_1
    58.     BSF     STATUS, RP0    
    59.     MOVLW   D'255'         
    60.     MOVWF   PR2        
    61.     BCF     TRISB, 3       
    62.     BCF     STATUS, RP0    
    63.     MOVLW   B'00000110'    
    64.     MOVWF   T2CON          
    65.     MOVLW   B'00001100'
    66.     MOVWF   CCP1CON              
    67.     RETURN 
    68.        
    69. SETUP
    70.     CLRF    PORTB
    71.     BSF     STATUS, RP0
    72.     CLRF    TRISB
    73.     BCF     STATUS, RP0
    74.     RETURN
    75. END
    76.  
    the image
    [​IMG]
     
    • TWM.zip
      File size:
      17.8 KB
      Views:
      11
  2. jvjtech

    Member

    Jan 26, 2008
    23
    0
    I looked at the code. Can you tell us what is working and what is not working? For example, are the motor control routines working? Regards. JJ
     
Loading...