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

 

 

© MCS Electronics, 1995-2007

'

I2cstart

'start condition

'

I2cwbyte &B1010_0000

'slave address

'

I2cwbyte H

'high address

'

I2cwbyte L

'low address

'

I2cwbyte Value

'value to write

'

I2cstop

'stop condition

'Waitms 10

IDLE

Action

Put the processor into the idle mode.

Syntax

IDLE

Remarks

In the idle mode, the system clock is removed from the CPU but not from the interrupt logic, the serial port or the timers/counters.

The idle mode is terminated either when an interrupt is received(from the watchdog, timers, external level triggered or ADC) or upon system reset through the RESET pin.

Most new chips have many options for Power down/Idle. It is advised to consult the data sheet to see if a better mode is available.

See also

POWERDOWN

Example

IDLE

IF-THEN-ELSE-END IF

Action

Allows conditional execution or branching, based on the evaluation of a Boolean expression.

Syntax

IF expression THEN

[ ELSEIF expression THEN ]

[ ELSE ]

END IF

page -528-

© MCS Electronics, 1995-2007

Remarks

Expression Any expression that evaluates to true or false.

The one line version of IF can be used :

IF expression THEN statement [ ELSE statement ]

The use of [ELSE] is optional.

Tests like IF THEN can also be used with bits and bit indexes. IF var.bit = 1 THEN

^--- bit is a variable or numeric constant in the range from0-255

Dim Var As Byte, Idx As Byte

Var = 255

Idx = 1

If Var.idx = 1 Then

Print "Bit 1 is 1"

EndIf

See also

ELSE

Example

Dim A As Integer

 

A = 10

'test expression

If A = 10 Then

Print "This part is executed."

'this will be

printed

 

Else

'this not

Print "This will never be executed."

End If

 

If A = 10 Then Print "New in BASCOM"

 

If A = 10 Then Goto Label1 Elseprint "A<>10"

 

Label1:

 

Rem The following example shows enhanced use of IF THEN

'test for bit

If A.15 = 1 Then

Print "BIT 15 IS SET"

 

EndIf

Rem the following example shows the 1 line use of IF THEN [ELSE]

If A.15 = 0 Then Print "BIT 15 is cleared" Else Print "BIT 15 is set"

INCR

Action

Increments a variable by one.

Syntax

INCR var

Remarks

Var Any numeric variable.

page -529-

© MCS Electronics, 1995-2007

See also

DECR

Example

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

 

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

: incr.bas

'name

'copyright

: (c) 1995-2005, MCS Electronics

'purpose

: demo: INCR

'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 A As Byte

 

A = 5

'assign value to a

Incr A

'inc (by one)

Print A

'print it

End

 

INITFILESYSTEM

Action

Initialize the file system

Syntax

bErrorCode = INITFILESYSTEM (bPartitionNumber)

Remarks

bErrorCode

(Byte) Error Result from Routine, Returns 0 if no Error

bPartitionNumber

(Byte) Partitionnumber on the Flashcard Drive (normally 1)

 

 

Reads the Master boot record and the partition boot record (Sector) fromthe flashcard and initializes the filesystem.

This function must be called before any other file-system function is used.

page -530-

© MCS Electronics, 1995-2007

See also

OPEN , CLOSE, FLUSH , PRINT, LINE INPUT, LOC, LOF , EOF , FREEFILE , FILEATTR , SEEK , BSAVE , BLOAD , KILL , DISKFREE , DISKSIZE , GET , PUT , FILEDATE , FILETIME , FILEDATETIME , DIR , FILELEN , WRITE , INPUT

ASM

Calls

_GetFileSystem

 

Input

r24: partitionnumber (1-based)

 

Output

r25: Errorcode

C-Flag: Set on Error

 

 

 

Partial Example

Dim bErrorCode as Byte bErrorCode = InitFileSystem(1) If bErrorCode > 0 then

Print "Error: "; bErrorCode Else

Print "Filesystem successfully initialized" End If

INITLCD

Action

Initializes the LCD display.

Syntax

INITLCD

Remarks

The LCD display is initialized automatic at start up when LCD statements are used by your code.

If fore some reason you would like to initialize it again you can use the INITLCD statement.

The LCD routines depend on the fact that the WR pin of the LCD is connected to ground. But when you connect it to as port pin, you can use INITLCD after you have set the WR pin to logic 0.

ASM

The generated ASM code :

Rcall _Init_LCD

See also

LCD

page -531-