Multiplexed Seven Segment Drive  


Figure above shows the circuit arrangment for 4 seven segment display drive in a multiplexed manner. Data to be displayed is put onto the display unit on PORTA of ATmega32. PORTB0..3 pins are used to enable one display at a time slice. R14 are transistors biasing resistors valued usually 10K.

Display used are common Anode that is high logic lit the corresponding segment on display.

First we need to identify the hex value to be written onto data PORTA, corresponding to number 0 to 9.

// Code for a kind of stop watch just for demonstration of multiplexing display

// One switch (PORTD_0)is meant for count stop (PORTD_1) for resume and last one(PORTD_2) for reset count to zero here is the code


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

unsigned int speed=0;

volatile unsigned char one=0,two=0,three=0,four=0;

unsigned char seg[10]={0xde,042,0xec,0xe6,072,0xb6,0xbe,0xc2,0xfe,0xf2};

SIGNAL(SIG_OVERFLOW0) //ISR for Timer Overflow INT
{
speed++;
if(speed==20)
{
four++;
if(four>9)
{
four=0;
three++;
if(three>9)
{
three=0;
two++;
if(two>9)
{
two=0;
one++;
if(one>9)
one=0;
}
}
}
speed=0;
}
}


int main(void)
{
unsigned int i;
DDRB=0xFF;
DDRA=0xFF;
DDRD=000;
PORTB=000;
PORTA=000;
PORTD=0xFF;
TCCR0=(1<<CS00)|(1<<CS02);
// Prescaling of clock TCNT0=0;
sei(); // Global INT enable
TIMSK=(1<<TOIE0); // Timer overflow INT enable

while(1)
{
if(!(PIND & 001))
{
while(!(PIND & 001));
cli();
}

if(!(PIND & 002))
{
while(!(PIND & 002));
sei();
}

if(!(PIND & 004))
{
while(!(PIND & 004));
four=three=two=one=0;
}

PORTB=001; // Display1 selected
PORTA=seg[four];
_delay_us(100);

PORTB=002; // Display2 selected
PORTA=seg[three];
_delay_us(100);

PORTB=004; // Display3 selected
PORTA=seg[two];
_delay_us(100);

PORTB=008; // Display4 selected
PORTA=seg[one];
_delay_us(100);
}
return 0;

}



devesh@electroons.com
Best viewed at Firefox 1024x768 resolution