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

Project PDL

Project PDL

The operation of the project is very similar to that for Project 2. Figure 6.14 shows the PDL for this project. At the beginning of the program the PORTC and PORTD pins are configured as outputs, and bit 0 of PORTB (RB0) is configured as input. The program then executes in a loop continuously and checks the state of the push-button switch. When the switch is pressed, two pseudorandom numbers between 1 and 6 are generated, and these numbers are sent to PORTC and PORTD. The LEDs remain at this state for 3 seconds, after which all the LEDs are turned OFF to indicate that the push-button switch can be pressed again for the next pair of numbers.

START
 Create DICE table
 Configure PORTC as outputs
 Configure PORTD as outputs
 Configure RB0 as input
 DO FOREVER
  IF button pressed THEN
   Get a random number between 1 and 6
   Find bit pattern
   Turn ON LEDs on PORTC
   Get second random number between 1 and 6
   Find bit pattern
   Turn on LEDs on PORTD
   Wait 3 seconds
   Turn OFF all LEDs
  ENDIF
 ENDDO
END


Figure 6.14: PDL of the project

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

Оглавление статьи/книги

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