A quick course in Binary



Download 2,72 Mb.
bet10/17
Sana03.07.2022
Hajmi2,72 Mb.
#736533
1   ...   6   7   8   9   10   11   12   13   ...   17
Bog'liq
6 bo`lim

Controlling the LED


We’ll control the LED display using the method discussed in Project 17, by connecting pins A through DP to the shift register outputs Q0 to Q7. Use the matrix shown in Table 6-2 as a guide to help you determine which segments to turn on and off to display a particular number or letter.
The top row in the matrix is the shift register output pin that controls the segments on the second row. Each row below this shows the digit that can be displayed with the corresponding binary and decimal value to send to the shift register.
Table 6-2: Display Segment Matrix

SR

Q0

Q1

Q2

Q3

Q4

Q5

Q6

Q7




Segment

A

B

C

D

E

F

G

DP

Decimal

0

1

1

1

1

1

1

0

0

252

1

0

1

1

0

0

0

0

0

96

2

1

1

0

1

1

0

1

0

218

3

1

1

1

1

0

0

1

0

242

4

0

1

1

0

0

1

1

0

102

5

1

0

1

1

0

1

1

0

182

6

1

0

1

1

1

1

1

0

190

7

1

1

1

0

0

0

0

0

224

8

1

1

1

1

1

1

1

0

254

9

1

1

1

1

0

1

1

0

246

A

1

1

1

0

1

1

1

0

238

B

0

0

1

1

1

1

1

0

62

C

1

0

0

1

1

1

0

0

156

D

0

1

1

1

1

0

1

0

122

E

1

0

0

1

1

1

1

0

158

F

1

0

0

0

1

1

1

0

142

For example, to display the digit 7 as shown in Figure 6-12, we need to turn on LED segments A, B, and C, which correspond to the shift register outputs Q0, Q1, and Q2. Therefore, we will send the byte B1110000 into the shift register (with shiftOut set to LSBFIRST) to turn on the first three outputs that match the desired LEDs on the module.

Figure 6-12: Displaying the digit 7
In the next example, we’ll create a circuit that displays, in turn, the digits 0 through 9 and then the letters A through F. The cycle repeats with the decimal-point LED turned on.

project #18: creating a single-digit display


In this project we’ll assemble a circuit to use a single-digit display.

The Hardware


The following hardware is required:

  • One 74HC595 shift register IC

  • One common-cathode seven-segment LED display

  • Eight 560 W resistors (R1 to R8)

  • One large breadboard

  • Various connecting wires

  • Arduino and USB cable

The Schematic


The schematic is shown in Figure 6-13.

When wiring the LED module to the shift register, LED pins A through G connect to pins Q0 through Q6, respectively, and DP connects to Q7.

The Sketch


In the sketch for Project 18, we store the decimal values (see Table 6-2) in the int digits[] array. In the void loop, we send these values to the shift register in sequential order at  and then repeat the process with the decimal point on by adding 1 to the value sent to the shift register at :
// Project 18 - Creating a Single-Digit Display
#define DATA 6 // connect to pin 14 on the 74HC595
#define LATCH 8 // connect to pin 12 on the 74HC595
#define CLOCK 10 // connect to pin 11 on the 74HC595
// set up the array with the segments for 0 to 9, A to F (from Table 6-2) int digits[] = {252, 96, 218, 242, 102, 182, 190, 224, 254, 246, 238, 62, 156, 122, 158, 142};
void setup()
{
pinMode(LATCH, OUTPUT); pinMode(CLOCK, OUTPUT); pinMode(DATA, OUTPUT); }
void loop()
{ int i;
for ( i = 0 ; i < 16 ; i++ ) // display digits 0-9, A-F
{
digitalWrite(LATCH, LOW);
 shiftOut(DATA, CLOCK, LSBFIRST, digits[i]); digitalWrite(LATCH, HIGH);
delay(250);
}
for ( i = 0 ; i < 16 ; i++ ) // display digits 0-9, A-F with DP
{
digitalWrite(LATCH, LOW);
 shiftOut(DATA, CLOCK, LSBFIRST, digits[i]+1); // +1 is to turn on the DP bit digitalWrite(LATCH, HIGH);
delay(250);
}
}
Seven-segment LCD displays are bright and easy to read. For example, Figure 6-14 shows the digit 9 with the decimal point displayed as a result of this sketch.

Figure 6-14: Digit displayed by Project 18

Displaying Double Digits


To use more than one shift register to control additional digital outputs, connect pin 9 of the 74HC595 (which receives data from the Arduino) to pin 14 of the second shift register. Once you’ve made this connection, 2 bytes of data will sent: the first to control the second shift register and the second to control the first shift register. Here’s an example:
digitalWrite(LATCH, LOW);
shiftOut(DATA, CLOCK, MSBFIRST, 254); // data for second 74HC595 shiftOut(DATA, CLOCK, MSBFIRST, 254); // data for first 74HC595 digitalWrite(LATCH, HIGH);

project #19: controlling two seven-segment led display modules


This project will show you how to control two, seven-segment LED display modules so that you can display two-digit numbers.

The Hardware


The following hardware is required:

  • Two 74HC595 shift register ICs

  • Two common-cathode seven-segment LED displays

  • Sixteen 560 W resistors (R1 to 16)

  • One large breadboard

  • Various connecting wires

  • Arduino and USB cable

The Schematic


Figure 6-15 shows the schematic for two display modules.

Note that the shift registers’ data and clock pins are connected to each other and then to the Arduino. The data line from Arduino digital pin 6 runs to shift register 1, and then a link from pin 9 of shift register 1 runs to pin 14 of shift register 2.
To display a number between 0 and 99, we’ll need a more complicated sketch. If a number is less than 10, then we can just send the number followed by a 0, as the right digit displays the number and the left digit displays 0. However, if the number is greater than 10, then we need to determine each of the number’s two digits and send each to the shift registers separately. To make this process easier, we’ll use the math function modulo.

Modulo


Modulo is a function that returns the remainder of a division operation. For example, 10 modulo (or mod) 7 equals 3—in other words, the remainder of 10 divided by 7 equals 3. We use the percent sign (%) to represent modulo. The following example uses modulo in a sketch:
int a = 8; int b = 3; c = a % b;
In this example, the value of c will be 2. So to determine a two-digit number’s right-hand digit, we use the modulo function, which returns the remainder when dividing the two numbers.
To automate displaying a single- or double-digit number, we’ll create the function displayNumber() for our sketch. We use modulo as part of this function to separate the digits of a two-digit number. For example, to display the number 23, we first isolate the left-hand digit by dividing 23 by 10, which equals 2 (and a fraction that we can ignore). To isolate the right-hand digit, we perform 23 modulo 10, which equals 3.
// Project 19 - Controlling Two Seven-Segment LED Display Modules
// set up the array with the segments for 0 to 9, A to F (from Table 6-2) int digits[] = {252, 96, 218, 242, 102, 182, 190, 224, 254, 246, 238, 62, 156, 122, 158, 142};
void displayNumber(int n)
{
int left, right=0;
 if (n < 10) {
digitalWrite(LATCH, LOW);
shiftOut(DATA, CLOCK, LSBFIRST, digits[n]); shiftOut(DATA, CLOCK, LSBFIRST, 0); digitalWrite(LATCH, HIGH);
}
else if (n >= 10)
{  right = n % 10; // remainder of dividing the number to display by 10 left = n / 10; // quotient of dividing the number to display by 10
digitalWrite(LATCH, LOW);
shiftOut(DATA, CLOCK, LSBFIRST, digits[right]); shiftOut(DATA, CLOCK, LSBFIRST, digits[left]);
digitalWrite(LATCH, HIGH);
}
}  void loop() { int i;
for ( i = 0 ; i < 100 ; i++ )
{
displayNumber(i); delay(100);
}
}
At , the function checks to see if the number to be displayed is less than 10. If so, it sends the data for the number and a blank digit to the shift registers. However, if the number is greater than 10, then the function uses modulo and division at  to separate the digits and then sends them to the shift registers separately. Finally, in void loop() at  we set up and call the function to display the numbers from 0 to 99.

Download 2,72 Mb.

Do'stlaringiz bilan baham:
1   ...   6   7   8   9   10   11   12   13   ...   17




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish