Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Line Label Best Practices with Include Files

 
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: 1054

usa.gif
PostPosted: Thu Aug 14, 2014 11:06 pm    Post subject: Line Label Best Practices with Include Files Reply with quote

Hello all,

Just starting to use Projects and Include files. In some cases, Line Labels are used. What is best practice for Line Labels, including those used by _Isr's, when using multiple include files?

Thank you,
Tim

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

Bascom Member



Joined: 22 Jun 2004
Posts: 1161
Location: France

france.gif
PostPosted: Fri Aug 15, 2014 4:20 pm    Post subject: Reply with quote

hello,
could you be more explicit ?
what do you want ?
use gosub....label where label is in file include ?
or use loadlabel ?
Would you please add a small code example.

JP

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

Bascom Member



Joined: 01 Jul 2006
Posts: 1054

usa.gif
PostPosted: Fri Aug 15, 2014 5:48 pm    Post subject: Reply with quote

Hello Duval JP,

Thank you for your response. The following are some specific examples.
Tim



'********************************************************************************************
'* Timer0 '1mS Timer '8 Bit Timer
'*************************************************************************************************
Const Timer0reload = 125
Config Timer0 = Timer , Prescale = 64
On Ovf0 Timer0_isr
Enable Timer0

'********************************************************************************************
'* Timer1 '500uS 16bit Timer
'*************************************************************************************************
Const Timer1reload = 4000
Config Timer1 = Timer , Prescale = 1
Load Timer1 , Timer1reload
On Ovf1 Timer1_isr



'**********************************************************************************************
'**********************************************************************************************
'* Timer0 '1mS Timer '8 Bit Timer
Timer0_isr: '1 mS Timer
Load Timer0 , Timer0reload
If Ack_interval_counter = 10000 Then Ack_interval_counter = 0
If Wait_4_ack = 1 Then Incr Ack_interval_counter
Return


'**********************************************************************************************
'**********************************************************************************************
'* Timer1 '500uS 16bit Timer
Timer1_isr: '500 uS Timer
Load Timer1 , Timer1reload
If Strt_debounce > 0 Then Decr Strt_debounce
Return



'*************************************************************************
Receive_data:
'poll RFM12 for Rx data.
Rfm12_get_status_bit
If Rx_status_bit = 1 Then
Rfm12_rx Rxbuffer(1)
Alarm_data_received = 1
Rxbuff(1) = Rxstring
End If
Return


'*************************************************************************
Isr_ffit:
Gosub Receive_data
Return
Back to top
View user's profile
i.dobson

Bascom Expert



Joined: 05 Jan 2006
Posts: 1570
Location: Basel, Switzerland

switzerland.gif
PostPosted: Fri Aug 15, 2014 9:00 pm    Post subject: Reply with quote

Hi,

I usually split my programs using includes based on functionality:-

l2c_bus.lib - contains the low level i2c routines
IO.lib - contains the alias definitions for PIN/ADC's
Sensors.lib - contains the Scaling/Smoothing and alarming routines
SF04.lib - contains the Sensirion flow sensor routines
Amsys.lib - contains the Pressure sensor routines
Sm.lib - contains the "Smart bus" battery routines

The main program then just consists of the code to setup the AVR, Interrupt service routines and the State machine handler.
The example above if doe a project I'm currently working on that at the moment consists of about 6000lines of code.

Breaking the cod down into functional groups makes testing a lot easier. I can create a small test program, add the required sensors and test it.

Regards
Ian Dobson

_________________
Walking on water and writing software to specification is easy if they're frozen.
Back to top
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Fri Aug 15, 2014 9:16 pm    Post subject: Reply with quote

