HSEROUT using STR modifier - length parameter as variable not working


+ Reply to Thread
Results 1 to 15 of 15

Hybrid View

  1. #1
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french part)
    Posts
    796

    Default HSEROUT using STR modifier - length parameter as variable not working

    Hi there,

    I'm using HSEROUT with the STR modifier and I can't find the way to set the number of characters "\n" in a variable instead.

    While this works:
    Code:
    HSEROUT [STR BalBuffer\40,26,13]
    ...this doesn't:
    Code:
    BalCount VAR BYTE
    BalCount = 40
    HSEROUT [STR BalBuffer\BalCount,26,13]
    It is to mention that it does compile without error in both cases.

    I didn't try this one, but according to some other post (from Bruce in 2005), DEBUG/DEBUGIN seem to accept a variable for the charater value.

    Is this a limitation for the STR modifier (= it has to be a number) in HSEROUT or is there a way to make it work with a variable?
    Last edited by flotulopex; - 21st February 2021 at 13:26.
    Roger

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,317

    Default Re: HSEROUT using STR modifier - length parameter as variable not working

    I don't know and I can't test/try if your code right now but a simple workaround would be
    Code:
    For i = 0 to BalCount   '  (Or possibly BalCount-1)
      HSEROUT [BalBuffer]
    NEXT
    HSEROUT [26,13]

  3. #3
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french part)
    Posts
    796

    Default HSEROUT using STR modifier - length parameter as variable not working

    Thanks Henrik,

    I went this way already but so it is correct, the number of characters cannot be replaced by a variable.

    Strange....
    Roger

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,317

    Default Re: HSEROUT using STR modifier - length parameter as variable not working

    Which device are you using?

    I compiled two different version and looked at the .lst and with my limited understanding of assembly I'd say it "should work"

    First, HSEROUT [STR Buffer\16]
    Code:
             movlw   low (010h)
             movwf   R4 + 1
             movlw   low (low (HSEROUTJ))
             movwf   R8
             clrf    (R8) + 1
             clrf    R2 + 1
             movlw   low (low (_Buffer))
             call    SEROUT2STRN
    Here it takes the literal 16 and moves it to the low byte (I think) of system variable R4.

    Second, HSEROUT [STR Buffer\Length]
    Code:
             movf    _Length, W
             movwf   R4 + 1
             movlw   low (low (HSEROUTJ))
             movwf   R8
             clrf    (R8) + 1
             clrf    R2 + 1
             movlw   low (low (_Buffer))
             call    SEROUT2STRN
    Here it takes the Length variable, and loads THAT to the low byte (I think) of system variable R4.

    In the actual serout macro it then decrements R4 to determine when it's done.

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,030

    Default Re: HSEROUT using STR modifier - length parameter as variable not working

    Page 47 of the manual says "STR must be followed by a backslash and a number that specifies how many
    characters (bytes) to collect."

    So, as I understand it, it should be a number, not a variable.

    If you want to change that on the fly, then Henrik's loop is the way to go.

    Ioannis

  6. #6
    Join Date
    May 2013
    Location
    australia
    Posts
    1,815

    Default Re: HSEROUT using STR modifier - length parameter as variable not working

    it works for me

    Name:  roger.jpg
Views: 75
Size:  73.2 KB

    Code:
     ;pic18f26k22 tx  demo
    #CONFIG
      CONFIG  FOSC = INTIO67
      CONFIG  PLLCFG = OFF
      CONFIG  PRICLKEN = OFF
      CONFIG  FCMEN = OFF
      CONFIG  IESO = OFF
      CONFIG  PWRTEN = OFF
      CONFIG  BOREN = SBORDIS
      CONFIG  BORV = 190
      CONFIG  WDTEN = ON
      CONFIG  WDTPS = 32768
      CONFIG  CCP2MX = PORTC1
      CONFIG  PBADEN = OFF
      CONFIG  CCP3MX = PORTB5
      CONFIG  HFOFST = ON
      CONFIG  T3CMX = PORTC0
      CONFIG  P2BMX = PORTB5
      CONFIG  MCLRE = EXTMCLR
      CONFIG  STVREN = ON
      CONFIG  LVP = OFF
      CONFIG  XINST = OFF
      CONFIG  DEBUG = OFF
      CONFIG  CP0 = OFF
      CONFIG  CP1 = OFF
      CONFIG  CP2 = OFF
      CONFIG  CP3 = OFF
      CONFIG  CPB = OFF
      CONFIG  CPD = OFF
      CONFIG  WRT0 = OFF
      CONFIG  WRT1 = OFF
      CONFIG  WRT2 = OFF
      CONFIG  WRT3 = OFF
      CONFIG  WRTC = OFF
      CONFIG  WRTB = OFF
      CONFIG  WRTD = OFF
      CONFIG  EBTR0 = OFF
      CONFIG  EBTR1 = OFF
      CONFIG  EBTR2 = OFF
      CONFIG  EBTR3 = OFF
      CONFIG  EBTRB = OFF
    #ENDCONFIG
      
      
    
    
    
    
    
    
    define OSC 8
    
    
    DEFINE DEBUG_REG PORTB  
    DEFINE DEBUG_BIT 7
    DEFINE DEBUG_BAUD 9600 
    DEFINE DEBUG_MODE 0
    DEFINE HSER_TXSTA 20h
    DEFINE HSER_BAUD 9600
    trisb=$7f 
    OSCCON = $60   ;  OSC 8
    anselc = 0
    BalBuffer VAR BYTE[60]
    BalCount VAR BYTE
    latb.7=1
    for   BalCount= 0 to 59
    BalBuffer[BalCount]=BalCount+"0"
    next
    BalBuffer[59]=0
    pause 2000
    debug "ready",13,10
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    BalCount = 40
    HSEROUT [STR BalBuffer\BalCount,13,10]
    debug   STR BalBuffer\BalCount,13,10
    debug "full load",13,10
    debug   STR BalBuffer,13,10
    end
    This is more entertaining than Free to Air TV

  7. #7
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french part)
    Posts
    796

    Default HSEROUT using STR modifier - length parameter as variable not working

    Quote Originally Posted by HenrikOlsson View Post
    Which device are you using?
    It's the one I always use: 16F690.
    Roger

Similar Threads

  1. Determining variable length (number of digits) possible?
    By CuriousOne in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 21st December 2020, 21:05
  2. Measuring a variable freq/length pulse and generating more pulses.
    By retepsnikrep in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 18th September 2014, 10:10
  3. hserout not working with parity
    By Pic2008 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 24th March 2010, 14:25
  4. HSERIN for variable length string
    By Pic2008 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 19th February 2010, 06:58
  5. Serin2 and STR Modifier
    By _Ian in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 22nd June 2005, 17:25

Posting Permissions

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