Multiplexed seven segment drive using AVR
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. R1–4 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.
which are as follows-
// Code for a kind of stop watch just for demonstration of multiplexing display
// One switch (PORTD_0)is meant for count stop(PORTD_1), one 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,0×42,0xec,0xe6,0×72,0xb6,0xbe,0xc2,0xfe,0xf2}; SIGNAL(SIG_OVERFLOW0) { 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=0×00; PORTB=0×00; PORTA=0×00; PORTD=0xFF; TCCR0=(1<<CS00)|(1<<CS02); TCNT0=0; TIMSK=(1<<TOIE0); sei(); while(1) { if(!(PIND & 0×01)) { while(!(PIND & 0×01)); cli(); } if(!(PIND & 0×02)) { while(!(PIND & 0×02)); sei(); } if(!(PIND & 0×04)) { while(!(PIND & 0×04)); four=three=two=one=0; //PORTB=0xFF; //PORTA=seg[0]; //_delay_ms(2); //PORTB=0×00; } PORTB=0×01; PORTA=seg[four]; _delay_us(100); PORTB=0×02; PORTA=seg[three]; _delay_us(100); PORTB=0×04; PORTA=seg[two]; _delay_us(100); PORTB=0×08; PORTA=seg[one]; _delay_us(100); } return 0; }