Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Config SubMode = New and Config Clock = User

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
mmarlette

Bascom Member



Joined: 30 Nov 2007
Posts: 303
Location: Delano, MN

usa.gif
PostPosted: Tue Apr 01, 2014 12:12 am    Post subject: Config SubMode = New and Config Clock = User Reply with quote

Can someone explain to me how to make the subject line work together?

Seems to be a chicken and egg scenario. All references must be defined before they are referenced per the help....Not quoting....

In the below code, the get/setdate/time are defined PRIOR to the CONFIG CLOCK. I will then get an assignment error on _SEC, _MIN because CONFIG CLOCK = USER hasn't be defined yet.

If I move the CONFIG CLOCK = USER to BEFORE the get/setdate/time routines, then I get errors that the GETDATETIME routine hasn't been defined yet.

How can I make this mode work with an external clock? This is just a test code to show the point. The SUBMODE = NEW has some very nice features that I would like to use but I am stuck ATM.

Please advise......seems like I am in the rinse cycle...... Smile

Code:

'-------------------------------------------------------------------------------
 '                           DS1307.BAS
 ' Shows how to use the ds1307 clock on the Arduino M2560. A timer is configured
 ' at a 1 second interval. The ISR will set a flag to allow the DS1307's
 ' getdatetime routine to be executed.
 '
 ' It takes ~965uS to get the date/time when called.
 '-------------------------------------------------------------------------------
 $regfile = "m2560def.dat"      ' specify the used micro
 Config SubMode = new

 $crystal = 16000000            ' used crystal frequency
 $baud = 115200                 ' use baud rate
 $hwstack = 200
 $swstack = 250
 $framesize = 1000
 $programmer=23                 ' Define programmer as ARDUINO V2 (using stk500v2 protocol)
 '$prog $fc,$c6,$df,$ff         ' Lock Bits, Fuse Bits Low, Fuse Bits High, Fuse Bits Extended
 '
 Const False = 0
 Const True = 1
 'address of ds1307
 Const Ds1307w = &HD0                     ' Addresses of Ds1307 clock
 Const Ds1307r = &HD1
 
 'dim other needed variables
 Dim Weekday As Byte
 Dim lngTick as long                     ' one second tick timer counter
 Dim booRTCupdate as boolean             ' Flag to allow event to occur
 Dim strTime As String * 8
 'Dim bytStatus as byte
 '
  'called from CONFIG CLOCK = USER
 '
 Getdatetime:
  'set PORTA.0
  I2cstart                                                  ' Generate start code
  I2cwbyte Ds1307w                                          ' send address
  I2cwbyte 0                                                ' start address in 1307
  I2cstart                                                  ' Generate start code
  I2cwbyte Ds1307r                                          ' send address
  I2crbyte _sec , Ack
  I2crbyte _min , Ack                                       ' MINUTES
  I2crbyte _hour , Ack                                      ' Hours
  I2crbyte Weekday , Ack                                    ' Day of Week
  I2crbyte _day , Ack                                       ' Day of Month
  I2crbyte _month , Ack                                     ' Month of Year
  I2crbyte _year , Nack                                     ' Year
  I2cstop
  _sec = Makedec(_sec) : _min = Makedec(_min) : _hour = Makedec(_hour)
  _day = Makedec(_day) : _month = Makedec(_month) : _year = Makedec(_year)
  'reset PORTA.0
Return

Setdate:
  _day = Makebcd(_day) : _month = Makebcd(_month) : _year = Makebcd(_year)
  I2cstart                                                  ' Generate start code
  I2cwbyte Ds1307w                                          ' send address
  I2cwbyte 4                                                ' starting address in 1307
  I2cwbyte _day                                             ' Send Data to SECONDS
  I2cwbyte _month                                           ' MINUTES
  I2cwbyte _year                                            ' Hours
  I2cstop
Return

