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

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

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

Добавлен: 12.06.2025

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

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

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

Basic for PIC Microcontrollers

57

Loop: goto Loop

End

4.29 {LET} Puts the value of the expression into a variable

Syntax:

{LET} {Var=Expression}

Description: LET instruction stores value of the expression into a variable. Expression can be a constant, variable or value of some other expression. Commonly, the optional command word LET is excluded.

Example:

let B0 = B1 * B2 + B3

B0 = B1 * B2 + B3

The two expressions are identical. The latter expression is missing command word “let”.

4.30 LOOKDOWN Searches the table of constants

Syntax:

LOOKDOWN Value, [Const {, Const...}], Var

Description: Instruction LOOKDOWN searches the list of constants and determines the presence of given value. If a given value matches some of the constants, index of the appropriate constant is stored into variable. If the first constant matches our given value, variable is set to zero. If the second constant from the list matches our given value, variable is set to one, etc. If our value isn’t present in the list, variable remains unchanged. Constants list can consist of both numerical and character (string) values. Each character of a string is treated as a separate ASCII value of a constant.

Example:

B0 var byte

B1 var byte

B0=$f

Basic for PIC Microcontrollers

58

Main:

lookdown B0, (“01234567890ABCDEF”), B1 ‘ convert hexadecimal character from B0 to a decimal value and store it into variable B1

PORTB=B1 ‘ PRIKAZI number on port B diodes

loop: goto loop

End

4.31 LOOKDOWN2 Searches the table of constants/variables

Syntax:

LOOKDOWN2 Search, {Test} [Value {, Value...}], Var

Description: LOOKDOWN2 searches the list of values and determines the presence of given value. If “Search” value matches some of the “Value” values, index of the appropriate constant is stored into “Var”.

If “Search” matches the first value of the list, “Var” set to zero. If it matches the second value of the list, “Var” is set to one, etc. If “Search” va lue isn’t present in the list, “Var” remains unchanged.

Optional parameter “Test” is used for testing if “Search” value is greater or lesser than a certain value. If “>” is used, index of the first matching constant is stored to “Var”. List of values can consist of 16-bit numbers, characters or variables. Every character of a string is treated as a separate ASCII value of that character (arrays of variables cannot be used with LOOKDOWN2 instruction). LOOKDOWN2 generates the code about 3 times greater than LOOKDOWN instruction does. Thus, when searching the list consisting of 8-bit constants and strings, use of LOOKDOWN is prefferrable.

Example:

lookdown2 W0, [512, 768, 1024], B0

If value of W0 is 512 B0 will have value of 0. If value of W0 is 768 then B0 will have value of 1, etc.


Basic for PIC Microcontrollers

59

lookdown2 W0, <[10,100,1000], B0

If value of W0 is 4 B0 will have value of 0. If value of W0 is 200 then B0 will have value of 2, etc.

4.32 LOOKUP Gets value from the table of constants

Syntax:

LOOKUP Index, ( Constant {, Constant}), Var

Description:

LOOKUP is used for reading values from the table of constants, according to the value of

variable “Index”. If “Index” equals zero, “Var” is set to the value of the first constant. If

“Index” equals one, “Var” is set to the value of the second constant, etc. If “Index” is

equal or greater than number of elements in the Look-up table “Var” remains unchanged.

List of constants can consist of numerical and string constants. Each character of a string

is treated as a separate ASCII value of a character.

Example:

Program below illustrates the use of LOOKUP instruction. for displaying digits on seven-

segment displays. Depending on value of parameter “Digit”, we get mask for appropriate

value of parameter “mask”.

Digit var byte

‘ value of digit to be displayed

Mask var byte‘

mask of digit to be displayed

Main:

for i=0 to 9

Digit=i

Lookup Digit, [$3F, $06, $5B, $4F, $66, $6D, $7D, $07, $7F, $6F], Mask

PORTB=Mask

‘ Send the mask of a digit to port B

pause 500 ‘

delay allowing to see digits changing


Basic for PIC Microcontrollers

60

next i

‘ Increase i by one

goto Main

‘ Repeat the whole program

end


Basic for PIC Microcontrollers

61

INSTRUCTIONS (3/4)

Introduction

4.1 @

4.17 GOSUB

4.33 LOOKUP2

4.49 RETURN

4.2 ASM..ENDASM

4.18 GOTO

4.34 LOW

4.50 REVERSE

4.3 ADCIN

4.19 HIGH

4.35 NAP

4.51 SELECT-CASE

4.4 BRANCH

4.20 HSERIN

4.36 OUTPUT

4.52 SERIN

4.5 BRANCHL

4.21 HPWM

4.37 OWIN

4.53 SERIN2

4.6 BUTTON

4.22 HSEROUT

4.38 OWOUT

4.54 SEROUT

4.7 CALL

4.23 I2CREAD

4.39 PAUSE

4.55 SEROUT2

4.8 CLEAR

4.24 I2CWRITE

4.40 PAUSEUS

4.56 SHIFTIN

4.9 CLEARWDT

4.25 INPUT

4.41 POT

4.57 SHIFTOUT

4.10 COUNT

4.26 IF-THEN-ELSE

4.42 PULSIN

4.58 SLEEP

4.11 DATA

4.27 LCDOUT

4.43 PULSOUT

4.59 SOUND

4.12 DTMFOUT

4.28 LCDIN

4.44 PWM

4.60 STOP

4.13 EEPROM

4.29 {LET}

4.45 RANDOM

4.61 SWAP

4.14 END

4.30 LOOKDOWN

4.46 RCTIME

4.62 TOGGLE

4.15 FREQOUT

4.31 LOOKDOWN2

4.47 READ

4.63 WRITE

4.16 FOR-NEXT

4.32 LOOKUP

4.48 READCODE

4.64 WRITECODE

4.65 WHILE-WEND

4.33 LOOKUP2 Gets value from the table of constants/variables

Syntax:

LOOKUP2 Index, [Value {, Value...}], Var

Description: Instruction LOOKUP2 can be used for reading values from the table of values by index. If “Index” equals zero, “Var” attains the value of the first element in the list. If “Index” equals one, “Var” attains value of the second element in the list, etc. If “Index” is equal or greater than number of elements in the Look -up table “Var” remains unchanged.

List of values can consist of 16-bit numbers, characters or variables. Every character of a string is treated as a separate ASCII value of that character. Arrays of variables cannot be used with LOOKUP2 instruction. LOOKUP2 generates the code about 3 times greater than LOOKUP instruction does. Thus, when searching the list consisting of 8-bit constants and strings, use of LOOKUP is prefferrable.

Example:

lookup2 B0, [256, 1024], W0

For B0=0, W0 will have value of 256

For B0=1, W0 will have value of 1024

For B0=2,3,... W0 will remain unchanged


Basic for PIC Microcontrollers

62

4.34 LOW Puts logical zero to output pin

Syntax:

LOW Pin

Description:

Sets specific pin to zero. Pins is automatically designated output. Same effect can be

achieved with PORTB=0.

Example:

Main:

low PORTB.7

‘ Set RB7 to a low level

Loop: goto Loop

End

4.35 NAP

Turns off the processor for a short period of time

Syntax:

NAP period

Description:

Instruction sets PIC microcontroller to low power mode (state of low energy consumption)

for a short period of time. During this "nap", energy consumption is minimized. Stated

periods are just approximations because these values were taken from watch dog timer

and depend on chip and temperature:

Period

Delay [ms]

0

18

1

36

2

72

3

144

4

288

5

576

6

1152

7

2304

Example:

Main: