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

© MCS Electronics, 1995-2007

You do not need to use OUT when setting a port variable. Port variables and other registers of the micro can be set like this : PORTB = value , where PORTB is the name of the register.

See also

INP , PEEK , POKE

Example

Out &H8000 , 1 'send 1 to the databus(d0-d7) at hexaddress 8000

End

PEEK

Action

Returns the content of a register.

Syntax

var = PEEK( address )

Remarks

Var

Numeric variable that is assigned with the content of the memory

 

location address

Address

Numeric variable or constant with the address location.(0-31)

 

 

Peek() will read the content of a register.

Inp() can read any memory location

See also

POKE , CPEEK , INP , OUT

Example

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

 

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

: peek.bas

'name

'copyright

: (c) 1995-2005, MCS Electronics

'purpose

: demonstrates PEEk, POKE, CPEEK, INP and OUT

'micro

: Mega48

'suited for demo

: yes

'commercial addon needed

: no

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

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

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

page -585-

 

© MCS Electronics, 1995-2007

for the SW stack

' default use 40

$framesize = 40

for the frame space

 

Dim I As Integer , B1 As Byte

'dump internal memory

For I = 0 To 31

'only 32 registers

in AVR

'get byte from

B1 = Peek(i)

internal memory

";

Print Hex(b1) ; "

'Poke I , 1

'write a value into memory

Next

'new line

Print

'be careful when writing into internal memory !!

'now dump a part ofthe code-memory(program)

For I = 0 To 255

'get byte from

B1 = Cpeek(i)

internal memory

";

Print Hex(b1) ; "

Next

 

'note that you can not write into codememory!!

Out &H8000 , 1

'write 1 into XRAM

at address 8000

'return value from

B1 = Inp(&H8000)

XRAM

 

Print B1

 

End

POKE

Action

Write a byte to an internal register.

Syntax

POKE address , value

Remarks

Address

Numeric variable with the address of the memory location to set. (0-31)

Value

Value to assign. (0-255)

 

 

See also

PEEK , CPEEK , INP , OUT

Example

Poke 1 , 1 'write 1 to R1

End

page -586-

© MCS Electronics, 1995-2007

POPALL

Action

Restores all registers that might be used by BASCOM.

Syntax

POPALL

Remarks

When you are writing your own ASM routines and mix them with BASIC you are unable to tell which registers are used by BASCOM because it depends on the used statements and interrupt routines that can run on the background.

That is why Pushall saves all used registers and POPALL restores all registers.

See also

PUSHALL

POWER

Action

Returns the power of a single or double variable and its argument

Syntax

var = POWER( source, raise )

Remarks

Var

A numeric variable that is assigned with the power of variable

 

source ^ raise.

Source

The single or double variable to get the power of.

 

 

The POWER function works for positive floating point variables only.

When you use a ^ b , the sign will be preserved.

While Excel does not allow raising a negative single, QB does allow it.

The Power functions uses less code compared with the code that is generated when you use ^ for floating point values.

It is important that you use single variables for both single and raise. Constants are not accepted.

See Also

EXP ,LOG, LOG10 , SQR

Example

page -587-

© MCS Electronics, 1995-2007

Show sample

POWERDOWN

Action

Put processor into power down mode.

Syntax

POWERDOWN

Remarks

In the power down mode, the external oscillator is stopped. The user can use the WATCHDOG to power up the processor when the watchdog timeout expires. Other possibilities to wake up the processor is to give an external reset or to generate an external level triggered interrupt.

Most new chips have many options for Power down/Idle. It is advised to consult the data sheet to see if a better mode is available.

See also

IDLE , POWERSAVE

Example

Powerdown

POWERSAVE

Action

Put processor into power save mode.

Syntax

POWERSAVE

Remarks

The POWERSAVE mode is only available in the 8535, Mega8, Mega163.

Most new chips have many options for Power down/Idle. It is advised to consult the datasheet to see if a better mode is available.

See also

IDLE, POWERDOWN

page -588-