Simple dynamic LED display drive

I have got a simple 4 digit LED display routine. This is simulated using the Proteus simulator. So in the picture, you see a simplified version of the circuit. In the real world, you might need to strobe digits using transistor keys. The control program is written using the WinAVR toolchain.

Bellow is a complete C file

//----------------------------------------------------
uint8_t numbers[]={
0b11000000,//0
0b11111001,//1
0b10100100,//2
0b10110000,//3
0b10011001,//4
0b10010010,//5
0b10000010,//6
0b11111000,//7
0b10000000,//8
0b10010000,//9
0b01111111//.
};
uint8_t i;
void initAmega8()
{
PORTD=0xFF; //Port D all to "1" - LEDS OFF
DDRD=0xFF; //Port D all to output
//Port B control lines to "1" - Transistors OFF
PORTB &=~((1<<<<
//Port B control lines as output
DDRB |=((1<<<<
}
void sendNumber(uint8_t digit, uint8_t position)
{
//0...9 for digit; 1..4 for position
PORTD=numbers[digit];
PORTB|=_BV(position-1);
_delay_us(100);
PORTB&=~_BV(position-1);
_delay_us(100);
}
int main(void)
{
initAmega8();
while(1)
{
sendNumber(2,1);//LCD display shows "2006"
sendNumber(0,2);
sendNumber(0,3);
sendNumber(6,4);
}
return 0;
}
//----------------------------------------------------

Leave a Reply