Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
BASCOM AVR, help reference (2007).PDF
Скачиваний:
305
Добавлен:
12.08.2013
Размер:
17.02 Mб
Скачать

© MCS Electronics, 1995-2007

Do

Incr Tel

Print Tel;" test serial port 1"

Print#1 ,Tel;" test serial port 2"

Print#2 ,Tel;" test serial port 3"

Print#3 ,Tel;" test serial port 4"

B= Inkey(#3)

IfB <> 0Then

Print#3 ,B ;" from port 4"

End If

Waitms 500

Loop

Close#1

Close#2

Close#3

End

CONFIG DATE

Action

Configure the Format of the Date String for Input to and Output fromBASCOM – Date functions

Syntax

CONFIG DATE = DMY , Separator = char

Remarks

DMY

The Day, month and year order. Use DMY, MDY or YMD.

Char

A character used to separate the day, month and year.

 

Use / , - or . (dot)

 

 

The following table shows the common formats of date and the associated statements.

Country

Format

Statement

American

mm/dd/yy

Config Date = MDY, Separator = /

 

 

 

ANSI

yy.mm.dd

Config Date = YMD, Separator = .

Britisch/French

dd/mm/yy

Config Date = DMY, Separator = /

German

dd.mm.yy

Config Date = DMY, Separator = .

Italian

dd-mm-yy

Config Date = DMY, Separator = -

Japan/Taiwan

yy/mm/dd

Config Date = YMD, Separator = /

USA

mm-dd-yy

Config Date = MDY, Separator = -

 

 

 

When you live in Holland you would use :

CONFIG DATE = DMY, separator = -

This would print 24-04-02 for 24 November 2002.

page -330-

© MCS Electronics, 1995-2007

When you line in the US, you would use :

CONFIG DATE = MDY , separator = /

This would print 04/24/02 for 24 November 2002.

See also

CONFIG CLOCK , DATE TIME functions , DayOfWeek , DayOfYear , SecOfDay , SecElapsed , SysDay , SysSec , SysSecElapsed , Time , Date

Example

'-----------------------------------------------------------------------------

 

------------

: megaclock.bas

'name

'copyright

: (c) 1995-2005, MCS Electronics

'purpose

: shows the new TIME$ and DATE$ reserved variables

'micro

: Mega103

'suited for demo

: yes

'commercial addon needed

: no

'-----------------------------------------------------------------------------

------------

$regfile = "m103def.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

 

'With the 8535 and timer2 or the Mega103 and TIMER0 you can 'easily implement a clock by attaching a 32768 Hz xtal to the timer 'And of course some BASCOM code

'This example is written for the STK300 with M103

Enable Interrupts

'[configure LCD]

'address for E and

$lcd = &HC000

RS

'address for only

$lcdrs = &H8000

E

'nice display from

Config Lcd = 20 * 4

bg micro

'we run it in bus

Config Lcdbus = 4

mode and I hooked up only db4-db7

'tell about the

Config Lcdmode = Bus

bus mode

 

'[now init the clock]

' ANSI-Format

Config Date = Mdy , Separator = /

Config Clock = Soft

'this is how

simple it is

'The above statement will bind in an ISR so you can not use the TIMER anymore! 'For the M103 in this case it means that TIMER0 can not be used by the user anymore

'assign the date to the reserved date$

page -331-

© MCS Electronics, 1995-2007

'The format is MM/DD/YY Date$ = "11/11/00"

'assign the time, format in hh:mm:ss military format(24 hours)

'You may not use 1:2:3 !! adding support for this would mean overhead 'But of course you can alter the library routines used

Time$ = "02:20:00"

 

'---------------------------------------------------

 

'clear the LCD display

 

Cls

 

Do

'cursor home

Home

Lcd Date$ ; " " ; Time$

'show the date and

time

 

Loop

 

'The clock routine does use the following internal variables: '_day , _month, _year , _sec, _hour, _min

'These are all bytes. You can assign or use them directly _day = 1

'For the _year variable only the year is stored, not the century

End

CONFIG DCF77

Action

Instruct the compiler to use DCF-77 radio signal to get atom clock precision time

Syntax

CONFIG DCF77 = pin , timer = timer [ INVERTED=inv, CHECK=check, UPDATE=upd, UPDATETIME=updtime , TIMER1SEC=tmr1sec, SWITCHPOWER=swpwr, POWERPIN=pin, POWERLEVEL = pwrlvl , SECONDTICKS=sectick ,DEBUG=dbg ]

Remarks

PIN

The input pin that is connected to the DCF-77 signal

TIMER

The timer that is used to generate the compare interrupts, needed to

 

determine the level of the DCF signal.

INVERTED

CHECK

This value is 0 by default. When you specify 1, the compiler will assume you use an inverted DCF signal. Most DCF-77 receivers have a normal output and an inverted output.

Check is 1 by default. The possible values are :

0 - The DCF-77 parity bits are checked. No other checks are performed.

Use it when you have exceptional signal strength

1 - The received minutes are compared with the previous received minutes. And the difference must be 1.

2 - All received values(minutes, hours, etc. ) are compared with their previous received values. Only the minutes must differ with 1, the other values must be exactly the same.

This value uses more internal ram but it gives the best check. Use this when you have bad signal reception.

page -332-

© MCS Electronics, 1995-2007

UPDATE

Upd determines how often the internal date/time variables are updated with the DCF received values. The default value is 0.

There are 3 possible values :

0 - Continuous update. The date and time variables are updated every time the correct values have been received

1 - Hourly update. The date and time variables are updated once an hour.

2- Daily update. The date and time variables are updated once a day. The UPDATE value also determines the maximum value of the UPDATETIME option.

UPDATETIME

This value depends on the used UPDATE parameter.

 

When UPDATE is 1, the value must be in the range from 0-23.

 

When UPDATE is 2, the value must be in the range from 0-59.

 

The default .

TIMER1SEC

16 bit timers with the right crystal value can generate a precise

 

interrupt that fires every second. This can be used to synchronize only

 

once a day or hour with the DCF values. The remaining time, the 1-sec

 

interrupt will update the soft clock. By default this value is 0.

SWITCHPOWER

POWERPIN

This option can be used to turn on/off the DCF-77 module with the control of a port pin. The default is 0. When you specify a value of 1, the DCF receiver will be switched off to save power, as soon as the clock is synchronized.

The name of a pin like pinB.2 that will be used to turn on/off the DCF module.

POWERLEVEL This option controls the level of the output pin that will result in a power ON for the module.

0 - When a logic 0 is applied to the power pin, the module is ON. 1 - When a logic 1 is applied to the power pin, the module is ON.

Use a transistor to power the module. Do not power it froma port PIN directly. When you do power from a pin, make sure you sink the current. Ie : connect VCC to module, and GND of the module to ground. A logic 0 will then turn on the module.

SECONDTICKS

DEBUG

The number of times that the DCF signal state is read. This is the number of times per second that the interrupt is executed. This value is calculated by the compiler. The highest possible timer pre scale value is used and the lowest possible number of times that the interrupt is executed. This gives least impact on your main application. You can override the value by defining your own value. For example when you want to run some own code in the interrupt and need it to execute more often.

Optional value to fill 2 variables with debug info. DEBUG is on when a value of 1 is specified. By default, DEBUG is off. This has nothing to do with other DEBUG options of the compiler, it is only for the DCF77 code!

When 1 is specified the compiler will create 2 internal variable named : bDCF_Pause and bDCF_Impuls. These values contain the DCF pulse length of the pause and the impulse. In the sample these values are printed.

The DCF decoding routines use a status byte. This byte can be examined as in the example. The bits have the following meaning.

Bit Explanation

0The last reading of the DCF pin.

1This bit is reserved.

2This Bit is set, if after a complete time-stamp at second 58 the time-stamp is checked and it is OK. If after a minute mark (2 sec pause) this bit is set, the time from the DCF-Part is copied to the Clock-Part and this bit reset too. Every second mark also

page -333-

© MCS Electronics, 1995-2007

resets this bit. So time is only set, if after second 58 a minute mark follows. Normally this bit is only at value 1 from Second 58 to second 60/00.

3This Bit indicates, that the DCF-Part should be stopped, if time is set. (at the option of updating once per hour or day).

4This Bit indicated that the DCF-Part is stopped.

5This bit indicates, that the CLOCK is configured the way, that during DCF-Clock is stopped, there is only one ISR-Call in one second.

6This Bit determines the level of the DCF input-pin at the pulse (100/200 mSec part).

7This bit indicates, that the DCF-Part has set the time of the Clock-part.

You can read the Status-Bit 7 (DCF_Status.7), to check whether the internal clock was synchronized by the DCF-Part. You can also reset this Bit with RESET DCF_Status.7. The DCF-Part will set this bit again, if a valid time-stamp is received.

You can read all other bits, but don’t change them.

The DCF-77 signal is broadcasted by the German Time and Frequency department. The following information is copied from : http://www.ptb.de/en/org/4/44/_index.htm

The main task of the department time and frequency is the realization and dissemination of the base unit time (second) and the dissemination of the legal time in the Federal Republic of Germany.

The second is defined as the duration of 9 192 631 770 periods of the radiation corresponding to the transition between the two hyperfine levels of the ground state of the caesium-133 atom.

For the realization and dissemination of the unit of time, the department develops and operates caesium atomic clocks as primary standards of time and frequency. In the past decades, these, as the worldwide most accurate atomic clocks, have contributed to the international atomic time scale (TAI) and represent the basis for the legal time in Germany. Dissemination of the legal time to the various users in industry, society, and research is performed via satellite, via a low frequency transmitter DCF77 and via an internetand telephone service.

The department participates in the tests for the future European satellite navigation system „Gallileo“.

Presently the primary clocks realizing the time unit are augmented by Cs clocks with laser cooled atoms („Cs-fountain clocks“) whose accuracy presently exceeds the clocks with thermal beams by a factor of 10 (frequency uncertainty of 1 . 10-15).

Future atomic clocks will most likely be based on atomic transitions in the optical range of single stored ions. Such standards are presently being developed along with the means to relate their optical frequencies without errors to radio-frequencies or 1 second pulsed.

As one may expect transitions in nuclei of atoms to be better shielded from environmental perturbations than electron-shell transitions which have been used so far as atomic clock references, the department attempts to use an optical transition in the nucleus of 229Th for a future generation of atomic clocks.

The work of the department is complemented by research in nonlinear optics (Solitons) and precision time transfer techniques, funded in the frame of several European projects and by national funding by Deutsche Forschungsgemeinschaft particularly in the frame of Sonderforschungsbereich 407 jointly with Hannover University.

The following information is copied from wikipedia : http://en.wikipedia.org/wiki/DCF77

page -334-

© MCS Electronics, 1995-2007

The signal can be received in this area:

DCF77 is a longwave time signal and standard-frequency radio station. Its primary and backup transmitter are located in Mainflingen, about 25 km south-east of Frankfurt, Germany. It is operated by T-Systems Media Broadcast, a subsidiary of Deutsche Telekom AG, on behalf of the Physikalisch-Technische Bundesanstalt, Germany's national physics laboratory. DCF77 has been in service as a standard-frequency station since 1959; date and time information was added in 1973.

The 77.5 kHz carrier signal is generated from local atomic clocks that are linked with the German master clocks in Braunschweig. With a relatively-high power of 50 kW, the station can be received in large parts of Europe, as far as 2000 km from Frankfurt. Its signal carries an amplitude-modulated, pulse-width coded 1 bit/s data signal. The same data signal is also phase modulated onto the carrier using a 511-bit long pseudorandomsequence (direct-sequence spread spectrum modulation). The transmitted data repeats each minute Map showing the range of the DCF77 signal.

Map showing the range of the DCF77 signal.

*the current date and time;

*a leap second warning bit;

*a summer time bit;

*a primary/backup transmitter identification bit;

*several parity bits.

Since 2003, 14 previously unused bits of the time code have been used for civil defence emergency signals. This is still an experimental service, aimed to replace one day the German network of civil defense sirens.

The callsign stands for D=Deutschland (Germany), C=long wave signal, F=Frankfurt, 77=frequency: 77.5 kHz. It is transmitted three times per hour in morse code.

Radio clocks have been very popular in Europe since the late 1980s and most of them use the DCF77 signal to set their time automatically.

For further reference see wikipedia, a great on line information resource.

The DCF library parameters state diagram looks as following:

page -335-

© MCS Electronics, 1995-2007

page -336-

© MCS Electronics, 1995-2007

See also

CONFIG DATE

ASM

_DCF77 from DCF77.LBX is included by the compiler when you use the CONFIG statement.

Example

$regfile = "M88def.dat" $crystal = 8000000

$hwstack = 128 $swstack = 128 $framesize = 128

$baud = 19200

'Config Dcf77 = Pind.2 , Debug = 1 , Inverted = 0 , Check = 2 , Update = 0 , Updatetime = 30 , Switchpower = 0 , Secondticks = 50 , Timer1sec = 1 , Powerlevel = 1 , Timer = 1

Config Dcf77 = Pind.2 , Timer = 1 , Timer1sec = 1 , Debug = 1

Enable Interrupts

Config Date = Dmy , Separator = .

Dim I As Integer

Dim Sec_old As Byte , Dcfsec_old As Byte

Sec_old = 99 : Dcfsec_old = 99

': DCF_Debug_Timer

= 0

 

' Testroutine für die DCF77 Clock

Print "Test DCF77 Version 1.00"

Do

For I = 1 To 78

Waitms 10

If Sec_old <> _sec Then

Exit For End If

If Dcfsec_old <> Dcf_sec Then

Exit For End If

Next Waitms 220

Sec_old = _sec Dcfsec_old = Dcf_sec

Print Time$ ; " " ; Date$ ; " " ; Time(dcf_sec) ; " " ; Date(dcf_day) ; " " ; Bin(dcf_status) ; " " ; Bin(dcf_bits) ; " " ; Bdcf_impuls ; " " ; Bdcf_pause

Loop

End

CONFIG DATE

page -337-