Settime:
  _sec = Makebcd(_sec) : _min = Makebcd(_min) : _hour = Makebcd(_hour)
  I2cstart                                                  ' Generate start code
  I2cwbyte Ds1307w                                          ' send address
  I2cwbyte 0                                                ' starting address in 1307
  I2cwbyte _sec                                             ' Send Data to SECONDS
  I2cwbyte _min                                             ' MINUTES
  I2cwbyte _hour                                            ' Hours
  I2cstop
 Return

 $lib "i2c_twi.lbx"                       ' using hardware I2C/TWI

 Config Sda = Portd.1                     ' define pin names, scl and sda pins
 Config Scl = Portd.0
 Config Twi = 100000                      ' CONFIG TWI will ENABLE the TWI master interface, 100KHZ
 i2cinit                                  ' initialize the I2C bus

 Config Date = mdy , Separator = /        ' configure the date format
 config clock = user                      ' define USER clock, it dims date / time vars
                                          ' The USER must have the calls of settime, setdate, getdatetime
                                          ' to talk to the USER's hardware

 '-----[ Output Timer ISR  for Oscilloscope Check on Porta.0 ]-----------------
 Config Porta.0 = Output                  '
 Porta.0 = 1                              ' LED off, active lo.
 TickBit Alias Porta.0
 '-----[ Setup Timer1 for Tick ISR off system XTAL]----------------------------
 ' Timer1 is used for Tick counter at 1Hz
 Config Timer1 = Timer , Prescale = 1024 , Compare A = Disconnect , Clear Timer = 1
 ' crytal   / prescale / x Hz    = Compare1a val needed
 ' 18432000 / 1024     / 100(Hz) = 180
 ' 16000000 / 1024     / 1(Hz) = 15625
 ' 14745600 / 1024     / 1(Hz) = 14400
 ' 14745600 / 1024     / 100(Hz) = 144
 ' 7372800 / 1024     / 100(Hz) = 72
 Compare1a = 15625
 On Compare1a T1_TickCounter_ISR          ' Define ISR Entry Point
 Enable Timer1
 Enable Compare1a
 '-----[Serial Port(s)]--------------------------------------------------------
 Config Com1 = 115200, Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
 Open "com1:" For Binary As #1
 Waitms 5
 '
 Enable Interrupts                       ' Using a timer to generate 1 second ISR interval

 Print #1, "DS1307"
 'Print #1, "Setting SQW bit on"
 'I2cstart                                                  ' Generate start code
 'I2cwbyte Ds1307w                                          ' send address
 'I2cwbyte 7                                                ' control register in 1307
 'I2crbyte bytStatus, Ack                                  ' read the status register first
 'print #1, "DS1307 READ-status register=$"; hex(bytStatus)
 'bytStatus = bytStatus and &h93                             ' pass only used bits
 'bytStatus = bytStatus or &h10                              ' set SQWout on
 'print #1, "DS1307 WRITE-status register=$"; hex(bytStatus)
 'I2cstart                                                  ' Generate start code
 'I2cwbyte Ds1307w                                          ' send address
 'I2cwbyte 7
 'I2cwbyte bytStatus                                        ' send to status register
 'I2cstop                                                   ' 32.768KHZ clock on SQWout pin of DS1307
 '
 ' Clear Vars
 '
 lngTick = 0
 booRTCupdate = false
 '
 Do                                 ' Main Loop
    if booRTCupdate = true then
       booRTCupdate = false
       call GetDateTime             ' read from RTC
       strTime = Time(_sec)         ' use system vars to create time string
       'strDate = Date(_day)         ' use system vars to create date string
       Print #1, "Date : "; _Month;"/";_day;"/20";_year; "  Time : "; strTime
    endif
 Loop

'------[ Timer ISR routine ]----------------------------------------------------
T1_TickCounter_ISR:
    Incr lngTick                            ' inc event counter
    Toggle TickBit                          ' allow visual on scope
    booRTCupdate = true                     ' every tick, allow DS1307 RTC to read date/time
    Return
'------------------------------------------------------------------------------
 


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

Administrator



Joined: 09 Apr 2004
Posts: 5093
Location: Holland

blank.gif
PostPosted: Tue Apr 01, 2014 9:23 am    Post subject: Reply with quote

it is really simple. you are not using subs/functions.

have a look at the difference:

Code:
$regfile = "m2560def.dat"      ' specify the used micro
 Config SubMode = new

 $crystal = 16000000            ' used crystal frequency
 $baud = 115200                 ' use baud rate
 $hwstack = 200
 $swstack = 250
 $framesize = 1000
 $programmer=23                 ' Define programmer as ARDUINO V2 (using stk500v2 protocol)
 '$prog $fc,$c6,$df,$ff         ' Lock Bits, Fuse Bits Low, Fuse Bits High, Fuse Bits Extended
 '
 Const False = 0
 Const True = 1
 'address of ds1307
 Const Ds1307w = &HD0                     ' Addresses of Ds1307 clock
 Const Ds1307r = &HD1

 'dim other needed variables
 Dim Weekday As Byte
 Dim lngTick as long                     ' one second tick timer counter
 Dim booRTCupdate as boolean             ' Flag to allow event to occur
 Dim strTime As String * 8
 'Dim bytStatus as byte
 '
 'called from CONFIG CLOCK = USER
 Config Date = mdy , Separator = /        ' configure the date format
 config clock = user                      ' define USER clock, it dims date / time vars
                                          ' The USER must have the calls of settime, setdate, getdatetime
                                          ' to talk to the USER's hardware



 '
