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

© 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-