View previous topic :: View next topic |
Author |
Message |
EDC
Joined: 26 Mar 2014 Posts: 971
|
Posted: Tue Aug 16, 2016 2:24 pm Post subject: Some idea to make one file libs with labels and data |
|
|
I do not know which one of sections (Share code or this Arduino) forum will be better to show my Idea.
I like Arduino method to include one file at the beginning of main code.
In Bascom writing own library for some devices was not so easy because when you need some LABELS or DATA to be stored
then you must include them after END statement.
Yesterday bring me one idea.
Config Submode = New is a great future because you don`t need to declare subs and also unused subs are not compiled.
But Config Submode Help says one more thing. "Subs will be placed at the program end after END statement automatically"
I test Idea where LABEL and DATA statement is enclosed in dummy sub, then I force BASCOM compiler to attach this sub.
And gues what? Everything works exellent
So for now I can add anything I want into INCL/LIB file even initialisations bytes for some devices or whatever. In one single file at the main code begining.
I attach simple code for PCF8583 where Labels Getdatetime, Setdatetime and Data must be attached if you want to use this chip with bullit in Bascom routines
$Time &Date etc.
I think this will be helpfull or maybe Mark add some future that will allow adding something after END statement
Code: | $regfile = "m32adef.dat"
$crystal = 8000000
$hwstack = 64
$swstack = 64
$framesize = 64
Config Submode = New
' I2C config
$lib "i2c_twi.lbx"
Config Scl = Portc.0
Config Sda = Portc.1
I2cinit
Config Twi = 100000
Const Language = 0
$include "pcf8583.inc"
'-[SELECT LANGUAGE]-
'0 = PL
'1 = EN
'2 = DE
Config Lcdpin = Pin , Db4 = Porta.3 , Db5 = Porta.4 , Db6 = Porta.5 , Db7 = Porta.6 , E = Porta.2 , Rs = Porta.0 , Wr = Porta.1
Config Lcd = 20x4
Cursor Off , Noblink
#if Language = 0 'Polish
Deflcdchar 1 , 12 , 4 , 4 , 6 , 12 , 4 , 14 , 32 ' ł
Deflcdchar 2 , 2 , 4 , 14 , 16 , 16 , 17 , 14 , 32 ' ć
Deflcdchar 3 , 2 , 4 , 14 , 16 , 14 , 1 , 30 , 32 ' ś
Deflcdchar 4 , 32 , 32 , 14 , 1 , 15 , 17 , 15 , 1 ' ą
Deflcdchar 5 , 32 , 32 , 14 , 17 , 31 , 16 , 14 , 1 ' ę
Deflcdchar 6 , 2 , 4 , 14 , 17 , 17 , 17 , 14 , 32 ' ó
#endif
Cls
Config Porta.7 = Output : Led Alias Porta.7
Dim Lang As Byte , Day_nr As Byte , Day_str As String * 15
Dim Name_end_pos As Byte , Name_start_pos As Byte
Name_start_pos = 1
Lang = Language
Enable Interrupts
Do
Locate 1 , 1 : Lcd Time$ 'odczytuje czas - uzywac co jakiś czas a nie wkółko w petli
Locate 1 , 11 : Lcd Date$
Day_nr = Dayofweek()
Select Case Lang
Case 0
Day_str = Lookupstr(day_nr , Dni_tygodnia)
Case 1
Day_str = Lookupstr(day_nr , Weekdays)
Case 2
Day_str = Lookupstr(day_nr , Dni_de)
End Select
'Locate 2 , Name_end_pos : Lcd Spc(5)
Locate 2 , Name_start_pos : Lcd Day_str
Waitms 500
Toggle Led
Loop
End |
pcf8583.incl
Code: | '*********************************************************
'* *
'* INTEGRATING PCF8583 WITH $TIME and $DATE *
'* *
'* 18.01.2016 BARTek niveasoft(at)tlen.pl *
'* *
'* DECLARATION FILE SHOULD BE INCLUDED AFTER I2C CONFIG *
'* *
'* $include "pcf8583.inc" *
'* *
'* Dim .... *
'* *
'* Do *
'* ....... *
'* Loop *
'* End *
'* *
'* *
'* *
'*********************************************************
$nocompile
Config Clock = User
Config Date = Dmy , Separator = /
' adresy układu PCF8583
' jeżeli noga A0 układ PCF8583 jest podłączony do GND to:
' adres do odczytu = &HA1
' adres do zapisu = &HA0
' jeżeli noga A0 układ PCF8583 jest podłączony do VCC to:
' adres do odczytu = &HA3
' adres do zapisu = = &HA2
'Const Pcf8583w = &HA0 'PCF address for write
'Const Pcf8583r = &HA1 'PCF address for read
Const Pcf8583w = &HA2 'PCF address for write
Const Pcf8583r = &HA3 'PCF address for read
Dim Rtc_year_date As Byte , Rtc_weekdays_months As Byte , Temp_b As Byte
Dim Pcf8583_kalendarz_baza As Byte , Pcf8583_year_old As Byte
Sub Store_year
I2cstart
I2cwbyte Pcf8583w
I2cwbyte 16
I2cwbyte Pcf8583_kalendarz_baza
End Sub
Sub Read_year
I2cstart
I2cwbyte Pcf8583w
I2cwbyte 16
I2crbyte Pcf8583_kalendarz_baza , Nack
I2cstop
End Sub
Sub Dummy_sub
Getdatetime:
'called when date or time is read
I2cstart
If Err = 0 Then
I2cwbyte Pcf8583w
If Err = 0 Then
I2cwbyte 2
If Err = 0 Then
I2cstart
If Err = 0 Then
I2cwbyte Pcf8583r
I2crbyte _sec , Ack 'sec
I2crbyte _min , Ack 'min
I2crbyte _hour , Ack 'hour
I2crbyte Rtc_year_date , Ack 'date
I2crbyte Rtc_weekdays_months , Nack 'date
_sec = Makedec(_sec) : _min = Makedec(_min) : _hour = Makedec(_hour)
Temp_b = Rtc_year_date ' rok
Shift Temp_b , Right , 6
Temp_b = Makedec(temp_b)
_year = Pcf8583_kalendarz_baza + Temp_b ' baza + wartość kalendarza czteroletniego
If Pcf8583_year_old <> Temp_b Then ' jeżeli zmienił się rok
If Temp_b = 0 And Pcf8583_year_old = 3 Then ' jeżeli skończył się kalendarz czteroletni
Pcf8583_kalendarz_baza = Pcf8583_kalendarz_baza + 4 ' zmień bazę kalendarza
End If
Pcf8583_year_old = Temp_b 'dopiero tu może dostać nowa wartość
'zapisz dane o aktualnym roku w układzie PCF8583
Call Store_year
End If
Temp_b = Rtc_year_date And &B0011_1111 ' dzień
_day = Makedec(temp_b)
Temp_b = Rtc_weekdays_months And &B0001_1111 ' miesiąc
_month = Makedec(temp_b)
End If
End If
End If
I2cstop
End If
Return
Setdate:
Rtc_year_date = Makebcd(_day) 'w bajcie zapisz dzień w kodzie BCD
Temp_b = _year Mod 4
Temp_b = Makebcd(temp_b)
Pcf8583_year_old = Temp_b 'zapamietaj bo przyda sie kiedy rok w PCF się zmieni
Pcf8583_kalendarz_baza = _year - Temp_b
Shift Temp_b , Left , 6
Rtc_year_date = Rtc_year_date Or Temp_b
Rtc_weekdays_months = Makebcd(_month) ' dzień tygodnia i miesiąc
Temp_b = Dayofweek()
Temp_b = Makebcd(temp_b)
Shift Temp_b , Left , 5
Rtc_weekdays_months = Rtc_weekdays_months Or Temp_b
I2cstart
I2cwbyte Pcf8583w
I2cwbyte 5
I2cwbyte Rtc_year_date
I2cwbyte Rtc_weekdays_months
Call Store_year
I2cstop
Return
Settime:
_sec = Makebcd(_sec) : _min = Makebcd(_min) : _hour = Makebcd(_hour)
I2cstart '
I2cwbyte Pcf8583w
I2cwbyte 2
I2cwbyte _sec
I2cwbyte _min '
I2cwbyte _hour
I2cstop
Return
Dni_tygodnia:
Data "Poniedzia{001}ek" , "Wtorek" , "Sroda" , "Czwartek" , "Pi{004}tek" , "Sobota" , "Niedziela"
Weekdays:
Data "Monday" , "Tuesday" , "Wednesday" , "Thursday" , "Friday" , "Saturday" , "Sunday"
Dni_de:
Data "Montag" , "Dienstag" , "Mittwoch" , "Donnerstag" , "Freitag" , "Samstag" , "Sonntag"
End Sub
Dim Dummy As Byte
'## THIS IS NEVER CALLED BUT FORCE BASCOM TO INCLUDE THIS SUBS ##
'## AND THEY WILL BE PLACED AT THE PROGRAM END AUTOMATICALLY ##
If Dummy = 1 Then
Call Dummy_sub
End If
|
|
|
Back to top |
|
|
bzijlstra
Joined: 30 Dec 2004 Posts: 1179 Location: Tilburg - Netherlands
|
Posted: Tue Aug 16, 2016 3:48 pm Post subject: Nice work |
|
|
config submode = new is real strong!!!
Nice work
Ben Zijlstra |
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
Posted: Tue Aug 16, 2016 5:48 pm Post subject: |
|
|
Yes. One can look at this sample. Even interrupt service routine can be declared/added to code at the beginning
Code: | $regfile = "m328pdef.dat"
$crystal = 11059200
$hwstack = 64
$swstack = 64
$framesize = 128
Config Submode = New ' <-IMPORTANT!
$include "ticker.bas"
Enable Interrupts
Do
Loop
End
|
ticker.bas
Code: | $nocompile
'timer
Config Timer1 = Timer , Prescale = 64 , Compare_a = Disconnect , Compare_b = Disconnect , Clear Timer = 1
Enable Compare1a : On Compare1a Timer1_isr : Compare1a = 31249 '500ms @16MHz
Config Portb.0 = Output : Led Alias Portb.0
Dim Dummy As Byte
Sub Tim_dummy
Timer1_isr :
Toggle Led
Return
End Sub
If Dummy = 1 Then Call Tim_dummy 'once Sub is called even in condition statement then will be attached to main code after END |
|
|
Back to top |
|
|
|
|
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
|
|