0% found this document useful (0 votes)
55 views9 pages

AAROH-A Step Towards Real Engineering: Day2 Seven Segment Display

This document discusses seven segment displays and provides examples of coding to control seven segment displays and motors. It begins with an overview of seven segment displays, noting they are used to display numerals as an alternative to dot matrix displays. It then provides a table showing the segment patterns for each numeral from 0 to 9. The document provides examples of coding to display increasing and decreasing numerals on a seven segment display. It also provides examples of coding for a traffic light and button interfacing. It concludes with an overview of motor interfacing using an L293D motor driving IC and provides sample motor control coding.

Uploaded by

Brajesh Chouhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views9 pages

AAROH-A Step Towards Real Engineering: Day2 Seven Segment Display

This document discusses seven segment displays and provides examples of coding to control seven segment displays and motors. It begins with an overview of seven segment displays, noting they are used to display numerals as an alternative to dot matrix displays. It then provides a table showing the segment patterns for each numeral from 0 to 9. The document provides examples of coding to display increasing and decreasing numerals on a seven segment display. It also provides examples of coding for a traffic light and button interfacing. It concludes with an overview of motor interfacing using an L293D motor driving IC and provides sample motor control coding.

Uploaded by

Brajesh Chouhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

AAROH- A step towards real engineering

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.

Seven segment basically are of 2 types:-


Common Cathode (CC)- The part which we have to glow, we need to keep it in high.
Common Anode (CA)- The part which we have to glow, we need to keep it in low.
Table for Common Anode Seven segment display:-

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

In addition to digits from 0 to 9, some letters of alphabet - A, C, E, J, F, U, H, L, b, c, d, o, r, t –can


also be displayed by performing appropriate masking.
If the event that common cathode displays are used all units in the table should be replaced by zeros
and vice versa.

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 7­segment 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 7­segment 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 Bi­polar 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

#define F_CPU 1000000UL


#include<avr/io.h>
#include<util/delay.h>
#define btnon !PINA&(1<<PA0)
void main()
{
;
DDRD|=(1<<PA0);

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.

PIN NAME PIN NUMBER TYPE FUNCTION

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 ­ 5­v 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 

#define F_CPU 1000000UL


#include<avr/io.h>
#include<util/delay.h>
void main()
{
DDRD=0xff;
while(1)
{
PORTD=0b10100000; // forward movement
_delay_ms(3000);
PORTD=0b01010000; // backward movement
_delay_ms(3000);
PORTD=0b00100000; // light turn movement
_delay_ms(3000);
PORTD=0b10000000; // right turn movement
_delay_ms(3000);
}
}

You might also like