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

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

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

Добавлен: 12.06.2025

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

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

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

© MCS Electronics, 1995-2007

Since the microprocessor has internal pull up resistors, you do not need externalpull up resistors for most encoders.

Example

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

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

: encoder.bas

'name

'copyright

: (c) 1995-2005, MCS Electronics

'purpose

: demonstration of encoder function

'micro

: Mega128

'suited for demo

: yes

'commercial addon needed

: no

'An encoder has 2 outputs

and a ground

'We connect the outputs to pinb.0 and pinb.1

'You may choose different pins as long as they are at the same PORT 'The pins must be configured to work as input pins

'This function works for all PIN registers '-----------------------------------------------------------------------------

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

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

Print "Encoder test"

Dim B As Byte

'we have dimmed a byte because we need to maintain the state of the encoder

Portb = &B11

' activate pull up

registers

Do

B = Encoder(pinb.0 , Pinb.1 , Links , Rechts , 1)

1 means wait for

'

^---

change which blocks programflow

^

labels which are

'

^--------

called

^

^

port PINs

'

Print B

Waitms 10

Loop

End

'so while you can choose PINB0 and PINB7,they must be both member of PINB 'this works on all PIN registers

Links:

Print "left rotation"

Return

Rechts:

Print "right rotation"

Return

page -480-


© MCS Electronics, 1995-2007

End

END

Action

Terminate program execution.

Syntax

END

Remarks

STOP can also be used to terminate a program.

When an END statement is encountered, all interrupts are disabled and a never-ending loop is generated.

When a STOP is encountered the interrupts will not be disabled. Only a never ending loop will be created.

In an embedded application you probably do not want to end the application. But there are cases where you do want to end the application. For example when you controlsome motors, and you determine a failure, you do not want to use a Watchdog reset because then the failure will occur again. In that case you want to display an error, and wait for service personal to fix the failure.

It is important to notice that without the END statement, your programcan behave strange in certain cases. For example :

Print "Hello"

Note that there is no END statement. So what will happen? The program will print "Hello". But as the compiler places the library code behind the program code, the micro will execute the library code ! But without being called. As most library code are assembler sub routines that end with a RET, your program will most likely crash, or reset and repeat for ever.

See also

STOP

Example

Print "Hello"

'print this

End

'end program execution and disable all interrupts

EOF

Action

Returns the End of File Status.

Syntax

page -481-


© MCS Electronics, 1995-2007

bFileEOFStatus = EOF(#bFileNumber)

Remarks

bFileEOFStatus

(Byte) A Byte Variable, which assigned with the EOF Status

bFileNumber

(Byte) Number of the opened file

This functions returns information about the End of File Status

Return value

Status

0

NOT EOF

255

EOF

In case of an error (invalid file number) 255 (EOF) is returned too.

See also

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

ASM

Calls

_FileEOF

Input

r24: Filenumber

Output

r24: EOF Status

r25: Error code

C-Flag: Set on Error

Partial Example

Ff =Freefile()' get file handle

Open "test.txt" For Input As #ff ' we can use a constant for the file too Print Lof(#ff); " length of file"

Print Fileattr(#ff); " file mode"' should be 1 for input Do

LineInput #ff , S ' read a line

' line input is used to read a line of text from a file Print S ' print on terminal emulator

Loop Until Eof(#ff)<> 0

'The EOF() function returns a non-zero number when the end of the file is reached 'This way we know that there is no more data we can read

Close #ff

EXIT

Action

Exit a FOR..NEXT, DO..LOOP , WHILE ..WEND, SUB..END SUB or FUNCTION..END FUNCTION.

page -482-


© MCS Electronics, 1995-2007

Syntax

EXIT FOR

EXIT DO

EXIT WHILE

EXIT SUB

EXIT FUNCTION

Remarks

With the EXIT statement you can exit a structure at any time.

Example

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

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

: exit.bas

'name

'copyright

: (c) 1995-2005, MCS Electronics

'purpose

: demo: EXIT

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

B1 = 50

'assign var

For A = 1 To 100

'for next loop

If A = B1 Then

'decision

Exit For

'exit loop

End If

Next

Print "Exit the FOR..NEXT when A was " ; A

A = 1

Do

Incr A

If A = 10 Then

Exit Do

End If

Loop

Print "Loop terminated"

End

EXP

page -483-


© MCS Electronics, 1995-2007

Action

Returns e( the base of the natural logarithm) to the power of a single or double variable.

Syntax

Target = EXP(source)

Remarks

Target

The single or double that is assigned with the Exp() of the target.

Source

The source to get the Exp of.

See also

LOG , LOG10

Example

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

--

: (c) 1995-2005, MCS Electronics

'copyright

'micro

: Mega88

'suited for demo

: no, but without the DOUBLE, it works for DEMO too

in M48

: no

'commercial addon needed

'purpose

: demonstrates EXP function

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

--

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

for the SW stack

' default use 40

$framesize = 40

for the frame space

Dim X As Single

X = Exp(1.1)

Print X

'prints 3.004166124

X = 1.1

X = Exp(x)

Print X

'prints 3.004164931

Dim D As Double

D = Exp(1.1)

Print D

'prints 3.00416602394643

D = 1.1

D = Exp(d)

Print D

page -484-