sub Getdatetime()
  'set PORTA.0
  I2cstart                                                  ' Generate start code
  I2cwbyte Ds1307w                                          ' send address
  I2cwbyte 0                                                ' start address in 1307
  I2cstart                                                  ' Generate start code
  I2cwbyte Ds1307r                                          ' send address
  I2crbyte _sec , Ack
  I2crbyte _min , Ack                                       ' MINUTES
  I2crbyte _hour , Ack                                      ' Hours
  I2crbyte Weekday , Ack                                    ' Day of Week
  I2crbyte _day , Ack                                       ' Day of Month
  I2crbyte _month , Ack                                     ' Month of Year
  I2crbyte _year , Nack                                     ' Year
  I2cstop
  _sec = Makedec(_sec) : _min = Makedec(_min) : _hour = Makedec(_hour)
  _day = Makedec(_day) : _month = Makedec(_month) : _year = Makedec(_year)
  'reset PORTA.0
end sub

sub Setdate()
  _day = Makebcd(_day) : _month = Makebcd(_month) : _year = Makebcd(_year)
  I2cstart                                                  ' Generate start code
  I2cwbyte Ds1307w                                          ' send address
  I2cwbyte 4                                                ' starting address in 1307
  I2cwbyte _day                                             ' Send Data to SECONDS
  I2cwbyte _month                                           ' MINUTES
  I2cwbyte _year                                            ' Hours
  I2cstop
end sub

sub Settime()
  _sec = Makebcd(_sec) : _min = Makebcd(_min) : _hour = Makebcd(_hour)
  I2cstart                                                  ' Generate start code
  I2cwbyte Ds1307w                                          ' send address
  I2cwbyte 0                                                ' starting address in 1307
  I2cwbyte _sec                                             ' Send Data to SECONDS
  I2cwbyte _min                                             ' MINUTES
  I2cwbyte _hour                                            ' Hours
  I2cstop
end sub

 $lib "i2c_twi.lbx"                       ' using hardware I2C/TWI

 Config Sda = Portd.1                     ' define pin names, scl and sda pins
 Config Scl = Portd.0
 Config Twi = 100000                      ' CONFIG TWI will ENABLE the TWI master interface, 100KHZ
 i2cinit                                  ' initialize the I2C bus

 '-----[ Output Timer ISR  for Oscilloscope Check on Porta.0 ]-----------------
 Config Porta.0 = Output                  '
 Porta.0 = 1                              ' LED off, active lo.
 TickBit Alias Porta.0
 '-----[ Setup Timer1 for Tick ISR off system XTAL]----------------------------
 ' Timer1 is used for Tick counter at 1Hz
 Config Timer1 = Timer , Prescale = 1024 , Compare A = Disconnect , Clear Timer = 1
 ' crytal   / prescale / x Hz    = Compare1a val needed
 ' 18432000 / 1024     / 100(Hz) = 180
 ' 16000000 / 1024     / 1(Hz) = 15625
 ' 14745600 / 1024     / 1(Hz) = 14400
 ' 14745600 / 1024     / 100(Hz) = 144
 ' 7372800 / 1024     / 100(Hz) = 72
 Compare1a = 15625
 On Compare1a T1_TickCounter_ISR          ' Define ISR Entry Point
 Enable Timer1
 Enable Compare1a
 '-----[Serial Port(s)]--------------------------------------------------------
 Config Com1 = 115200, Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
 Open "com1:" For Binary As #1
 Waitms 5
 '
 Enable Interrupts                       ' Using a timer to generate 1 second ISR interval

 Print #1, "DS1307"
 'Print #1, "Setting SQW bit on"
 'I2cstart                                                  ' Generate start code
 'I2cwbyte Ds1307w                                          ' send address
 'I2cwbyte 7                                                ' control register in 1307
 'I2crbyte bytStatus, Ack                                  ' read the status register first
 'print #1, "DS1307 READ-status register=$"; hex(bytStatus)
 'bytStatus = bytStatus and &h93                             ' pass only used bits
 'bytStatus = bytStatus or &h10                              ' set SQWout on
 'print #1, "DS1307 WRITE-status register=$"; hex(bytStatus)
 'I2cstart                                                  ' Generate start code
 'I2cwbyte Ds1307w                                          ' send address
 'I2cwbyte 7
 'I2cwbyte bytStatus                                        ' send to status register
 'I2cstop                                                   ' 32.768KHZ clock on SQWout pin of DS1307
 '
 ' Clear Vars
 '
 lngTick = 0
 booRTCupdate = false
 '
 Do                                 ' Main Loop
    if booRTCupdate = true then
       booRTCupdate = false
       call GetDateTime             ' read from RTC
       strTime = Time(_sec)         ' use system vars to create time string
       'strDate = Date(_day)         ' use system vars to create date string
       Print #1, "Date : "; _Month;"/";_day;"/20";_year; "  Time : "; strTime
    endif
 Loop

