Menu

HSerReceive in a Do..While loop

Help
Peter
2017-03-07
2017-03-08
  • Peter

    Peter - 2017-03-07

    I have a GSM modem which communicates via serial.

    To send an SMS I need to wait for a ">" prompt to appear.

    This works

      Dim inChar as Byte
      Do
        HSerReceive inChar
      Loop While inChar <> 62
    

    But this doesn't:

      Do
      Loop While HSerReceive <> 62
    

    Is there a way to get the second version to work, just to keep the code neater?

    I'm using 0.97.01.

     
  • Anobium

    Anobium - 2017-03-07

    Post the section of errant ASM please. Let us look at what is happening.

     
  • Peter

    Peter - 2017-03-07

    I think this is the working ASM:

    ;Do
    SysDoLoop_S1
    ;HSerReceive inChar
      pagesel HSERRECEIVE377
      call  HSERRECEIVE377
      pagesel $
      movf  SERDATA,W
      movwf INCHAR
    
    ;Loop While inChar <> 62 'Wait for > prompt
      movlw 62
      subwf INCHAR,W
      btfss STATUS, Z
      goto  SysDoLoop_S1
    SysDoLoop_E1
    

    And I think this is the one that doesn't work:

    ;Do
    SysDoLoop_S1
    ;Loop While HSerReceive <> 62
      movlw 62
      subwf HSERRECEIVE,W
      btfss STATUS, Z
      goto  SysDoLoop_S1
    SysDoLoop_E1
    

    In the second case is it treating HSERRECEIVE as a variable and not a function?

     
  • William Roth

    William Roth - 2017-03-08

    Hserreceiveive subroutine and not a function so the second method will not work.

    Correction. It is both a sub and a function so it should work I think

    But the the ASM does not show an HserReceive sub. Only the HserReceive Variable

    With limited testing it appears that a function cannot be used as part of a conditional statement

    This DOES NOT Work

    waitforchar62:   
    If hserreceive <> 62 then goto waitforChar62
    

    The function is never called since there is no function or sub for hserreceive in the ASM

    ASM

     

    Last edit: William Roth 2017-03-08
  • mmotte

    mmotte - 2017-03-08

    Peter,
    We have run into similar situation because of function overloading.

    I tried William's example and as he says it don't call the HSerreceive function.

    But if you change the hserreceive to hserreceive1 then it might work.

    WAITFORCHAR62
    ;If hserreceive1 <> 62 then goto waitforChar62
        rcall   FN_HSERRECEIVE1
        movlw   62
        subwf   HSERRECEIVE1,W,BANKED
        btfss   STATUS, Z,ACCESS
        bra WAITFORCHAR62
    

    Note now it does call FN_HSERRECEIVE1 and returns the value into the variable HSERRECEIVE1.

    HSERRECEIVE1 is a valid function saying it is using com port number 1. it is in help file.

    Calling hserreceive as a function don't really lessen your code because it calls the same subroutine and then puts it into a variable like your very first code.

    BR
    M

     
  • Anobium

    Anobium - 2017-03-08

    @Mmotte is correct. This is caused by the compiler.

    I thought I had written this up in the Help. But, I have failed you all.

    Hugh will correct me....

    These work;

      'Call the function by adding the braces 
      '
      Do
      Loop While HSerReceive() <> 62
    
      'Please the constant first - this is the general rule.  Always put the constant first.
      '
      Do
      Loop While 62 <> HSerReceive
    

    This fails as the function will not be called

      Do
      Loop While HSerReceive <> 62
    
     

    Last edit: Anobium 2017-03-08
    • Peter

      Peter - 2017-03-08

      Both of those alternatives are neat enough for me.

       
  • Anobium

    Anobium - 2017-03-08

    Please review this Help.. you will have to scroll to the bottom of the page....

    What changes are needed to improve this Help page?

    And, this is a constraint of the current compiler. This constraint is a low priority in terms of being removed.

     

    Last edit: Anobium 2017-03-08
  • William Roth

    William Roth - 2017-03-08

    @Peter
    While using the function may make neater looking GCB source code, it also uses 5 more words of program memory and takes longer to execute than using the sub with no function.

     

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.