Menu

How GCB works with single variables?

2022-02-10
2022-02-10
  • Pekka Ritamaki

    Pekka Ritamaki - 2022-02-10

    How GCB works with single variables?

    I have tried to work with GCB and PICs now more than week.
    I have found solutions almost all my problems.
    Now I know how to stop GCB going to fault when I had a problem in my code.
    Just close under the error message.
    Here is my code.
    Using the Integer variables.
    I know how to calculate the difference
    Using the Integer variables
    .
    But I do no know how to divine single variables.
    But I do no know how to divine single variables.
    Here is my code.
    #chip 16F886, 8
    #option explicit
    #config INTOSC_OSC_NOCLKOUT, BODEN_OFF 'this is important on GCB and PIC when there is no external oscillator

    ' Define the USART port
    #define USART_BAUD_RATE 9600
    #define USART_BLOCKING 'If defined, this constant will cause the USART routines to wait until data can be sent or received.
    #define USART_DELAY off 'This is the delay between characters.
    #define SerInPort PORTC.7
    #define SerOutPort PORTC.6
    'Set pin directions
    Dir SerOutPort Out
    Dir SerInPort In

    Dim steinhart as single ' stainahart count for

    include <maths.h></maths.h>

    sub steinhart1
    steinhart = 100.2
    steinhart =steinhart/ 4000 ' count this, but this is only example 1/B * ln(R/Ro)
    HSerPrint steinhart
    HSerPrint 13
    end sub

    Do
    HSerPrint "Test": HSERPRINTCRLF
    steinhart1
    wait 1 s
    Loop

    This is the results:
    Test
    fÈBA&ffÈBzE4ó,ÃRÿï@X® A¹€›ð§òA@XDGa¶ûÿïQ6ßÿR„ÿÿ¿13Test
    fÈBA&ffÈBzE4ó,ÃRÿï@X® A¹€›ð§òA@XDGa¶ûÿïQ6ßÿR„ÿÿ¿13Test
    fÈBA&ffÈBzE4ó,ÃRÿï@X® A¹€›ð§òA@XDGa¶ûÿïQ6ßÿR„ÿÿ¿13Test

    So how I can divide or multiply Single?
    Regards Pekka
    ps. somehow the row #inlcude <maths.h> were not right. but do not care this row. </maths.h>

     
  • Anobium

    Anobium - 2022-02-10

    Please see https://sourceforge.net/p/gcbasic/discussion/596084/thread/b867317011/

    Do not use floats - they are in development.

     
    • Anobium

      Anobium - 2022-02-10

      So, use integer maths with factorisation to do your maths.

      :-)

       
  • mmotte

    mmotte - 2022-02-10

    Pekka,

    Welcome to Great Cow Basic!

    At the moment GCB does not support "single" or decimal values. It does use bit, byte, word, integer, and long. Decimals are under development right now.

    "HSerPrint 13" should be "HSerSend 13" because you are trying to give a CR.

    HSerPrint is overload to each of the variable types. So if you feed it a string, it will print a string. If you feed it a long , it will print the long. etc. If you need a hex then use "hex(AB)" to change it to string.

    Also "USART_BLOCKING" is tricky on receive because if there is no char to receive it sends back a default value. Check out the help section.

     Start:
        comport = 1
        HSerReceive(InChar)    'Subroutine needs the comport set
        'InChar = HSerReceive    ' This function will get from comport 1
          If InChar <> 255 Then    ' check if for received byte
                      'return 255 if old data
            HSerSend InChar    'send back char to UART
          End If
      Goto Start
    

    Checkout the demos for small programs demonstrating the different features.

    GL
    Mike

     

Log in to post a comment.