Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

7 segment display problem ATMEL

Status
Not open for further replies.

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:

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		
				
	}
}

}

26_1336201545.jpg


Thank you very much !
 

Attachments

  • 7segment.jpg
    7segment.jpg
    27 KB · Views: 128

Hello, It would help if you have a wiring diagram, but If I got it right, this should work... I wouldn't do it like this, but I've tried not to change too much your code.. Otherwise you would loose all the fun on figure out the rest by your self :)

between other problems your where having PORTB overflow

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;
[B]int[/B] original = 1;  // start on display 1

while (1)
{
	for (int i = 1; i <= [B]10[/B]; i++)
	{					
		
		for (int j = 1; j < 20; j++)
		{	
	                [B]PORTB = (char) original ;[/B]
			PORTC = BCD(1);   // shows 1
			delay_ms(5);
	
			PORTB = [B](char)(original >> 1)[/B]; // display next to the first 
			PORTC = BCD(2);  // shows 2
			delay_ms(5);
	
			PORTB =[B](char)(original >> 2)[/B];  // display next to the second
			PORTC = BCD(0);  // shows 0
			delay_ms(5);	
			
					
		}                           // so if PORTB is e.g. 8, then PORTB 4 and PORTB 2 shows number		
	
               [B] original = original << 1; [/B] // second, third... display ... 1,2,4,8,16,32,64,128
		
	}
}

}
 
Last edited:
To: mgate

Thanks a lot! That's a pity I can't try it, I must wait till friday, I haven't got microcontroler at home :)

---------- Post added at 12:25 ---------- Previous post was at 12:11 ----------

OK... i think I understand. But if I would like to run it over and over again, from left to right, I have to add /original = 1;/ in the beginning of program, right after while (1), am I right?
 

I hope its working now... Anyway if it is still not working, or if you need help for adding a bigger message, just post again your issues :) .. I guess you will need to be patient ..

---------- Post added at 11:31 ---------- Previous post was at 11:27 ----------

OK... i think I understand. But if I would like to run it over and over again, from left to right, I have to add /original = 1;/ in the beginning of program, right after while (1), am I right?

Yes, That would do the trick :)
 

Thanks again!
I want to "upgrade" it little more. I'd like to move a counter (0 - 59, lets say it increments every second) - and I want it to move along the displays like the number "120" before. Every second it changes and moves ... next second change and move ... round and round ...

I tried to put the two algorithms together. Can you please give a comment? I can't try the algorithm now, so it is really hard to say if its ok or a really stupidity :)

Counter algorithm:
Code:
		for (int i = 0; i < 60; i++)
		{	
			for (int j = 0; j < 100; j++)  // 100 * 10 ms = 1 second
			{
				PORTB = 1;	
				PORTC = BCD(i%10);  // displays numbers
				delay_ms(5);
			
				PORTB = 2;
				PORTC = BCD(i/10);   // displays decades
				delay_ms(5);

And if I put it together with the "moving" algorithm, I got this:

Code:
int original = 1;
int counter = 1;

while (1) {	

		for (int i = 0; i < [B]60[/B]; i++)   // I changed to 60 - I need it (the 60) for the clock algorithm in the second for loop
		{	
			for (int j = 0; j < 100; j++)  // 100 * 10 ms = 1 second
			{
				PORTB = (char) original ;	
				PORTC = BCD(i%10);    // displays numbers
				delay_ms(5);
			
				PORTB = (char)(original >> 1) ;
				PORTC = BCD(i/10);   // displays decades
				delay_ms(5);						
			}

			counter++;  // every second counter increments
			
			if (counter == 10)  // if there were already 9 moves - end of displays, and this is the 10th move 
			{
			  counter = 1;   // reset counter
			  original = 1;  // go to the beginning - position 1 (on the right)
			}
			
			original = original << 1;  // every second move one position left
		}

So if you be so kind and tell me, what you mean about it :)
Thank you!
 

I think it might work as long as you check if is the end of the display on the beginning of the main for loop... because of the interaction with the ( original <=1).

Code:
int original = 1;
int counter = 1;

while (1) {	

		for (int i = 0; i < 60; i++)   // I changed to 60 - I need it (the 60) for the clock algorithm in the second for loop
		{	
			if (counter == 10)  // if there were already 9 moves - end of displays, and this is the 10th move 
			{
			  counter = 1;   // reset counter
			  original = 1;  // go to the beginning - position 1 (on the right)
			}

			for (int j = 0; j < 100; j++)  // 100 * 10 ms = 1 second
			{
				PORTB = (char) original ;	
				PORTC = BCD(i%10);    // displays numbers
				delay_ms(5);
			
				PORTB = (char)(original >> 1) ;
				PORTC = BCD(i/10);   // displays decades
				delay_ms(5);						
			}

			counter++;  // every second counter increments

			original = original << 1;  // every second move one position left
		}
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top