Today 10:24
Forum: The Lounge
Starter: Henk57
Views: 0
Replies: 113
Today 10:08
Forum: Website / Forum Issues
Starter: pe1pme
Views: 0
Replies: 49
Today 10:07
Forum: The Lounge
Starter: craig
Views: 0
Replies: 1
Yesterday 13:42
Forum: The Lounge
Starter: basparky
Views: 0
Replies: 3
Yesterday 12:48
Forum: The Lounge
Starter: towlerg
Views: 0
Replies: 2
+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Trouble with variable types951 days old

  1. #1
    Junior Member Broderic's Avatar
    Join Date
    Jan 2016
    Posts
    80
    Thumbs Up
    Received: 1
    Given: 1
    Total Downloaded
    184.42 MB

    0 Not allowed!

    Default Trouble with variable types

    Hello.
    To read data from an EEprom, I need to read mDA and mDB byte variables and then join them in a signed 16 bit variable.
    Problem: Amicus 18 does not have signed 16 bit variable.

    I tried to solve in this way: see code below
    ---------------------------------------------------------

    Dim AC1 As Dword
    Dim AC2 As Dword
    Dim B As Dword
    Dim mDA As Byte
    Dim mDB As Byte
    Dim AC4 As AC1.Word1
    mDA=209
    mDB=246

    AC1 = mDA << 24
    AC1 = AC1|(mDB << 16)

    B=AC4*2

    main:


    HRSOut "mDA=",Dec mDA, 13
    HRSOut "mDB=",Dec mDB, 13
    HRSOut "AC1 =", SDec AC1 ,13
    HRSOut "AC4 =", SDec AC4 ,13
    HRSOut "B =", SDec B ,13

    GoTo main
    ---------------------------------------------------------------------------

    That is I put the byte variable in a Dword and then I extract higher word.

    In this case I have a negative value for AC4 (first bit of the 16-bit is 1).
    But when I make a multiplication 2 times in to assign the value in a B variable, I do not have the negative value anymore (wrong results).

    Is anyone so kind to help and explain where I'm wrong?

    Thanks a lot

  2. #2
    Fanatical Contributor Les's Avatar
    Join Date
    Feb 2002
    Posts
    2,966
    Thumbs Up
    Received: 295
    Given: 109
    Total Downloaded
    1.50 GB

    0 Not allowed!

    Default Re: Trouble with variable types

    The Amicus18 compiler has been replaced with the full Proton compiler because the devices PIC18F25K20 and PIC18F25K22 do not require the USB key and the compiler operates fully.

    You will also get the Proton24 compiler which does not require a key for some PIC24 devices.

    The Proton compiler can be downloaded from here:

    Proton compiler version 3.5.7.4 and Proton24 compiler version 1.0.2.9

    Then apply the patch downloadable from here:

    Proton compiler version 3.5.7.5 patch
    Last edited by Les; 8th January 2016 at 17:06.
    For more example programs for Proton and Proton24 or updates, please visit: Proton WIKI or Proton Files

  3. #3
    Junior Member Broderic's Avatar
    Join Date
    Jan 2016
    Posts
    80
    Thumbs Up
    Received: 1
    Given: 1
    Total Downloaded
    184.42 MB

    0 Not allowed!

    Default Re: Trouble with variable types

    Hello Les.

    Many many thanks for your kind help!

    I ran the code and it works.

    Below please find the code to read pressure and temperature with BMP180 sensor.
    It is just an adaptation of jeremy smith's code MS5611.

    The way I read the coefficient is not elegant, I know.
    I'm just a beginner.

    Regards.
    Code:
    '****************************************************************'*                                        *
    
    
    ' * This is an adaptation of jeremy smith's code MS5611 for the BMP180 sensor
    ' * using Amicus 18 Harware and EADOG 128M_ 6W graphic display
    
    
    '******************************************************************
      Include "Amicus18.inc"
    
    
        All_Digital = True 
        Declare Watchdog = True
       
    ' ****************I2C declared pins for the MS5611 *****************************
     Symbol SDAPin = PORTC.2
     Symbol SCLPin = PORTC.3
     Declare SDA_Pin PORTC.2
     Declare SCL_Pin PORTC.3
     Symbol PI = 0.77
    '****************** Variables to hold the MS5611 calculations ******************
    Dim PRESSURE As Word
    Dim RAW_T As Word
    Dim T As Word
    Dim x1 As Float
    Dim x2 As Float
    Dim TEMP As Float
    
    
    Dim msb As Word
    Dim lsb As Word
     
        Dim AC1                 As SWord
        Dim AC2                 As SWord
        Dim AC3                 As SWord
        Dim AC4                 As Word
        Dim AC5                 As Word
        Dim AC6                 As Word
        Dim B1                  As SWord
        Dim B2                  As SWord   
        Dim MB                  As SWord
        Dim MC                  As SWord
        Dim MD                  As SWord
     
        Dim mTA As Byte
        Dim mTB As Byte
        Dim mPA As Byte
        Dim mPB As Byte
        
         Dim g1 As Float
        Dim g2 As Float
        Dim g3 As Float
        
        Dim mDA As Byte
        Dim mDB As Byte   
       
        
        
        Dim b6 As Float
        Dim x3 As Word
        Dim b3 As Float
        Dim p As Dword
        Dim b4 As Float
        Dim b7 As Float
        Dim pera As Float
        Dim PRESSIONE As Float
     
    '*************************** DOG displat text **********************************
    Dim index As Byte       'dim for column selecting
    Dim lcd_page As Byte    'dim for page increments
    Dim page_index As Byte  'to clear pages in clear screen routine
    Dim Col_MSB As Byte     'column MSB part
    Dim Col_LSB As Byte     'column LSB part
    Dim LCD_Row As Byte     'selects Row 
    Dim i As Byte
    Dim j As Word
    Dim k As Byte
    Dim LcdStr[26] As Byte
    Dim Lcd_Data As Byte
    Dim Lcd_column As Byte
    Dim LCD_COL As Byte
    Dim databyte As Byte
    Dim fontcash[6] As Byte 'font data 6 bits of data per chr ie "$E0,$E0,$E0,$00,$00,$00"
    Dim BIGfontcash[11] As Byte
    Dim INDEXROW As Byte
    Dim char_mode As Byte
    
    
    '***************************Ring Buffer for pressure averaging Dims ************
    Symbol AvgCount = 8 ' = Number of samples to average
    Symbol FAspread = 400 ' = Fast Average threshold +/-
    Dim ADavg As Float
    Dim temp1 As Float
    Dim temp2 As Float
    ADavg = 0
    
    
    '****************************EADOG 128x64 LCD PINS******************************
    Symbol SI = PORTC.7   'pin 36 SI PIN
    Symbol CS = PORTC.4   'pin 40 cs
    Symbol A0 = PORTC.5   'pin 38 A0 PIN
    Symbol CLK = PORTC.6  'pin 37  clock
    High PORTB.0          'pin 39 reset pin hid high
    '*******************************************************************************
    
    
    
    
    
    
    
    
    GoSub  Init_LCD       'initilise the dislpay
    GoSub Clear_Screen    'clear the screen
    GoSub calibration
    
    
    main:
    
    
    GoSub READ_TEMP
    
    
            T = (RAW_T - AC6)
            x1 = T * AC5/32768 
            'x2 = -24137728 / (x1+ MD)
              
            x2 = MC * 2048      
            x2 = x2/(x1+MD) 
            TEMP = ((x1+x2)+8)
            TEMP = TEMP/160
             
            
    GoSub READ_PRESSURE 
    
    
       b6 = (x1+x2)-4000 
          
            g1 =  (b6*b6)/4096
            g1= (g1*B2)/2048
            g2 = (AC2*b6)/2048 
            g3 = g1 + g2
            b3= AC1*4+g3
            b3 = (b3 + 2)/4
            g1 = AC3 *b6/8192 
            g2=  b6 * b6/4096
            g2 = (g2 *B1)/65536
            g3 = g1 + g2
            g3 = (g3 + 2)/4
            b4 = (g3 + 32768)
            b4 = (b4/32768)* AC4  
            
           b7 = PRESSURE - b3
           b7 = b7*50000 
             
            'p = (b7/b4)*2
            p = (b7*2)/b4
            g1 = (p/65536)*p
            g1=(g1*3038)/65536
             
           g2 = (-7357 * p)/65536
            pera= (g1 + g2 +3791)
            PRESSIONE = p + pera /16
            PRESSIONE=PRESSIONE/100
    
    
    
    
       lcd_page = 177                 'selects the line 1 to 7,  176=page 1
        Lcd_column = 5                 'Selects column 0 - 128
        GoSub lcd_gotoxy
        Str LcdStr = "Hpa: ",0          'enter your text here
        GoSub Lcd_SentString           'goto string loading routine 
        lcd_page = 177
        Lcd_column = 30                'Selects column 0 - 128
        GoSub lcd_gotoxy
        Str LcdStr = Str$ (SDec1 PRESSIONE)    'prints the pressure in Hpa
        
        GoSub Lcd_SentString          'goto string loading routine      
      
      ' HRSOut "mDA=",Dec mDA, 13
       ' HRSOut "mDB=",Dec mDB, 13
       ' HRSOut  "g1 =", SDec g1 ,13
      '  HRSOut  "X2 =", SDec x2 ,13
      ' HRSOut  "RAW_T =", Dec RAW_T ,13
      ' HRSOut  "TEMP =", Dec TEMP ,13
      '  HRSOut  "PRESSURE =", Dec PRESSURE ,13
     ' HRSOut  "PRESSIONE =", Dec PRESSIONE ,13
       ' HRSOut  "AC1 =", Dec AC1 ,13
       'HRSOut  "AC2 =", sDec AC2 ,13
      ' HRSOut  "AC3 =", Dec AC3 ,13
      ' HRSOut  "AC4 =", Dec AC4 ,13
       ' HRSOut  "AC5 =", Dec AC5 ,13
      '  HRSOut  "AC6 =", Dec AC6 ,13
      '  HRSOut  "B1 =", Dec B1 ,13
      '   HRSOut "B2 =", Dec B2 ,13
       ' HRSOut  "MB =", Dec MB ,13
        'HRSOut  "MC =", SDec MC ,13
       ' HRSOut  "MD =", Dec MD ,13
        
        lcd_page = 180                 'selects the line 1 to 7,  176=page 1
        Lcd_column = 5                 'Selects column 0 - 128
        GoSub lcd_gotoxy
        Str LcdStr = "Temp: ",0          'enter your text here
        GoSub Lcd_SentString           'goto string loading routine 
        
        lcd_page = 180
        Lcd_column = 30                 'Selects column 0 - 128
        GoSub lcd_gotoxy
        Str LcdStr = Str$ (Dec1 TEMP)   'prints the temperature
        GoSub Lcd_SentString            'goto string loading routine 
       
         
    GoTo main
    
    
    
    
    '********************************CLEAR SCREEN ********************************** 
    'this function clears the screen by selecting each row in turn and setting each
    'pixel to zero in each row, then it selects the next row and so on  it also has  
    'reset the column number to 0 after each page increment.
    '******************************************************************************* 
    Clear_Screen:
    
    
    
    
    Low A0                                      'prepare LCD for command send                                    
    For page_index = 176 To 183                 ' 0 - 7 pages on screen or page rows
        Low CS
        SHOut SI,CLK, MsbFirst, [page_index]    'page address
        High CS                                 'de select lcd
        
        
    '******* this sets the column back to zero after each page increment ***********  
      Col_MSB = 0 >>4                  ' shifts data in MSB 4 places to right
      Col_LSB = 0 <<4                  
      Col_LSB = Col_LSB >>4
      Col_MSB = Col_MSB + 16                    'need to add 16 as D4 is always 16
     Low A0                                     'pepare LCD for Command
     Low CS  
     SHOut SI,CLK, MsbFirst, [Col_LSB,Col_MSB] 'page address is 100 col=9=(9=lsb+16=msb)
     High CS
     High A0                                    'prepare LCD for data send 
        For index = 0 To 127                    '128 columns
            Low CS                              'select lcd
            SHOut SI,CLK, MsbFirst, [$00]       'turn each pixel off in column
            High CS                             'de select lcd
             Next 
        Low A0                                  'select command send
     '   DelayMS 100
    Next page_index                             'increment to next row
    Return                                      'go back to old kent road
    
    
    '************************GOTO X (Column),Y (Page) Pos on LCD *******************
    ' Two 8bit commands are req for col bit shifting ensures MSB and LSB are joined 
    '*******************************************************************************  
    lcd_gotoxy:
        Low A0
        Low CS
        SHOut SI,CLK, MsbFirst, [lcd_page]      'page address
        High CS      
      Col_MSB = Lcd_column >>4                  'shifts data in MSB 4 places to right
      Col_LSB = Lcd_column <<4                  
      Col_LSB = Col_LSB >>4
      Col_MSB = Col_MSB + 16                    'need to add 16 as D4 is always 16
     Low A0                                     'pepare LCD for Command
     Low CS  
     SHOut SI,CLK, MsbFirst, [Col_MSB, Col_LSB] 'page address is 100 col=9=(9=lsb+16=msb)
     High CS
     High A0
    Return
    '*******************************************************************************  
    'Lcd_SentChar:
      '  j=databyte * 6                 ' does this increment through car cread line ???????
      '  For i=0 To 5                   ' five bytes in the character
      '    databyte=CRead Font+j+i      ' can not sus what j does butthink its incrementing through cread table
       '   fontcash[i] = databyte
       '   Next
      
      '    High A0
        '  Low CS
       '   SHOut SI,CLK, MsbFirst, [fontcash[0],fontcash[1],fontcash[2],fontcash[3],fontcash[4],fontcash[5]]
      '    High CS
    'Return
    '*****************************************************************************
    'Lcd_SentString:
      '  For k=0 To 26                 ' this sets the max string lengh to equall LCD width
        '    databyte=LcdStr[k]       ' loads char into string
      '     If databyte=0 Then Break ' stops at end
       '     GoSub Lcd_SentChar       ' sends each char in turn to cread byte send routine
      '  Next
    'Return
            
    
    
    
    
    Lcd_SentChar:
        j=databyte * 6                 ' does this increment through car cread line ???????
        For i=0 To 5                   ' five bytes in the character
          databyte=CRead Font+j+i      ' can not sus what j does butthink its incrementing through cread table
          fontcash[i] = databyte
          Next
      
          High A0
          Low CS
          SHOut SI,CLK, MsbFirst, [fontcash[0],fontcash[1],fontcash[2],fontcash[3],fontcash[4],fontcash[5]]
          High CS
    Return
    '*****************************************************************************
    Lcd_SentString:
        For k=0 To 26                 ' this sets the max string lengh to equall LCD width
            databyte=LcdStr[k]       ' loads char into string
            If databyte=0 Then Break ' stops at end
            GoSub Lcd_SentChar       ' sends each char in turn to cread byte send routine
        Next
    Return
    
    
    '****************************Initialise the LCD ************************************
    ' This fuction sends the init commands for lcd  all in one SHOUT statement
    '***********************************************************************************          
    Init_LCD:
        Low A0              ' Prepare LCD for command send
        Low CS              ' select LCD
        SHOut SI,CLK, MsbFirst, [$40,$A1,$C0,$A6,$A2,$2F,$F8,$00,$27,$81,$16,$AC,$00,$AF] 
       'SHOut SI,CLK, MsbFirst, [$40,$A1,$C0,$A6,$A2,$2F,$F8,$00,$27,$81,$16,$AC,$00,$AF]
        High CS             ' de selects LCD
    Return                  ' go back to old kent road
    '***********************************************************************************
    
    
    
    
    READ_PRESSURE:
      BStart
      BusOut $EE              ' MS5611 CONTROL ADDRESS   WRITE COMMAND
      BusOut $F4              ' SEND THE PRESSURE CONVERSION COMMAND
      BusOut $34  
      BStop
      
      DelayMS 9               ' SEE DATA SHEET NEED 9MS TO GET RESULT
      BStart
      BusOut $EE              ' MS5611 CONTROL ADDRESS
      BusOut $F6              ' READ THE ADC CONVERSION 
      BStop
      
      BStart
      BusOut $EF              ' MS5611 CONTROL ADDRESS READ COMMAND
      mPA  = BusIn       ' get the ADC result and put it in PRESSURE variable
      BusAck
      mPB=BusIn
      BusNack
      BStop
      PRESSURE = mPA << 8
     PRESSURE = PRESSURE | mPB  
    GoSub Av_reading
    
    
    
    
    Return
       
     READ_TEMP:
      BStart
      BusOut $EE      ' MS5611 CONTROL ADDRESS   WRITE COMMAND
      BusOut $F4      ' SEND THE TEMP CONVERSION COMMAND
      BusOut $2E
      BStop
      
      DelayMS 9       ' SEE DATA SHEET NEED 9MS TO GET RESULT
      BStart
      BusOut $EE      ' MS5611 CONTROL ADDRESS
      BusOut $F6      ' READ THE ADC CONVERSION 
      BStop
      
      BStart
      BusOut $EF     ' MS5611 CONTROL ADDRESS READ COMMAND
      
      mTA = BusIn       ' get the ADC result and put it in PRESSURE variable
      BusAck
      mTB = BusIn
      BusNack
      BStop
      RAW_T = mTA << 8
      RAW_T = RAW_T | mTB   
     
    Return 
     
    '*****************  Ring Buffer type averaging on the hoof *********************
    Av_reading:
    If PRESSURE = ADavg Then NoChange
    If Abs (PRESSURE - ADavg) > FAspread Or PRESSURE < AvgCount Then FastAvg
    If Abs (PRESSURE - ADavg) < AvgCount Then RealClose
    ADavg = ADavg - (ADavg/AvgCount)
    ADavg = ADavg + (PRESSURE/AvgCount)
    GoTo AVGok
    FastAvg:
    ADavg = PRESSURE
    GoTo AVGok
    RealClose:
    temp1 =  (ADavg/(AvgCount/4))
    temp2 =(PRESSURE/(AvgCount/4))
        ADavg = ADavg - temp1
        ADavg = ADavg + temp2
    
    
    
    
    AVGok:
    PRESSURE = ADavg ' Put Average back into altim
    NoChange:
    Return
    
    
     '***********************************************
     'Read coefficients from BMP180 EEPROM
     '**********************************************
    calibration:
    
    
      BStart
      BusOut $EE              '  CONTROL ADDRESS
      BusOut $AA              ' READ THE ADC CONVERSION 
      BStop
      
      BStart
      BusOut $EF              '  CONTROL ADDRESS READ COMMAND
      mDA  = BusIn       ' get the ADC result and put it in PRESSURE variable
      BusAck
      mDB=BusIn
      BusNack
      BStop
     AC1 = mDA << 8
     AC1 = AC1|mDB  
     
       
    BStart
      BusOut $EE              '  CONTROL ADDRESS
      BusOut $AC              ' READ THE ADC CONVERSION 
      BStop
      BStart
      BusOut $EF              '  CONTROL ADDRESS READ COMMAND
     mDA  = BusIn       ' get the ADC result and put it in PRESSURE variable
      BusAck
      mDB=BusIn
      BusNack
      BStop
     AC2 = mDA << 8
     AC2 = AC2 | mDB   
    
    
      
      
    BStart
      BusOut $EE              '  CONTROL ADDRESS
      BusOut $AE              ' READ THE ADC CONVERSION 
      BStop
      
      BStart
      BusOut $EF              '  CONTROL ADDRESS READ COMMAND
      mDA  = BusIn       ' get the ADC result and put it in PRESSURE variable
      BusAck
      mDB=BusIn
      BusNack
      BStop
      AC3 = mDA << 8
     AC3 = AC3 | mDB     
     
      
      
      
     BStart
      BusOut $EE              '  CONTROL ADDRESS
      BusOut $B0              ' READ THE ADC CONVERSION 
      BStop
      
     BStart
      BusOut $EF              '  CONTROL ADDRESS READ COMMAND
      mDA  = BusIn       ' get the ADC result and put it in PRESSURE variable
      BusAck
     mDB=BusIn
      BusNack
      BStop
      AC4= mDA << 8
     AC4 = AC4 | mDB  
    
    
     
      
     BStart
      BusOut $EE              '  CONTROL ADDRESS
      BusOut $B2              ' READ THE ADC CONVERSION 
      BStop
      
      BStart
      BusOut $EF              '  CONTROL ADDRESS READ COMMAND
      mDA  = BusIn       ' get the ADC result and put it in PRESSURE variable
      BusAck
      mDB=BusIn
      BusNack
      BStop
      AC5 = mDA << 8
     AC5 = AC5 | mDB  
     
      
     BStart
      BusOut $EE              '  CONTROL ADDRESS
      BusOut $B4             ' READ THE ADC CONVERSION 
      BStop
      
      BStart
      BusOut $EF              '  CONTROL ADDRESS READ COMMAND
      mDA  = BusIn       ' get the ADC result and put it in PRESSURE variable
      BusAck
      mDB=BusIn
      BusNack
      BStop
      AC6 = mDA << 8
     AC6 = AC6 | mDB  
     
       
     BStart
      BusOut $EE              '  CONTROL ADDRESS
      BusOut $B6             ' READ THE ADC CONVERSION 
      BStop
      
      BStart
      BusOut $EF              '  CONTROL ADDRESS READ COMMAND
      mDA  = BusIn       ' get the ADC result and put it in PRESSURE variable
      BusAck
      mDB=BusIn
      BusNack
      BStop
      B1 = mDA << 8
     B1 = B1  | mDB   
     
      
      
     BStart
      BusOut $EE              '  CONTROL ADDRESS
      BusOut $B8             ' READ THE ADC CONVERSION 
      BStop
      
      BStart
      BusOut $EF              '  CONTROL ADDRESS READ COMMAND
      mDA  = BusIn       ' get the ADC result and put it in PRESSURE variable
      BusAck
      mDB=BusIn
      BusNack
     BStop
     B2 = mDA << 8
     B2 = B2 | mDB  
     
     
      
     BStart
     BusOut $EE              '  CONTROL ADDRESS
      BusOut $BA             ' READ THE ADC CONVERSION 
     BStop
      
      BStart
      BusOut $EF              '  CONTROL ADDRESS READ COMMAND
       
     mDA  = BusIn       ' get the ADC result and put it in PRESSURE variable
      BusAck
      mDB=BusIn
      BusNack
      BStop
      MB = mDA << 8
      MB = MB | mDB  
     
      
      
     BStart
      BusOut $EE              '  CONTROL ADDRESS
      BusOut $BC             ' READ THE ADC CONVERSION 
      BStop
      
      BStart
      BusOut $EF              '  CONTROL ADDRESS READ COMMAND
      mDA  = BusIn       ' get the ADC result and put it in PRESSURE variable
      BusAck
      mDB=BusIn
      BusNack
      BStop
     MC = mDA << 8
     MC = MC | mDB    
     
        
      
     BStart
      BusOut $EE              '  CONTROL ADDRESS
     BusOut $BE             ' READ THE ADC CONVERSION 
      BStop
      
      BStart
      BusOut $EF              '  CONTROL ADDRESS READ COMMAND
      
     mDA  = BusIn       ' get the ADC result and put it in PRESSURE variable
      BusAck
      mDB=BusIn
      BusNack
      BStop
      MD = mDA << 8
     MD = MD | mDB     
      Return
    
    Include "Font_Amicus.inc"
    Last edited by Les; 7th January 2016 at 11:34.

  4. #4
    Fanatical Contributor Les's Avatar
    Join Date
    Feb 2002
    Posts
    2,966
    Thumbs Up
    Received: 295
    Given: 109
    Total Downloaded
    1.50 GB

    0 Not allowed!

    Default Re: Trouble with variable types

    You're welcome Ivano.

    If that is what you call beginners code, then you are very welcome to the forum as it looks far from beginners code. You must be a natural programmer, well done!

    I hope you don't mind, but I enclosed your listing in a Code section so that it does not overwhelm the post.

    Hopefully, John will add this code to the Wiki, where it belongs for future users.
    Last edited by Les; 7th January 2016 at 11:36.
    For more example programs for Proton and Proton24 or updates, please visit: Proton WIKI or Proton Files

  5. #5
    Administrator John Drew's Avatar
    Join Date
    Feb 2002
    Posts
    2,500
    Thumbs Up
    Received: 98
    Given: 29
    Total Downloaded
    2.25 GB

    1 Not allowed!

    Default Re: Trouble with variable types

    Broderic,
    I've created an article in the WIKI. You'll find it under wiki/example code/Temperature Sensing.
    Thanks for your work, I'm sure others will find it useful.
    Here
    If you need to edit it you should be able to do this by clicking on the pencil next to the heading.
    John
    Last edited by John Drew; 8th January 2016 at 00:46. Reason: added edit comment

  6. #6
    Junior Member Broderic's Avatar
    Join Date
    Jan 2016
    Posts
    80
    Thumbs Up
    Received: 1
    Given: 1
    Total Downloaded
    184.42 MB

    0 Not allowed!

    Default Re: Trouble with variable types

    Hello.

    I just revised the code to add the graph of pressure Vs time and SPI communication with EADOGM.
    Find attached "BMP 180 sensor pressure_Proton Compiler with Amicus18_EA DOG SPI.zip".

    Of course it is just a modification of other codes: no need to say many thanks to Barak Dar, Reymond Pascal and Jeremy Smith.

    What makes me really crazy is that in the part of the code below, if I do not put the "Print At 7,57,Dec var2" after the clear line command "Line 0, pos+1,15,pos+1,46", the code does not enter the second For... next cycle, and only the first part of the graph is drawned.

    It seems that the Line clear command prevents me from entering the second For..next cycle.

    Don't really know why.

    However, with the print command inserted it works well (not well enough for me if I do not understand the above mentionned problem).

    If someone has some idea will be very appreciated.

    Thanks and bye.

    Bye.



    ...........
    For ig = k+1 To 124
    DelayMS 2
    var2= ERead ig
    If var2=126 Then
    Else
    GoSub ComputePoints
    '------ actualisation ligne ----
    GoSub Actualisationligne
    '------ actualisation ligne ----
    precVar2=var3

    End If
    Inc pos
    Next ig

    '-- Cursor --
    Line 1,pos,15,pos,46
    Line 0, pos+1,15,pos+1,46
    '-- Cursor --

    Print At 7,57,Dec var2

    For ig = 1 To k
    DelayMS 2
    var2= ERead ig

    If var2=126 Then
    Else

    GoSub ComputePoints

    '------ update of graph ----
    GoSub Actualisationligne
    '------ update of graph ----
    precVar2=var3
    ' prechMoy=vMoy
    Inc pos
    End If

    Next ig
    ..........

  7. #7
    Junior Member Broderic's Avatar
    Join Date
    Jan 2016
    Posts
    80
    Thumbs Up
    Received: 1
    Given: 1
    Total Downloaded
    184.42 MB

    0 Not allowed!

    Default Re: Trouble with variable types

    Hello.

    I just revised the little weather station with Amicus18.

    Barometric pressure, external temp and wind are plotted on EADOG with X and Y axis.

    As it is, it works nice, but if I move a the "Dim zoom as float" variable declaration from the early positions where it is now together with other graph variables, to have a more ordered code, I have a graph crash.

    Don't know why, and furthermore I don't know how to debug, because if I 'm not wrong MPLAB does not debug SPI code.

    Any suggestion will be appreciated. Thanks a lot in advance.

    Enclosed please find code and circuit schematic. Hope it can be of some occasional interest for others.

    Bye

  8. #8
    Fanatical Contributor Les's Avatar
    Join Date
    Feb 2002
    Posts
    2,966
    Thumbs Up
    Received: 295
    Given: 109
    Total Downloaded
    1.50 GB

    0 Not allowed!

    Default Re: Trouble with variable types

    A quick look at the code shows a block of Asm in the "LCD_ST7565R_SPI.inc" file.

    Remember, asm mnemonics do not manage RAM banks, so if more variables are placed at the beginning of the Dim setups, it will move some variables out of Bank0, which means the asm code may need RAM bank switching mnemonics added. i.e. Movlb.

    Try to convert the asm mnemonics into Proton code because it will be just as efficient, if not more so, and will manage RAM banks.
    For more example programs for Proton and Proton24 or updates, please visit: Proton WIKI or Proton Files

  9. #9
    Junior Member Broderic's Avatar
    Join Date
    Jan 2016
    Posts
    80
    Thumbs Up
    Received: 1
    Given: 1
    Total Downloaded
    184.42 MB

    0 Not allowed!

    Default Re: Trouble with variable types

    Many thanks Les.

    I think that's the problem, because the "Dim zoom as Float" movement from one place to another, for instance, affect only graph, i.e. EADOG, i.e.ST7565R, where I have asm code.

    I'll try to convert asm code in Proton code, but I'm not sure of success: I'm not so expert

    Thank you.

  10. #10
    Fanatical Contributor Les's Avatar
    Join Date
    Feb 2002
    Posts
    2,966
    Thumbs Up
    Received: 295
    Given: 109
    Total Downloaded
    1.50 GB

    0 Not allowed!

    Default Re: Trouble with variable types

    Try this code where the Asm code is inside the "LCD_ST7565R_SPI.inc" file, not forgetting to comment out, or remove the asm mnemonics. It's untested, but does exactly the same job as the asm mnemonics, but with RAM bank switching (where required).

    This is always the problem with writing native asm mnemonics in libraries. Unless RAM bank switching is used alongside them, they will fail when RAM usage increases. This is true of all compilers that operate on devices that implement RAM switching.

    Code:
    '
    ' Bring some of the compiler's system variables into the BASIC code
    '
    Dim BPF As Byte System
    Dim GEN As Byte System
    Dim GENH As Byte System
    Dim GEN2 As Byte System
    Dim GEN2H As Byte System
        '---[Redirect PDS GLCD lib]----------------------
    GlcdLibRedirect:
        '------------------------------------------------
    Asm-
    GLCD@CLS                                        ' Cls - clear the screen and the memory image
    Endasm-
        GoTo ClsRedirect                  
        '------------------------------------------------
    Asm-
    GLCD@CUR                                        ' Cursor ypos, xpos - Position the cursor on graphic LCD
    Endasm-
        $ifdef COM_REVERSE
            WREG = WREG + REVOFFSET        ' add 4 pixel offset for reverse scan to xpos vlue in WREG
        $endif
        xpos = WREG                                     ' WREG = XPOS
        ypos = GEN                                      ' GEN = YPOS (Line)            
        GoTo CursorRedirect                  
    
        '-----------------------------------------------
    Asm-
    Print                                           ' Print or Print at ypos, xpos 
    Endasm-
        strbyte = WREG                                   ' WREG = character to display
        GoTo PrintRedirect            
        Return
        '------------------------------------------------
    Asm-
    __LCD_PLOT_                                     ' Plot ypos, xpos
    Endasm-
        $ifdef COM_REVERSE
            WREG = WREG + REVOFFSET                             ' add 4 pixel offset for reverse scan to xpos vlue in WREG
        $endif
        xpos = WREG                                      ' WREG = XPOS
        lpos = GEN                                ' GEN = lpos is the row number 0-63 (Not Page/Line!)            
        Set pix_bit                                     ' set bit plot a pixel
        GoTo PlotRedirect                  
        Return
        '-----------------------------------------------
    Asm-
    __LCD_UNPLOT_                                   ' UnPlot ypos, xpos
    Endasm-
        $ifdef COM_REVERSE
            WREG = WREG + REVOFFSET                             ' add 4 pixel offset for reverse scan to xpos vlue in WREG
        $endif
        xpos = WREG                                      ' WREG = XPOS
        lpos =  GEN                                 ' GEN = lpos is the row number 0-63 (Not Page/Line!)            
        Clear pix_bit                                     ' clear bit to unplot
        GoTo PlotRedirect                  
     
        '-----------------------------------------------
    Asm-
    __LCD_LINE_                                         ' Line set_clear, x-start, y-start, x-end, y-end
    Endasm-
        y1 = WREG                                       ' WREG = YPOS end
        $ifdef COM_REVERSE
            GENH = GENH + REVOFFSET                     ' add 4 pixel offset for reverse scan to xpos vlue in WREG
        $endif                              
        x1 = GENH                                       ' GENH = XPOS end
        lpos = GEN2H                                    ' GEN2H = YPOS start
        $ifdef COM_REVERSE
            GEN2 = GEN2 + REVOFFSET                     ' add 4 pixel offset for reverse scan to xpos vlue in WREG
        $endif
        xpos = GEN2                                     ' GENH = XPOS start
        pix_bit = BPF.2                                 ' BPF Bit 2 is Set for Plot - skip next if bit is 1
        GoTo LineRedirect
        
        '-----------------------------------------------
    Asm-
    __LCD_CIRCLE_                                       ' Circle set_clear, xpos, ypos, radius
    Endasm-
        radius = WREG                                   ' WREG = radius
        $ifdef COM_REVERSE
            GEN2 = GEN2 + REVOFFSET                     ' add 4 pixel offset for reverse scan to xpos vlue in WREG
        $endif
        x0 = GEN2                                       ' GEN2 = YPOS
        y0 = GEN2H                                     ' GEN2H = XPOS 
        pix_bit = BPF.2                                 ' skip next if bit is 1
        GoTo CircleRedirect
        
        '------------------------------------------------
    Asm-
    __LCD_BOX_                                          ' box set_clear, xpos, ypos, size (only a square - see Rectangle below)
    Endasm-
        radius = WREG                                   ' WREG = radius
        x0 = GEN2                                      ' GEN2 = YPOS
        y0 = GEN2H                                      ' GEN2H = XPOS 
        pix_byte = BPF                                  ' BPF to a var bit#2 is the plot/unplot flag
        GoTo BoxRedirect                                ' BoxRedirect will add offset for reveresed coms
        
        '------------------------------------------------
    Asm-
    __LCD_WRITEBYTE_                                    ' LCDWrite ypos, xpos,[byte,{byte etc...}]
    Endasm-
        ypos = GEN                                      ' load to page var
        $ifdef COM_REVERSE
            GENH = GENH + REVOFFSET                     ' add 4 pixel offset for reverse scan to xpos vlue in WREG
            xpos = GENH                                 ' load to col var
            Dec GENH                                    ' bring back to original xpos for the next Byte If any
        $else
            xpos = GENH                                 ' load xpos to col var
        $endif
        Inc GENH                                       ' col + 1 for next byte if any
        GoTo LCDWriteRedirect
        
        '-----------------------------------------------
    Also, as a note. Add Declare Reminders = Off to the top of your main BASIC code. This will stop the Hint message appearing in the IDE, and will give you the code size and RAM size info.
    Last edited by Les; 25th June 2016 at 15:25.
    For more example programs for Proton and Proton24 or updates, please visit: Proton WIKI or Proton Files

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Data types
    By dmTulsa in forum Proton Plus Compiler v3
    Replies: 1
    Last Post: 14th March 2007, 16:58
  2. Different types of PICBASIC!!!!
    By omary in forum Proton Plus Compiler v3
    Replies: 6
    Last Post: 19th July 2006, 17:45
  3. GLCD types
    By mikedownunder in forum Proton Plus Compiler v3
    Replies: 9
    Last Post: 6th June 2006, 21:25
  4. [SOLVED !] File types
    By mobyuk in forum Proton Plus Compiler v3
    Replies: 4
    Last Post: 28th January 2005, 17:38

Tags for this Thread

Posting Permissions

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