A seven segment display is the most basic electronic display device that can display digits from 0-9. They find wide application in devices that display numeric information like digital clocks, radio, microwave ovens, electronic meters etc. The most common configuration has an array of eight LEDs arranged in a special pattern to display these digits. They are laid out as a squared-off figure ‘8’. Every LED is assigned a name from 'a' to 'h' and is identified by its name. Seven LEDs 'a' to 'g' are used to display the numerals while eighth LED 'h' is used to display the dot/decimal.
A seven segment is generally available in ten pin package. While eight pins correspond to the eight LEDs, the remaining two pins (at middle) are common and internally shorted. These segments come in two configurations, namely, Common cathode (CC) and Common anode (CA). In CC configuration, the negative terminals of all LEDs are connected to the common pins. The common is connected to ground and a particular LED glows when its corresponding pin is given high. In CA arrangement, the common pin is given a high logic and the LED pins are given low to display a number. Find out more information about a seven segment display and its working.
Depending on whether anode or cathode of all the leds are common they are of two types.
1) Common anode 2)Common cathode
Interfacing with MCU
Interfacing these displays are same as interfacing LEDs with MCU. You need 7 MCU port pins to control them. If you also want to control the decimal point you need one extra pin. The connection is simple.
Here I have interfaced a common anode(+) 7 segment display with PORTD of AVR.If you have made the “home made avr dev board” then you can easily connect this to PORTD of the board by using 8PINconnectors. The segments will be "on" when levels on the PORT is low, that is 0.
Programming
These displays are very easy to program in C. I am giving here a function, which you may use to display digits in 7-segment display. The sample program uses the function to continuously display digits from 0-9 and then repeating the sequence.
/*
A program to demonstrate the use of seven segment displays.
Hardware:
A single seven segment display connected to PORTD as
a->PD7
b->PD6
c->PD5
d->PD4
e->PD3
f->PD2
g->PD1
DP->PD0
*/
#include <avr/io.h>
#include <util/delay.h>
//Configurations
//**************
// Here you may cange the port in which you have connected the display
#define SEVEN_SEGMENT_PORT PORTD
#define SEVEN_SEGMENT_DDR DDRD
void SevenSegment(uint8_t n,uint8_t dp)
{
/*
This function writes a digit given by n to the display
the decimal point is displayed if dp=1
Note:
n must be less than 9
*/
if(n<10)
{
switch (n)
{
case 0:
SEVEN_SEGMENT_PORT=0b00000011;
break;
case 1:
SEVEN_SEGMENT_PORT=0b10011111;
break;
case 2:
SEVEN_SEGMENT_PORT=0b00100101;
break;
case 3:
SEVEN_SEGMENT_PORT=0b00001101;
break;
case 4:
SEVEN_SEGMENT_PORT=0b10011001;
break;
case 5:
SEVEN_SEGMENT_PORT=0b01001001;
break;
case 6:
SEVEN_SEGMENT_PORT=0b01000001;
break;
case 7:
SEVEN_SEGMENT_PORT=0b00011111;
break;
case 8:
SEVEN_SEGMENT_PORT=0b00000001;
break;
case 9:
SEVEN_SEGMENT_PORT=0b00001001;
break;
}
if(dp)
{
//if decimal point should be displayed
//make 0th bit Low
SEVEN_SEGMENT_PORT&=0b11111110;
}
}
else
{
//This symbol on display tells that n was greater than 9
//so display can't handle it
SEVEN_SEGMENT_PORT=0b11111101;
}
}
void Wait()
{
// An approx one second delay for 12Mhz CPU clock
uint8_t i;
for(i=0;i<46;i++)
{
_delay_loop_2(0);
}
}
void main()
{
//Setup
SEVEN_SEGMENT_DDR=0xFF; //All output
SEVEN_SEGMENT_PORT=0xFF; //All segments off
uint8_t count=0;
while(1)
{
SevenSegment(count,0);
count++;
if(count==10)
{
count=0;
}
Wait();
}
}
No comments:
Post a Comment