Interfacing Seven Segment Display with AVR Breakout
After blinking the LED , Let's display user information like numeric value using seven segment display. In this tutorial we will interface a seven segment display to AVR breakout board and display a single digit hex (0-F).
Basics
For this tutorial we are using common anode seven segment display. To drive this display we require a BC 547 transistor. The PORT B is connected to data lines of the display and PORT D0 is connacted to base of the transistor through 1k ohm resistor and collector is connected to VCC through 68 ohm resistor as shown in hook up.
check out Interfacing Seven Segment Displays with AVR tutorial for basics of seven segment display.
Hook Up
Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define Segment 0x01 | |
int main() { | |
char seg_code[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e}; | |
int cnt; | |
/* Configure the ports as output */ | |
DDRB = 0xff; // Data lines | |
DDRD = 0x01; // Control signal PORTD0 | |
while (1) | |
{ | |
for (cnt = 0x00; cnt < 0x0f; cnt++) // loop to display 0-F | |
{ | |
PORTD = Segment; | |
PORTB = seg_code[cnt]; | |
_delay_ms(1000); | |
} | |
} | |
} |