For my "test board" I have done configurations and subroutines in files that I include only. Configuration for Lcd, Timers and what ever can be included before Do Loop and Sub`s after Loop. It does not matter whether it's IRQ. For new projects do not have to write this again
Code:

$regfile = "m8def.dat"
$crystal = 8000000
$hwstack = 64
$swstack = 64
$framesize = 64

'$loadersize = 1024

$include "encoder_config_new.bas"
$include "lcd_config_new.bas"
$include "menu_config.bas"
$include "sterowanie_config.bas"
$include "temperatura_config.bas"

'Dim Hbyte(2) As Byte , Hword(2) As Word , N As Byte , T(2) As Word

Flaga_zegar = 1 : Flaga_menu = 0 : Flaga_odliczanie = 1
Dim Autolight As Byte
Light = 0

Do


If Stan_enc <> 0 Then
 Alarms = 0                                                 'kasuje alarm do czasu ostygni&#281;cia pieca
 Wygaszenie = 0                                             'pozwala pika&#263;
End If
' automatyczne wyj&#347;cie z menu
  If Menu_timeout = 0 And Flaga_odliczanie = 1 Then
      Flaga_odliczanie = 0                                  ' wyzeruj flage
      Flaga_zegar = 1
      Flaga_menu = 0
      Nr_podprogramu = 0
      Light = 1
      Cls
      Lcd "PIEC:--"
      Lowerline
      Lcd Chr(0) ; " BOJLER" ; Chr(126)
   End If


 If Zegarek_licznik = 0 Then
    Zegarek_licznik = 250                                   'to co sekunde
   If Flaga_zegar = 1 And Flaga_menu = 0 Then               'jesli nie wyswietlane menu
      Gosub Glowna
   If Light = 0 Then Incr Autolight
   End If
     Gosub Temperatura
     Gosub Sterowanie

 End If

  If Autolight = 2 Then
     Autolight = 0
     Light = 1
  End If

   If Stan_enc = Enc_enter Then                             ' sprawd&#378; czy ekran g&#322;ówny i wci&#347;ni&#281;ty przycisk ENTER

       If Flaga_menu = 0 And Nr_podprogramu = 0 And Enc_menu > 650 Then
          Flaga_zegar = 0                                   ' ustaw flage
          Flaga_menu = 1                                    ' ustaw flag&#281; &#380;e wy&#347;wietlane jest menu
          Menu_nr_linii = 1                                 ' kursor w pierwszej linii menu
          Flaga_odswiez_kursor = 1
          Pozycja_menu = Loadlabel(menu_glowne)             ' zapamietaj adres danych pierwszej linii menu
          Call Wyswietl_menu(pozycja_menu , 1 , Down)
          Stan_enc = 0                                      ' kasuj zapami&#281;tany przycisk

          Menu_timeout = 2000
          Flaga_odliczanie = 1

        Else
         Enc_menu = 0
        End If
       Light = 0
   End If

' obs&#322;uga menu
Call Obsluga_menu()
' wykonanie podprogramu wybranego z menu
Gosub Menu_podprogramy
' kasuj zapami&#281;tany stan enkodera

   Stan_enc = 0

Loop
End

$include "encoder.bas"        'encoder
$include "menu.bas"            'menu control and siplay    
$include "temperatura.bas"  'read multiple DS18B20
$include "sterowanie.bas"    'control fan, relays..
$include "lcd.bas"
' display main page
Back to top
View user's profile Visit poster's website
TSEYFARTH

Bascom Member



Joined: 01 Jul 2006
Posts: 1054

usa.gif
PostPosted: Sat Aug 16, 2014 12:06 am    Post subject: Reply with quote

Hello i.dobson and EDC,

Thank you for your replies! Interesting, that EDC includes.bas files. So it appears that you can include both .inc and .bas files. I thought that only 1 .bas file could be in the project.

i.dobson, as you described you put line labels like those used for ISR's in the main .bas, from my brief work, that seemed to be the only place they would work. I also noted that your file names are of .lib - does this mean that any file extension can be used?

EDC, in you include.bas files. In those, do you have also ISRs, timers and other items as necessary - or are they only in your main .bas file?

In both cases, this was quite enlightening! I think it will make it much easier to work on a large project having the ability to organize in to file size chunks. Also nice is that the same files can be used elsewhere when necessary as you both did.

Thanks again for your replies!
Tim
Back to top
View user's profile
i.dobson

Bascom Expert



Joined: 05 Jan 2006
Posts: 1570
Location: Basel, Switzerland

switzerland.gif
PostPosted: Sat Aug 16, 2014 6:15 am    Post subject: Reply with quote

Hi Tim,

Woops your right, the file names are with .inc not .lib

Regards
Ian Dobson

_________________
Walking on water and writing software to specification is easy if they're frozen.
Back to top
View user's profile
TSEYFARTH

Bascom Member



Joined: 01 Jul 2006
Posts: 1054

usa.gif
PostPosted: Sat Aug 16, 2014 6:20 am    Post subject: Reply with quote

Hi Ian,
Thanks for the clarification. I had not tried it yet, but it would be kind of cool if you could use different file extensions. Especially since the whole file name has to be stated in the $Include line.

Do all &Include files need to be in the same folder as the Project / main .bas file? If not is it correct that the source has to have a hard coded full path to the files.

In your case, I can see there the above would come into play since the $Includes are used in many projects, probably at one time. So a central repository would make sense. Is this what you do?

Thanks again Ian,
Tim
Back to top
View user's profile
i.dobson

Bascom Expert



Joined: 05 Jan 2006
Posts: 1570
Location: Basel, Switzerland

switzerland.gif
PostPosted: Sat Aug 16, 2014 6:42 am    Post subject: Reply with quote

Hi,

I've never tried with different directories. I usually just copy the required modules from my central module directly into the project directory.

I work for pharmaceutical companies and testing/documentation/validation if very important for them and using standard/pre-tested modules makes my life much easier. When I start testing/documenting a project I can just pull in the modules documentation and set a reference to the previous tests performed, rather than having to test everything again. I still need to test the interface to the main application but not the low level code within the module.

Regards
Ian Dobson

_________________
Walking on water and writing software to specification is easy if they're frozen.
Back to top
View user's profile
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 1161
Location: France

france.gif
PostPosted: Sat Aug 16, 2014 8:46 am    Post subject: Reply with quote

I add a good practice :


see the help : "on interrupt"
"Finally some tips :
* when you use a timer interrupt that occurs each 10 uS for example, be sure that the interrupt code can execute in 10 uS. Otherwise you would loose time.
* it is best to set just a simple flag in the interrupt routine and to determine it's status in the main program. This allows you to use the NOSAVE option that saves stack space and program space. You only have to Save and Restore R24 and SREG in that case.
--"

jp Wink
Back to top
View user's profile Visit poster's website
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Sat Aug 16, 2014 9:41 am    Post subject: Reply with quote

Using $nocompile bas files is like hiding some knowed code from eyes. Compiler can hide some configurations but with $nocompile You can do more because override this. Eg. for test board I have Mega328p and target device is Mega8 whitch have diferent names for timer registers. In main Bas file I include config for Timer Isr and diferrent connection for Lcd.
Code:
$nocompile

#if Atmega328 = 1
Config Timer2 = Timer , Async = Off , Prescale = 256 , Compare_a = Disconnect , Compare_b = Disconnect , Clear Timer = 1
Enable Compare2a : On Compare2a Timer2_isr : Compare2a = 124

Config Lcdpin = Pin , Db4 = Portb.2 , Db5 = Portb.3 , Db6 = Portb.4 , Db7 = Portb.5 , E = Portb.0 , Rs = Portc.0
Config Lcd = 20 * 4

#else

Config Timer2 = Timer , Prescale = 256 , Compare = Disconnect , Clear Timer = 1
Enable Compare2 : On Compare2 Timer2_isr : Compare2 = 124

Config Lcdpin = Pin , Db4 = Portc.3 , Db5 = Portc.2 , Db6 = Portc.1 , Db7 = Portc.0 , E = Portc.4 , Rs = Portc.5       'mirley UPT M16
Config Lcd = 16 * 2
#endif


In main declare Const and Include
Code:
'$sim                                                        ' For the Bascom simulator only
'$regfile = "m328pdef.dat"
$regfile = "m8def.dat"
$crystal = 8000000
$hwstack = 64
$swstack = 64
$framesize = 64

Const Atmega328 = 0

$include "config_lcd_timer.bas"
$include "config_temperatura.bas"
'*********** START **********
Do
   'some code
   Gosub Temperatura
Loop
'*********** END ************

$include "timer_isr.bas"
$include "temperatura.bas"


Routines for Timer2_isr and reading dallas You can put in separate bas nocompile files.
Code:

$nocompile

Timer2_isr:

    If Menu_timeout <> 0 Then Decr Menu_timeout
   If Zegarek_licznik <> 0 Then Decr Zegarek_licznik
   If Temperatura_timer <> 0 Then Decr Temperatura_timer
   If Dth11_timer <> 0 Then Decr Dth11_timer
   Incr Minuta
    If Minuta = 60000 Then
       Minuta = 0
       Incr Minuty
    End If

   Return


Code:
$nocompile

Temperatura:
  Disable Interrupts
  1wreset
  Select Case Ktory_ds
    Case 0:
      1wwrite &HCC
      1wwrite &H44
    Case 1:
      1wwrite &H55
      1wwrite Ds1(1) , 8
      1wwrite &HBE
      Lsb = 1wread():
      Msb = 1wread():
    Case 2:
      1wwrite &H55
      1wwrite Ds2(1) , 8
      1wwrite &HBE
      Lsb = 1wread():
      Msb = 1wread():
   End Select

  Enable Interrupts

  If Ktory_ds > 0 Then
    T(ktory_ds) = Msb * 256
    T(ktory_ds) = T(ktory_ds) + Lsb

    T(ktory_ds) = T(ktory_ds) * 10
    T(ktory_ds) = T(ktory_ds) / 16
  End If

  Incr Ktory_ds
  If Ktory_ds = 3 Then Ktory_ds = 0

Return


If You compile main BAS file compiler test whole project and will tell You if code is no correct or some variable is missing for separate bas file with number of line Very Happy Eg. Error 43 Line 11 File not found Temperatura.bas or Error Line 24 in Temperatura.bas which is added nocompile file.
Back to top
View user's profile Visit poster's website
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