ВУЗ: Не указан
Категория: Не указан
Дисциплина: Не указана
Добавлен: 12.06.2025
Просмотров: 8168
Скачиваний: 1
© 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-
© MCS Electronics, 1995-2007
$XA
Action
Compiler directive to activate external memory access.
CONFIG XRAM should be used instead.
Syntax
$XA
Remarks
The $XA directive can be used to override the Compiler Chip Options setting.
This way you can store the setting in your program code. It is strongly advised to do this.
See also
$WAITSTATE , CONFIG XRAM
Example
$XA
$XRAMSIZE
Action
Specifies the size of the external RAM memory.
Syntax
$XRAMSIZE = [&H] size
Remarks
Size |
A constant with the size of the external RAM memory chip. |
The size of the chip can be selected from the Options Compiler Chip menu.
The $XRAMSIZE overrides this setting. It is important that $XRAMSTART precedes $XRAMSIZE
See also
$XRAMSTART
Example
'----------------------------------------------------------------------------- |
|
------------ |
: m128.bas |
'name |
|
'copyright |
: (c) 1995-2005, MCS Electronics |
'purpose |
: demonstrate using $XRAM directive |
page -252- |
© MCS Electronics, 1995-2007 |
|
'micro |
: Mega128 |
'suited for demo |
: yes |
'commercial addon needed |
: no |
'-----------------------------------------------------------------------------
------------
$regfile = "m128def.dat" |
' specify the used |
micro |
' used crystal |
$crystal = 1000000 |
|
frequency |
' default use 32 |
$hwstack = 32 |
|
for the hardware stack |
' default use 10 |
$swstack = 10 |
|
for the SW stack |
' default use 40 |
$framesize = 40 |
|
for the frame space |
|
$xramstart = &H1000 |
|
$xramsize = &H1000 |
|
Dim X As X |
$XRAMSTART
Action
Specifies the location of the external RAM memory.
Syntax
$XRAMSTART = [&H]address
Remarks
Address |
The (hex)-address where the data is stored. |
Or the lowest address that enables the RAM chip. |
|
You can use this option when you want to run your code in systems with |
|
external RAM memory. Address must be a constant. |
|
By default the extended RAM will start after the internal memory so the lower addresses of the external RAM can't be used to store information.
When you want to protect an area of the chip, you can specify a higher address for the compiler to store the data. For example, you can specify &H400. The first dimensioned variable will be placed in address &H400 and not in &H260.
It is important that when you use $XRAMSTART and $XRAMSIZE that $XRAMSTART comes before $XRAMSIZE.
See also
$XRAMSIZE
Example
'-----------------------------------------------------------------------------
page -253-
© MCS Electronics, 1995-2007 |
|
------------ |
: m128.bas |
'name |
|
'copyright |
: (c) 1995-2005, MCS Electronics |
'purpose |
: demonstrate using $XRAM directive |
'micro |
: Mega128 |
'suited for demo |
: yes |
'commercial addon needed |
: no |
'-----------------------------------------------------------------------------
------------
$regfile = "m128def.dat" |
' specify the used |
micro |
' used crystal |
$crystal = 1000000 |
|
frequency |
' default use 32 |
$hwstack = 32 |
|
for the hardware stack |
' default use 10 |
$swstack = 10 |
|
for the SW stack |
' default use 40 |
$framesize = 40 |
|
for the frame space |
|
$xramstart = &H1000 |
|
$xramsize = &H1000 |
|
Dim X As X |
1WIRECOUNT
Action
This statement reads the number of 1wire devices attached to the bus.
Syntax
var2 = 1WIRECOUNT()
var2 = 1WIRECOUNT( port , pin)
Remarks
var2 |
A WORD variable that is assigned with the number of devices on the bus. |
port |
The PIN port name like PINB or PIND. |
pin |
The pin number of the port. In the range from 0-7. May be a numeric |
constant or variable. |
|
The variable must be of the type word or integer.
You can use the 1wirecount() function to know how many times the 1wsearchNext() function should be called to get all the Id's on the bus.
The 1wirecount function will take 4 bytes of SRAM.
___1w_bitstorage , Byte used for bit storage : lastdeviceflag bit 0
id_bit bit 1 cmp_id_bit bit 2 search_dir bit 3
___1wid_bit_number, Byte
___1wlast_zero, Byte
page -254-
© MCS Electronics, 1995-2007
___1wlast_discrepancy , Byte
ASM
The following asm routines are called from mcs.lib.
_1wire_Count : (calls _1WIRE, _1WIRE_SEARCH_FIRST , _1WIRE_SEARCH_NEXT)
Parameters passed : R24 : pin number, R30 : port , Y+0,Y+1 : 2 bytes of soft stack, X : pointer to the frame space
Returns Y+0 and Y+1 with the value of the count. This is assigned to the target variable.
See also
1WWRITE , 1WRESET , 1WREAD , 1WSEARCHFIRST, 1WSEARCHNEXT , Using the 1wire protocol
Example
'----------------------------------------------------------------------------- |
|
--- |
: 1wireSearch.bas |
'name |
|
'copyright |
: (c) 1995-2005, MCS Electronics |
'purpose |
: demonstrates 1wsearch |
'micro |
: Mega48 |
'suited for demo |
: yes |
'commercial addon needed |
: no |
'----------------------------------------------------------------------------- |
|
--- |
|
$regfile = "m48def.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 |
|
Config 1wire = Portb.0 |
'use this pin |
'On the STK200 jumper B.0 |
must be inserted |
'The following internal bytes are used by the scan routines '___1w_bitstorage , Byte used for bit storage :
'lastdeviceflag bit 0
' |
id_bit |
bit |
1 |
|
' |
cmp_id_bit |
bit |
2 |
|
' |
search_dir |
bit |
3 |
|
'___1wid_bit_number, Byte |
||||
'___1wlast_zero, Byte |
||||
'___1wlast_discrepancy , Byte |
||||
'___1wire_data , string * |
7 |
(8 bytes) |
||
'[DIM variables used]
'we need some space from at least 8 bytes to store the ID
Dim Reg_no(8) As Byte
page -255-