© MCS Electronics, 1995-2007
End If
Case 3
Mday = 31
Case 4
Mday = 30
Case 5
Mday = 31
Case 6
Mday = 30
Case 7
Mday = 31
Case 8
Mday = 31
Case 9
Mday = 30
Case 10
Mday = 31
Case 11
Mday = 30
Case 12
Mday = 31
End Select
If _day > Mday Then
_day = _day - Mday
Incr _month
If _month > 12 Then
_month = 1
Incr _year
End If
End If
End If
If _year > 99 Then
Exit Do
End If
Lsecofday = Secofday()
Lsyssec = Syssec()
Bweekday = Dayofweek()
Wdayofyear = Dayofyear()
Wsysday = Sysday()
Print Time$ ; " " ; Date$ ; " " ; Lsecofday ; " " ; Lsyssec ; " " ; Bweekday ;
" " ; Wdayofyear ; " " ; Wsysday
Loop
End
'only when we use I2C for the clock we need to set the clock date time
#if Clockmode = 0 |
|
'called from datetime.lib |
|
Dim Weekday As Byte |
|
Getdatetime: |
' Generate start |
I2cstart |
code |
' send address |
I2cwbyte Ds1307w |
I2cwbyte 0 |
' start address in |
1307 |
|
I2cstart |
' Generate start |
code |
' send address |
I2cwbyte Ds1307r |
I2crbyte _sec , Ack |
|
|
© MCS Electronics, 1995-2007 |
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)
Return
Setdate:
_day = Makebcd(_day) : _month = Makebcd(_month) : _year = Makebcd(_year)
I2cstart |
' Generate start |
code |
' send address |
I2cwbyte Ds1307w |
I2cwbyte 4 |
' starting address |
in 1307 |
' Send Data to |
I2cwbyte _day |
SECONDS |
' MINUTES |
I2cwbyte _month |
I2cwbyte _year |
' Hours |
I2cstop |
|
Return |
|
Settime:
_sec = Makebcd(_sec) : _min = Makebcd(_min) : _hour = Makebcd(_hour)
I2cstart |
' Generate start |
code |
' send address |
I2cwbyte Ds1307w |
I2cwbyte 0 |
' starting address |
in 1307 |
' Send Data to |
I2cwbyte _sec |
SECONDS |
' MINUTES |
I2cwbyte _min |
I2cwbyte _hour |
' Hours |
I2cstop |
|
Return |
|
#endif |
|
Weekdays:
Data "Monday" , "Tuesday" , "Wednesday" , "Thursday" , "Friday" , "Saturday" ,
"Sunday"
DBG
Action
Prints debug info to the hardware UART
Syntax
DBG
Remarks
See $DBG for more information
© MCS Electronics, 1995-2007
DEBUG
Action
Instruct compiler to start or stop debugging, or print variable to serial port
Syntax
DEBUG ON | OFF | var
Remarks
ON |
Enable debugging |
OFF |
Disable debugging |
var |
A variable which values must be printed to the serial port |
|
|
During development of your program a common issue is that you need to know the value of a variable.
You can use PRINT to print the value but then it will be in the application as well. You can use conditional compilation such as :
CONST TEST=1 #IF TEST
print var #ENDIF
But that will result in a lot of typing work. The DEBUG option is a combination of conditional compilation and PRINT. Whenever you activate DEBUG with the ON parameter, all 'DEBUG var' statements will be compiled.
When you turn DEBUG OFF, all 'DEBUG var' statements will not be compiled.
You can not nest the ON and OFF. The last statements wins.
Typical you will have only one DEBUG ON statement. And you set it to OFF when your program is working.
An example showing nesting is NOT supported:
DEBUG ON
DEBUG ON ' it is still ON
DEBUG OFF' it is OFF now
An example showing multiple DEBUG:
DEBUG ON
DEBUG var ' this is printed
DEBUG var2 ' this is also printed
DEBUG OFF
DEBUG var3 'this is NOT printed
DEBUG var4 ' this is not printed
DEBUG ON ' turn DEBUG ON
If A = 2 Then
DEBUG A ' this is printed
End If
© MCS Electronics, 1995-2007
See also
DBG
ASM
NONE
Example
DEBUG ON
Dim A As Byte
DEBUG A
End
DEBOUNCE
Action
Debounce a port pin connected to a switch.
Syntax
DEBOUNCE Px.y , state , label [ , SUB]
Remarks
Px.y |
A port pin like PINB.0 , to examine. |
State |
0 for jumping when PINx.y is low , 1 for jumping when PINx.y is high |
Label |
The label to GOTO when the specified state is detected |
SUB |
The label to GOSUB when the specified state is detected |
|
|
When you specify the optional parameter SUB, a GOSUB to label is performed instead of a GOTO.
The DEBOUNCE statement tests the condition of the specified pin and if true there willbe a delay for 25 mS and the condition will be checked again. (eliminating bounce of a switch)
When the condition is still true and there was no branch before, it branches to specified the label.
When the condition is not true, or the logic level on the pin is not of the specified evel, the code on the next line will be executed.
When DEBOUNCE is executed again, the state of the switch must have gone back in the original position before it can perform another branch. So if you are waiting for a pin to go low, and the pin goes low, the pin must change to high, before a new low level will result in another branch.
Each DEBOUNCE statement, which uses a different port, uses 1 BIT of the internal memory to hold its state. And as the bits are stored in SRAM, it means that even while you use only 1 pin/bit, a byte is used for storage of the bit.
DEBOUNCE will not wait for the input value to met the specified condition. You need to use BITWAIT if you want to wait until a bit will have a certain value.
page -445-
© MCS Electronics, 1995-2007
So DEBOUNCE will not halt your program while a BITWAIT can halt your program if the bit will never have the specified value. You can combine BITWAIT and DEBOUNCE statements by preceding a DEBOUNCE with a BITWAIT statement.
See also
CONFIG DEBOUNCE , BITWAIT
Example
'----------------------------------------------------------------------------- |
|
------------ |
: deboun.bas |
'name |
'copyright |
: (c) 1995-2005, MCS Electronics |
'purpose |
: demonstrates DEBOUNCE |
'micro |
: Mega48 |
'suited for demo |
: yes |
'commercial addon needed |
: no |
'-----------------------------------------------------------------------------
------------
$regfile = "m48def.dat" |
' specify the used |
micro |
' used crystal |
$crystal = 4000000 |
frequency |
' use baud rate |
$baud = 19200 |
$hwstack = 32 |
' default use 32 |
for the hardware stack |
' default use 10 |
$swstack = 10 |
for the SW stack |
' default use 40 |
$framesize = 40 |
for the frame space |
|
Config Debounce = 30 |
'when the config |
statement is not used a default of 25mS will be used but we override to use 30 mS
'Debounce Pind.0 , 1 , Pr 'try this for branching when high(1) Debounce Pind.0 , 0 , Pr , Sub
Debounce Pind.0 , 0 , Pr , Sub
' |
|
^----- |
label to branch to |
' |
^ |
^---------- |
Branch when P1.0 goes low(0) |
' |
|
Examine P1.0 |
'When Pind.0 goes low jump to subroutine Pr 'Pind.0 must go high again before it jumps again 'to the label Pr when Pind.0 is low
Debounce Pind.0 , 1 , Pr |
'no branch |
Debounce Pind.0 , 1 , Pr |
'will result in a |
return without gosub |
|
End |
|
Pr: |
|
Print "PIND.0 was/is low" |
|
Return |
|