Tuesday, December 29, 2009

Seven Segment Interfacing and Display using mikroC

A Seven segment display consists of seven LED’s arranged in pattern of digit like 8


We use a bcd to seven segment decoder which saves pin of microcontroller from seven(one for each Led) to four.So we have to give bcd code for desired digit to be displayed on it.
Now also we can display more then one seven segment display simultaneously.but it will take a number of pins of controller.So we use two pins from controller to control the display of seven segment one by one from same port such that it appears to be displaying simultaneously.
This is done by providing a very small delay such that our eyes cant even detect  the change over from one display to another. The code given below will work on any PIC16F7X device.

CODING FOR DISPLAY

void main()
{
 TRISB=0xf0;
TRISC=0xf0;
PORTC=0x00;

while(1)
 {
 PORTB=0x00  ;         //code for 0
 delay_ms(1000);

PORTB=0x08  ;         //code for 1
 delay_ms(1000);

 PORTB=0x04  ;        //code for 2
 delay_ms(1000);

 PORTB=0x0c  ;         //code for 3
 delay_ms(1000);

 PORTB=0x02  ;          //code for 4
 delay_ms(1000);

 PORTB=0x09  ;          //code for 5
 delay_ms(1000);

 PORTB=0x06  ;         //code for 6
 delay_ms(1000);

 PORTB=0x0e  ;          //code for 7
 delay_ms(1000);

PORTB=0x01  ;           //code for 8
 delay_ms(10000);

 PORTB=0x09  ;          //code for 9
 delay_ms(10000);
 }
 }

The above program will display 0 to 9 on one seven segment display with a delay of one second between it.

NOW TO DISPLAY ON FOUR DISPLAYS CONNECTED..

CODE IS

void main()
{
 TRISB=0xf0;
 TRISC=0xf0;
  PORTC=0x00;
 while(1)
 {
 PORTB=0x00  ;        //code for 0
PORTC=0xfe  ;         //DISPLAYS ON FIRST  11111110
 delay_ms(100);

PORTB=0x08  ;        //code for 1
PORTC=0xfd  ;         //DISPLAYS ON SECOND 11111101
 delay_ms(100);
PORTB=0x04  ;        //code for 2
PORTC=0xfb  ;         //DISPLAYS ON THIRD 11111011
 delay_ms(100);
PORTB=0x0C  ;        //code for 3
PORTC=0xf7  ;         //DISPLAYS ON FIRST  11110111
 delay_ms(100);

 }
 }

No comments:

Post a Comment