Monday, 23 July 2018

Interfacing 7-Segment to PIC Microcontroller (PIC18F4520)

Aim:

The main aim of this project is how to interface 7-segment and display 0 to 99 values on 7-segments.

Description:


Introduction
Till now you have learn what is an embedded system, basic memory architecture of a microcontroller, how to implement assembly language and use of some softwares like pinnacle 52, keil-C and flash magic; we also have come across how to interface LEDs from a microcontroller and how to generate different pattern through it. now its time to move forward and learn one more step ahead towards the completion of our 6-weak training. so here today we will learn about 7-Segment display; How to interface and program it; and some of the applications of it.
 7-Segment Display
A 7-Segment display is a useful electronic component use to produce numeric, alphabetic and some non-alphabetic symbols using a specific arrangement of LEDs as shown in figure here.
A 7-Segment display has 10-Pins representing each abcbefgand h LEDs respectively along with two extra pins for GND andVSS. following shown an original 7-Segment display device along with its pin diagram. LED h is also denoted by symbol dp.
As we have studied in LED interfacing a 7-segment display is also interfaced in same way as it is also made of LEDs. So we can interface LEDs in three ways bu here difference is that 7-Segment displays comes in two types by manufacturers i.e. “Common Anode” and “Common Cathode“; the logics are shown in figure below.
and thus which logic is o implement is on the bases of these specifications provided by manufacturer.
Digit Drive Pattern:
To display the digits on 7 segment, we need to glow different logic combinations of segments. For example if you want to display the digit 3 on seven segment then you need to glow the segments a, b, c, d and g. The below table show you the Hex decimal values what we need to send from PORTB to Display the digits from 0 to 9.
DIGITDPGFEDCBAHEX VALUE
0001111110x3f
1000001100x06
2010110110x5b
3010011110x4f
4011001100x66
5011011010x6d
6011111010x7d
7000001110x07
8011111110x7f
9011001110x67

Block Diagram

7seg

Schematic

7 seg

Code

// ******************************************************
// Project: 0 to 99 display in 7-segments using PIC18F4520
// Author: Hack Projects India
// Module description: Operate two 7-segments
// ******************************************************
#include<p18f4520.h>
#pragma config OSC=HS, FCMEN=ON, WDT=OFF, IESO=OFF, XINST=OFF, LVP=OFF
void delay(unsigned short long x);
int main(void)
{
 ADCON1=0x0f;
 TRISB=0x00;
 DDRD=0x00;
 int i,j,k,l,a[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7c,0x07,0x7f,0x67};
 while(1)
 {
  for(k=0;k<10;k++)
  {
   for(l=0;l<10;l++)
   {
   PORTD=~0x02;
   PORTB=a[k];
   _delay_ms(100);
   PORTD=~0x01;
   PORTB=a[l];
   _delay_ms(1000);
   }
  }
 }
}
void delay(unsigned short long x)
{
while(x>0)
{
x--;
}
return;
}

Downloads:

The code was compiled in Keil uvision4 and simulation was made in Proteus v7.7.
To download code and proteus simulation click here.

Further Reading suggestions:

No comments:

Post a Comment