AAROH-A Step Towards Real Engineering: Day2 Seven Segment Display
AAROH-A Step Towards Real Engineering: Day2 Seven Segment Display
Day2
Seven Segment Display
A seven-segment display, or seven-segment indicator, is a form of electronic display device for
displaying decimal numerals that is an alternative to the more complex dot-matrix displays. Seven-
segment displays are widely used in digital clocks, electronic meters, and other electronic devices
for displaying numerical information’s.
DIGITS TO
D I S P L AY S E G M E N T S
D I S P L AY
dp a b c d e f g
0 1 0 0 0 0 0 0 1
1 1 0 0 1 1 1 1 1
2 1 0 0 1 0 0 1 0
3 1 0 0 0 0 1 1 0
4 1 1 0 0 1 1 0 0
5 1 0 1 0 0 1 0 0
6 1 0 1 0 0 0 0 0
7 1 0 0 0 1 1 1 1
8 1 0 0 0 0 0 0 0
9 1 0 0 0 0 1 0 0
FEW EXAMPLES :-
Things required:
Name Proteus code
ATmega16 microcontroller Atmega16
LEDs Led active
7 segment Display 7 seg cc
wires
Task1
Write a programme to display numeric digits from 0 to 9 in increasing order and vice versa
in 7segment LED display.
#define F_CPU 1000000UL
#include
#include
void main()
DDRD=0XFF;
char mynum[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
//Defining ARRAY values
int i=0,j=0;
while(1)
for(i=0;i<10;i++) //To run a function for 9 times in increasing value.
{
PORTD= mynum[i];
//taking values from ARRAY function to illuminate PortD's LED.
_delay_ms(500);//delay
}
PORTD= 0x00;
_delay_ms(500);
//turning off PORTD to make a visual gap between execution of 0 to 9 and 9 to 0.
for(j=9;j>=0;j)
{
PORTD= mynum[j];
_delay_ms(500);
PORTD= 0x00;
_delay_ms(500);
Task2
Write a programme to display numeric digits from 00 to 99 in increasing order and vice
versa in 7segment LED display.
#define F_CPU 1000000UL
#include
#include
void main()
DDRD=DDRC=0XFF;
char mynum[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
int i,j=0;
while(1)
for(i=0;i<10;i++)
{
PORTC= mynum[i];
for(j=0;j<10;j++)
{
PORTD= mynum[j];
_delay_ms(300);
}
}
PORTD=PORTC=0x00;
_delay_ms(300);
for(i=9;i>=0;i)
{
PORTC= mynum[i];
for(j=9;j>=0;j)
{
PORTD= mynum[j];
_delay_ms(300);
}
}
PORTD=PORTC=0x00;
_delay_ms(300);
}
}
NOTE:
If we want to change any PIN’s value of any PORT without disturbing
other PIN’s values, then using this we can easily do that;
• PORTX|= (1<<PXn);
• PORTX&= ~(1<<PXn);
Traffic Light
Source code:-
#define F_CPU 1000000UL
#include<avr/io.h>
#include<util/delay.h>
void count30()
{
char mynum[10]={0X3f,0X06,0X5b,0X4f,0X66,0X6d,0X7d,0X07,0x7f,0x6f};
int i,j=0;
PORTC=mynum[3];
PORTD=mynum[0];
_delay_ms(1000);
for(j=2;j>=0;j--)
{PORTC=mynum[j];
for(i=9;i>=0;i--)
{PORTD=mynum[i];
_delay_ms(1000);
}}
}
void main()
{
DDRD=DDRA=DDRB=DDRC=0Xff;
while(1)
{PORTA=0B01101010;
count30();
PORTA=0B10011010;
count30();
PORTA=0B10100110;
count30();
PORTA=0B10101001;
count30();
}
}
Button Interfacing
Button basics
A button is a two terminal Bipolar device also known as the SPST (Single Pole
& Single Throw) as shown in figure :
Connection of Button:
To use the Button Both of its terminals should have different logic levels i.e.
we have set different Logics on both terminals to ON the button and Observe
its ON State.
Source code:-
For button on/off
while(1)
{
if(btnon)
{
PORTC=0xff;
}
else
{
PORTC=0x00;
}}
Motor Interfacing
As we know that a microcontroller has it’s own limitations of operation. Most of the
microcontrollers operate at loe voltages and requires a small amount of current to operate
while the motors usually requires a relatively higher values of current and voltages. To
solve these problem we come up with a solution and the solution is L293D motor driving
IC.
L293D motor Driving IC
For more detailed explaination do visit the link given below
Data sheet:http://www.ti.com/lit/ds/symlink/l293.pdf
Pin configuration
It is a 16 pin IC. With 4 input and 4 output pins.
We can connect 2 motors silmultaneously to it.
Enable 1,2 1 I Enables driver 1 and 2
Input<1,4> 2,7,10,15 I Driver inputs(connected to Arduino)
Output<1,4> 3,6,11,14 O Driver outputs(connected with respective motor)
Enable 3,4 9 I Enables driver 3,4
Ground 4,5,12,13 Device ground
Vcc1 16 5v power supply
Vcc2 8 Power VCC for drivers
Task To make a autonomous bot using ATMEGA16
Source code:
For input logic
Motor 1 Motor2 Movement
1 0 1 0 Forward
0 1 0 1 Backward
0 0 1 0 Left
1 0 0 0 Right
0 1 1 0 Sharp left
1 0 0 1 Sharp right
0 0 0 0 Stop