Monday, December 15, 2014

4 Digits 7-Seg Display Using Shift Register

We can improve the previous circuit by adding a shift register where we can reduce the number of used I/O pins to 6 instead of 11 I/O pins as shown in this picture.
7-Seg Display Using Shift Register Circuit:
7 segment display multiplexing and shift register pic16f84a mikroc code
Also we can add another shift register to the multiplexing circuit and reduce the pins used to 2.
The crystal used is 12MHz and the 7-seg is common cathode type and the shift register is 74HCT164.
7-Seg Display Using Shift Register mikroC code:

int i=0,j=0,k=0,l=0,d0=0,m=0,n=0,p=0;
unsigned short seg(unsigned short num) {
switch (num) {
case 0 : return 0x3F;
case 1 : return 0x06;
case 2 : return 0x5B;
case 3 : return 0x4F;
case 4 : return 0x66;
case 5 : return 0x6D;
case 6 : return 0x7D;
case 7 : return 0x07;
case 8 : return 0x7F;
case 9 : return 0x6F;
}
}
void interrupt(){

    i++;
    TMR0 = 0;
    INTCON = 0x20;
}
void main() {
            OPTION_REG = 0x84;
            TMR0 = 0;
            INTCON = 0xA0;
TRISA=0;
PORTA=0;
TRISB=0XFC;
PORTB=0;
  for(;;){
  if(i>300){
  i=0;
  j++;}
  if(d0==0){
  PORTA=0X1E;
  p=seg(j);
            for(m=0;m<7;m++){
             PORTB.F1=p;
             PORTB.F0=0;
             PORTB.F0=1;
             p=p>>1;}
                  d0=1;
                  delay_ms(4);}
  if(d0==1){
  if(j>9) {j=0;k++;}
  PORTA=0X1D;
  p=seg(k);
  for(m=0;m<7;m++){
             PORTB.F1=p;
             PORTB.F0=0;
             PORTB.F0=1;
             p=p>>1;}
              d0=2;
               delay_ms(4);            }
  if(d0==2){
  if(k>9) {k=0;l++;}
  PORTA=0X1B;
  p=seg(l);
  for(m=0;m<7;m++){
             PORTB.F1=p;
             PORTB.F0=0;
             PORTB.F0=1;
             p=p>>1;}
              d0=3;
               delay_ms(4);            }
 if(d0==3){
  if(l>9) {l=0;n++;}
  PORTA=0X17;
  p=seg(n);
  for(m=0;m<7;m++){
             PORTB.F1=p;
             PORTB.F0=0;
             PORTB.F0=1;
             p=p>>1;}
              d0=0;
               delay_ms(4);            }
  if(n>9)n=0;
                                     }


7-Seg Display Using Shift Register Video:
This video shows the circuit in reality.