DISPLAY 7 SEG LEDS AND A BUTTON

Go To Last Post
33 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi.

I have to do a project with atmelstudio.

PORTA is used to control 2 displays 7 segment in parallel.

PORTB is used to control green led in PINB0, yellow led in PINB1, red led in PINB2 and a button in PINB7.

Yellow led is high at the start.

If you press the button the yellow led is low and green led is high.

If you press the button 99 times the red led is high.

When you press the button it restarts.

Every time you press the button display shows 00-01-02-03-04-05-06-07-08-09-10-11-12-13-14-15-16-17-18-19-20

maybe i fault the circuit please help

#include <util/delay.h>
int i=0;
int main(){
	DDRA = 0xFF;	//DISPLAY = 0xFF DISPLAY OUTPUT (1)
	DDRB = 0x0F;	//(LED out) button input
	PORTA = 0x00;	//off
	PORTB = 0x02;	//yellow on
	while(1){
		PORTA=PINB7;
		if(PORTA!=0x02 && PORTA!=0x01 && PORTA!=0x04){
			PORTB=0x01;
			if(i==0){
				PORTA=0b00111111;	//0
				_delay_ms(1000);
			}
			if(i==1){
				PORTA=0b01111001;	//1
				_delay_ms(1000);
			}
			if(i==2){
				PORTA=0b00100100;	//2
				_delay_ms(1000);
			}
			if(i==3){
				PORTA=0b00110000;	//3
				_delay_ms(1000);
			}
			if(i==4){
				PORTA=0b00011001;	//4
				_delay_ms(1000);
			}
			if(i==5){
				PORTA=0b00010010;	//5
				_delay_ms(1000);
			}
			if(i==6){
				PORTA=0b00000010;	//6
				_delay_ms(1000);
			}
			if(i==7){
				PORTA=0b01111000;	//7
				_delay_ms(1000);
			}
			if(i==8){
				PORTA=0b00000000;	//8
				_delay_ms(1000);
			}
			if(i==9){
				PORTA=0b00010000;	//9
				_delay_ms(1000);
			}
			i++;
			PORTC=0x00;
			if(i>99){
				i=0;
			}
		}

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You seem to have just posted your homework assignment, but not decribed what problem(s) you are having with it?

 

Giacomo2000 wrote:
maybe i fault the circuit please help

maybe you did - but, as we have no idea what your circuit is, how can we help?

 

Instructions to post your schematic (aka "circuit diagram") - see tip #1

 

Some good, clear, in-focus photost of your setup would also help.

 

 

EDIT

 

Note that Atmel Studio has a simulator - so you could step through your code with that to see what it's doing ...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Sun. Mar 18, 2018 - 12:54 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
PORTA=PINB7

is almost certainly not doing what you expect. "PINB7" is defined simply as 7 so the line just says

PORTA=7

If you meant to read the single bit 7 in port B then PINB7 is NOT the way to do it. Also do really mean to assign that one bit to all 8 bits of PORTA? Or are you just trying to set one bit in A depending on the input state of bit 7 in B?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

https://imgur.com/a/6Q8wv

This is the circuit. 

I tried to put pin b 7 and pin b 6 toghether and i did this. 

int main(){
	int i=0;
	DDRB=0x0F; //I WANT TO MAKE ONLY LED OUTPUT SWITCH INPUT
	PORTB=0x82; //LED YELLOW ON AND SWITCH ON
	DDRA=0xFF;  //OUTPUT DISPLAY
	while(1){
		PORTB=PINB; //I NEED TO KNOW WHAT IT MEANS I SAW IT ON INTERNET ANOTHER METHOD TO MAKE THE BUTTON AND LED WORK TOGeTHER?
		if(PORTB==0xC1 | PORTB==0xC2 | PORTB==0xC4)//IF ANY LED IS ON WITH THE BUTTON PRESSED I HOPE IT MEANS
		{
			PORTB=0x81; //LED GREEN ON AND SWITCH ON
			if(i>99){
				i=0;
				PORTB=0x84; //LED RED ON AND THE GREEN OFF
			}
		}
		//THIS IS THE PART FOR LEDS: PROBLEM IS THAT WHEN YOU PRESS THE BUTTON
		//RED LED IS HIGH SOMETIMES MAYBE ANTI-DELAY SYSTEM?
while(1){
		PORTA=PINB; //BO
		i=0;
		if(PORTA=PINB){ //RANDOM I DONT KNOW HOW TO DO
		switch(i){
			case 0:
			{
				PORTA=0b01000000;	//value 0
				_delay_ms(1000);
				break;
			}
			case 1:
			{
				PORTA=0b01111001;	//1
				_delay_ms(1000);
				break;
			}
			case 2:
			{
				PORTA=0b00100100;	//2
				_delay_ms(1000);
				break;
			}
			case 3:
			{
				PORTA=0b00110000;	//3
				_delay_ms(1000);
				break;
			}
			case 4:
			{
				PORTA=0b00011001;	//4
				_delay_ms(1000);
				break;
			}
			case 5:
			{
				PORTA=0b00010010;	//5
				_delay_ms(1000);
				break;
			}
			case 6:
			{
				PORTA=0b00000010;	//6
				_delay_ms(1000);
				break;
			}
			case 7:
			{
				PORTA=0b01111000;	//7
				_delay_ms(1000);
				break;
			}
			case 8:
			{
				PORTA=0b00000000;	//8
				_delay_ms(1000);
				break;
			}
			case 9:
			{
				PORTA=0b00010000;	//9
				_delay_ms(1000);
				break;
			}
		}
		i++;
		}
		//THIS IS THE PART OF THE DISPLAY AND IT IS NOT WORKING, THE DISPLAY
		//SHOWS ONLY THE VALUE IN THE ALLEGATED IMAGE

 

Last Edited: Sun. Mar 18, 2018 - 01:47 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Please put the image in the post - as instructed - where we can all see it in context:

 

 

You appear to have no series resistors for your displays or LEDs?

 

EDIT

 

And you can't just connect displays (or any LEDs) in parallel like that!

 

 

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Sun. Mar 18, 2018 - 02:48 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
if(PORTA=PINB)

does not make much sense for starters but I bet it was supposed to be == not =

 

EDIT you appear to be making the classic mistake we see from almost everyone who posts here. Do not make this up as you go along typing C into your editor. Instead DESIGN what you plan to do then implement it later. It will lead to a better solution and seems to be a key design skill that no one is ever taught any more.

Last Edited: Sun. Mar 18, 2018 - 03:06 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:

Please put the image in the post - as instructed - where we can all see it in context:

 

 

You appear to have no series resistors for your displays or LEDs?

 

EDIT

 

And you can't just connect displays (or any LEDs) in parallel like that!

 

 

 

 

displays in parallel was the question to resolve. The teacher says to connect them in this mode. The leds are not parallel. Every led has the own pin

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

if(PORTA=PINB)

does not make much sense for starters but I bet it was supposed to be == not =

what does it mean? portx==pinx

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Giacomo2000 wrote:
what does it mean? portx==pinx

clawson already explained that in #3

 

Sounds like you need to step back and understand some basics before proceeding with this project.

 

Beginner's getting-started tips here: https://www.avrfreaks.net/commen...

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

displays in parallel was the question to resolve. The teacher says to connect them in this mode. The leds are not parallel. Every led has the own pin

Only the anodes are meant to be in parallel.  You also have the cathodes connected together:

 

 

How do you expect to control them separately?

 

Seems like this assignment is meant to teach you about classic multiplexing.  That's what you should Google:

https://www.google.ca/search?q=seven+segment+multiplexing

 

Andy and Cliff have also pointed out more than a few errors in your C code (by no means all of them) which seem to suggest that you also need to spend some time understanding C.  Do this >>before<< jumping head first into a project like this.  Follow Andy's link above and do some reading.

 

 

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"Read a lot.  Write a lot."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:

Giacomo2000 wrote:
what does it mean? portx==pinx

clawson already explained that in #3

 

Sounds like you need to step back and understand some basics before proceeding with this project.

 

Beginner's getting-started tips here: https://www.avrfreaks.net/commen...

 

i'm not a beginner, even if it seems to be like that :P

int main(){
	int i=0;
	DDRB=0x0F; //I WANT TO MAKE ONLY LED OUTPUT SWITCH INPUT
	PORTB=0x82; //LED YELLOW ON AND SWITCH ON
	DDRA=0xFF;  //OUTPUT DISPLAY
	while(1){
		PORTB=PINB; //I NEED TO KNOW WHAT IT MEANS I SAW IT ON INTERNET ANOTHER METHOD TO MAKE THE BUTTON AND LED WORK TOGeTHER?
		if(PORTB==0xC1 | PORTB==0xC2 | PORTB==0xC4)//IF ANY LED IS ON WITH THE BUTTON PRESSED I HOPE IT MEANS
		{
			PORTB=0x81; //LED GREEN ON AND SWITCH ON
			if(i>99){
				i=0;
				PORTB=0x84; //LED RED ON AND THE GREEN OFF
			}
		}
		//THIS IS THE PART FOR LEDS: PROBLEM IS THAT WHEN YOU PRESS THE BUTTON
		//RED LED IS HIGH SOMETIMES MAYBE ANTI-DELAY SYSTEM?

 

while(1){
		PORTA=PINB; //BO
		i=0;
		if(PORTA=PINB){ //RANDOM I DONT KNOW HOW TO DO
		switch(i){
			case 0:
			{
				PORTA=0b01000000;	//value 0
				_delay_ms(1000);
				break;
			}
			case 1:
			{
				PORTA=0b01111001;	//1
				_delay_ms(1000);
				break;
			}
			case 2:
			{
				PORTA=0b00100100;	//2
				_delay_ms(1000);
				break;
			}
			case 3:
			{
				PORTA=0b00110000;	//3
				_delay_ms(1000);
				break;
			}
			case 4:
			{
				PORTA=0b00011001;	//4
				_delay_ms(1000);
				break;
			}
			case 5:
			{
				PORTA=0b00010010;	//5
				_delay_ms(1000);
				break;
			}
			case 6:
			{
				PORTA=0b00000010;	//6
				_delay_ms(1000);
				break;
			}
			case 7:
			{
				PORTA=0b01111000;	//7
				_delay_ms(1000);
				break;
			}
			case 8:
			{
				PORTA=0b00000000;	//8
				_delay_ms(1000);
				break;
			}
			case 9:
			{
				PORTA=0b00010000;	//9
				_delay_ms(1000);
				break;
			}
		}
		i++;
		}
		//THIS IS THE PART OF THE DISPLAY AND IT IS NOT WORKING, THE DISPLAY
		//SHOWS ONLY THE VALUE IN THE ALLEGATED IMAGE

My questions are in the last comments

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i'm not a beginner, even if it seems to be like that :P

Really? ;-)

 

All kidding aside, this:

		if(PORTA=PINB){ //RANDOM I DONT KNOW HOW TO DO

... suggests otherwise.  The operator for assigning an lvalue is '='.  The operator for testing equality is '=='.  This is in Chapter 1 of K&R.

 

Perhaps this is just an honest typo, rather than an indication of your knowledge of C ?

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"Read a lot.  Write a lot."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

joeymorin wrote:

i'm not a beginner, even if it seems to be like that :P

Really? ;-)

 

All kidding aside, this:

		if(PORTA=PINB){ //RANDOM I DONT KNOW HOW TO DO

... suggests otherwise.  The operator for assigning an lvalue is '='.  The operator for testing equality is '=='.  This is in Chapter 1 of K&R.

 

Perhaps this is just an honest typo, rather than an indication of your knowledge of C ?

Yes, i fault 

sorry

but please help me in what i asked.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

but please help me in what i asked.

Have you read my post #10?

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"Read a lot.  Write a lot."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Please also read the edit I made on #6 a long time back. Your whole approach is wrong. You should not be coding in C until your DESIGN is finished.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Giacomo2000 wrote:
but please help me in what i asked.

The trouble is, you did not actually ask any clear question at all in your opening post.

 

You say you are not a beginner, and let you are making many beginner mistakes - like omitting LED series resistors; not understanding the difference between = and ==

 

Anyhow, it seems that your question is "how to multiplex two 7-segment digits?"

 

In your googling, you will, no doubt, come across an animation something like this:

 

Image result for multiplex 7-segment site:8052.com

Which sows that, in addition to the 7 segment connections, you also need a separate connection to select  each digit in turn.

 

 

EDIT

 

See: https://www.avrfreaks.net/forum/... - but do not follow the links there!

 

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Sun. Mar 18, 2018 - 04:38 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i have experiences in C++ but i never worked with PORT PIN AND DDRA and my experience is basic (basic libraries (iostream.h))

i tried a lot of times doing this program. i need to ask you a question.

i already watched in internet and in some datasheets but i cant understand how to control a port output using a switch in another port input. if i know this i have done 70%

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Im so excited, it works!!!!!!!!!!!!!!!!!!!!!!!

#include <avr/io.h>
#include <util/delay.h>
int codici[10]={0b11111100, 0b01100000, 0b11011010, 0b11110010, 0b01100110, 0b10110110, 0b10111110, 0b11100000, 0b11111110, 0b11110110};
#define PULSANTE PINB
int main(){
	DDRA=0xFF;
	DDRB=0x0F;
	PORTB=0x02;
	DDRD=0xFF;
	int i=0, c=0;
	while(1){
		PULSANTE=128;
		if(PULSANTE==1 || PULSANTE ==2 || PULSANTE==4)
		{
			PORTB=0x01;
			_delay_ms(270);
			PORTA=codici[c];
			PORTD=codici[i];
			i++;
			if(i==10){
				i=0;
				c++;
			}
			if(c==10){
				PORTB=0x04;
				c=0;
				i=0;
			}
		}
	}
}

I put one display in porta and one in portd i dont know if i can put 2 displays at one time in the same ports. if you can do please tell me

Thank you so much

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So, basically, you've ignored all of the advice you've been given, and you've ignored the requirement given to you by your teacher.
You will find that the willingness of strangers to help you for free will quickly evaporate if you continue to ignore them.
One last time: look up how to multiplex 7-segment displays. Both Andy and I have given you plenty of hints, and plenty of links.

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"Read a lot.  Write a lot."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Giacomo2000 wrote:
i dont know if i can put 2 displays at one time in the same ports.

See #16.

 

hint: google "multiplexing", etc

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Also you have simply given PINB a new name (PULSANTE) then you assign 128 to it (bit 7 set). Do you know what a write to PIN registers does?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Given that the OP has been ignoring advice, I will just post this picture that I found after 2minutes googling 7 segment multiplexing and probably not invest any more time. It should be clear enough.

 

Note that this circuit is wrong because each segment needs its own resistor, but it illustrates the multiplexing concept correctly, at least.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Your LEDs (outputs) belong on the right side of your schematic.  Remember: inputs on the left, outputs on the right, unless that is impossible due to a massive rat's nest of components.

 

Why are you using such a massive chip to run 2 LEDS?

When in the dark remember-the future looks brighter than ever.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

having one series resistor per digit is not good; there should be one series resistor per segment.

 

EDIT

 

Google image search finds that diagram here: https://www.electronicshub.org/arduino-4-digit-7-segment-led-display/

 

That page also has this photo:

4 digit 7-segment display

which does appear to have per-segment resistors ...

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Mon. Mar 19, 2018 - 09:56 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

Also you have simply given PINB a new name (PULSANTE) then you assign 128 to it (bit 7 set). Do you know what a write to PIN registers does?

yes i ve done it for it. now i have done a program with 2 displays in porta and 2 bjt to control them. the code is:

#include <avr/io.h>
#include <util/delay.h>
int main(){
	int digits [10]={0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0xFD, 0x07, 0xFF, 0xEF};
	int i, u, t;
	DDRA=0xFF;
	DDRD=0xFF;
	while(1){
		for(i=0;i<=100; ){
			i++;
			if(i==10)
			{
				t++;
				i=0;
			}
			if(t==10)
			{
				t=0;
				i=0;
			}
			PORTA=digits[t];
			PORTD=0x02;
			_delay_ms(1000);
			PORTA=digits[i];
			PORTD=0x01;
			_delay_ms(1000);
		}
	}
}//1 2 3 4 5 7 IT WORKS BUT WHEN IN THE UNITS YOU PUT  THESE NUMBERS THE SECOND DISPLAYS SHOWS THE SAME NUMBER AS THE UNIS
//EXAMPLE      D=0 --> U=0 --> D=1 --> U=1 D=1 --> D=0 --> U=2 D=2 --> D0 -->
// U=3 D=3 --> D=0 --> U=4 D=4 --> D=0 --> U=5 D=5 --> D=0 --> U=6 --> D=0 -->
//D=10 U U=unit

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

8 is ok

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

5 is not ok (dont watch the button and the leds) 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Giacomo2000 wrote:

clawson wrote:

Also you have simply given PINB a new name (PULSANTE) then you assign 128 to it (bit 7 set). Do you know what a write to PIN registers does?

yes i ve done it for it. now i have done a program with 2 displays in porta and 2 bjt to control them. the code is:

#include <avr/io.h>
#include <util/delay.h>
int main(){
	int digits [10]={0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0xFD, 0x07, 0xFF, 0xEF};
	int i, u, t;
	DDRA=0xFF;
	DDRD=0xFF;
	while(1){
		for(i=0;i<=100; ){
			i++;
			if(i==10)
			{
				t++;
				i=0;
			}
			if(t==10)
			{
				t=0;
				i=0;
			}
			PORTA=digits[t];
			PORTD=0x02;
			_delay_ms(1000);
			PORTA=digits[i];
			PORTD=0x01;
			_delay_ms(1000);
		}
	}
}//1 2 3 4 5 7 IT WORKS BUT WHEN IN THE UNITS YOU PUT  THESE NUMBERS THE SECOND DISPLAYS SHOWS THE SAME NUMBER AS THE UNIS
//EXAMPLE      D=0 --> U=0 --> D=1 --> U=1 D=1 --> D=0 --> U=2 D=2 --> D0 -->
// U=3 D=3 --> D=0 --> U=4 D=4 --> D=0 --> U=5 D=5 --> D=0 --> U=6 --> D=0 -->
//D=10 U U=unit

 

pinb reads the output of a port and you can use pin for if and for and to control a button

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It's a good thing your doing this in simulation as real h/w would go up in smoke!

 

No current limiting resistors in series with the segment LED's and no current limiting resistors in series with the transistor bases!!!!!

 

Jim

 

Click Link: Get Free Stock: Retire early!

share.robinhood.com/jamesc3274

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You really aren't listening, are you?

 

  • Still missing current-limit resistors in all of your LEDs.
  • Missing base resistors for the transistors.
  • Q2 is wrong.
  • Why have you drawn Q1 upside down - so that your connections are a mess?

 

 

EDIT

 

Also:

 

avrcandies wrote:
Remember: inputs on the left, outputs on the right
 

 

also: ground at the bottom; positive supply at the top.

 

 

EDIT 2

 

 typo

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Mon. Mar 19, 2018 - 07:30 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

avrcandies wrote:
Your LEDs (outputs) belong on the right side of your schematic.  Remember: inputs on the left, outputs on the right, unless that is impossible due to a massive rat's nest of components.

I guess he's just sticking with the Proteus symbol for the AVR as-is - so the pins he's using are all on the left-hand side?

 

It would be an unnecessary rat's nest to get that reading left-to-right ...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You didn't connect q2 correctly, check the base and collector.

 

And when you go to real hardware don't forget all those resistors: 1 per transistor base, 1 per segment and 1 per LED.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ki0bk wrote:
real h/w would go up in smoke!

No, it's OK - there's no power connected anywhere to the AVR!!

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...