7-Segment Display Interfacing with AVR ATmega16
7-Segment LED Display
7-segment displays are made up of 8 LED segments. 7 of these LED segments are in the shape of
a line, whereas 1 segment is circular.
The 7 line-shaped LED segments are used for displaying numbers 0 to 9 and a few letters like A,
c, d, e, F, H, L, O, P, U, etc. The circular segment is used for displaying a decimal point.
Each of the 8 elements has a pin associated with it which can be driven HIGH or LOW according
to the type of display and the number or alphabet to be displayed.
The common anode and common cathode types are available in a 7-segment display. Depending
on which type is used, the control signal required to light up a segment in the display changes.
Common anode requires a LOW signal whereas common cathode requires a HIGH signal to light
up a segment.
. Interfacing 7-Segment LED Display With AVR ATmega16
Program
#define F_CPU 8000000UL
#include <avr/io.h>
#include <util/delay.h>
int main(void)
{
DDRA= 0xff; /* define 7 segment port direction is output */
PORTA = 0xff;
char array[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
/* write hex value for CA display from 0 to 9 */
while(1)
{
for(int i=0;i<10;i++)
{
PORTA = array[i]; /* Send data to the 7 segment display */
_delay_ms(1000); /* wait for 1 second */
}
}
}