'------[ Timer ISR routine ]----------------------------------------------------
T1_TickCounter_ISR:
    Incr lngTick                            ' inc event counter
    Toggle TickBit                          ' allow visual on scope
    booRTCupdate = true                     ' every tick, allow DS1307 RTC to read date/time
    Return
 

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

Bascom Member



Joined: 30 Nov 2007
Posts: 303
Location: Delano, MN

usa.gif
PostPosted: Tue Apr 01, 2014 2:07 pm    Post subject: Reply with quote

Uggh, the joys of creating test examples....My DS1307.inc file is as you described.

I created another test code module with your code with subs defined as you made in the example above and compiled.

I still get an error of 111 on line 131 sub or function not declared [GETDATETIME] in .......path info......

I hope this isn't another silly mistake on my part. Not a newbie with BASCOM, but that was embarrassing.

It ONLY generates an error if you click on the check syntax(Ctl F7) icon. If you click on Compile Program(F7) icon, then NO ERROR is reported. I always check syntax first....Thus the problem here with your example.

Please advise.

Can you add the copy function to the Error output list box? Nice to copy that info at times.

Thanks Mark!

Regards,

Mark
Back to top
View user's profile
mmarlette

Bascom Member



Joined: 30 Nov 2007
Posts: 303
Location: Delano, MN

usa.gif
PostPosted: Tue Apr 01, 2014 2:21 pm    Post subject: Reply with quote

I went back to some code that I tried to port over the the CONFIG SUBMODE=NEW format before and gave up on due to so many errors with using the check syntax, never thought of trying to push the compile icon.

It compiled the first time using the Compile program icon after I made the adjustments as listed in the help file.

Using the check syntax button produces MANY errors on the same code..

So there is something different about these two buttons on how they compile the program.
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5093
Location: Holland

blank.gif
PostPosted: Tue Apr 01, 2014 8:46 pm    Post subject: Reply with quote

ok, you meant syntax check. that is indeed different. i fixed this problem some weeks ago. it was also reported on this forum. if you want you can download a beta from the SLA area (register.mcselec.com)
_________________
Mark
Back to top
View user's profile Visit poster's website
mmarlette

Bascom Member



Joined: 30 Nov 2007
Posts: 303
Location: Delano, MN

usa.gif
PostPosted: Tue Apr 01, 2014 11:36 pm    Post subject: Reply with quote

Mark-

I went and updated to the beta version and all is fine now.

I check the forums daily, several times a day but I missed the check syntax update.

I did see the single type lib update thread.

All good, thanks!!!!!
Back to top
View user's profile
mmarlette

Bascom Member



Joined: 30 Nov 2007
Posts: 303
Location: Delano, MN

usa.gif
PostPosted: Mon Dec 08, 2014 4:51 pm    Post subject: Reply with quote

Mark,

In your response code above, showing the config sub mode = new use of getdatetime, setdate and settime.

If I add this code prior to the main loop

Code:

lngTick = 0
 booRTCupdate = false
 date$ = "12/05/14"
 time$ = "14:00:00"
 


I get the errors on compile that setdate / settime labels are not found.

I even added labels to the subs but still errors.

Code:

sub Setdate
setdate:
  _day = Makebcd(_day) : _month = Makebcd(_month) : _year = Makebcd(_year)
  I2cstart                                                  ' Generate start code
  I2cwbyte Ds1307w                                          ' send address
  I2cwbyte 4                                                ' starting address in 1307
  I2cwbyte _day                                             ' Send Data to SECONDS
  I2cwbyte _month                                           ' MINUTES
  I2cwbyte _year                                            ' Hours
  I2cstop
  end sub

sub Settime
settime:
  _sec = Makebcd(_sec) : _min = Makebcd(_min) : _hour = Makebcd(_hour)
  I2cstart                                                  ' Generate start code
  I2cwbyte Ds1307w                                          ' send address
  I2cwbyte 0                                                ' starting address in 1307
  I2cwbyte _sec                                             ' Send Data to SECONDS
  I2cwbyte _min                                             ' MINUTES
  I2cwbyte _hour                                            ' Hours
  I2cstop
 end sub
 


The only way I can get this method to compile is to move the setdate / settime code to after the ISR label and remove the setdate / settime from being sub modules(IE: add label, remove sub / end sub, add return. GetDateTime of course is fine as the system doesn't call that routine, I do.

Please advise what the intended method is suppose to be or if I am trying to cross intentions of the compiler.

It appears that the compiler can't see the setdate / settime when the defined label is in a sub.

Regards,

Mark
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR 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