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

© MCS Electronics, 1995-2007

ABS

Action

Returns the absolute value of a numeric signed variable.

Syntax

var = ABS(var2)

Remarks

Var

Variable that is assigned with the absolute value of var2.

Var2

The source variable to retrieve the absolute value from.

 

 

var : Integer , Long, Single or Double. var2 : Integer, Long, Single or Double.

The absolute value of a number is always positive.

See also

NONE

ASM

Calls: _abs16 for an Integer and _abs32 for a Long

Input: R16-R17 for an Integer and R16-R19 for a Long

Output:R16-R17 for an Integer and R16-R19 for a Long

Calls _Fltabsmem for a single from the fp_trig library.

Example

Dim a as Integer, c as Integer a =-1000

c = Abs(a) Print c End

ACOS

Action

Returns the arccosine of a single in radians.

Syntax

var = ACOS( x )

page -270-

 

© MCS Electronics, 1995-2007

Remarks

Var

A floating point variable such as single or double, that is assigned with

 

 

the ACOS of variable x.

 

X

The float to get the ACOS of. Input is valid from –1 to +1 and returns

 

 

p to 0.

 

 

If Input is < -1 than p and input is > 1 than 0 will returned.

 

 

 

 

If Input is cause of rounding effect in float-operations a little bit over 1 or -1, the value for 1.0 (-1.0) will be returned. This is the reason to give the value of the limit-point back, if Input is beyond limit. Generally the user have to take care, that Input to this function lies within –1 to +1.

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

See Also

RAD2DEG , DEG2RAD , COS , SIN , TAN , ATN , ASIN , ATN2

Example

$regfile = "m48def.dat"

' specify the used

micro

' used crystal

$crystal = 8000000

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

 

Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0

Dim S As Single , X As Single

x= 0.5 : S = Acos(x)

Print S

End

ALIAS

Action

Indicates that the variable can be referenced with another name.

Syntax

newvar ALIAS oldvar

Remarks

oldvar Name of the variable such as PORTB.1

page -271-

© MCS Electronics, 1995-2007

newvar New name of the variable such as direction

Aliasing port pins can give the pin names a more meaningful name. For example, when your program uses 4 different pins to control 4 different relays, you could name them portb.1, portb.2, portb.3 and portb.4.

But it would be more convenient to refer to them as relais1, relais2, relais3 and realais4.

When you later on change your PCB and decide that relays 4 must be connected to portD.4 instead of portb.4, you only need to change the ALIAS line, and not your whole program.

See also

CONST

Example

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

 

--

: (c) 1995-2005, MCS Electronics

'copyright

'micro

: Mega48

'suited for demo

: yes

'commercial addon needed

: no

'purpose

: demonstrates ALIAS

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

 

--

 

$regfile = "m48def.dat"

' 4 MHz crystal

$crystal = 4000000

Const On = 1

 

Const Off = 0

 

Config Portb = Output

 

Relais1 Alias Portb.1

 

Relais2 Alias Portb.2

 

Relais3 Alias Portd.5

 

Relais4 Alias Portd.2

 

Set Relais1

 

Relais2 = 0

 

Relais3 = On

 

Relais4 = Off

 

End

 

ASC

Action

Assigns a numeric variable with the ASCII value of the first character of a string.

Syntax

var = ASC(string)

Remarks

Var Target numeric variable that is assigned.

page -272-

© MCS Electronics, 1995-2007

String String variable or constant from which to retrieve the ASCII value.

Note that only the first character of the string will be used.

When the string is empty, a zero will be returned.

ASCII stands for American Standard Code for Information Interchange. Computers can only understand numbers, so an ASCII code is the numerical representation of a character such as 'a' or '@' or an action of some sort. ASCII was developed a long time ago and now the non-printing characters are rarely used for their original purpose. Below is the ASCII character table and this includes descriptions of the first 32 non-printing characters. ASCII was actually designed for use with teletypes and so the descriptions are somewhat obscure. If someone says they want your CV however in ASCII format, all this means is they want 'plain' text with no formatting such as tabs, bold or underscoring - the raw format that any computer can understand. This is usually so they can easily import the file into their own applications without issues. Notepad.exe creates ASCII text, or in MS Word you can save a file as 'text only'

Extended ASCII

As people gradually required computers to understand additional characters and non-printing characters the ASCII set became restrictive. As with most technology, it took a while to get

page -273-

© MCS Electronics, 1995-2007

a single standard for these extra characters and hence there are few varying 'extended' sets. The most popular is presented below.

See also

CHR

ASM

NONE

Example

$regfile = "m48def.dat"

' specify the used

micro

' used crystal

$crystal = 8000000

frequency

' use baud rate

$baud = 19200

$hwstack = 32

' default use 32

for the hardware stack

 

page -274-