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

© MCS Electronics, 1995-2007

 

subroutine

 

Print "This will be executed"

'return from

Return

subroutine

 

GOTO

Action

Jump to the specified label.

Syntax

GOTO label

Remarks

Labels can be up to 32 characters long.

When you use duplicate labels, the compiler will give you a warning.

See also

GOSUB

Example

Dim A As Byte

Start:

 

'a label must end with a colon

A = A + 1

'increment a

If A < 10 Then

'is it less than 10?

Goto Start

 

'do it again

End If

'close IF

Print

"Ready"

'that is it

GRAY2BIN

Action

Returns the numeric value of a Gray code.

Syntax

var1 = GRAY2BIN(var2)

Remarks

var1

Variable that will be assigned with the binary value of the Grey code.

var2

A variable in Grey format that will be converted.

 

 

Gray code is used for rotary encoders. Gray2bin() works for byte, integer, word and long variables.

page -518-

© MCS Electronics, 1995-2007

See also

BIN2GRAY

ASM

Depending on the data type of the target variable the following routine will be called from mcs.lbx:

_Bin2grey for bytes , _Bin2Grey2 for integer/word and _Bin2grey4 for ongsl.

Example

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

 

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

: graycode.bas

'name

'copyright

: (c) 1995-2005, MCS Electronics

'purpose

: show the Bin2Gray and Gray2Bin functions

'micro

: Mega48

'suited for demo

: yes

'commercial addon needed

: no

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

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

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

 

'Bin2Gray() converts a byte,integer,word or long into grey code.

'Gray2Bin() converts a gray code into a binary value

 

Dim B As Byte

' could be

word,integer or long too

 

Print "BIN" ; Spc(8) ; "GREY"

For B = 0 To 15

Print B ; Spc(10) ; Bin2gray(b)

Next

Print "GREY" ; Spc(8) ; "BIN"

For B = 0 To 15

Print B ; Spc(10) ; Gray2bin(b)

Next

End

HEX

Action

Returns a string representation of a hexadecimal number.

page -519-

© MCS Electronics, 1995-2007

Syntax

var = HEX( x )

Remarks

var

A string variable.

X

A numeric variable of data type Byte, Integer, Word, Long,

 

Single or Double.

 

 

See also

HEXVAL , VAL , STR , BIN , BINVAL

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 B As Byte , J As Integer , W As Word , L As Long

B = 1 : J = &HF001

W = &HF001

L = W

Print B ; Spc(3) ; Hex(b)

Print J ; Spc(3) ; Hex(j)

Print W ; Spc(3) ; Hex(w)

Print L ; Spc(3) ; Hex(l)

End

HEXVAL

Action

Convert string representing a hexadecimal number into a numeric variable.

Syntax

var = HEXVAL( x )

Remarks

Var

The numeric variable that must be assigned.

 

page -520-

© MCS Electronics, 1995-2007

X The hexadecimal string that must be converted.

In VB you can use the VAL() function to convert hexadecimal strings.

But since that would require an extra test for the leading &H signs that are required in VB, a separate function was designed.

See also

HEX , VAL , STR , BIN , BINVAL

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 L As Long

Dim S As String * 8

Do

Input "Hex value " , S

L = Hexval(s)

Print L ; Spc(3) ; Hex(l)

Loop

HIGH

Action

Retrieves the most significant byte of a variable.

Syntax

var = HIGH( s )

Remarks

Var

The variable that is assigned with the MSB of var S.

S

The source variable to get the MSB from.

 

 

See also

LOW , HIGHW

page -521-