Shop OBEX P1 Docs P2 Docs Learn Events
LCD_Program For PrpBASIC — Parallax Forums

LCD_Program For PrpBASIC

caskazcaskaz Posts: 957
edited 2010-03-23 14:11 in Propeller 1
Hi.

I try to make LCD-driver by PropBASIC.
Display for LCD works.

I translate from spin to BASIC.

Spin file (Decimal display)
PUB DEC(VALUE) | TEMP
  IF (VALUE< 0)
    -VALUE
    CHAR("-")
  TEMP := 1_000_000_000
  REPEAT 10
    IF (VALUE => TEMP)
      CHARA(VALUE/TEMP + "0")
      VALUE //= TEMP
      RESULT~~
   ELSEIF (RESULT OR TEMP == 1)
      CHAR("0")
   TEMP /= 10




pbasic file
SUB CONV_DEC
  NUM    VAR   __param1
  n        VAR   __param2
  NNUM VAR    __param3
  zz      VAR    __param4
  zero   VAR    Long
  figure VAR    Long

  figure = 1_000_000_000
  zero = 0

  IF NUM < 0 THEN
     NUM = -NUM
     CHAR "-"
  ENDIF
  FOR n = 1 TO 10
     IF NUM >= figure THEN
       NNUM = NUM / figure
       NNUM = NNUM + "0"
       CHAR NNUM
       NUM = NUM // figure
       zero = 1
     ELSE
       zz = zero | figure
       IF zz = 1 THEN
         CHAR "0"
       ENDIF
     EMDIF
     figure = figure / 10
  NEXT
  ENDSUB




If CONV_DEC 0(zero), display for LCD is "0".
Display for 0 - 9 ar OK.

BUT more than 10, they were bad.
10 -> 15 94 -> 95
100 -> 15 900 -> 95

Where are incorrect?

And how can subroutine(CONV_DEC) modify more smart?

Post Edited (caskaz) : 3/23/2010 6:48:27 AM GMT

Comments

  • Gerry KeelyGerry Keely Posts: 75
    edited 2010-03-23 08:22
    Hi Caskaz
    Attached is a progam to print decimal numbers on the Parallax Serial Terminal. it may be of some use
    ' Device Settings
    ' ----------------------------------------------------------------------
    DEVICE          P8X32A, XTAL1, PLL16X
    XIN             6_000_000
    
    ' ----------------------------------------------------------------------
    ' Conditional Compilation Symbols
    ' ----------------------------------------------------------------------
    
    ' ----------------------------------------------------------------------
    ' Constants
    ' ----------------------------------------------------------------------
     Baud      CON "T115200"
     Term_CLR  CON 0
     CR        CON 13
    
    ' ----------------------------------------------------------------------
    ' Cog Variables (Long only)
    ' ----------------------------------------------------------------------
      Vstring VAR LONG(10)
      V VAR LONG
      SIGN VAR LONG
      c var long
    ' ----------------------------------------------------------------------
    ' SUB/FUNC Definitions
    ' ----------------------------------------------------------------------
     Ser  Sub 1
    ' ======================================================================
      PROGRAM Start
    ' ======================================================================
    Start:
    SIGN ="+"
    ser Term_Clr
    V= 12345
    If V < 0 then
    V =-V
    SIGN ="-"
    endif
    Do
     STR Vstring, V,10
     ser SIGN
     for c = 0 to 9
     ser Vstring(c)
     next
     ser CR
     Loop
    
      END
    
    ' ----------------------------------------------------------------------
    ' SUB/FUNC Code
    ' ----------------------------------------------------------------------
    Sub Ser
    serout 30,Baud,__param1
    return
    'end sub
    
    



    Gerry
  • caskazcaskaz Posts: 957
    edited 2010-03-23 10:54
    Gerry, Thanks.

    You sample work fine.

    I test below

    test_num = 1
    STR aaa, test_num,10
    CHAR aaa

    But "1" don't display on LCD.

    CHAR "A" display "A" on LCD.
  • BeanBean Posts: 8,129
    edited 2010-03-23 11:15
    caskaz,
    You need to send each character from aaa.

    FOR temp = 0 TO 9
    CHAR aaa(temp)
    NEXT

    Bean

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Use BASIC on the Propeller with the speed of assembly language.

    PropBASIC thread http://forums.parallax.com/showthread.php?p=867134

    March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
    ·
  • caskazcaskaz Posts: 957
    edited 2010-03-23 11:34
    Bean, Thanks.
    I see.



    And where does first pbas_sample I post is wrong?

    Post Edited (caskaz) : 3/23/2010 12:35:23 PM GMT
  • caskazcaskaz Posts: 957
    edited 2010-03-23 12:49
    I modified CONV_DEC.
    Thanks for your help.

    SUB CONV_DEC
      NUM    VAR   __param1
      n        VAR   __param2
      num_str  VAR   Long(10)
    
      IF NUM < 0 THEN
        NUM = -NUM
        CHAR "-"
      ENDIF
    
      STR num_str, NUM, 10
      FOR n = 0 TO 9
         IF num_str <>  " "  THEN
             CHAR num_str(n)
         ENDIF
      NEXT
      ENDSUB
    
    

    Post Edited (caskaz) : 3/23/2010 1:13:39 PM GMT
  • Gerry KeelyGerry Keely Posts: 75
    edited 2010-03-23 13:29
    Hi Caskaz

    Your original program will work if you declare NUM as a cog variable and

    if you change the first line in SUB·CONV_DEC
    ·from ·NUM····VAR···__param1 to· NUM = __param1

    I think the problem is that NUM is assigned the value in __param1 but that this value is changed when you call "CHAR" as this also uses __param1

    Gerry
  • caskazcaskaz Posts: 957
    edited 2010-03-23 14:11
    Gerry, Thanks.

    I understand for your reply.
Sign In or Register to comment.