Menu

Aliens in defines

sfyris
2019-09-13
2019-09-18
  • sfyris

    sfyris - 2019-09-13

    From this code (please remove the "-" signs before defines, I put them because without them text becomes weird)

    ;Chip Settings
    -#chip 16F887,20

    'Pin mappings for LCD
    -#define LCD_IO 4
    -#define LCD_NO_RW
    -#define LCD_RW PORTB.1
    -#define LCD_RS PORTB.0
    -#define LCD_Enable PORTB.2
    -#define LCD_Data_Port PORTD
    -#define LCD_DB4 PORTD.4
    -#define LCD_DB5 PORTD.5
    -#define LCD_DB6 PORTD.6
    -#define LCD_DB7 PORTD.7

    -#define ARC 70 'επιθυμητό τόξο κίνησης
    -#define SERVO_L_LIMIT 650 'δεξί όριο κίνησης (ms)
    -#define SERVO_R_LIMIT 2450 'αριστερό κίνησης (ms)
    -#define SERVO_L 1200
    -#define SERVO_R 1900
    -#define SERVO_STEP (SERVO_R - SERVO_L)/ARC
    -#define SCREEN_L_LIMIT 0 'αριστερό όριο οθόνης 55
    -#define SCREEN_R_LIMIT 180 'δεξί όριο οθόνης 125
    -#define SCREEN_L (SCREEN_L_LIMIT + SCREEN_R_LIMIT)/2 - ARC/2
    -#define SCREEN_R (SCREEN_L_LIMIT + SCREEN_R_LIMIT)/2 + ARC/2

    locate 1,1
    print SERVO_STEP
    print " "
    print SERVO_R
    print " "
    print SERVO_L
    wait 500 ms
    

    I get the first attach, Everything ok.
    But with this code (highlighted the changes):

    'Pin mappings for LCD
    -#define LCD_IO 4
    -#define LCD_NO_RW
    -#define LCD_RW PORTB.1
    -#define LCD_RS PORTB.0
    -#define LCD_Enable PORTB.2
    -#define LCD_Data_Port PORTD
    -#define LCD_DB4 PORTD.4
    -#define LCD_DB5 PORTD.5
    -#define LCD_DB6 PORTD.6
    -#define LCD_DB7 PORTD.7

    -#define ARC 70 'επιθυμητό τόξο κίνησης
    -#define SERVO_L_LIMIT 650 'δεξί όριο κίνησης (ms)
    -#define SERVO_R_LIMIT 2450 'αριστερό κίνησης (ms)
    -#define SERVO_L (SERVO_L_LIMIT + SERVO_R_LIMIT)/2 - (ARC10)/2
    -#define SERVO_R (SERVO_L_LIMIT + SERVO_R_LIMIT)/2 + (ARC
    10)/2

    -#define SERVO_STEP (SERVO_R - SERVO_L)/ARC
    -#define SCREEN_L_LIMIT 0 'αριστερό όριο οθόνης 55
    -#define SCREEN_R_LIMIT 180 'δεξί όριο οθόνης 125
    -#define SCREEN_L (SCREEN_L_LIMIT + SCREEN_R_LIMIT)/2 - ARC/2
    -#define SCREEN_R (SCREEN_L_LIMIT + SCREEN_R_LIMIT)/2 + ARC/2

    locate 1,1
    print SERVO_STEP
    print " "
    print SERVO_R
    print " "
    print SERVO_L
    wait 500 ms
    

    Green small creatures make me getting the second attach. If you make the maths by hand In every code SERVO_STEP has the same value (10). I give up...

     
  • sfyris

    sfyris - 2019-09-13

    oups! attachments dont upload...one more try

     
  • Anobium

    Anobium - 2019-09-13

    Try adding this to your code (Always do this!)

    #option Explicit

    And, if you use this editor correctly you do not have to change the code.

    And, by 'hacking the code in the editor means the ARC*10 has become ARC10....

    However, the answer to your issue - is use a script. Scripts are detailed in the help but they are not easy to use.

    #chip 16F887,20
    #option Explicit
    #define LCD_IO 4
    #define LCD_NO_RW
    #define LCD_RW PORTB.1
    #define LCD_RS PORTB.0
    #define LCD_Enable PORTB.2
    #define LCD_Data_Port PORTD
    #define LCD_DB4 PORTD.4
    #define LCD_DB5 PORTD.5
    #define LCD_DB6 PORTD.6
    #define LCD_DB7 PORTD.7
    
    #define ARC 70       'επιθυμητό τόξο κίνησης
    #define SERVO_L_LIMIT 650    'δεξί όριο κίνησης (ms)
    #define SERVO_R_LIMIT 2450   'αριστερό κίνησης (ms)
    #define SCREEN_L_LIMIT 0   'αριστερό όριο οθόνης 55
    #define SCREEN_R_LIMIT 180 'δεξί όριο οθόνης 125
    
    #script
    
          SERVO_L = INT( (SERVO_L_LIMIT + SERVO_R_LIMIT)/2 - (ARC*10)/2 )
          SERVO_R = INT((SERVO_L_LIMIT + SERVO_R_LIMIT)/2 + (ARC*10)/2)
          SERVO_STEP = INT((SERVO_R - SERVO_L)/ARC)
          SCREEN_L = INT((SCREEN_L_LIMIT + SCREEN_R_LIMIT)/2 - ARC/2)
          SCREEN_R = INT((SCREEN_L_LIMIT + SCREEN_R_LIMIT)/2 + ARC/2)
    
    'Delete these when you calcs are correct
          warning SERVO_L
          warning SERVO_R
          warning SERVO_STEP
          warning SCREEN_L
          warning SCREEN_R
    
    #endscript
    
        locate 1,1
        print SERVO_STEP
        print " "
        print SERVO_R
        print " "
        print SERVO_L
        wait 500 ms
    

    Provides... the following:

    Source-File  =  C:\temp\New95.gcb
    >>>  WARNINGs / ERRORs reported by Great Cow BASIC  (if Syntax Error, doubleclick on the errormessage below)  <<<
    Warning: 1200
    Warning: 1900
    Warning: 10
    Warning: 55
    Warning: 125
    Duration:   1.3  Seconds.
    

    Simples....

     
  • sfyris

    sfyris - 2019-09-13

    After compile new errors after using the described solution
    Errors have been found:

    xxx.gcb (29): Error: Array/Function INT has not been declared
    xxx.gcb (31): Error: Array/Function INT has not been declared
    xxx.gcb (33): Error: Array/Function INT has not been declared
    xxx.gcb (35): Error: Array/Function INT has not been declared
    xxx.gcb (37): Error: Array/Function INT has not been declared
    xxx.gcb (39): Error: Array/Function INT has not been declared

    The message has been logged to the file Errors.txt.

     

    Last edit: sfyris 2019-09-13
  • Anobium

    Anobium - 2019-09-13

    Not here....

    19:48:56 G+Stool started with parameter 'asm' -> processing C:\GCB@Syn\G+Stools\makeASM.bat
    Source-File = C:\temp\New95.gcb

    WARNINGs / ERRORs reported by Great Cow BASIC (if Syntax Error, doubleclick on the errormessage below) <<<
    Warning: 1200
    Warning: 1900
    Warning: 10
    Warning: 55
    Warning: 125
    Duration: 1.3 Seconds.

    You need to post your code as an attachment. I cannot guess what you have in the editor.

     
  • sfyris

    sfyris - 2019-09-13

    Oups sorry Anobium, just forget to remove the #defines, its ok now it works, thank you. But anyway why is this necessary, that shouldn't be. And specially to only one var, the SERVO_STEP. Why not for the others?

     

    Last edit: sfyris 2019-09-13
  • Anobium

    Anobium - 2019-09-13

    OK.

    I am not sure why #define 'constant' complex_calc does not do what you expect.

    But, we use #script - #endscript to complete the task.

     
    ❤️
    1
  • stan cartwright

    stan cartwright - 2019-09-15

    option Explicit

    ALWAYS USED IT!

     
  • sfyris

    sfyris - 2019-09-18

    Yes sure it is usefull when writing a variable wrong accidentaly, without this option compiler assumes the wrong variable as byte and continue using it without warning. In small programs someone can easy observe what is going wrong but in bigger ones things go hard when this happens.

     

    Last edit: sfyris 2019-09-18

Log in to post a comment.