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

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

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

Добавлен: 12.06.2025

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

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

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

© MCS Electronics, 1995-2007

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

ELSE

Action

Executed if the IF-THEN expression is false.

Syntax

ELSE

Remarks

You don't have to use the ELSE statement in an IF THEN .. END IF structure. You can use the ELSEIF statement to test for another condition.

IF a = 1 THEN

...

ELSEIF a = 2 THEN

..

ELSEIF b1 > a THEN

...

ELSE

...

END IF

See also

page -476-


© MCS Electronics, 1995-2007

IF , END IF , SELECT-CASE

Example

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

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

: if_then.bas

'name

'copyright

: (c) 1995-2005, MCS Electronics

'purpose

: demo: IF, THEN, ELSE

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

Input "Number " , A

'ask for number

If A = 1 Then

'test number

Print "You got it!"

End If

If A = 0 Then

'test again

Print "Wrong"

'thats wrong

Else

'print this if a

is not 0

Print "Almost?"

End If

Rem You Can Nest If Then Statements Like This

B1 = 0

If A = 1 Then

If B1 = 0 Then

Print "B1=0"

End If

Else

Print "A is not 0"

End If

Input "Number " , A

'

If A = 1 Then

Print "Ok"

'use elseif for

Elseif A = 2 Then

more tests

Print "2" : A = 3

Elseif A = 3 Then

Print "3"

End If

If A.1 = 1 Then Print "Bit 1 set"

'test for a bit

End

page -477-


© MCS Electronics, 1995-2007

ENABLE

Action

Enable specified interrupt.

Syntax

ENABLE interrupt

Remarks

Interrupt

Description

INT0

External Interrupt 0

INT1

External Interrupt 1

OVF0,TIMER0,

TIMER0 overflow interrupt

COUNTER0

OVF1,TIMER1,

TIMER1 overflow interrupt

COUNTER1

CAPTURE1, ICP1

INPUT CAPTURE TIMER1 interrupt

COMPARE1A,OC1A or

TIMER1 OUTPUT COMPARE A interrupt

COMPARE1, OC1

In case of only one compare interrupt

COMPARE1B,OC1B

TIMER1 OUTPUT COMPARE B interrupt

SPI

SPI interrupt

URXC

Serial RX complete interrupt

UDRE

Serial data register empty interrupt

UTXC

Serial TX complete interrupt

SERIAL

Disables URXC, UDRE and UTXC

ACI

Analog comparator interrupt

ADC

A/D converter interrupt

By default all interrupts are disabled.

To enable the enabling and disabling of interrupts use ENABLE INTERRUPTS.

Other chips might have additional interrupt sources such as INT2, INT3 etc.

See also

DISABLE

Partial Example

Enable Interrupts

'allow interrupts to be set

Enable Timer1

'enables the TIMER1 interrupt

ENCODER

page -478-


© MCS Electronics, 1995-2007

Action

Reads pulses from a rotary encoder.

Syntax

Var = ENCODER( pin1, pin2, LeftLabel, RightLabel , wait)

Remarks

Var

The target variable that is assigned with the result

Pin1 and pin2

These are the names of the PIN registers to which the output of the

encoder is connected. Both pins must be on the same PIN register. So

Pinb.0 and Pinb.7 is valid while PinB.0 and PinA.0 is not.

LeftLabel

The name of the label that will be called/executed when a transition

to the left is encoded.

RightLabel

The name of the label that will be called/executed when a transition

to the right is encountered.

wait

A value of 0 will only check for a rotation/pulse. While a value of 1

will wait until a user actual turns the encoder. A value of 1 will thus

halt your program.

There are some conditions you need to fulfill :

The label that is called by the encoder must be terminated by a RETURN statement.

The pin must work in the input mode. By default all pins work in input mode.

The pull up resistors must be activated by writing a logic 1 to the port registers as the examples shows.

Rotary encoders come in many flavors. Some encoders also have a build in switch.

A sample of an encoder

page -479-