ВУЗ: Не указан

Категория: Не указан

Дисциплина: Не указана

Добавлен: 12.06.2025

Просмотров: 8225

Скачиваний: 1

ВНИМАНИЕ! Если данный файл нарушает Ваши авторские права, то обязательно сообщите нам.

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


© MCS Electronics, 1995-2007

All trig functions work with radians. Use deg2rad and rad2deg to convert between radians and angles.

See Also

DEG2RAD

Example

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

--

: (c) 1995-2005, MCS Electronics

'copyright

'micro

: Mega48

'suited for demo

: yes

'commercial addon needed

: no

'purpose

: demonstrates DEG2RAD function

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

--

Dim S As Single

S = 90

S = Deg2Rad(s)

Print S

S = Rad2deg(s)

Print S

End

RC5SEND

Action

Sends RC5 remote code.

Syntax

RC5SEND togglebit, address, command

Uses

TIMER1

Remarks

Togglebit

Make the toggle bit 0 or 32 to set the toggle bit

Address

The RC5 address

Command

The RC5 command.

The resistor must be connected to the OC1A pin. In the example a 2313 micro was used. This micro has pin portB.3 connected to OC1A.

Look in a datasheet for the proper pin when used with a different chip.

Most audio and video systems are equipped with an infra-red remote control. The RC5 code is a 14-bit word bi-phase coded signal.

The two first bits are start bits, always having the value 1.

page -600-


© MCS Electronics, 1995-2007

The next bit is a control bit or toggle bit, which is inverted every time a button is pressed on the remote control transmitter.

Five system bits hold the system address so that only the right system responds to the code.

Usually, TV sets have the system address 0, VCRs the address 5 and so on. The command sequence is six bits long, allowing up to 64 different commands per address.

The bits are transmitted in bi-phase code (also known as Manchester code). An IR booster circuit is shown below:

See also

CONFIG RC5 , GETRC5 , RC6SEND

Example

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

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

: sendrc5.bas

'name

'copyright

: (c) 1995-2005, MCS Electronics

'purpose

: code based on application note from Ger Langezaal

'micro

: AT90S2313

'suited for demo

: yes

'commercial addon needed

: no

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

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

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

for the SW stack

' default use 40

$framesize = 40

for the frame space

' +5V <---[A Led K]---[220 Ohm]---> Pb.3 for 2313.

'RC5SEND is using TIMER1, no interrupts are used

'The resistor must be connected to the OC1(A) pin , in this case PB.3

Dim Togbit As Byte , Command As Byte , Address As Byte

Command =

12

' power on off

32

Togbit = 0

' make it 0 or

to set the toggle bit

Address =

0

page -601-