Menu

GLCD not printing negative numbers

Help
MBB
2019-02-27
2019-02-27
  • MBB

    MBB - 2019-02-27

    I'm using this GLCD https://www.adafruit.com/product/1770

    I wrote this simple program to print out a negative number on my LCD and GLCD.

       ;Chip Settings
      #chip 18F4550,48
      #config PLLDIV=1, CPUDIV=OSC1_PLL2, OSC=HSPLL_HS, LVP=OFF, MCLRE=ON
    
      ;Defines (Constants)
      #define LCD_IO 2
      #define LCD_CB PORTE.1
      #define LCD_DB PORTE.0
      '
    'Defines for ILI9341  240 x 320
      #define GLCD_TYPE GLCD_TYPE_ILI9341
    
      #define GLCD_DI portd.0
      #define GLCD_SCK portd.1
      #define GLCD_DC portd.2
      #define GLCD_CS portd.3
      #define GLCD_RESET portd.4
      #define GLCD_DO portd.5
    
     #include <glcd.h>
    
            Dim xx as Integer
            xx = -17
    
            locate 0, 0
                print xx   ;prints out -17
    
            GLCDPrint(10, 10, xx, TFT_YELLOW)   ;prints out 65519 NOT -17
    

    '****
    Why does the LCD correctly print -17 but the GLCD incorrectly print 65519?

    It appears to be something with twos complement in reverse as the twos complement 0f 65519 is -17.

    This happens with other negative numbers, too. Positive numbers print correctly.

     
  • Anobium

    Anobium - 2019-02-27

    What happens when you use glcddrawstring ( 10, 10, str(xx)) or
    glcdprint (10, 10, str(xx))

     

    Last edit: Anobium 2019-02-27
  • MBB

    MBB - 2019-02-27

    Using glcddrawstring ( 10, 10, str(xx)) or glcdprint (10, 10, str(xx)) gives the same results 65519.

    Why STR? I'm trying to print an integer

     
  • MBB

    MBB - 2019-02-27

    I tried some more. This works:

    Dim xxSTR as string
        xx = -17
            xxSTR = strinteger(xx)
                GLCDPrint(10, 10, xxSTR, TFT_YELLOW) ;prints out 65519 NOT -17   WHY?
                        glcddrawstring ( 20, 20, xxSTR)
    
     
  • Anobium

    Anobium - 2019-02-27

    Stupid me.... you are correct. strinteger

    What happens when you use glcddrawstring ( 10, 10, strinteger(xx)) or
    glcdprint (10, 10, strinteger(xx))

    I will update the Help now. Please confirm this works.

     
  • Anobium

    Anobium - 2019-02-27

    To answer why use strinteger. GLCDPrint only support byte, word, long or string.

    If you think is it critical to add the integer type to GLCDPrint then it is relatively simple ( I think).

    Add? You will have to test.

     
  • MBB

    MBB - 2019-02-27

    Its not critical for me.

    Thanks for your help!

     
  • Anobium

    Anobium - 2019-02-27

    OK.   I have updated the Help. That was less work.

    CHEERS

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.