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

Project PDL

Project PDL

The operation of the project is described in PDL in Figure 6.9. At the beginning of the program 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 increments a variable between 1 and 6. The state of the push-button switch is checked and when the switch is pressed (switch output at logic 0), the current number is sent to the LEDs. A simple array is used to find out the LEDs to be turned ON corresponding to the dice number.

START
 Create DICE table
 Configure PORTC as outputs
 Configure RB0 as input
 Set J = 1
 DO FOREVER
  IF button pressed THEN
   Get LED pattern from DICE table
   Turn ON required LEDs
   Wait 3 seconds
   Set J = 0
   Turn OFF all LEDs
  ENDIF
  Increment J
  IF J = 7 THEN
   Set J = 1
  ENDIF
 ENDDO
END


Figure 6.9: PDL of the project

Table 6.1 gives the relationship between a dice number and the corresponding LEDs to be turned ON to imitate the faces of a real dice. For example, to display number 1 (i.e., only the middle LED is ON), we have to turn on D4. Similarly, to display number 4, the LEDs to turn ON are D1, D3, D5, and D7.

Table 6.1: Dice number and LEDs to be turned ON

Required number LEDs to be turned on
1 D4
2 D2, D6
3 D2, D4, D6
4 D1, D3, D5, D7
5 D1, D3, D4, D5, D7
6 D1, D2, D3, D5, D6, D7

The relationship between the required number and the data to be sent to PORTC to turn on the correct LEDs is given in Table 6.2. For example, to display dice number 2, we have to send hexadecimal 0x22 to PORTC. Similarly, to display number 5, we have to send hexadecimal 0x5D to PORTC, and so on.

Table 6.2: Required number and PORTC data

Required number PORTB data (Hex)
1 0x08
2 0x22
3 0x2A
4 0x55
5 0x5D
6 0x77

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


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