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

© MCS Electronics, 1995-2007

'this label is called when the master receives data and needs a byte

'the variable twi_btr is a byte variable that holds the index of the needed byte 'so when sending multiple bytes from an array, twi_btr can be used for the index Twi_master_needs_byte:

'Print "Master needs byte : " ; Twi_btr

 

Select Case Twi_btr

'firstbyte

Case 1:

W= Getadc(0)

'in this example the conversion is done here

' but a better option would have been to just pass the value of W and do the conversion in the main

loop

 

Twi= Low(w)

' send second byte

Case 2

Twi= High(w)

 

End Select

 

Return

 

'when the mast has all bytes received this label will be called Twi_master_need_nomore_byte:

' Print "Master does not need anymore bytes"

Return

CONFIG WAITSUART

Action

Compiler directive that specifies that software UART waits after sending the last byte.

Syntax

CONFIG WAITSUART = value

Remarks

value

A numeric value in the range of 1-255.

 

A higher value means a longer delay in mS.

 

 

When the software UART routine are used in combination with serial LCD displays it can be convenient to specify a delay so the display can process the data.

See also

OPEN

Example

See OPEN example for more details.

CONFIG WATCHDOG

Action

Configures the watchdog timer.

page -399-

© MCS Electronics, 1995-2007

Syntax

CONFIG WATCHDOG = time

Remarks

Time

The interval constant in mS the watchdog timer will count to before it

 

will reset your program.

Possible settings :

16 , 32, 64 , 128 , 256 , 512 , 1024 and 2048. Some chips : 4098, 8192.

Note that some new AVR's might have additional reset values such as 4098 and 8192.

When the WD is started, a reset will occur after the specified number of mS.

With 2048, a reset will occur after 2 seconds, so you need to reset the WD in your programs periodically with the RESET WATCHDOG statement.

Some AVR's might have the WD timer enabled by default. You can change this with the Fuse Bits.

See also

START WATCHDOG , STOP WATCHDOG , RESET WATCHDOG

Example

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

 

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

: watchd.bas

'name

'copyright

: (c) 1995-2005, MCS Electronics

'purpose

: demonstrates the watchdog timer

'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 Watchdog = 2048

'reset after 2048

mSec

'start the

Start Watchdog

watchdog timer

 

Dim I As Word

 

For I = 1 To 1000

 

Print I

'print value

page -400-

© MCS Electronics, 1995-2007

'Reset Watchdog

'you will notice that the for next doesnt finish because of the reset 'when you unmark the RESET WATCHDOG statement it will finish because the 'wd-timer is reset before it reaches 2048 msec

Next

End

CONFIG X10

Action

Configures the pins used for X10.

Syntax

CONFIG X10 = pinZC , TX = portpin

Remarks

PinZC

The pin that is connected to the zero cross output of the TW-523. This si a

 

pin that will be used as INPUT.

Portpin

The pin that is connected to the TX pin of the Tw-523.

 

TX is used to send X10 data to the TW-523. This pin will be used in output

 

mode.

 

 

The TW-523 RJ-11 connector has the following pinout:

Pin

 

Description

Connect to micro

 

1

 

Zero Cross

Input pin. Add 5.1K pull up.

 

2

 

GND

GND

 

3

 

RX

Not used.

 

4

 

TX

Output pin. Add 1K pull up.

 

 

 

 

 

 

See also

X10DETECT , X10SEND

Example

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

 

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

: x10.bas

'name

'copyright

: (c) 1995-2005, MCS Electronics

'purpose

: example needs a TW-523 X10 interface

'micro

: Mega48

'suited for demo

: yes

'commercial addon needed

: no

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

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

$regfile = "m48def.dat"

' specify the used

micro

' used crystal

$crystal = 8000000

frequency

' use baud rate

$baud = 19200

 

page -401-

^--- transmission pin

© MCS Electronics, 1995-2007

$hwstack = 32

for the hardware stack $swstack = 10

for the SW stack $framesize = 40

for the frame space

'define the house code Const House = "M"

Waitms 500

not really needed

'dim the used variables

Dim X As Byte

'configure the zero cross pin and TX pin Config X10 = Pind.4 , Tx = Portb.0

'^--zero cross

'

'detect the TW-523 X = X10detect() Print X

means 50 Hz, 2 means 60 Hz

Do

Input "Send (1-32) " , X 'enter a key code from 1-31 '1-16 to address a unit '17 all units off

'18 all lights on '19 ON

'20 OFF

'21 DIM '22 BRIGHT

'23 All lights off '24 extended code '25 hail request '26 hail acknowledge '27 preset dim

'28 preset dim

'29 extended data analog '30 status on

'31 status off '32 status request

X10send House , X

Loop

Dim Ar(4) As Byte

X10send House , X , Ar(1) , 4 additional bytes

End

'default use 32

'default use 10

'default use 40

'use code A-P

'optional delay

' 0 means error, 1

'send the code

'send 4

CONFIG XRAM

Action

Instruct the compiler to set options for external memory access.

page -402-