stepan89
Newbie level 4
- Joined
- Aug 16, 2010
- Messages
- 7
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Location
- Czech Republic
- Activity points
- 1,339
Hello everyone,
I am a very beginner in microcontrolers. I need to program a 7-segment display - I need to show 3 (or more) digit number and move it from the first display to the last. I have got 8 seven-segment displays. I uploaded an image for better imagination, what I need. I should be really easy, but I'm stucked with this. So any help would be appreciated.
I wrote a program that ALMOST works - I want it to show like this: 1. show first digit, 2. show first and second digit, 3. show first, second and third digit 4. move along the 8 displays till eighth display, where it should do the same but vice versa - show only 2 digit, show 1 digit, show 0 digit ....
I have attached simple illustration.
Here's the part of my code:
Thank you very much !
I am a very beginner in microcontrolers. I need to program a 7-segment display - I need to show 3 (or more) digit number and move it from the first display to the last. I have got 8 seven-segment displays. I uploaded an image for better imagination, what I need. I should be really easy, but I'm stucked with this. So any help would be appreciated.
I wrote a program that ALMOST works - I want it to show like this: 1. show first digit, 2. show first and second digit, 3. show first, second and third digit 4. move along the 8 displays till eighth display, where it should do the same but vice versa - show only 2 digit, show 1 digit, show 0 digit ....
I have attached simple illustration.
Here's the part of my code:
Code:
// Want to display 3 digit number e.g. 120
// BCD function convert numbers to hexadecimal
// PORTB - the display
// PORTC - segments on display
DDRC = 255;
DDRB = 255;
char original = 1;
while (1)
{
PORTB = 1; // start on display 1
for (int i = 1; i <= 8; i++)
{
PORTB = PORTB * 2; // second, third... display ... 1,2,4,8,16,32,64,128
if (i == 1) // in first step I want to be on display 1, next on 2, 4, 8 ...
{
original = 1;
PORTB = 1;
}
else
original = PORTB;
for (int j = 1; j < 20; j++)
{
PORTC = BCD(1); // shows 1
delay_ms(5);
PORTB = PORTB >> 1; // display next to the first
PORTC = BCD(2); // shows 2
delay_ms(5);
PORTB = PORTB >> 1; // display next to the second
PORTC = BCD(0); // shows 0
delay_ms(5);
PORTB = original; // resets the position of PORTB, 20 times it would shift more than need
} // so if PORTB is e.g. 8, then PORTB 4 and PORTB 2 shows number
}
}
}
Thank you very much !