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

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

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

Добавлен: 12.06.2025

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

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

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

© MCS Electronics, 1995-2007

Remarks

var1

Variable that will be assigned with the converted value.

var2

Variable that holds the BCD value.

When you want to use an I2C clock device, which stores its values as BCD values you can use this function to convert variables from BCD to decimal.

See also

MAKEBCD , MAKEBCD, MAKEINT

Example

Dim A As Byte

A = 65

Print A

Print Bcd(a)

A = Makedec(a)

Print Spc(3) ; A

End

MAKETCP

Action

Creates a TCP/IP formatted long variable.

Syntax

var = MAKETCP(b1,b2,b3,b4 [opt]) var = MAKETCP(num)

Remarks

var

The target variable of the type LONG that is assigned with the IP number

b1-b4

Four variables of numeric constants that form the IP number.

b1 is the MSB of the IP/long

b4 is the LSB of the IP/long

example var = MakeTCP(192,168,0, varx).

We can also use reverse order with the optional param:

example var = MakeTCP(var3,0,168, 192, 1 ).

A value of 1 will use reverse order while a value of 0 will result in normal

order.

When you use a constant, provide only one param:

example var = MakeTCP(192.168.0.2). Notice the dots !

MakeTCP is a helper routine for the TCP/IP library.

See also

page -569-


© MCS Electronics, 1995-2007

CONFIG TCPIP , IP2STR

Example

NONE

MAX

Action

Returns the maximum value of a byte or word array.

Syntax

var1 = MAX(var2) MAX(ar(1), m ,idx)

Remarks

var1

Variable that will be assigned with the maximum value.

var2

The first address of the array.

The MAX statement can return the indextoo

Ar(1)

Starting element to get the maximum value and index of.

M

Returns the maximum value of the array.

Idx

Return the index of the array that contains the maximum value. Returns 0 if

there is no maximum value.

The MIN() and MAX() functions work on BYTE and WORD arrays only.

See also

MIN

Example

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

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

: minmax.bas

'name

'copyright

: (c) 1995-2005, MCS Electronics

'purpose

: show the MIN and MAX 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

page -570-


© MCS Electronics, 1995-2007

$framesize = 40

' default use 40

for the frame space

' These functions only works on BYTE and WORD arrays at the moment !!!!!

'Dim some variables

Dim Wb As Byte , B As Byte

Dim W(10) As Word ' or use a BYTE array

'fill the word array with values from 1 to 10

For B = 1 To 10 W(b) = B

Next

Print "Max number " ; Max(w(1))

Print "Min number " ; Min(w(1))

Dim Idx As Word , M1 As Word

Min(w(1) , M1 , Idx)

Print "Min number " ; M1 ; " index " ; Idx

Max(w(1) , M1 , Idx)

Print "Max number " ; M1 ; " index " ; Idx

End

MEMCOPY

Action

Copies a block of memory

Syntax

bts = MEMCOPY(source, target , bytes[ , option])

Remarks

bts

The total number of bytes copied. This must be a word or integer

source

The first address of the source variable that will be copied.

target

The first address of the target variable that will be copied to.

bytes

The number of bytes to copy from "source" to "target"

option

An optional numeric constant with one of the following values :

1 - only the source address will be increased after each copied byte

2 - only the target address will be increased after each copied byte

3 - both the source and target address will be copied after each copied byte

By default, option 3 is used as this will copy a block of memory from one memory location to another location. But it it also possible to fill an entire array of memory block with the value of 1 memory location. For example to clear a whole block or preset it with a value.

And with option 2, you can for example get a number of samples from a register like PINB and store it into an array.

See also

page -571-


© MCS Electronics, 1995-2007

NONE

ASM

NONE

Example

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

: MEMCOPY.BAS

'name

'copyright

: (c) 1995-2006, MCS Electronics

'purpose

: show memory copy function

'suited for demo

: yes

'commercial addon needed

: no

'use in simulator

: possible

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

' specify the used

$regfile = "m88def.dat"

micro

' used crystal

$crystal = 8000000

frequency

' use baud rate

$baud = 19200

$hwstack = 32

' default use 32

for the hardware stack

' default use 10

$swstack = 16

for the SW stack

$framesize = 40

Dim Ars(10) As Byte

'source bytes

Dim Art(10) As Byte

'target bytes

Dim J As Byte

'index

For J = 1 To 10

'fill array

Ars(j) = J

Next

J = Memcopy(ars(1) , Art(1) , 4)

'copy 4 bytes

Print J ; " bytes copied"

For J = 1 To 10

Print Art(j)

Next

J = Memcopy(ars(1) , Art(1) , 10 , 2)

'assign them all

with element 1

Print J ; " bytes copied"

For J = 1 To 10

Print Art(j)

Next

Dim W As Word , L As Long

W = 65511

'copy 2 bytes from

J = Memcopy(w , L , 2)

word to long

End

MIN

page -572-