Книга: Advanced PIC Microcontroller Projects in C

6.1.4 DO-ENDDO

6.1.4 DO-ENDDO

Use Do and ENDDO keywords to show iteration in the PDL code.

Example:

To create an unconditional loop in a program we can write:

Turn on LED
DO 10 times
 Set clock to 1
 Wait for 10ms
 Set clock to 0
ENDDO

A variation of the DO-ENDDO construct is to use other keywords like DO-FOREVER, DO-UNTIL, etc. as shown in the following examples.

Example:

To create a conditional loop in a program we can write:

Turn off buzzer
IF switch = 1 THEN
 DO UNTIL Port 1 = 1
  Turn on LED
  Wait for 10ms
  Read Port 1
 ENDDO
ENDIF

The following construct can be used when an endless loop is required:

DO FOREVER
 Read data from Port 1
 Send data to PORT 2
 Wait for 1 second
ENDDO

Оглавление книги


Генерация: 1.560. Запросов К БД/Cache: 3 / 1
поделиться
Вверх Вниз