Arduino + 7 Segmentos (74HC595, 74HC4511)
Este circuito permite controlar vários displays 7-Segmentos com apenas 3 pinos de um Arduino. Para isso utiliza-se um registo de deslocamento (74HC595) e um controlador do 7-Segmentos para fazer a descodificação dos algarismos (binário –> 7-Segmentos).
Materiais
- 1 ATMega328p (*)
- 1 Cristal 16MHz (*)
- 2 Condesadores Cerâmicos 22pF (*)
- 14 Resistências 220 Ohm
- 2 74HC4511 – BCD to 7-segment latch/decoder/driver
- 1 74HC595 – 8 Bit Shift Registers with 3-State Output Register
Caso seja utilizado um Arduino os componentes assinalados com (*) não são necessários.
Para representar o maior algarismo em binário (9 –> 1001) necessitamos de 4-bits, assim podemos utilizar o 74HC595 para controlar 2 display de 7-Segmentos, uma vez que este é um registo de deslocamento de 8 bits. Para que o número em binário possa ser representado no display é necessário utilizar o 74HC4511 para efectuar o controlo dos 7 LED’s do display.
É necessário um registo de deslocamento por cada 2 displays e por cada display é necessário um driver (74HC4511).
Caso sejam utilizados 4 displays de 7-Segmentos serão necessários 2 shift registers ligados em cascata e 4 driver dos 7-Segmentos. Serão também necessárias algumas alterações no código de modo a poder controlar os 4 displays.
Esquema do Circuito
Código Arduino
/* * LCD circuit: * LCD RS pin to digital pin 12 * LCD Enable pin to digital pin 11 * LCD D4 pin to digital pin 5 * LCD D5 pin to digital pin 4 * LCD D6 pin to digital pin 3 * LCD D7 pin to digital pin 2 * LCD R/W pin to ground * 10K resistor: * ends to +5V and ground * wiper to LCD VO pin (pin 3) */ #include <LiquidCrystal.h> //Pin connected to latch pin (ST_CP) of 74HC595 const int latchPin = 9; //Pin connected to clock pin (SH_CP) of 74HC595 const int clockPin = 12; ////Pin connected to Data in (DS) of 74HC595 const int dataPin = 11; // initialize the library with the numbers of the interface pins LiquidCrystal lcd(8, 7, 6, 4, 3, 2); int seven_seg_digits[10][4] = { { 0,0,0,0 }, // = 0 { 0,0,0,1 }, // = 1 { 0,0,1,0 }, // = 2 { 0,0,1,1 }, // = 3 { 0,1,0,0 }, // = 4 { 0,1,0,1 }, // = 5 { 0,1,1,0 }, // = 6 { 0,1,1,1 }, // = 7 { 1,0,0,0 }, // = 8 { 1,0,0,1 } // = 9 }; void disp7Segm(int digit) { digitalWrite(5, seven_seg_digits[digit][0]); digitalWrite(9, seven_seg_digits[digit][1]); digitalWrite(10, seven_seg_digits[digit][2]); digitalWrite(11, seven_seg_digits[digit][3]); } void setup() { // set up the LCD's number of columns and rows: lcd.begin(16, 2); pinMode(latchPin, OUTPUT); pinMode(dataPin, OUTPUT); pinMode(clockPin, OUTPUT); } void loop() { // Print a message to the LCD. lcd.print("hello, world!"); // set the cursor to column 0, line 1 // (note: line 1 is the second row, since counting begins with 0): lcd.setCursor(0, 1); // print the number of seconds since reset: lcd.print(millis()/1000); for(int j=0; j<200; j++){ disp7SegmWrite(j); delay(100); } } // This method sends bits to the shift register: void registerWrite(int whichPin, int whichState) { // the bits you want to send byte bitsToSend = 0; // turn off the output so the pins don't light up // while you're shifting bits: digitalWrite(latchPin, LOW); // turn on the next highest bit in bitsToSend: bitWrite(bitsToSend, whichPin, whichState); // shift the bits out: shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend); // turn on the output so the LEDs can light up: digitalWrite(latchPin, HIGH); } void disp7SegmWrite(int number) { int num1=0, num2=0; if((number < 0) || (number > 99)){ number = 0; } num1=number/10; num2=number%10; // the bits you want to send byte bitsToSend = 0; // turn off the output so the pins don't light up // while you're shifting bits: digitalWrite(latchPin, LOW); //Escreve num1 (digito mais significativo) bitWrite(bitsToSend, 0, seven_seg_digits[num1][3]); bitWrite(bitsToSend, 1, seven_seg_digits[num1][2]); bitWrite(bitsToSend, 2, seven_seg_digits[num1][1]); bitWrite(bitsToSend, 3, seven_seg_digits[num1][0]); //Escreve num2 (digito menos significativo) bitWrite(bitsToSend, 4, seven_seg_digits[num2][3]); bitWrite(bitsToSend, 5, seven_seg_digits[num2][2]); bitWrite(bitsToSend, 6, seven_seg_digits[num2][1]); bitWrite(bitsToSend, 7, seven_seg_digits[num2][0]); // shift the bits out: shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend); // turn on the output so the LEDs can light up: digitalWrite(latchPin, HIGH); }
Bom dia!
Achei muito legal teu post! Me ajudou muito! Caso você tenha um esquema com 10 7-segments…
Estou montando um placar eletronico para tenis. Qualquer dica ajuda! 🙂
Muito bom o post.
Tenho uma dúvida, o display que você usa é do tipo Common Anode ou Cathode?