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

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

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

Добавлен: 12.06.2025

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

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

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

Basic for PIC Microcontrollers

69

pwm PORTB.7, 127, 100 ‘ Send pwm cycle with 50% of signal (ON) to RB7

goto Main

End

4.45 RANDOM Generates pseudo-random number

Syntax:

RANDOM Variable

Description:

Instruction RANDOM stores pseudo-random number to variable. Variable should be 16-

bit.

Example:

W0 var word

Main :

random W0

Put random number to variable W0

lcdoout #W0

Display random number on LCD

goto Main

End

4.46 RCTIME Measures impulse duration on pin (similar to PULSIN)

Syntax:

RCTIME Pin, State, Variable

Description:

RCTIME measures time period during which "pin" remains in a certain state. If ihe state

remains unchanged variable is set to zero. RCTIME can be used for reading potentiometer

or some other resistive element based on the time necessary for filling RC constant.

Typical resistance measured is within 5K~50K range.

Resolution depends n oscillator frequency. 4MHz oscillator has 10us resolution, while

20MHz oscillator has 2us resolution.

Example:

W0 var word

Main :

low PORTA.0

‘ Discharge the condenser


Basic for PIC Microcontrollers

70

pause 10

Discharging lasts for 10ms

rctime PORTA.0, 0, W0

‘ Measure duration of charging

lcdout #W0

Display value of W0 on LCD

goto Main

End

4.47 READ Reads one byte of data from data EEPROM

Syntax:

READ Address, Variable

Description:

Instruction READ reads data from internal EEPROM memory from the specified address

and stores the result to "Variable". This instruction can only be used with PIC

microcontrollers which have EEPRO M built in the chip. If microcontroller is supplied with

external EEPROM, instruction I2CREAD should be used instead.

Example:

B0 var byte

W var word

Main :

READ 5, B0

read data from EEPROM, address 5 and put it to variable B0

READ 6, W.BYTE0

load 16-bit data

READ 7, W.BYTE1

from addresses 6 and 7 to variable W

Loop: goto Loop

End

4.48 READCODE Reads 2 bytes (word) of program code from the address

Syntax:

READCODE Address, Variable

Description: READCODE reads program code from a given address and puts the result to 16-bit variable. PIC16F87X microcontroller family allows reading and writing program code while microcontroller is in operation.

Example:

Wo var word


Basic for PIC Microcontrollers

71

Main :

readcode 100, W0 ‘ load data from program FLASH memory, address 100 to var. W0

Loop : goto Loop

End

Basic for PIC Microcontrollers

72

INSTRUCTIONS (4/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.49 RETURN

Return from the subroutine

Syntax:

RETURN

Description:

Instruction RETURN executes return from the program routine which program jumped

onto via GOSUB instruction.

Example:

Main :

gosub portb_on

call a subroutine init_ram

Loop : goto Loop

portb_on:

PORTB=$FF

Light all port B diodes

return

return from subroutine

End


Basic for PIC Microcontrollers

73

4.50 REVERSE Changes pin orientation

Syntax:

REVERSE Pin

Description:

Instruction REVERSE inverts orientation of a specified pin. If pin is input, REVERSE

changes it to output and vice versa.

Example:

Main :

reverse PORTA.0

‘ Change orientation of RA0 pin

Loop : goto Loop

End

4.51 SELECT-CASE Conditional multiple program branching

Syntax:

SELECT CASE Var

CASE Expression1 {, Expression}

Instructions...

CASE Expression2 {, Expression}

Instructions...

CASE Expression3 {, Expression}

Instructions...

CASE ELSE

Instructions...

END SELECT

Description:

Although conditional SELECT -CASE branching can be made with multiple IF -THEN

instructions, it is easier and more sensible to use this instruction in certain

situations. Instruction allows "Expression" to be a constant, one of the constants or a

comparison to a certain constant.

Example:

W var byte