Negetive Numbers with minus sign


+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 21

Thread: Negetive Numbers with minus sign70 days old

  1. #1
    Member amod's Avatar
    Join Date
    Mar 2018
    Posts
    145
    Thumbs Up
    Received: 38
    Given: 5
    Total Downloaded
    326.89 MB

    0 Not allowed!

    Default Negetive Numbers with minus sign

    Hi, Iam making a load indicator with HX711.My Problem is with negetive numbers and minus sign.Iam using 4 digit seven segment display.fourth display is dedicated to minus sign.By my code i get values blinking on seven segment display.Minus sign also blinks.Negetive value does not go below -009,it hangs up here then i have to restart my hardware.below is my code.
    Code:
    Device = 16F877AXtal = 20
    
    
    TRISA=%00000011
    TRISB=0
    TRISD=%11110000
    TRISC=%00010000
    
    
    Dim DG As Byte
    Dim DIGIT As Byte
    Dim n As Float
    Dim countt As Byte
    Dim cnt As Word
    Dim dg1 As Byte
    Dim dg2 As Byte
    Dim DG3 As Byte 
    Dim dg4 As Byte
    
    
    Dim telbit As Byte
    Dim telbitt As Byte
    Dim teller As Byte
    Dim coun As SWord
    Dim i As Byte
    Dim gram As Float
    Dim adjval As Float
    Dim disval As Float
    
    
    Symbol ADDO = PORTC.4
    Symbol ADSK = PORTC.5
    
    
    Symbol TARE  PORTD.4
    Symbol UP  PORTD.5
    Symbol DOWN  PORTD.6
    Symbol SETT  PORTD.7
    
    
    
    
    
    
    
    
    MAIN:
     If n<0 Then GoSub  NEGETIVE    ;minus sign
     ADDO=1                         ;hx711 code
     ADSK=0
     coun=0
     While ADDO=1:Wend
     For i= 0 To 23
     ADSK=1
     coun=coun<<1
     ADSK=0
     If ADDO =1 Then Inc coun
     Next i 
     ADSK=1
     coun=coun^0x800000
     gram=8388608-coun
     gram=gram/100
     n=gram
     ADSK=0
     
     GoSub ZERO
     GoSub DISPLAY
     GoSub DIGITCALC
     GoTo MAIN   
     
     
     
     ZERO:
     If TARE=1 Then
     adjval=gram
     EndIf
     disval=gram-adjval
     n=disval
     GoSub DISPLAY
     GoSub DIGITCALC
     GoTo MAIN
     
     NEGETIVE:              ;minus sign
     DG=%01000000
     PORTB=DG
     PORTD.3=1
     DelayUS 1000
     PORTD.3=0
     
     
     
     GoSub DISPLAY
     GoSub DIGITCALC
     GoTo MAIN
     
    DISPLAY: ;breaking digits into 4 display
            
            
            For countt=0 To 99
            
            'PORTB=dg1
            'PORTD.3=1
            'DelayUS 100
            'PORTD.3=0
    
    
            PORTB=dg2
            PORTD.2=1
            DelayUS 100
            PORTD.2=0
            
            PORTB=DG3
            PORTD.1=1
            DelayUS 100 
            PORTD.1=0
            
            PORTB=dg4
            PORTD.0=1
            DelayUS 100 
            PORTD.0=0
    
    
            Next countt
    
    
            Return
    
    
           '________________________________________________________________
    
    
    
    
    
    
    '__________________________________________________________________________
    DIGITCALC: ;data to each display ones,tens,hundred,thousands
    
    
           
    DIGIT=0
    'LP1:
    'If n<1000 Then DS1
    'n=N-1000
    'DIGIT=DIGIT+1
    'GoTo LP1
            'DS1:
            'GoSub FND
            'dg1=DG
           
    
    
    DIGIT=0
    LP2:
    If n<100 Then DS2
    n=N-100
    DIGIT=DIGIT+1
    GoTo LP2
            
            DS2:
            GoSub FND
            dg2=DG
            
           
    DIGIT=0
    LP3:
    If n<10 Then DS3
    n=N-10
    DIGIT=DIGIT+1
    GoTo LP3
    
    
            DS3:
            GoSub FND
            DG3=DG                    'DG3=128 | dg
    
    
    DIGIT=n
    GoSub FND
    dg4=DG
     
    Return
    
    
    
    
    
    
    '__________________________________________________________________________
    
    
    
    
    '__________________________________________________________________________
    FND:  ;data for each segment.
     
                                            
    
    
    FND0:                          ;zero
    If DIGIT>0 Then FND1
    DG=%00111111                          
    GoTo FNDEND
    
    
    FND1:                           ;one
    If DIGIT>1 Then FND2
    DG=%00000110                             
    GoTo FNDEND
    
    
    FND2:                            ;two
    If DIGIT>2 Then FND3
    DG=%01011011                            
    GoTo FNDEND
    
    
    FND3:                             ;three
    If DIGIT>3 Then FND4
    DG=%01001111                            
    GoTo FNDEND
    
    
    FND4:                             ;four
    If DIGIT>4 Then FND5
    DG=%01100110                            
    GoTo FNDEND
    
    
    FND5:                             ;five
    If DIGIT>5 Then FND6
    DG=%01101101                            
    GoTo FNDEND
    
    
    FND6:                             ;six
    If DIGIT>6 Then FND7
    DG=%01111100                            
    GoTo FNDEND
    
    
    FND7:
    If DIGIT>7 Then FND8              ;seven
    DG=%00000111                            
    GoTo FNDEND
    
    
    FND8:                              ;eight
    If DIGIT>8 Then FND9
    DG=%01111111                            
    GoTo FNDEND
    
    
    FND9:
    DG=%01100111                       ;nine    
    
    
    FNDEND:
    Return
    '_____________________________

  2. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  3. #2
    Member keytapper's Avatar
    Join Date
    Jun 2019
    Posts
    196
    Thumbs Up
    Received: 8
    Given: 5
    Total Downloaded
    331.75 MB

    0 Not allowed!

    Default Re: Negetive Numbers with minus sign

    I got very curious about your source and I spend a little time to make it a bit optimized. Don't be offended I'd like to show some trick to obtain same results with less complications. For example you might find interesting the use of the modulus.

    Code:
    Device  =  16F877A
    Xtal  =  20
    
    Symbol ADDO  PORTC.4
    Symbol ADSK  PORTC.5
    Symbol TARE  PORTD.4
    Symbol UP    PORTD.5
    Symbol DOWN  PORTD.6
    Symbol SETT  PORTD.7
    
    TRISA  =  000011
    TRISB  =  0
    TRISD = 110000
    TRISC = 010000
    
    Dim countt As Byte
    Dim dg1 As Byte
    Dim dg2 As Byte
    Dim DG3 As Byte
    Dim dg4 As Byte
    Dim i As Byte
    Dim cnt As Word
    Dim coun As SWord
    Dim n As Dword
    Dim gram As Float
    Dim adjval As Float
    Dim disval As Float
    Dim digi7seg[11] As Byte            ' 7 segments array for the display
    
    Str digi7seg = 111111, 000110, 011011, 001111, _
     100110, 101101, 111100, 000111, 111111, 100111, %%01000000
    MAIN:
     If n < 0 Then GoSub  NEGETIVE      ;minus sign
     ADDO = 1                           ;hx711 code
     ADSK = 0
     coun = 0
     While ADDO = 1: Wend
     For i = 0 To 23
      ADSK = 1
      coun = coun << 1
      ADSK = 0
      If ADDO  = 1 Then Inc coun
     Next i
     ADSK = 1
     coun = coun ^ $800000
     gram = 8388608 - coun
     gram = gram / 100
     n = gram
     ADSK = 0
    
     GoSub ZERO
     GoSub DISPLAY
     GoSub DIGITCALC
     GoTo MAIN
    
     ZERO:
     If TARE = 1 Then
      adjval = gram
     EndIf
     disval = gram - adjval
     n = disval
     GoSub DISPLAY
     GoSub DIGITCALC
    GoTo MAIN
    
     NEGETIVE:                          ;minus sign
     PORTB = digi7seg[10]
     PORTD.3 = 1
     DelayUS 1000
     PORTD.3 = 0
     GoSub DIGITCALC
     GoSub DISPLAY
    GoTo MAIN
    
    DISPLAY:                            ;breaking digits into 4 display
      For countt = 0 To 99
        'PORTB = dg1
        'PORTD.3 = 1
        'DelayUS 100
        'PORTD.3 = 0
        PORTB = digi7seg[dg2]
        PORTD.2 = 1
        DelayUS 100
        PORTD.2 = 0
        PORTB = digi7seg[DG3]
        PORTD.1 = 1
        DelayUS 100
        PORTD.1 = 0
        PORTB = digi7seg[dg4]
        PORTD.0 = 1
        DelayUS 100
        PORTD.0 = 0
      Next countt
    Return
    
    '__________________________________________________________________________
    DIGITCALC:
    dg2 = n / 100                       ' hundred digit
    n = n // 100                        ' remainder
    DG3 = n / 10                        ' tens digit
    dg4 = n // 10                       ' units
    Return
    I got just to convert the N variable in order to use the modulus.
    Be aware that the compiler is case insensitive.

    PS, the binary representation is modified by some reason during the post. But the array should contain the same code as you need to send to the port for one of 7 segment digit.
    Last edited by keytapper; 29th March 2020 at 03:53. Reason: Code error

  4. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  5. #3
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    2,354
    Thumbs Up
    Received: 83
    Given: 183
    Total Downloaded
    5.30 GB

    0 Not allowed!

    Default Re: Negetive Numbers with minus sign

    PS, the binary representation is modified by some reason during the post. But the array should contain the same code as you need to send to the port for one of 7 segment digit.
    Bug in board software. If you refrain from editing binary representation comes out OK.
    George.

  6. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  7. #4
    Member amod's Avatar
    Join Date
    Mar 2018
    Posts
    145
    Thumbs Up
    Received: 38
    Given: 5
    Total Downloaded
    326.89 MB

    0 Not allowed!

    Default Re: Negetive Numbers with minus sign

    Code is not working ,I changed the binary for seven segment.

    Code:
    Device  =  16F877AXtal  =  20
    
    
    Symbol ADDO  PORTC.4
    Symbol ADSK  PORTC.5
    Symbol TARE  PORTD.4
    Symbol UP    PORTD.5
    Symbol DOWN  PORTD.6
    Symbol SETT  PORTD.7
    
    
    TRISA=%00000011
    TRISB=0
    TRISD=%11110000
    TRISC=%00010000
    
    
    Dim countt As Byte
    Dim dg1 As Byte
    Dim dg2 As Byte
    Dim DG3 As Byte
    Dim dg4 As Byte
    Dim i As Byte
    Dim cnt As Word
    Dim coun As SWord
    Dim n As Dword
    Dim gram As Float
    Dim adjval As Float
    Dim disval As Float
    Dim digi7seg[11] As Byte            ' 7 segments array for the display
    
    
    Str digi7seg =%00111111, %00000110, %01011011, %01001111,_ 
    %01100110,%01101101,%01111100,%00000111,%01111111,%01100111, %01000000
    MAIN:
     If n < 0 Then GoSub  NEGETIVE      ;minus sign
     ADDO = 1                           ;hx711 code
     ADSK = 0
     coun = 0
     While ADDO = 1: Wend
     For i = 0 To 23
      ADSK = 1
      coun = coun << 1
      ADSK = 0
      If ADDO  = 1 Then Inc coun
     Next i
     ADSK = 1
     coun = coun ^ $800000
     gram = 8388608 - coun
     gram = gram / 100
     n = gram
     ADSK = 0
    
    
     GoSub ZERO
     GoSub DISPLAY
     GoSub DIGITCALC
     GoTo MAIN
    
    
     ZERO:
     If TARE = 1 Then
      adjval = gram
     EndIf
     disval = gram - adjval
     n = disval
     GoSub DISPLAY
     GoSub DIGITCALC
    GoTo MAIN
    
    
     NEGETIVE:                          ;minus sign
     PORTB = digi7seg[10]
     PORTD.3 = 1
     DelayUS 1000
     PORTD.3 = 0
     GoSub DIGITCALC
     GoSub DISPLAY
    GoTo MAIN
    
    
    DISPLAY:                            ;breaking digits into 4 display
      For countt = 0 To 99
        'PORTB = dg1
        'PORTD.3 = 1
        'DelayUS 100
        'PORTD.3 = 0
        PORTB = digi7seg[dg2]
        PORTD.2 = 1
        DelayUS 100
        PORTD.2 = 0
        PORTB = digi7seg[DG3]
        PORTD.1 = 1
        DelayUS 100
        PORTD.1 = 0
        PORTB = digi7seg[dg4]
        PORTD.0 = 1
        DelayUS 100
        PORTD.0 = 0
      Next countt
    Return
    
    
    '__________________________________________________________________________
    DIGITCALC:
    dg2 = n / 100                       ' hundred digit
    n = n // 100                        ' remainder
    DG3 = n / 10                        ' tens digit
    dg4 = n // 10                       ' units
    Return
    Last edited by amod; 29th March 2020 at 14:23.

  8. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  9. #5
    Member amod's Avatar
    Join Date
    Mar 2018
    Posts
    145
    Thumbs Up
    Received: 38
    Given: 5
    Total Downloaded
    326.89 MB

    0 Not allowed!

    Default Re: Negetive Numbers with minus sign

    My code started working .only problem is with negative sign it is not glowing.

    Code:
    Device  =  16F877AXtal  =  20
    
    
    Symbol ADDO  PORTC.4
    Symbol ADSK  PORTC.5
    Symbol TARE  PORTD.4
    Symbol UP    PORTD.5
    Symbol DOWN  PORTD.6
    Symbol SETT  PORTD.7
    
    
    TRISA=%00000011
    TRISB=0
    TRISD=%11110000
    TRISC=%00010000
    
    
    Dim digit As Byte
    Dim dg As Byte
    Dim countt As Byte
    Dim dg1 As Byte
    Dim dg2 As Byte
    Dim DG3 As Byte
    Dim dg4 As Byte
    Dim i As Byte
    
    
    Dim coun As Word
    Dim n As Float
    Dim gram As SWord
    Dim adjval As Word
    Dim disval As Word
    
    
    GoSub DISPLAY
    GoSub DIGITCALC
    
    
    MAIN:
       GoSub HX711
       GoSub  NEGETIVE
       GoSub ZERO
       If n<0 Then GoTo NEGETIVE
    
    
     HX711:
       ADDO=1
       ADSK=0
       coun=0
       While ADDO=1:Wend
       For i= 0 To 23
       ADSK=1
       coun=coun<<1
       ADSK=0
       If ADDO =1 Then Inc coun
       Next i 
       ADSK=1
       coun=coun^0x800000
       gram=8388608-coun
       gram=gram/100
       n=gram
       ADSK=0
     
     GoSub DISPLAY
     GoSub DIGITCALC
     GoTo MAIN   
     
     
     
     ZERO:                   ;zero value(tare)
     If TARE=1 Then
     adjval=gram
     EndIf
     disval=gram-adjval
     n=disval
     GoSub DISPLAY
     GoSub DIGITCALC
     GoTo MAIN
     
     NEGETIVE:                 ;minus display
      
     dg=%01000000
     
     PORTB=dg
     PORTD.3=1
     DelayUS 100
     PORTD.3=0
    
    
     
     
     GoSub DISPLAY
     GoSub DIGITCALC
     GoTo MAIN
     
    DISPLAY: ;breaking digits into 4 display
            
            
            For countt=0 To 99
            
            'PORTB=dg1
            'PORTD.3=1
            'DelayUS 100
            'PORTD.3=0
    
    
            PORTB=dg2
            PORTD.2=1
            DelayUS 500
            PORTD.2=0
            
            PORTB=DG3
            PORTD.1=1
            DelayUS 500 
            PORTD.1=0
            
            PORTB=dg4
            PORTD.0=1
            DelayUS 500 
            PORTD.0=0
    
    
            Next countt
    
    
            Return
    
    
           '________________________________________________________________
    
    
    
    
    
    
    '__________________________________________________________________________
    DIGITCALC: ;data to each display ones,tens,hundred,thousands
    
    
           
    digit=0
    'LP1:
    'If n<1000 Then DS1
    'n=N-1000
    'DIGIT=DIGIT+1
    'GoTo LP1
            'DS1:
            'GoSub FND
            'dg1=DG
           
    
    
    digit=0
    LP2:
    If n<100 Then DS2
    n=N-100
    digit=DIGIT+1
    GoTo LP2
            
            DS2:
            GoSub FND
            dg2=dg
            
           
    digit=0
    LP3:
    If n<10 Then DS3
    n=N-10
    digit=DIGIT+1
    GoTo LP3
    
    
            DS3:
            GoSub FND
            DG3=dg                    'DG3=128 | dg
    
    
    digit=n
    GoSub FND
    dg4=dg
     
    Return
    
    
    
    
    
    
    '__________________________________________________________________________
    
    
    
    
    '__________________________________________________________________________
    FND:  ;data for each segment.
     
                                            
    
    
    FND0:                          ;zero
    If digit>0 Then FND1
    dg=%00111111                          
    GoTo FNDEND
    
    
    FND1:                           ;one
    If digit>1 Then FND2
    dg=%00000110                             
    GoTo FNDEND
    
    
    FND2:                            ;two
    If digit>2 Then FND3
    dg=%01011011                            
    GoTo FNDEND
    
    
    FND3:                             ;three
    If digit>3 Then FND4
    dg=%01001111                            
    GoTo FNDEND
    
    
    FND4:                             ;four
    If digit>4 Then FND5
    dg=%01100110                            
    GoTo FNDEND
    
    
    FND5:                             ;five
    If digit>5 Then FND6
    dg=%01101101                            
    GoTo FNDEND
    
    
    FND6:                             ;six
    If digit>6 Then FND7
    dg=%01111100                            
    GoTo FNDEND
    
    
    FND7:
    If digit>7 Then FND8              ;seven
    dg=%00000111                            
    GoTo FNDEND
    
    
    FND8:                              ;eight
    If digit>8 Then FND9
    dg=%01111111                            
    GoTo FNDEND
    
    
    FND9:
    dg=%01100111                       ;nine    
    
    
    FNDEND:
    Return
    '_____________________________
    Last edited by amod; 29th March 2020 at 17:48.

  10. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  11. #6
    Prolific Poster See_Mos's Avatar
    Join Date
    Feb 2004
    Posts
    1,322
    Thumbs Up
    Received: 19
    Given: 0
    Total Downloaded
    1.01 GB

    0 Not allowed!

    Default Re: Negetive Numbers with minus sign

    Hi Amod,

    A lot of your display code can be replaced by this complete code

    Code:
    ' A simple 4 digit LED drive for common cathode displays
    ' simulates in ISIS
    ' for a negative symbol PortB = 64
    ' for a decimal point add 128 to bit pattern
    
    Device = 18F452
    Xtal 20
    TRISB = 0
    TRISD = 0
    Dim ANumber As Word
    Dim ADigit As Byte
    Dim I As Byte
    Dim DG As Byte
    Dim K As Byte
    Dim MyPortPin As Byte
    Dim Negative As Bit
    
    Dim True As 1
    Dim False As 0
    
        Clear
        ANumber = 1234
        Negative = False  ' <<<<<<<<<<<<<<<<<<<<< change this to true or false to show symbol
    ' ---------------------------- Main_Loop    
        While 1 = 1
            GoSub Display
        Wend
    ' ---------------------------- end of main loop    
    
    Display:            
        K = 0
        
        For I = Pin_D0 To Pin_D3
            ADigit = Dig ANumber,K
            DG = LookUp ADigit, [63,6,91,79,102,109,124,7,127,103]
            If Negative = True And K = 3 Then DG = 64   ' 3 is left digit of display
            If K = 2 Then DG = DG + 128
            PORTB = DG        
            SetPin I
            DelayUS 500
            ClearPin I
            Inc K       
        Next
    Return
    My RAM is failing

  12. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  13. #7
    Member keytapper's Avatar
    Join Date
    Jun 2019
    Posts
    196
    Thumbs Up
    Received: 8
    Given: 5
    Total Downloaded
    331.75 MB

    0 Not allowed!

    Default Re: Negetive Numbers with minus sign

    I understand that OP is just a beginner and self learner. So the mileage may be longer to know the tricks and facilities that the language is offering.

    In my attempt I used to load an array for the value to send to the 7 segments, instead of a Lookup table. For this small source the 10 bytes consumed is not a big issue.

    I praise his fantasy to realize the result, with his own knowledge. I hope Amod will discover many simplification as long as reading those novelties on the provided manual.

    Regarding the original fault is that a certain point on the source is calling NEGETIVE subroutine which has no return but jumps back to the main.
    Last edited by keytapper; 31st March 2020 at 16:28. Reason: Typo

  14. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  15. #8
    Member amod's Avatar
    Join Date
    Mar 2018
    Posts
    145
    Thumbs Up
    Received: 38
    Given: 5
    Total Downloaded
    326.89 MB

    0 Not allowed!

    Default Re: Negetive Numbers with minus sign

    See_Moss your code is working but it is flickering.when i put any load on load cell is displays 05.67 only when i empty load then it displays 00.00. Please check my code.
    Code:
    Device = 16F877AXtal 20
    Symbol ADDO  PORTC.4                ' pin connected to hx711 data
    Symbol ADSK  PORTC.5                ' pin connected to hx711 clock
    TRISA = 000011                   ' bit 0 and 1 to input
    TRISB = 0                           ' all output for the 7segment
    TRISD = 110000                   ' low nibble for the 7segment cathod
                                        ' high nibble for the buttons
    TRISC = 010000                   ' connected to the hx711
    Dim coun As SWord
    Dim gram As SWord
    Dim n As Float
    Dim ANumber As SWord
    Dim ADigit As Byte
    Dim I As Byte
    Dim DG As Byte
    Dim K As Byte
    Dim MyPortPin As Byte
    Dim Negative As Bit
    
    
    Dim True As 1
    Dim False As 0
    
    
        Clear
        
        Negative = True  ' <<<<<<<<<<<<<<<<<<<<< change this to true or false to show symbol
    ' ---------------------------- Main_Loop    
        main:
        ADDO = 1                          ' set Data input High (may not have effect)
      ADSK = 0                          ' set output low
      coun = 0                          ' reset the reading value, for a new one
      While ADDO = 1: Wend              ' wait for the pin go low
      For I =  0 To 23                  ' loop for 3 bytes, to serialize ADC value
        ADSK = 1                        ' set pin high, start signal
        coun = coun << 1                ' shift coun one position
        ADSK = 0                        ' low the pin
        If ADDO = 1 Then Inc coun       ' if the input is high then increase coun
      Next I                            ' repeat for 24 bits
      ADSK = 1                          ' set the bit high
      coun = coun ^ $800000             ' toggle the most significant bit
      ADSK = 0                          ' set output low, end the connection
      gram = 8388608 - coun             ' calculate the grams
      ANumber = gram /1000000  
      GoSub Display
        GoTo main
    ' ---------------------------- end of main loop    
    
    
    Display:            
        K = 0
        
        For I = Pin_D0 To Pin_D3
            ADigit = Dig ANumber,K
            DG = LookUp ADigit, [63,6,91,79,102,109,124,7,127,103]
            If Negative = True And K = 3 Then DG = 64   ' 3 is left digit of display
            If K = 2 Then DG = DG + 128
            PORTB = DG        
            SetPin I
            DelayUS 100
            ClearPin I
            Inc K       
        Next
    Return

  16. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  17. #9
    Member keytapper's Avatar
    Join Date
    Jun 2019
    Posts
    196
    Thumbs Up
    Received: 8
    Given: 5
    Total Downloaded
    331.75 MB

    0 Not allowed!

    Default Re: Negetive Numbers with minus sign

    Dim gram As SWord

    gram = 8388608 - coun ' calculate the grams


    I suppose that you won't get the correct result. a SWord is from -32678 up to 32678. The red constant is 256 times greater.
    There some hideous thing that you are using in your source that is not have the same result as what we propose here.

    So you should hook up the serial and give some information over that.

    Also it might be necessary to publish your discovering in order to obtain better guides.

    One first thing is the design to visualize the information, which in most of the cases might not need a Float to represent the Kilos and the grams. That approach is rather resources eager, but won't give a gram representation the same over 4 digit 7segment display.

    You might prefer a Dword size for the 24 bit result of the HX711, then use a calculation to determine the hundredth of a kilo. As long as 32 bits can old 4 billion and over.

  18. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  19. #10
    Prolific Poster See_Mos's Avatar
    Join Date
    Feb 2004
    Posts
    1,322
    Thumbs Up
    Received: 19
    Given: 0
    Total Downloaded
    1.01 GB

    0 Not allowed!

    Default Re: Negetive Numbers with minus sign

    Sometimes it is easier to copy a piece of working code.

    Looking at Amod code in post #5. If we increase the delay to 500uS then cut the code

    Code:
    NEGETIVE:                 ;minus display
      
     dg=000000
     
     PORTB=dg
     PORTD.3=1
     DelayUS 500             ' #### was 100uS
     PORTD.3=0
    And paste it into the display code

    Code:
    DISPLAY: ;breaking digits into 4 display
          
            
            For countt=0 To 99
    NEGETIVE:                 ;minus display
      
             dg=000000
             
             PORTB=dg
             PORTD.3=1
             DelayUS 500             ' #### was 100uS
             PORTD.3=0  
             
            'PORTB=dg1
            'PORTD.3=1
            'DelayUS 100
            'PORTD.3=0
    the negative symbol works.

    We can also add a check to show a negative symbol or blank

    Code:
    DISPLAY: ;breaking digits into 4 display
          
            
            For countt=0 To 99
    NEGETIVE:                 ;minus display
            If Negative = True Then  
                dg=%01000000
            Else
                dg = 0
            EndIf         
             PORTB=dg
             PORTD.3=1
             DelayUS 500             ' #### was 100uS
             PORTD.3=0  
             
            'PORTB=dg1
            'PORTD.3=1
            'DelayUS 100
            'PORTD.3=0
    There are other coding errors, for example GOSUB HX711, the RETURN is missing or in the wrong place.
    Last edited by See_Mos; 1st April 2020 at 16:35.
    My RAM is failing

  20. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  21. #11
    Member keytapper's Avatar
    Join Date
    Jun 2019
    Posts
    196
    Thumbs Up
    Received: 8
    Given: 5
    Total Downloaded
    331.75 MB

    0 Not allowed!

    Default Re: Negetive Numbers with minus sign

    For my taste I'd put an interrupt routine to handle the display and its refreshing rate. So the main will have just to care about to load the N variable.

  22. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  23. #12
    Prolific Poster See_Mos's Avatar
    Join Date
    Feb 2004
    Posts
    1,322
    Thumbs Up
    Received: 19
    Given: 0
    Total Downloaded
    1.01 GB

    0 Not allowed!

    Default Re: Negetive Numbers with minus sign

    So would I, but we are trying to keep it simple to help Amod learn
    My RAM is failing

  24. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  25. #13
    Member amod's Avatar
    Join Date
    Mar 2018
    Posts
    145
    Thumbs Up
    Received: 38
    Given: 5
    Total Downloaded
    326.89 MB

    0 Not allowed!

    Default Re: Negetive Numbers with minus sign

    A very thanks to all for helping me.

  26. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  27. #14
    Member keytapper's Avatar
    Join Date
    Jun 2019
    Posts
    196
    Thumbs Up
    Received: 8
    Given: 5
    Total Downloaded
    331.75 MB

    0 Not allowed!

    Default Re: Negetive Numbers with minus sign

    As we fear the lockdown, we may have plenty of time, so I feel just a little bit of enjoyment if I can do something useful.

    Regarding the Hx711, I'd say that there's no much sources written for PIC, most are Arduino oriented. But with a bit of patience it is possible to translate some library into proton basic (well not many).
    Lately the proton basic's procedures implementation has widen the chance to cope with those libraries just with a little effort.

  28. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  29. #15
    Member amod's Avatar
    Join Date
    Mar 2018
    Posts
    145
    Thumbs Up
    Received: 38
    Given: 5
    Total Downloaded
    326.89 MB

    0 Not allowed!

    Default Re: Negetive Numbers with minus sign

    Please give me a full code for hx711.Iam getting raw values ,which are very fluctuating till 5 digit.Iam not able to write calibration formula.

    Code:
    Device = 16F877AXtal = 16
    Include "MODEDEFS.BAS"
    All_Digital = True
    Declare LCD_DTPin = PORTB.4
    Declare LCD_RSPin = PORTB.2
    Declare LCD_ENPin = PORTB.3
    Declare LCD_Interface = 4
    Declare LCD_Lines = 2
    Declare LCD_Type = 0
    
    
    Symbol ADDO  PORTC.4
    Symbol ADSK  PORTC.5
    Symbol TARE  PORTD.4
    Symbol UP    PORTD.5
    Symbol DOWN  PORTD.6
    Symbol SETT  PORTD.7
    
    
    TRISA=%00000011
    TRISB=0
    TRISD=%11100000
    TRISC=%00010000
    
    
    Dim i As Byte
    Dim coun As SDword
    Dim adjval As SDword
    Dim disval As Float
    
    
    
    main:
    
    
       ADDO=1
       
       
       ADSK=0
       coun=0
       While ADDO=1:Wend
       For i= 0 To 23
       ADSK=1
       coun=coun<<1
       ADSK=0
       If ADDO =1 Then Inc coun
       Next i 
       ADSK=1
       coun=coun^0x800000
       ADSK=0
       coun=coun/5454
       
       If TARE=1 Then
       adjval=coun
       EndIf
       disval=coun-adjval
       Print At 2,1,"count=",Dec0 disval
       GoTo main
     
       
     
     
     GoTo main
    Last edited by amod; 4th April 2020 at 19:17.

  30. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

Thread Information

Users Browsing this Thread

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

     

Similar Threads

  1. Test for sign
    By John Drew in forum Proton Plus Compiler v3
    Replies: 2
    Last Post: 23rd September 2012, 11:43
  2. sign for a 32 bit variable
    By yvesmazzon in forum Proton Plus Compiler v3
    Replies: 4
    Last Post: 21st February 2011, 21:29
  3. Running led sign
    By Roshan in forum Proton Plus Compiler v3
    Replies: 8
    Last Post: 31st January 2011, 21:54
  4. [SOLVED !] Plus/Minus sign as symbol
    By picprotonguy in forum Proton Plus Compiler v3
    Replies: 3
    Last Post: 11th March 2009, 12:00
  5. Print line numbers and page numbers
    By See_Mos in forum Mecanique - IDE
    Replies: 7
    Last Post: 29th January 2005, 11:53

Posting Permissions

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