Drive 4-digit 7segment

Go To Last Post
6 posts / 0 new
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hi guy's,

I'm trying to drive four 7segments by ATmega32A

The purpose of this Project is that I can display a number on this.

but when I programmed the micro it just showed a number on first digit and other digits are off.

/*project info :

using OCR compare match interrupt on TIMER0 for multiplexing

if U have proteus I uploaded the schematics.

and I uploded the codes.

Thank U.

and remember "still I'm a kid!!!"wink



Just believe yourself !!!

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

First up, write 'you' instead of U. You don't need to fit your message into 160 chars for a SMS.
What have you done to solve your problem? Find another hobby if you expect things to work first time. Perform experiments to show you what is working. Before long you will have identified the problem.
As for what is in your zip file, i don't know as my iphone don't do zip.

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

Some years ago in university i was used 7segments with 74HC573 and multiplexing. Was on 8051 mC and ASM but its the same.


I cant see your schematic. Attach is please, i have allready some working schematic and code it you have troubles with yours.


P.S its much easier,less components,lower cost.. to build an 4digit diplay with MAX7219 with SPI. Something like this :

Wireless remote car device using hand movements:

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

Kartman wrote:
First up, write 'you' instead of U



Kartman wrote:
Find another hobby if you expect things to work first time.



Debugging is a key skill for any form of development.


Learn to think about the problem:


  • What did you expect to happen?
  • What actually does happen?
  • Think about what could cause the discrepancy
  • Devise tests/experiments to investigate the potential causes
  • Once you've found the cause of the problem, solving it is much easier!



SavKokki wrote:
I cant see your schematic. Attach it please

Don't just attach it; embed it in your post - so that it can be seen in context.


Instructions here:

Top Tips:

  1. How to properly post source code - see: - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see:
  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 oscillator
  5. When your question is resolved, mark the solution:
  6. Beginner's "Getting Started" tips:
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Now you're getting better, Ehsan.

Ehsan2754 wrote:


if U have proteus I uploaded the schematics.

and I uploded the codes.

Please as Kartman said:

write 'you' instead of U

You have checked your problem in real or proteus?

give up using proteus because it doesn't work correctly always. (and also if you don't have a valid licence).

working on a project in real is much more delightful. for start off you can purchase an arduino here:


For compiler and IDE you can use Arduino IDE. it's nice and has a bunch prepared libs that could make easy your job. Atmel Studio is a good option as well. it has a good and beautiful interface + debugger + simulator

another point that you should memorize is that never pack your project and put it here because nobody would like download it, then it's better to put your code here. ok, let me to do it for you. then this is your code:


   Written by Ozhan KD -
   Pressing a key displays the keyboard defined character on 7segments from left to right

   -|--|--|--|-- PB0
   -|--|--|--|-- PB1
   -|--|--|--|-- PB2
   PB3   PB5
      PB4   PB6

   PC0 --- a
   PC1 --- b
   PC2 --- c
   PC3 --- d
   PC4 --- e
   PC5 --- f
   PC6 --- g
   PC7 --- dp

   PA0 --- LEDs_select
   PA1 --- DIGIT0_select
   PA2 --- DIGIT1_select
   PA3 --- DIGIT2_select
   PA4 --- DIGIT3_select
   PA5 --- DIGIT4_select
   PA6 --- DIGIT5_select


#include <mega32.h>
#include <delay.h>
#define nokey_code 12

// 7 segment codes
flash unsigned char display_codes[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x00,0x40};

//keyboard codes
flash unsigned char keyboard_codes[]={0x76,0x6E,0x5E,0x3E,0x75,0x6D,0x5D,0x3D,0x73,0x6B,0x5B,0x3B};

volatile unsigned char data[]={11,11,11,11,11,11},leds=0; // initial values for display ( ------ )
volatile unsigned char key_code=nokey_code;

void main()
 unsigned char i=5;
 unsigned char temp_key_code,old_key_code=nokey_code;

 //initialize timer
 TCCR0=(1<<WGM01)|(1<< CS01);

  // Update key code.
  // This is necessary because of possible change of key code during loop
  if (temp_key_code!=nokey_code)leds=1; // Turn on LED if any key pressed
  else leds=0;
  if (temp_key_code!= old_key_code)
   if (temp_key_code!=nokey_code)
    if (--i==0xff) i=5;


interrupt [TIM0_COMP] void timer0_compare_isr(void)
 static unsigned char select=0;
 static unsigned char x20=0;
 unsigned char temp , i;
 // Turn off all 7segments  and LEDs
 if (select)PORTC =display_codes[data[select-1]];
 else PORTC=leds;
 PORTA &=~(1<<select);
 if (++x20==20)
  delay_us(5); // delay for signal stablization
  temp=(PINB & 0X78);
  delay_us(5); // delay for signal stablization
  temp |=(PINB & 0X07);
   else key_code=nokey_code;



WTF, I don't know why code editor doesn't work for me.sad


at end, follow Andy(awneil)'s recommendations and advices.


P.S. I don't have proteus, then show us what you have wired up in schematic.


Edit: it just worked.

"One's value is inherent; money is not inherent"


Chuck, you are in my heart!

Last Edited: Wed. Jul 1, 2015 - 11:42 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Let the ready projects and try to build your own. I will post my solution maybe later.




I see you found the solution ,but as i built it allready maybe helps someone else. ( last time did this on 8051 lmao )


 * SegmentMultiplexing.c
 * Created: 7/1/2015 5:21:20 PM
 *  Author: SavKokki

#define F_CPU 8000000UL

#define EnableA 0		//	First transistor
#define EnableB 1		//	Second transistor

#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>

unsigned char Data[10] = {0x81, 0xCF, 0x92, 0x86, 0xCC, 0xA4, 0xA0, 0x8F, 0x80, 0x84} ;  // 0,1,2,3,4,5,6,7,8,9
unsigned char counter = 0;	
volatile unsigned char x1 = 0;			// variable to display on 1Digit
volatile unsigned char x10 = 0;			// variable to display on 2Digit

void setup (void)
	DDRA =  0xFF;          					// PORTC output , Data to display
	DDRB |= (1<<EnableA) | (1<<EnableB);	// PortB.0 & PortB.1 outputs for the transistors
	PORTB |= (1<<EnableA) | (1<<EnableB);   // Both digits off
	//***   Timer0 initialize ***//
	OCR0 = 60  ;								 // Interrupt every  8 mSec
	TCCR0 |= (1<<WGM01) | (1<<CS02)| (1<<CS00);  // CTC mode , prescaler 1024 ... every tick is 128uSec ( clock is 8 Mhz ! )
	TIMSK |= (1<<OCIE0);						  // Enable Timer0 compare match interrupt
	sei();											 // Enable global interrupts

int main(void)
		x1 = counter/10;			// display to 10 system
		x10 = counter%10;
		_delay_ms(120);				// INC counter with some delay to test our programm
	    if(counter==100) {counter = 0;}		// limit counter

					PORTA =  Data[x1];	     // Send value f 1st Digit
					PORTB &= ~(1<<EnableA);	 // Turn on 1st Digit
					_delay_us(80);            // w8 some time
					PORTB |=  (1<<EnableA);	 // Turn off 1st Digit}	
					PORTA = Data[x10];	    // Send the value of 2nd Digit
					PORTB &= ~(1<<EnableB);	 // Turn on 2nd Digit
					_delay_us(80);       	// w8 some time
					PORTB |= (1<<EnableB);   // Turn off 2nd Digit







Wireless remote car device using hand movements:

Last Edited: Wed. Jul 1, 2015 - 03:47 PM