7 Segment MUX Using PIC16F877A
By Bernice Zuiya
Code and Comment
With the seven segment display, we combined different segment to display an hexadecimal number at a time and depending to the configuration when using a micro-controller such as in our case the seven segments will be driven by a micro-controller.
You will need to add the lines directive for LCD display, This code were written using mikroC compiler software, you can copy and compile it or modify it as well, ultrasonic range meter project.
Download the full project here
/* 7 segment OSat shield, connections
RB7>A , RB6>B , RB5>C , RB4>D , RB3>E , RB2>F , RB1>G
The MUX select line is connected on port PORTC (RC 0-3 )
BY Bernice Zuiya */
int array_[5];
int Display_( int stt1 ) {
static unsigned int i;
switch(stt1){
case 0:
PORTB =0X03; // display <0>
break;
case 1:
PORTB =0X9F; // display <1>
break;
case 2:
PORTB =0X25; // display <2>
break;
case 3:
PORTB =0X0D; // display <3>
break;
case 4:
PORTB =0X99; // display <4>
break;
case 5:
PORTB =0X49; // display <5>
break;
case 6:
PORTB =0X41; // ddisplay <6>
break;
case 7:
PORTB =0X1F; // display <7>
break;
case 8:
PORTB =0X01; // display <8>
break;
case 9:
PORTB =0X09; // display <9>
break;
}
}
int _7S_Write_Number(int stt1){
unsigned int j;
static int num_=0;
array_[0] = stt1 / 1000; // first digit to display
array_[1] = stt1 % 1000;
array_[2] = array_[1] / 100; // second digit to display
array_[3] = array_[1] % 100;
array_[4] = array_[3] / 10; // third digit to display
array_[5] = array_[3] % 10; // fourth digit to display
Delay_ms(1);
for(j = 0 ; j <= 8 ;){
if( j == 1){PORTC = 0x01 ;Delay_ms(7);
//num_ = num_ + 1;
Delay_ms(1);
}else{
if (j % 2 == 0){
if(j == 6){}
else{
PORTC = j ;Delay_ms(2);
num_ = num_ + 1;
switch(num_){
case 1:
Display_(array_[5]);
break;
case 2:
Display_(array_[4]);
break;
case 3:
Display_(array_[2]);
break;
case 4:
Display_(array_[0]);
break;
} // end switch statement
Delay_ms(1);
}
}
}
if (num_ == 4){num_ = 0;}
j++;
} //end for(j = 0 ; j <= 8 ;)
} // end int _7S_Write_Number(int stt1)
void main(void){
int aa=0;
TRISC=0X00;
PORTC=0X00;
TRISB=0X00;
PORTB=0X00;
for(;;){
aa=111;
_7S_Write_Number(aa);
}// End for(;;) loop
} // end main function
WORKING :
the working of this seven segment MUX (Multiplex) is that all terminal of the 4 seven segment display are connected as shown in the diagram above to display hexadecimal characters, and here the seven segment (a,b,c,d,e,f and g) are all connected to PORTB of the micro-controller; the select line which are used to select which display to use are taken from PORTC refer to the code bellow. all select line are connected with a resistance of 10Kohm in series connected to the base of respective transistor (BC547), 300 ohm resistance are used in series with each segment from the display for limiting the current.
in case you are using our 7 segment shield then you will probably do not face any problem because the connection are mentioned, what you have to do is to follow the steps and connect the circuit as per the diagram shown above.
the first test of this 7 segment MUX here will be to display an integer number will 3 digit and lastly we will make a counter or maybe the code will be given at the end
the circuit works with a crystal of 20 MHz
Circuit Diagram
The 7 Segment Display is one of the most electronic component used to display hexadecimal characters 16-characters ( 0 to 9 and A to F). They are basically of two type, common anode and common cathode, they have commonly 10 pins where 2 pins are common , 1 is used for decimal number and finally 7 pins which are used to display hexadecimal characters by combining different segments of the display which are basically the set of LED. the figure 1 in the left side is the 7 segment display showing 7 bar segment and dot DP ( For decimal number) and the figure 2 represent a one single LED representing one segment. Mostly all pins must be connected with a resistance of 300 Ohm resistance in series for limiting the flow of current through the LED.
We just come to describe the seven segment display in above lines, now let write some lines about our project (seven segment MUX) The word MUX used here describes simply the multiplexing technique which is going to be used to drive the 4 seven segment display using a micro-controller.
the seven segment has 7 pins used to display and hexadecimal character at a time, so driving the all four seven segment using a micro-controller; the very first thing coming to our mind is that we will use 28 pins form the controller to drive the seven segment display, then here is the solution !
the Multiplexing technique is a technique used to multiplex the display where each seven segment display display a character at a finite time slot (1ms for example), then at that speed the human eye can not see the change of state of LEDs. but what we need to drive this is to add some select line connected also to the circuit, the display are basically basically multiplexed with the help of the select line. which means when one line is ON all remaining OFF.