Hello guys, I've a project for college where I need to use a 7 segment display with 4 digits( is 5641AH CC) and a temperature sensor, but I'll add it later. But I can't move forward because I can't make the 7 segment display show my value (n). It's been 2 days of trying and nothing, I really don't know what to do more and I'm asking for some help .
with n=8795 it shows on display 8 on digit 432 then 7 on 431, 9 on digit 421 and 5 on 321
how can I make it show exactly the value without moving and shifting also I can't use pin mode only direct port like in the code?
here is the code
//afisarea numarului pe display
#include<avr/io.h>
int n=8795;
void display (char p, char c)
{
PORTB &= 0b11110000;
PORTD &= 0b00000000;
switch(c) {
case 0:
PORTD |= 0b00111111;
break;
case 1:
PORTD |= 0b00000110;
break;
case 2:
PORTD |= 0b01011011;
break;
case 3:
PORTD |= 0b01001111;
break;
case 4:
PORTD |= 0b01100110;
break;
case 5:
PORTD |= 0b01101101;
break;
case 6:
PORTD |= 0b01111101;
break;
case 7:
PORTD |= 0b00000111;
break;
case 8:
PORTD |= 0b01111111;
break;
case 9:
PORTD |= 0b01101111;
break;
}
switch(p)
{
case 1:
PORTB|=0b00000001;
break;
case 2:
PORTB|=0b00000010;
break;
case 3:
PORTB|=0b00000100;
break;
case 4:
PORTB|=0b00001000;
break;
}
delay(1000);
}
void setup () {
DDRB |= 0b00001111;
DDRD |= 0b11111111;
}
void loop()
{
display(1, n%10);
display(2, (n/10)%10);
display(3, (n/100)%10);
display(4 ,(n/1000)%10);
}
n is the value which I want to show on display but, using the current code I get on display 8 on the digits 4,3,2 then 7 on digits 4,3,1, then 9 on digits 4,2,1, then 5 on digits 3,2,1 and so on.
Cross-posting is against the rules of the forum. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend 15 minutes (or more) writing a detailed answer on this topic, without knowing that someone else already did the same in the other topic.
Repeated cross-posting will result in a suspension from the forum.
In the future, please take some time to pick the forum board that best suits the topic of your question and then only post once to that forum board. This is basic forum etiquette, as explained in the sticky "How to use this forum - please read." post you will find at the top of every forum board. It contains a lot of other useful information. Please read it.
gmbogdan:
n is the value which I want to show on display but, using the current code I get on display 8 on the digits 4,3,2 then 7 on digits 4,3,1, then 9 on digits 4,2,1, then 5 on digits 3,2,1 and so on.
I think understand now.
case 1:
PORTB|=0b00000001;
should be
case 1:
PORTB|=0b00001110;
and so on for the other digits. You need to make the pin connected to the common cathode low so that current flows through only that digit. The pins connected to the other 3 common cathodes should be high to prevent current flowing through them.
You should also post a schematic so we can check your circuit will not damage the Arduino. Hand drawn is ok.
somehow is okay, but you got the wrong idea, sorry for my explications.
I need it to show exactly the number I put in code which is 8795 because after this I need to put a LM35 to get the temperature from the room and show it on display but, if the other digits are off I can't do that.
For example if the temperature sensor gets 25 degrees, I need to show that value exactly on display and if the temperature will rise, on the display should change it to. That's why I'm trying to fix the display now and show the value I insert in n.
Also I' ll post later my drawing, right now the display is connected on the Arduino board like this digits to pin 8,9,10,11 and the segments are + decimal point form 0 to 7 pins with 220 ohms resistance
gmbogdan:
somehow is okay, but you got the wrong idea
This is not a helpful response. If you want help, you must provide information. What is the circuit/code doing now? I cannot see what you can see.
Let me take a guess. The display is now showing "8795", but only one digit at a time, for 1 second each? So "8" for 1 second on the first digit, then "7" for 1 second on the second digit, then "9" for 1 second and so on. Correct?
gmbogdan:
the display is connected on the Arduino board like this digits to pin 8,9,10,11 and the segments are + decimal point form 0 to 7 pins with 220 ohms resistance
This will burn the Arduino pins. If you are not using transistors or driver chips for the common cathodes, you need to use much higher value series resistors, like 780R or 1K. Right now, the pins connected to the common cathodes are sinking over 100mA and the maximum is 40mA before damage begins.
Also, what type of Arduino are you using? With Uno, Nano and many others, you should not use pins 0, 1 for your circuit because these are used for uploading the sketch and using the Serial monitor.
It looks like you forgot to buy a controller with that display...
Sure you can multiplex the digits yourself, but you can save yourself a world of pain by using a display with driver IC, such as the dirt cheap TM1637. Install the library, connect the four wires, and you're set.
Of course mutiplexing a display is a very interesting exercise in itself but if all you want is to get numbers to display... don't. Not worth the effort.
wvmarle:
Of course multiplexing a display is a very interesting exercise in itself but if all you want is to get numbers to display... don't. Not worth the effort.