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

© MCS Electronics, 1995-2007

'Now it is time to show a picture

 

'SHOWPIC X,Y,label

 

'The label points to a label that holds the image data

 

Test:

 

Showpic 0 , 0 , Plaatje

' show 2 since we

Showpic 0 , 64 , Plaatje

have a big display

 

Wait 2

' clear the text

Cls Text

End

 

'This label holds the mage data Plaatje:

'$BGF will put the bitmap into the program at this location $bgf "mcs.bgf"

'You could insert other picture data here

PS2MOUSEXY

Action

Sends mouse movement and button information to the PC.

Syntax

PS2MOUSEXY X , Y, button

Remarks

X

Y

Button

The X-movement relative to the current position.

The range is –255 to 255.

The Y-movement relative to the current position.

The range is –255 to 255.

A variable or constant that represents the button state.

0 – no buttons pressed

1- left button pressed

2- right button pressed

4- middle button pressed

You can combine these values by adding them. For example, 6 would emulate that the right and middle buttons are pressed.

To send a mouse click, you need to send two ps2mouseXY statements. The first must indicate that the button is pressed, and the second must release the button.

Ps2mouseXY 0,0,1 ' left mouse pressed

PsmouseXY 0,0,0 ' left mouse released

The SENDSCAN statement could also be used.

page -594-

© MCS Electronics, 1995-2007

See also

SENDSCAN, CONFIG PS2EMU

PULSEIN

Action

Returns the number of units between two occurrences of an edge of a pulse.

Syntax

PULSEIN var , PINX , PIN , STATE

Remarks

var

A word variable that is assigned with the result.

PINX

A PIN register like PIND

PIN

The pin number(0-7) to get the pulse time of.

STATE

May be 0 or 1.

 

0 means sample 0 to 1 transition.

 

1 means sample 1 to 0 transition.

 

 

ERR variable will be set to 1 in case of a time out. A time out will occur after 65535 unit counts. With 10 uS units this will be after 655.35 mS.

You can add a bitwait statement to be sure that the PULSEIN statement will wait for the start condition. But when using the BITWAIT statement and the start condition will never occur, your program will stay in a loop.

The PULSIN statement will wait for the specified edge.

When state 0 is used, the routine will wait until the level on the specified input pin is 0. Then a counter is started and stopped until the input level gets 1.

No hardware timer is used. A 16 bit counter is used. It will increase in 10 uS units. But this depends on the XTAL. You can change the library routine to adjust the units.

See also

PULSEOUT

ASM

The following ASM routine is called from mcs.lib _pulse_in (calls _adjust_pin)

On entry ZL points to the PINx register , R16 holds the state, R24 holds the pin number to sample.

On return XL + XH hold the 16 bit value.

page -595-

© MCS Electronics, 1995-2007

Example

Dim w As Word

pulsein w , PIND , 1 , 0 'detect time from 0 to 1 print w

end

PULSEOUT

Action

Generates a pulse on a pin of a PORT of specified period in 1uS units for 4 MHz.

Syntax

PULSEOUT PORT , PIN , PERIOD

Remarks

PORT

Name of the PORT. PORTB for example

PIN

Variable or constant with the pin number (0-7).

PERIOD

Number of periods the pulse will last. The periods are in uS

 

when an XTAL of 4 MHz is used.

 

 

The pulse is generated by toggling the pin twice, thus the initial state of the pin determines the polarity.

The PIN must be configured as an output pin before this statement can be used.

See also

PULSEIN

Example

Dim A As Byte

'PORTB all output

Config Portb = Output

pins

'all pins 0

Portb = 0

Do

 

For A = 0 To 7

'generate pulse

Pulseout Portb , A , 60000

Waitms 250

'wait a bit

Next

'loop for ever

Loop

PUSHALL

Action

Saves all registers that might be used by BASCOM.

page -596-

© MCS Electronics, 1995-2007

Syntax

PUSHALL

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. Use POPALL to restore the registers.

The saved registers are : R0-R5, R7,R10,R11 and R16-R31

See also

POPALL

PUT

Action

Writes a byte to the hardware or software UART.

Writes data to a file opened in BINARY mode.

Syntax

PUT #channel, var

PUT #channel, var ,[pos] [,length]

Remarks

PUT in combination with the software/hardware UART is provided for compatibility with BASCOM-8051. It writes one byte

PUT in combination with the AVR-DOS file system is very flexible and versatile. It works on files opened in BINARY mode and you can write all data types.

#channel

