pls help me verify my code not work, why???


+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2005
    Posts
    70

    Default pls help me verify my code not work, why???

    my protect for control stepping motor

    case 11 and 12 , we cannot read data frome eeprom

    case 21 , we cannot write data frome eeprom
    case 22 , we cannot write data frome eeprom
    case 23 , work fine no problem

    I very confuse why case 21 and case22 don't work but case 23 work , code same

    Code:
    DEFINE LOADER_USED 1
    INCLUDE "modedefs.bas"
    DEFINE OSC 4   ' Oscillator frequency  4 MHz
    ADCON1 = 7
    ANSEL = 0
    '-------------------------- Ports settings ---------------------------------
    TRISA = %00000001
    PORTA = %00000001 
    TRISB = %00000111  
    PORTB = %00000111                                                                 
    '-------------------------- Variables ---------------------------
    '*****74HC595 DE???KENLER?N? TANIMLA*****
    DTA var PORTB.5     '21--14 b7
    Latch var PORTB.6  '22--12 b6
    CLK var PORTB.7   '23--11  b5                                                                 
    Digit_1 var PORTB.4
    Digit_2 var PORTB.0
    
    IN_1 var PORTA.3
    IN_2 var PORTA.1
    IN_3 var PORTA.2
    IN_4 var PORTA.4
    sw_mode var PORTA.0
    sw_up var PORTB.1
    sw_down var PORTB.2
    sw_Mode_data VAR Byte
    sw_up_data var  Byte
    sw_down_data VAR Byte
    Data_mode VAR Byte
    
    I VAR Byte
    M VAR Byte    ' delay for motro step
    N  VAR  Byte
    T1  VAR  Word
    loaddata VAR BYTE
    Dataorg VAR Byte			' keep data position
    Dataorg_ADDRESS con 0
    DATA_MOTOR VAR Byte
    DATA_MOTORx VAR Byte
    DATA_MOTOR_ADDRESS con 2
    VALUE VAR Byte
    DATA_save_ADDRESS con 4
    DATA_power_ADDRESS con 6
    ''------------------- Start -------------------------------------------
    '-------------------------- Main program -------------------------
    pause 200
     M = 10       ' delay for motro step
     N = 0         ' data motor conter
     Read  DATA_MOTOR_ADDRESS,DATA_MOTOR                                                                
     data_motor = data_motor & %01111111   'clar bit 8 to zero
    MainProgram:
      If sw_mode = 0 Then 
         GoTo  sw_m
      EndIf  
     CHK_sw:
       GoSub  Show_7seg 
     If sw_up = 0 Then
          pause 150
          GoSub T_Right    'up OPEN
      Else
          If sw_down = 0 Then
              pause 150
              GoSub T_left       'up close
          EndIf
      EndIf
    PORTA = %00000001                                                                    
    GoTo  MainProgram   ' Return to main program
    '++++++ mode ++++++++                                                                   
    Mode_option:
    T1 = 2300
    loop:
    If T1 = 0 Then GoTo Select_A
    T1 = t1-1
       If sw_mode = 0 Then 
    sw_m:
          sw_Mode_data = sw_Mode_data+10
          pause 200     ' delay 3 sec
          T1=2300             'T1 ******
          VALUE = sw_Mode_data
          GoSub Show_7segx
       EndIf  
       If sw_up_data <> 2 Then
           If sw_up = 0 Then 
              pause 150
              sw_up_data = 2
              T1=2300         'T1 ******
              Data_mode = sw_Mode_data + sw_up_data
              VALUE = Data_mode
              GoSub Show_7segx
           EndIf 
       EndIf
       If sw_down_data <> 1 Then 
           If sw_down = 0 Then 
              pause 150
              sw_down_data = 1
              T1=2300           'T1******
              Data_mode = sw_Mode_data + sw_down_data
              VALUE = Data_mode
              GoSub Show_7segx
           EndIf
       EndIf 
       Data_mode = sw_Mode_data + sw_up_data + sw_down_data
       VALUE = Data_mode
       If Data_mode >= 40 Then
          pause 150
          Data_mode = 0
          VALUE = DATA_MOTOR
          sw_Mode_data = 0
          sw_up_data = 0
          sw_down_data = 0
          GoTo CHK_sw
       EndIf
    gosub Show_7segx
    GoTo loop
    Select_A: 
    Select case Data_mode       ' mode 10  preset
    Case 11                    'Read save data
         If sw_up = 0 Then
             sw_Mode_data = 0
             sw_up_data = 0
             sw_down_data = 0
             Read  DATA_save_ADDRESS,DATA_MOTORx
             If DATA_MOTOR > DATA_MOTORx Then
             'n = 13 - 2  = 11
             N = DATA_MOTOR - DATA_MOTORx                                                                 
             GoSub MOVE_down          'load data                                                       
             EndIf
          Else
             sw_Mode_data = 0
             sw_up_data = 0
             sw_down_data = 0
          EndIf   
    Case 12                      'Read power data
          If sw_down =0 Then
             sw_Mode_data = 0
             sw_up_data = 0
             sw_down_data = 0
             Read  DATA_power_ADDRESS, DATA_MOTORx
             If DATA_MOTORx > DATA_MOTOR Then
             'n = 50 - 8  = 48
             N = DATA_MOTORX - DATA_MOTOR                                                                 
             GoSub MOVE_up          'load data
             EndIf
          Else
             sw_Mode_data = 0
             sw_up_data = 0
             sw_down_data = 0
          EndIf
    Case 21
         If sw_up = 0 Then
             sw_Mode_data = 0
             sw_up_data = 0 
             sw_down_data = 0
             DATA_MOTOR = DATA_MOTOR +1
            Write DATA_save_ADDRESS , DATA_MOTOR
         Else
             sw_Mode_data = 0
             sw_up_data = 0 
             sw_down_data = 0
         EndIf
    Case 22
         If sw_down = 0 Then
             sw_Mode_data = 0
             sw_up_data = 0 
             sw_down_data = 0
             DATA_MOTOR = DATA_MOTOR +1
             Write DATA_power_ADDRESS , DATA_MOTOR
         Else
             sw_Mode_data = 0
             sw_up_data = 0 
             sw_down_data = 0
         EndIf
    Case 23      
         If sw_up = 0 And sw_down = 0 Then
             sw_Mode_data = 0
             sw_up_data = 0 
             sw_down_data = 0
             DATA_MOTOR = DATA_MOTOR +1
             Write Dataorg_ADDRESS , DATA_MOTOR
         Else
             sw_Mode_data = 0
             sw_up_data = 0 
             sw_down_data = 0
         EndIf
    Case 33
         If sw_up = 0 And sw_down = 0 Then
             sw_Mode_data = 0
             sw_up_data = 0
             sw_down_data = 0
             GoSub Reset_motor
         Else
             sw_Mode_data = 0
             sw_up_data = 0
             sw_down_data = 0
         EndIf
    Case else
         sw_Mode_data = 0
         sw_up_data = 0
         sw_down_data = 0
    End Select
    GoSub Show_7seg
    sw_up_data = 0
    sw_down_data = 0
    GoTo CHK_sw 
    '-------------------------- User subroutine_1--------------------------
    Show_7seg:
    VALUE = DATA_MOTOR
    
    Show_7segx:
    For I = 0 To 1		' Loop through 4 digits
    		N = VALUE Dig I	' Get digit to display
    		GoSub Display1	' Display the digit
    		If sw_Mode_data > 1 Then
    		   loaddata = loaddata  | %10000000     ' led on setup
            EndIf
            If I = 0 Then
                SHIFTOUT DTA,CLK,1,[loaddata\8]
                High Latch
                Low Digit_1
                High Digit_2
                Low Latch
            Else
                SHIFTOUT DTA,CLK,1,[loaddata\8]
                High Latch
                High Digit_1
                Low Digit_2
                Low Latch 
            EndIf
        Next			' Do next digit
        Return    ' Return from subroutine
    Display1:  ' looup data for 7 seg                                               
    LookUp N, [$3F,$06,$5B,$4F,$66,$6D,$7D,$07,$7F,$6F],loaddata
    Return                                                                   
    ''-------------------------- User subroutine_2--------------------------
    T_Right:                     ' 3 1 2 4     'up OPEN
    PORTA =%00001011   '2
    pause M
    PORTA =%00000111   '4
    pause M 
    PORTA =%00010101   '6
    pause M
    PORTA =%00011001   '8
    pause M
    DATA_MOTOR = DATA_MOTOR+1
    If DATA_MOTOR >= 60 Then
        DATA_MOTOR = 60
        WRITE DATA_MOTOR_ADDRESS ,  DATA_MOTOR 
    Else
        Write DATA_MOTOR_ADDRESS , DATA_MOTOR
    EndIf
    Toggle Digit_2                            
    Toggle Digit_1
    Return
    '---------------------
    T_left:                 'down CLOSE
    PORTA =%00011001   '8
    pause M
    PORTA =%00010101   '6
    pause M
    PORTA =%00000111   '4
    pause M
    PORTA =%00001011   '2
    pause M
    DATA_MOTOR = DATA_MOTOR - 1
    If DATA_MOTOR <= 0 Then
        DATA_MOTOR = 0
        WRITE DATA_MOTOR_ADDRESS ,  DATA_MOTOR 
    Else
        Write DATA_MOTOR_ADDRESS ,  DATA_MOTOR 
    EndIf
    Toggle Digit_2
    Toggle Digit_1
    Return
    '=============================
    'Original position 
    Reset_motor:  ' move down
    N = N + 1
    PORTA =%00011001   '8
    pause M
    PORTA =%00010101   '6
    pause M
    PORTA =%00000111   '4
    pause M
    PORTA =%00001011   '2
    pause M
    If N < 65 Then
        Toggle Digit_1
        GoTo Reset_motor
    EndIf
    '======================= 
    'Variable = EREAD Address 
    Read  Dataorg_ADDRESS  , n
    DATA_MOTOR = 0      'KEEP DATA FOR SHOW DISPLAY
    '=======================
    MOVE1:
    PORTA =%00001011   '2
    pause M
    PORTA =%00000111   '4
    pause M
    PORTA =%00010101   '6
    pause M
    PORTA =%00011001   '8
    pause M
    If N <> 0 Then
        N = N - 1
        Toggle Digit_1
        DATA_MOTOR = DATA_MOTOR + 1
        GoTo MOVE1
    EndIf
    PORTA = %00000001
    Write DATA_MOTOR_ADDRESS , DATA_MOTOR 
    GoTo CHK_sw
    '=====================================
    MOVE_down:        'per-set save
    MOVE_down1:
    PORTA =%00011001   '8
    pause M
    PORTA =%00010101   '6
    pause M
    PORTA =%00000111   '4
    pause M
    PORTA =%00001011   '2
    pause M
    If N > 0 Then
    N = N - 1
    Toggle Digit_1
    DATA_MOTOR = DATA_MOTOR - 1
    GoSub Show_7seg
    GoTo MOVE_down1
    EndIf
    PORTA = %00000001
    Write DATA_MOTOR_ADDRESS , DATA_MOTOR 
    Return
    '===================================
    MOVE_up:        'per-set power
    MOVE_up1: 
    PORTA =%00001011   '2
    pause M
    PORTA =%00000111   '4
    pause M
    PORTA =%00010101   '6
    pause M
    PORTA =%00011001   '8
    pause M
    If N > 0 Then 
        N = N - 1
        Toggle Digit_1
        DATA_MOTOR = DATA_MOTOR + 1
        GoTo MOVE_up1
    EndIf
    PORTA = %00000001
    Write DATA_MOTOR_ADDRESS , DATA_MOTOR 
    Return
    end

  2. #2
    Join Date
    May 2005
    Posts
    70

    Unhappy

    Ok ,my problem was resolve by we remove If founction out,

    code:

    Case 11 'Read save data
    ' If sw_up = 0 Then
    sw_Mode_data = 0
    sw_up_data = 0
    sw_down_data = 0
    Read DATA_save_ADDRESS,DATA_MOTORx
    If DATA_MOTOR > DATA_MOTORx Then
    'n = 13 - 2 = 11
    N = DATA_MOTOR - DATA_MOTORx
    GoSub MOVE_down 'load data
    EndIf
    ' Else
    sw_Mode_data = 0
    sw_up_data = 0
    sw_down_data = 0
    ' EndIf
    Case 12 'Read power data
    ' If sw_down =0 Then
    sw_Mode_data = 0
    sw_up_data = 0
    sw_down_data = 0
    Read DATA_power_ADDRESS, DATA_MOTORx
    If DATA_MOTORx > DATA_MOTOR Then
    'n = 50 - 8 = 48
    N = DATA_MOTORX - DATA_MOTOR
    GoSub MOVE_up 'load data
    EndIf
    ' Else
    sw_Mode_data = 0
    sw_up_data = 0
    sw_down_data = 0
    ' EndIf
    Case 21
    ' If sw_up = 0 Then
    sw_Mode_data = 0
    sw_up_data = 0
    sw_down_data = 0
    DATA_MOTOR = DATA_MOTOR +1
    Write DATA_save_ADDRESS , DATA_MOTOR
    ' Else
    sw_Mode_data = 0
    sw_up_data = 0
    sw_down_data = 0
    'EndIf
    Case 22
    ' If sw_down = 0 Then
    sw_Mode_data = 0
    sw_up_data = 0
    sw_down_data = 0
    DATA_MOTOR = DATA_MOTOR +1
    Write DATA_power_ADDRESS , DATA_MOTOR
    ' Else
    sw_Mode_data = 0
    sw_up_data = 0
    sw_down_data = 0
    ' EndIf
    Last edited by chai98a; - 18th January 2010 at 10:51.

Similar Threads

  1. Minimizing code space
    By Tobias in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 30th May 2009, 08:25
  2. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 09:26
  3. Code: Why is this code greater than 2000 words?
    By DrDreas in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 1st June 2007, 20:51
  4. Please help ? RF Remote Source code
    By sorasit46 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 25th April 2007, 15:40
  5. Replies: 1
    Last Post: - 31st August 2005, 21:00

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts