Shop OBEX P1 Docs P2 Docs Learn Events
Newbe....with SPIN question... — Parallax Forums

Newbe....with SPIN question...

dennodenno Posts: 223
edited 2014-12-25 09:21 in Propeller 1
Question...why won't the second STRING display on my Scott Edwards 4x40 display. If I comment out one or the other, it works just fine, and on the right line. posCMD,64 is the first line, and posCMD,144 is the second line....but, both lines will not display on the LCD, plus, it seems to "hang up" and not increment the test_number.

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2014-12-24 11:56
    attachment.php?attachmentid=78421&d=1297987572
  • PublisonPublison Posts: 12,366
    edited 2014-12-24 11:58
    attachment.php?attachmentid=78421&d=1297987572

    Had incorrect url
  • dennodenno Posts: 223
    edited 2014-12-24 12:44
    To all...I deleted this, as it was not the proper way to post code...thank you...DennO
  • dennodenno Posts: 223
    edited 2014-12-24 12:45
    {{DEBUG_TEST.spin By DenO}}
    
    
    CON
    _clkmode = xtal1 + pll16x         'Standard clock mode * crystal frequency = 80 MHz
    _xinfreq = 5_000_000
    carr_return            =  13   
    clrLCD                 =  12          'clear the screen on the lcd
    posCMD                 =  16          'position the curser command
    hideCUR                =   4           'hide the curser command
    blinkCUR               =   6           'blink the curser command
    degreeSYM              = 223           'the "degree" symbol
    receive_data           = 255
    backLTon               =  14          'turn the back light on
    backLToff              =  15          'turn the back light off
    brightness_ctl         =  27
    quarter_bright         =  48
    half_bright            =  49
    three_quarter_bright   =  50
    full_bright            =  51
    beep                   =   7           'beep command
    right_align            =  18          'RIGHT ALIGN COMMAND
    start_big_char         =   2
    end_big_char           =   3
    astrike                =  42
    block_char             = 134
    carReturn              =  13          'carriage return command
    blank_char             =  32
    left_arrow             = 127
    right_arrow            = 126
    LR_arrow               = 131
    LL_arrow               = 128
    UR_arrow               = 129
    UL_arrow               = 130
    down_arrow             = 132
    up_arrow               = 133
    equal_sign             =  61
    VAR
      long  stack [10]
      long  test_number 
      
    OBJ
      'PST : "Parallax Serial Terminal"
      LCD : "proto_lcd"
    PUB main
      coginit(7,LCD.init,@stack)
      test_number := 0
      LCD.command(backLTon)
      repeat
      '
        LCD.str(STRING(clrLCD,posCMD,64,"TEST"))
        LCD.Dec(test_number,4)
        LCD.str(STRING(clrLCD,posCMD,144,"TEST"))
        LCD.Dec(test_number,4)
        test_number++
        waitcnt((clkfreq + cnt)) '1 second pause
    
    'PRI private_method_name
    
    
    'DAT
    'name    byte  "string_data",0        
            
    
  • MrBi11MrBi11 Posts: 117
    edited 2014-12-24 13:09
    LCD.str(STRING(clrLCD,posCMD,64,"TEST"))
    LCD.Dec(test_number,4)
    LCD.str(STRING(clrLCD,posCMD,144,"TEST"))
    LCD.Dec(test_number,4)


    you are clearing the screen twice.
    also clearing the screen each loop will end up causing the LCD to 'blink'
  • dennodenno Posts: 223
    edited 2014-12-24 16:30
    OK...I took the second clrLCD out, and still no joy....DenO
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-12-24 19:40
    The statement "coginit(7, LCD.init, @stack)" will not do what you expect it to. *** This has to be changed to get the program to work. ***

    You should only launch Spin cogs from within the object they are located. Also cognew is almost always better than coginit.

    10 longs of stack space is probably fine some some methods but a lot of methods will require more.

    I don't know what the LCD.init method does but generally one only starts a new cog with code running in a loop. Often "Start" methods start a new cog while "Init" methods just configure I/O pins and get the object ready to use without starting a cog.

    The start method will take care of any cog launching for you if it's needed.

    Since "Init" methods often configure I/O pins, it's a good idea to call Init methods from the cog which will be calling the methods in the object.

    I suggest replacing the line:
      coginit(7, LCD.init, @stack)
    

    With:
      LCD.init
    
  • dennodenno Posts: 223
    edited 2014-12-25 03:22
    Thank you Duane,,,I thought I was trying to put OBJECTS in certain COGS so I could keep track of them, like I do with the BS@sx and the eight different program slots. Anyways, I will try your suggestion, and could/would you explain a little more about a "start" method?

    Am I correct, if I want to put proto_LCD in cog 7, I should put cognew at the beginning of that OBJECT?
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-12-25 09:21
    Cogs and objects really have nothing to do with each other. You can have one object use all 8 cogs and you could easy have 8 objects in a single cog. Cogs run assembly code. The assembly code is either a PASM section of code launched with cognew or the Spin interpreter from ROM. The Spin interpreter is launched when a Spin method (from within the current object) and stack location are the parameters of the cognew statement.

    Cog #0 starts out running a Spin interpreter and generally continues to do so for the duration of most Spin programs.

    When you launch Spin code with cognew, you're starting a cog running another instance of the Spin interpreter. The Spin code stays in the hub and Spin interpreter running in a cog executes the instructions as it reads them from the hub (which Cog #0 is also doing).
    denno wrote: »
    Am I correct, if I want to put proto_LCD in cog 7, I should put cognew at the beginning of that OBJECT?

    So much of the answer to your question depends on what you want "proto-LCD" to do.

    There are lots of examples of launching cogs in various "Start" methods of objects. The Start method will either launch PASM code from the DAT section of the object or start a new Spin interpreter to run a Spin method which method generally contains a continuous loop.

    I haven't programmed the BS_SX chips so I'm not aware of how the program slots are used. I think it's safe to assume the slots of the BS_SX chips have little in common with cogs of the Propeller.

    I'm sure there are times with the coginit statement is the appropriate way of launching a cog but I personally have never used it and I think it's a good idea to use cognew unless there is some specific reason to use coginit.
Sign In or Register to comment.