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

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

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

Добавлен: 12.06.2025

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

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

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

© MCS Electronics, 1995-2007

$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

Dim V As Byte , B1 As Byte

Dim C As Integer , D As Byte

Dim S As String * 15

Input "Use this to ask a question " , V

'leave out for no

Input B1

question

Input "Enter integer " , C

Print C

Inputhex "Enter hex number (4 bytes) " , C

Print C

Inputhex "Enter hex byte (2 bytes) " , D

Print D

Input "More variables " , C , D

Print C ; " " ; D

Input C Noecho

'supress echo

Input "Enter your name " , S

Print "Hello " ; S

Input S Noecho

'without echo

Print S

End

INSTR

Action

Returns the position of a sub string in a string.

Syntax

var = INSTR( start , string , substr ) var = INSTR( string , substr )

Remarks

Var

Start

Numeric variable that will be assigned with the position of the sub string in the string. Returns 0 when the sub string is not found.

An optional numeric parameter that can be assigned with the first position where must be searched in the string. By default (when not used) the whole string is searched starting from position 1.

page -538-


© MCS Electronics, 1995-2007

String

The string to search.

Substr

The search string.

No constant can be used for string it must be a string variable.

Only substr can be either a string or a constant.

See also

SPLIT

Example

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

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

: instr.bas

'name

'copyright

: (c) 1995-2005, MCS Electronics

'purpose

: INSTR function demo

'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

'dimension variables

Dim Pos As Byte

Dim S As String * 8 , Z As String * 8

'assign string to search

' Z = "ab"

S = "abcdeab"

'assign search string

Z = "ab"

'return first position in pos Pos = Instr(s , Z)

'must return 1

'now start searching in the string at location 2 Pos = Instr(2 , S , Z)

'must return 6

Pos = Instr(s , "xx")

'xx is not in the string so return 0

End

page -539-


© MCS Electronics, 1995-2007

INT

Action

Returns the integer part of a single or double.

Syntax

var = INT( source )

Remarks

Var

A numeric variable that is assigned with the integer of variable

source.

Source

The source variable to get the integer of.

The fraction is the right side after the decimal point of a single.

The integer is the left side before the decimal point.

1234.567 1234 is the integer part, .567 is the fraction

See Also

FRAC , FIX , ROUND

Example

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

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

: round_fix_int.bas

'name

'copyright

: (c) 1995-2005, MCS Electronics

'purpose

: demo : ROUND,FIX

'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

Dim S As Single , Z As Single

For S = -10 To 10 Step 0.5

Print S ; Spc(3) ; Round(s) ; Spc(3) ; Fix(s) ; Spc(3) ; Int(s)

Next

End

page -540-


© MCS Electronics, 1995-2007

IP2STR

Action

Convert an IP number into it’s string representation.

Syntax

Var = IP2STR(num)

Remarks

An IP number is represented with dots like 192.168.0.1. The IP2STR function converts an IP number into a string.

This function is intended to be used in combination with the BASCOM TCP/IP routines.

Var

The string variable that is assigned with the IP number

Num

A variable that contains the ip number is numeric format.

See also

CONFIG TCPIP

ISCHARWAITING

Action

Returns one(1) when a character is waiting in the hardware UART buffer.

Syntax

var = ISCHARWAITING()

var = ISCHARWAITING(#channel)

Remarks

Var

Byte, Integer, Word or Long variable.

Channel A constant number that identifies the opened channel.

If there is no character waiting, a zero will be returned.

If there is a character waiting, a one (1) will be returned.

The character is not retrieved or altered by the function.

While the Inkey() will get the character from the HW UART when there is a character in the buffer, it will return a zero when the character is zero. This makes it unusable to work with binary data that might contain the value 0.

With IsCharWaiting() you can first check for the presence of a character and when the function returns 1, you can retrieve the character with Inkey or Waitkey.

See also

page -541-