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

© MCS Electronics, 1995-2007

Syntax

$SWSTACK = var

Remarks

Var A numeric decimal value.

While you can configure the SW Stack in Options, Compiler, Chip, it is good practice to put the value into your code. This way you do no need the cfg(configuration) file.

The $SWSTACK directive overrides the value from the IDE Options.

It is important that the $SWSTACK directive occurs in your main project file. It may not be included in an $include file as only the main file is parsed for $SWSTACK

See also

$HWSTACK , $FRAMESIZE

Example

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

 

---

: adc.bas

'name

'copyright

: (c) 1995-2005, MCS Electronics

'purpose

: demonstration of GETADC() function for 8535 or

M163 micro

: Mega163

'micro

'suited for demo

: yes

'commercial addon needed

: no

'use in simulator

: possible

' Getadc() will also work for other AVR chips that have an ADC converter

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

 

---

' we use the M163

$regfile = "m163def.dat"

$crystal = 4000000

 

$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

 

$TIMEOUT

Action

Enable timeout on the hardware UART 0 and UART1.

Syntax

$TIMEOUT = value

page -248-

© MCS Electronics, 1995-2007

Remarks

Value A constant that fits into a LONG , indicating how much time must be waited before the waiting is terminated.

All RS-232 serial statements and functions(except INKEY) that use the HW UART, will halt the program until a character is received. Only with buffered serial input you can process your main program while the buffer received data on the background.

$TIMEOUT is an alternative for normal serial reception. It is not intended to be used with buffered serial reception.

When you assign a constant to $TIMEOUT, you actual assign a value to the internal created value named ___TIMEOUT.

This value will be decremented in the routine that waits for serial data. When it reaches zero, it will terminate.

So the bigger the value, the longer the wait time before the timeout occurs. The timeout is not in seconds or microseconds, it is a relative number. Only the speed of the oscillator has effect on the duration. And the value of the number of course.

When the time out is reached, a zero/null will be returned to the calling routine. Waitkey() will return 0 when used with a byte. When you use INPUT with a string, the timeout will be set for every character. So when 5 characters are expected, and they arrive just before the timeout value is reached, it may take a long time until the code is executed.

When the timeout occurs on the first character, it will return much faster.

When you already sent data, this data will be returned. For example, "123" was sent but a RETURN was never sent, INPUT will return "123". While without the $TIMEOUT, INPUT will not return until a RETURN is received.

When you activate $TIMEOUT, and your micro has two UARTS(Mega128 for example) it will be active for both UART0 and UART1.

See Also

INPUT , WAITKEY

Example

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

 

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

: timeout.bas

'name

'copyright

: (c) 1995-2005, MCS Electronics

'purpose

: demonstration of the $timeout option

'micro

: Mega48

'suited for demo

: yes

'commercial addon needed

: no

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

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

$regfile = "m48def.dat"

' specify the used

micro

' used crystal

$crystal = 8000000

frequency

 

page -249-

 

© MCS Electronics, 1995-2007

$baud = 19200

' use baud rate

$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

 

'most serial communication functions and routines wait until a character 'or end of line is received.

'This blocks execution of your program. SOmething you can change by using buffered input

'There is also another option : using a timeout '$timeout Does Not Work With Buffered Serial Input

Dim Sname As String * 10

Dim B As Byte

Do

$timeout = 1000000

Input "Name : " , Sname

Print "Hello " ; Sname

$timeout = 5000000

Input "Name : " , Sname Print "Hello " ; Sname

Loop

'you can re-configure $timeout

$TINY

Action

Instruct the compiler to generate initialize code without setting up the stacks.

Syntax

$TINY

Remarks

The tiny11 for example is a powerful chip. It only does not have SRAM. BASCOM depends on SRAM for the hardware stack and software stack.

When you like to program in ASM you can use BASCOM with the $TINY directive.

Some BASCOM statements will also already work but the biggest part wil not work.

A future version will support a subset of the BASCOM statements and function to be used with the chips without SRAM.

Note that the generated code is not yet optimized for the tiny parts. Some used ASM statements for example will not work because the chip does not support it.

See also

NONE

page -250-

© MCS Electronics, 1995-2007

ASM

NONE

Example

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

 

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

: tiny15.bas

'name

'copyright

: (c) 1995-2005, MCS Electronics

'purpose

: demonstrate using ATtiny15

'micro

: Tiny15

'suited for demo

: yes

'commercial addon needed

: no

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

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

$regfile = "at15def.dat"

' specify the used

micro

' used crystal

$crystal = 1000000

frequency

 

$tiny

 

$noramclear

 

Dim A As Iram Byte

 

Dim B As Iram Byte

 

A = 100 : B = 5

 

A = A + B

 

nop

 

$WAITSTATE

Action

Compiler directive to activate external SRAM and to insert a WAIT STATE for a slower ALE signal.

CONFIG XRAM should be used instead.

Syntax

$WAITSTATE

Remarks

The $WAITSTATE can be used to override the Compiler Chip Options setting.

Wait states are needed for slow external components that can not handle the fast ALE signal from the AVR chip.

See also

$XA , CONFIG XRAM

Example

$WAITSTATE

page -251-