Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

CONFIG SUBMODE = NEW Problem and Question

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive
View previous topic :: View next topic  
Author Message
TSEYFARTH

Bascom Member



Joined: 01 Jul 2006
Posts: 1048

usa.gif
PostPosted: Thu Aug 14, 2014 8:58 pm    Post subject: CONFIG SUBMODE = NEW Problem and Question Reply with quote

Hello All,

I am breaking apart a working program into a new program that should come out the same, but will utilize includes. All Declare Subs are remarked. Many subs have been moved out of the main .bas file, but there remains some. My problem is, the compiler complains that the sub or function cannot be found. When using CONFIG SUBMODE = NEW, do ALL subs have to be outside the .bas file?


At the start of the program I have
Code:

      $regfile = "m168pdef.dat"
      $hwstack = 256                    '128                                         '32
      $swstack = 256                    '128                                         '20                                          '10
      $framesize = 160                  '144                   '128                                       '96                                       '40
      $crystal = 8000000                '8MHz (internal RC)

      $baud = 9600
      $noramclear
      Debug Off                         'Off

     CONFIG SUBMODE = NEW
 


Again, all Declare Subs are remarked. The compiler complains about ones that remain in the .bas file.

Code:

Call Update_Ack_Int
 


The compiler also complains about another sub, also in the main .bas file.

Code:

Call Assemblenibble(1)
 


These are at the end of the .bas file.

Code:

'**********************************************************************************************
'**********************************************************************************************
Sub Assemblenibble(byval Cnt As Byte)
  Txbuffer(8) = Device_type Or Cnt
End Sub



'**********************************************************************************************
'**********************************************************************************************
Sub Update_Ack_Int
          'ACK Interval managed by Random Number Generator
    _rseed = Address + 100              '_rseed = Address

    Do
      Ack_interval = RND(3100)          '   Rnd(253)            '65535
    Loop Until Ack_Interval > 270
End Sub
 



Also, is there anything "wrong" with using "Return" at the end of a Sub, or within a Sub? This is a habit from another IDE.

Thanks all,
Tim

(BASCOM-AVR version : 2.0.7.7 )
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5061
Location: Holland

blank.gif
PostPosted: Thu Aug 14, 2014 9:14 pm    Post subject: Reply with quote

you really should read the help.

When you use CONFIG SUBMODE=NEW, most behaviour is changed :
- there is no need to DECLARE a sub/function before you call it. But, the actual sub/function code must be placed before the actual call!


this means that you either need to use some $include or when you leave the sub in the main program, you need to have the code before the actuall call :

sub test()

end sub

test '
call test 'same as test

in this sample it is correct since the sub implementation is before the actuall call.
if you do call the sub/function without a DECLARE or without the code preceding it, the compiler does not know the sub/function.

RETURN : a bad idea. it can be done when you do not pass parameters. only use return when there is a matching label that is called like :

sub test()
print "test"
gosub abc
exit sub

abc:
print "abc"
return
End Sub

_________________
Mark
Back to top
View user's profile Visit poster's website
TSEYFARTH

Bascom Member



Joined: 01 Jul 2006
Posts: 1048

usa.gif
PostPosted: Thu Aug 14, 2014 9:30 pm    Post subject: Reply with quote

Hello Mark and thank you for your reply.

Quote:

you really should read the help.

I did sir.

Quote:

When you use CONFIG SUBMODE=NEW, most behaviour is changed :
- there is no need to DECLARE a sub/function before you call it.


The old Declares were remarked.


Quote:

But, the actual sub/function code must be placed before the actual call!


OK. This explains it. So really, when using CONFIG SUBMODE=NEW, it is best to have all subs in a .inc file with the $Include statement at the top. That would virtually put them all before any calls are made.

Makes sense since the old way required Declare Sub to be before any calling - just a little counter intuitive since it appeared that the Config statement somehow allowed no difference to where the Subs are located; by virtue of the compiler finding them first with the $Include at the top, the same requirement is met.

Thanks again for the reply,
Tim
[/quote]
Back to top
View user's profile
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum