Книга: Advanced PIC Microcontroller Projects in C
Project PDL
Project PDL
The operation of this project is very similar to that of Project 2. Figure 6.17 shows the PDL of the project. At the beginning of the program the PORTC 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 the bit pattern to be sent to PORTC is found by the method just described. This bit pattern is then sent to PORTC to display both dice numbers at the same time. The display shows the dice numbers for 3 seconds, and then all the LEDs turn OFF to indicate that the system is waiting for the push-button to be pressed again to display the next set of numbers.
START
Create DICE table
Configure PORTC as outputs
Configure RB0 as input
DO FOREVER
IF button pressed THEN
Get a random number between 1 and 6
Find low nibble bit pattern
Get second random number between 1 and 6
High high nibble bit pattern
Calculate data to be sent to PORTC
Wait 3 seconds
Turn OFF all LEDs
ENDIF
ENDDO
END
Figure 6.17: PDL of the project