A channel number, which

 

identifies an opened file. This can be a hard coded constant or a variable.

Var

The variable or variable array that will be written to the file

Pos

This is an optional parameter that may be used to specify the position where

 

the data must be written. This must be a long variable.

Length

This is an optional parameter that may be used to specify how many bytes

 

must be written to the file.

 

 

By default you only need to provide the variable name. When the variable is a byte, 1 byte will be written. When the variable is a word or integer, 2 bytes will be written. When the variable is a long or single, 4 bytes will be written. When the variable is a string, the number of bytes that will be written is equal to the dimensioned size of the string. DIM S as string * 10 , would write 10 bytes.

Note that when you specify the length for a string, the maximum length is 255. The maximum length for a non-string array is 65535.

page -597-

© MCS Electronics, 1995-2007

Example

PUT #1, var

PUT #1, var , , 2 ' write 2 bytes at default position

PUT #1, var ,PS, 2 ' write 2 bytes at location storied in variable PS

See also

INITFILESYSTEM , OPEN , CLOSE, FLUSH , PRINT, LINE INPUT, LOC, LOF , EOF , FREEFILE , FILEATTR , SEEK , BSAVE , BLOAD , KILL , DISKFREE , DISKSIZE , GET, FILEDATE , FILETIME , FILEDATETIME , DIR , FILELEN , WRITE , INPUT

ASM

current position

Goto new position first

Byte:

 

_FilePutRange_1

_FilePutRange_1

Input:

Input:

r24: File number

r24: File number

X: Pointer to variable

X: Pointer to variable

T-Flag cleared

r16-19 (A): New position (1-based)

 

T-Flag Set

Word/Integer:

 

_FilePutRange_2

_FilePutRange_2

Input:

Input:

r24: File number

r24: File number

X: Pointer to variable

X: Pointer to variable

T-Flag cleared

r16-19 (A): New position (1-based)

 

T-Flag Set

Long/Single:

 

_FilePutRange_4

_FilePutRange_4

Input:

Input:

r24: File number

r24: File number

X: Pointer to variable

X: Pointer to variable

T-Flag cleared

r16-19 (A): New position (1-based)

 

T-Flag Set

String (<= 255 Bytes) with fixed length

 

_FilePutRange_Bytes

_FilePutRange_Bytes

Input:

Input:

r24: File number

r24: File number

r20: Count of Bytes

r20: Count of bytes

X: Pointer to variable

X: Pointer to variable

T-Flag cleared

r16-19 (A): New position (1-based)

 

T-Flag Set

Array (> 255 Bytes) with fixed length

 

_FilePutRange

_FilePutRange

Input:

Input:

r24: File number

r24: File number

r20/21: Count of Bytes

r20/21: Count of bytes

X: Pointer to variable

X: Pointer to variable

T-Flag cleared

r16-19 (A): New position (1-based)

 

T-Flag Set

 

 

page -598-

© MCS Electronics, 1995-2007

Output from all kind of usage: r25: Error Code

C-Flag on Error

Example

'for the binary file demo we need some variables of different types Dim B AsByte, W AsWord, L AsLong, Sn AsSingle, Ltemp AsLong Dim Stxt AsString* 10

B = 1 : W = 50000 : L = 12345678 : Sn = 123.45 : Stxt ="test"

'open the file in BINARY mode Open"test.biN"ForBinaryAs#2 Put#2 , B ' write a byte Put#2 , W ' write a word Put#2 , L ' write a long

Ltemp =Loc(#2)+ 1 ' get the position of the next byte Print Ltemp ;" LOC"' store the location of the file pointer Print Seek(#2);" = LOC+1"

PrintLof(#2);" length of file"

PrintFileattr(#2);" file mode"' should be 32 for binary

Put#2 , Sn ' write a single

Put#2 , Stxt ' write a string

Flush#2 ' flush to disk

Close#2

'now open the file again and write only the single Open"test.bin"ForBinaryAs#2

L = 1 'specify the file position

B =Seek(#2 , L)' reset is the same as using SEEK #2,L Get#2 , B ' get the byte

Get#2 , W ' get the word Get#2 , L ' get the long Get#2 , Sn ' get the single Get#2 , Stxt ' get the string Close#2

RAD2DEG

Action

Converts a value in radians to degrees.

Syntax

var = RAD2DEG( Source )

Remarks

Var

A numeric variable that is assigned with the angle of variable

 

source.

Source

The single or double variable to get the angle of.

 

 

page -599-