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

 

© MCS Electronics, 1995-2007

Input S Noecho

'without echo

Print S

 

End

 

INPUT

Action

Allows input from the keyboard or file during program execution.

Syntax

INPUT [" prompt" ] , var[ , varn ]

INPUT #ch, var[ , varn ]

Remarks

Prompt

An optional string constant printed before the prompt character.

Var,varn

A variable to accept the input value or a string.

Ch

A channel number, which identifies an opened file. This can be a

 

hard coded constant or a variable.

 

 

The INPUT routine can be used when you have an RS-232 interface on your uP.

The RS-232 interface can be connected to a serial communication port of your computer. This way you can use a terminal emulator and the keyboard as an input device.

You can also use the built-in terminal emulator.

For usage with the AVR-DOS file system, you can read variables froman opened file. Since these variables are stored in ASCII format, the data is converted to the proper format automatically.

When you use INPUT with a file, the prompt is not supported.

Difference with VB

In VB you can specify &H with INPUT so VB will recognize that a hexadecimal string is being used.

BASCOM implements a new statement : INPUTHEX.

See also

INPUTHEX , PRINT , ECHO , WRITE , INPUTBIN

Example

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

 

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

: input.bas

'name

'copyright

: (c) 1995-2005, MCS Electronics

'purpose

: demo: INPUT, INPUTHEX

'micro

: Mega48

'suited for demo

: yes

'commercial addon needed

: no

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

 

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

 

page -537-

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