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

Project Hardware

Project Hardware

The circuit diagram of the project is shown in Figure 6.16. PORTC of a PIC18F452 microcontroller is used to drive the LEDs as follows:

• RC0 drives D2,D6 of the first dice

• RC1 drives D1,D3 of the first dice

• RC2 drives D5,D7 of the first dice

• RC3 drives D4 of the first dice

• RC4 drives D2,D6 of the second dice

• RC5 drives D1,D3 of the second dice

• RC6 drives D5,D7 of the second dice

• RC7 drives D4 of the second dice


Figure 6.16: Circuit diagram of the project

Since two LEDs are being driven on some outputs, we can calculate the required value of the current limiting resistors. Assuming that the voltage drop across each LED is 2V, the current through the LED is 10mA, and the output high voltage of the microcontroller is 4.85V, the required resistors are:

 

We will choose 100-ohm resistors.

We now need to find the relationship between the dice numbers and the bit pattern to be sent to the LEDs for each dice. Table 6.4 shows the relationship between the first dice numbers and the bit pattern to be sent to port pins RC0–RC3. Similarly, Table 6.5 shows the relationship between the second dice numbers and the bit pattern to be sent to port pins RC4–RC7.

Table 6.4: First dice bit patterns

Dice number RC3 RC2 RC1 RC0 Hex value
1 1 0 0 0 8
2 0 0 0 1 1
3 1 0 0 1 9
4 0 1 1 0 6
5 1 1 1 0 E
6 0 1 1 1 7

Table 6.5: Second dice bit patterns

Dice number RC3 RC2 RC1 RC0 Hex value
1 1 0 0 0 8
2 0 0 0 1 1
3 1 0 0 1 9
4 0 1 1 0 6
5 1 1 1 0 E
6 0 1 1 1 7

We can now find the 8-bit number to be sent to PORTC to display both dice numbers as follows:

• Get the first number from the number generator, call this P

• Index the DICE table to find the bit pattern for low nibble (i.e., L = DICE[P])

• Get the second number from the number generator, call this P

• Index the DICE table to find the bit pattern for high nibble (i.e., U = DICE[P])

• Multiply high nibble by 16 and add low nibble to find the number to be sent to PORTC (i.e., R = 16*U + L), where R is the 8-bit number to be sent to PORTC to display both dice values.

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


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