Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Multiplexing 4-digit seven segment display using PIC16F877a

Status
Not open for further replies.

kaizer002

Newbie level 5
Joined
Jan 6, 2010
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,356
Hi to all,

I'm making a project and I choose multiplexing 4 seven segment displays with my PIC16F877a.

Here's how it goes: the first two seven segments will display the "Minutes" and the last two seven segments will display "Seconds".



Please help me with the source code since I'm having difficulty with that. Thanks in advance..!
 

Re: Multiplexing 4-digit seven segment display using PIC16F8

kaizer002 said:
Hi to all,

I'm making a project and I choose multiplexing 4 seven segment displays with my PIC16F877a.

Here's how it goes: the first two seven segments will display the "Minutes" and the last two seven segments will display "Seconds".



Please help me with the source code since I'm having difficulty with that. Thanks in advance..!


do you want to use four ports doing that ? or you will use one port ?
 

Re: Multiplexing 4-digit seven segment display using PIC16F8

Yes, the source code will depend on the number of ports you want to use.
 

Re: Multiplexing 4-digit seven segment display using PIC16F8

Thanks for the reply guys,

@toto_nai16:

I want to use minimum ports or pins as long as possible.

@daviddlc:

Yes...but I don't have any idea how the program goes. I have a little knowledge of assigning ports. Pls help..
 

Re: Multiplexing 4-digit seven segment display using PIC16F8

You can use 4 LSB port pins connected to a 74LS247
Then for the multiplexing you can use two port pins connected to a 1-4 demultiplexer and one pin for the blinking LEDs for a total of 7 pins.

For example:
PORTB0 //To 74LS247 LSB
PORTB1 //To 74LS247
PORTB2 //To 74LS247
PORTB3 //To 74LS247 MSB
PORTB4 //To 1-4 demultiplexer
PORTB5 //To 1-4 demultiplexer
PORTB6 //For the blinking LEDs

The source code can be like this, be aware this is not tested and should be double checked, this is just to give you an idea.

byte Output;
byte Data [4];
byte Blinking;
byte Counter;

Data[0] = SecondsLSB;
Data[1] = SecondsMSB;
Data[2] = MinutesLSB;
Data[3] = MinutesMSB;

while(1)
{
for(Counter=0;Counter<=3;Counter++)
{

You need to update this section every second
{
//Blinking = 0x40 or Blinking = 0
//Data[0] = SecondsLSB;
//Data[1] = SecondsMSB;
//Data[2] = MinutesLSB;
//Data[3] = MinutesMSB;
}

Output = Data[Counter] || (Counter * 0x10) || Blinking;

}

}

Sometimes you need to add a small delay in the for loop, this depends on the processor speed and the brightness you want to achieve.

Added after 3 minutes:

I missed:

......
TRISB = 0x00 //This is to configure PORTB as outputs. (This command can be different according to the compiler you are using)

......


for(Counter=0;Counter<=3;Counter++)
{

You need to update this section every second
{
//Blinking = 0x40 or Blinking = 0
//Data[0] = SecondsLSB;
//Data[1] = SecondsMSB;
//Data[2] = MinutesLSB;
//Data[3] = MinutesMSB;
}

Output = Data[Counter] || (Counter * 0x10) || Blinking;
PORTB = Output

}

......
 

Re: Multiplexing 4-digit seven segment display using PIC16F8

Does transistor BC327 applicable for multiplexing?

By the way,
I used this code in MikroC but this time, I test 2-digit seven segments but the 1st display which is "tens" is overlapped and the 2nd digit which is "ones" is ok.
What seems to be the problem?

Code:
/*
 * Project name:
     Display7Seg_02 (Usage of 2 7Seg. displays)
 * Copyright:
     (c) MikroElektronika, 2005-2008.
 * Description:
     This code demonstrates displaying numbers (0,1,2..99) on two 7-segment
     displays. Each digit is on for 1 second.
 * Test configuration:
     MCU:             PIC16F877A
     Dev.Board:       EasyPIC5
     Oscillator:      HS, 08.0000 MHz
     Ext. Modules:    -
     SW:              mikroC v8.0
*/

#include "Display_utils.h"

unsigned short digit_no, digit10, digit1, digit, i;

void interrupt() {
  if (digit_no==0) {
    PORTA = 0;          // Turn off all 7seg displays
    PORTD = digit1;     //  send mask for ones digit to PORTD
    PORTA = 1;          //  turn on 1st 7 seg., turn off 2nd
    digit_no = 1;
  } else {
    PORTA = 0;          // Turn off all 7seg displays
    PORTD = digit10;    //  send mask for tens digit to PORTD
    PORTA = 2;          //  turn on 2nd 7 seg., turn off 1st
    digit_no = 0;
    }
  TMR0 = 0;             //  clear TMRO
  INTCON = 0x20;        //  clear TMR0IF and set TMR0IE
}

void main() {
  OPTION_REG  = 0x80;   // Timer0 settings
  TMR0        =   0;
  INTCON      = 0xA0;   // Disable PEIE,INTE,RBIE,T0IE
  PORTA       =    0;   // clear PORTA (make sure both displays are off)
  TRISA       =    0;   // designate PORTA pins as output
  PORTD       =    0;   // clear PORTD (make sure LEDs are off)
  TRISD       =    0;   // designate PORTD pins as output
  do {
    for (i = 0; i<=99; i++) {          // count from 0 to 99
      digit   = i % 10u;
      digit1  = mask(digit);           // prepare ones digit
      digit   = (char)(i / 10u) % 10u;
      digit10 = mask(digit);           // prepare tens digit
      Delay_ms(1000);
    }
  } while (1);                         // endless loop
}

 

Re: Multiplexing 4-digit seven segment display using PIC16F8

I suggest using 8-bit latch

this will help you to use one port and additional four pins for controlling which latch to open
 

Re: Multiplexing 4-digit seven segment display using PIC16F8

hello again, please check my program

Code:
#include<16f877.h>
#fuses XT,NOLVP,NOWDT,PUT
#use delay (clock=1000000)   // defind crystal = 4MHz
#byte port_d=8
#byte port_a=5
byte CONST LED_MAP[10]={0x3F,0x06,0x5b,0x4F,0x66,0x6D,0x7D,0x07,0X7F,0x6F};

//===========================================
// this function use to display number 00=99
// input : n = number to display
//===========================================
void display_number(int n)
{

   output_d(LED_MAP[n/10]);//tens position;n=0 to 9
   output_low(PIN_A2);
   delay_ms(20);
   output_high(PIN_A2);
   output_d(LED_MAP[n%10]) ;//unit position
   output_low(PIN_A1);
   delay_ms(20);
   output_high(PIN_A1);
}
//============================================
// main program
//============================================
void main()
{
   int i,count=0;

   while(TRUE)
   {
      for (i=0;i<=200;i++)
         display_number(count);      // dispay 200 times
    count=(count==59) ? 0: count+1;//count+1=++count

   }
}

I can't change the 200 value. When I change it, e.g. to 500, the segments are not counting, it stays to "0"..what seems to be the problem?

by the way the code is not mine, I copied it from other sites so I don't understand this part:

Code:
while(TRUE)
   {
      for (i=0;i<=200;i++)
         display_number(count);      // dispay 200 times
    count=(count==59) ? 0: count+1;//count+1=++count

   }

Please help me!
 

Re: Multiplexing 4-digit seven segment display using PIC16F8

could any body tell me how to interface pic16f877a with lm35 and 3 seven segment to display
my problem is in the source code in mikroc

plz help
 

Re: Multiplexing 4-digit seven segment display using PIC16F8

HI mr DAHROUG



LM35 output is connectd to PIC any PORT A pin.. u can convert Analog Temp value into digital ...
and how u connected these 3 seven segment display DIGITS..??

R u using Single port to 3 DIGIT if its true u should switch COM1, COM2, COM3 using other port pin so that u can Switch ON each sement in minute time....

if ur using Individual port for every digit.. its so simple.. to write the code...


k reply me so that i can get u .........

Added after 3 minutes:



unsigned char n,d,count=0;
unsigned char a,b,c;

void keypadscan();
void display();
void disp_dig(char );

void main()
{
d=123;

while(1)
{
n=d;
display();
//keypadscan();
}
}

void display() // DISPLAYING all DIGITS

{
TRISB=0; // Configured PORTB as OUTPUT
TRISD=0; // Configured PORTD as OUTPUT
if(count==0)
{
a=n%10; n=n/10; // a=3
b=n%10; n=n/10; // b=2
c=n%10; n=n/10; // c=1
count=1;
}
disp_dig(c);
PORTD=0x01; // SD1 ON
DelayUs(500);

disp_dig(b);
PORTD=0x02; //SD2 ON
DelayUs(500);

disp_dig(a);
PORTD=0x04; //SD3 ON
DelayUs(500);

}


void disp_dig(char k)
{
switch(k)
{
case 0:{ PORTB=0X3F; break; }
case 1:{ PORTB=0X06; break; }
case 2:{ PORTB=0X5B; break; }
case 3:{ PORTB=0X4F; break; }
case 4:{ PORTB=0X66; break; }
case 5:{ PORTB=0X6D; break; }
case 6:{ PORTB=0X7D; break; }
case 7:{ PORTB=0X07; break; }
case 8:{ PORTB=0X7F; break; }
case 9:{ PORTB=0X6F; break; }
}

}


i thnk u get from this code..............how to use 3 digit display

Added after 1 minutes:

Here SD1 , SD2 , SD3 are.. COM pins of 3 DIGITS

Added after 1 minutes:

in this code SD1, SD2 SD3 are the

COM1, COM2 , COM 3 of 3 DIGITs Supply pins through ULN

so understand the logic i hope u can do it.. by seeing this
 
Re: Multiplexing 4-digit seven segment display using PIC16F8

THANK U SO MUCH MR/srinu
ur answer was so clear and i was excellent

i attached the schematic to have a look and plz tell me how to modify the code to rebuild it as temperature control or room control if u don't mind .


or if u have another similar project with the code and schematic plz upload it...

and thank u again

Added after 1 minutes:

this is the schematic
 

Re: Multiplexing 4-digit seven segment display using PIC16F8

HI mr DAHROUG



LM35 output is connectd to PIC any PORT A pin.. u can convert Analog Temp value into digital ...
and how u connected these 3 seven segment display DIGITS..??

R u using Single port to 3 DIGIT if its true u should switch COM1, COM2, COM3 using other port pin so that u can Switch ON each sement in minute time....

if ur using Individual port for every digit.. its so simple.. to write the code...


k reply me so that i can get u .........

Added after 3 minutes:



unsigned char n,d,count=0;
unsigned char a,b,c;

void keypadscan();
void display();
void disp_dig(char );

void main()
{
d=123;

while(1)
{
n=d;
display();
//keypadscan();
}
}

void display() // DISPLAYING all DIGITS

{
TRISB=0; // Configured PORTB as OUTPUT
TRISD=0; // Configured PORTD as OUTPUT
if(count==0)
{
a=n%10; n=n/10; // a=3
b=n%10; n=n/10; // b=2
c=n%10; n=n/10; // c=1
count=1;
}
disp_dig(c);
PORTD=0x01; // SD1 ON
DelayUs(500);

disp_dig(b);
PORTD=0x02; //SD2 ON
DelayUs(500);

disp_dig(a);
PORTD=0x04; //SD3 ON
DelayUs(500);

}


void disp_dig(char k)
{
switch(k)
{
case 0:{ PORTB=0X3F; break; }
case 1:{ PORTB=0X06; break; }
case 2:{ PORTB=0X5B; break; }
case 3:{ PORTB=0X4F; break; }
case 4:{ PORTB=0X66; break; }
case 5:{ PORTB=0X6D; break; }
case 6:{ PORTB=0X7D; break; }
case 7:{ PORTB=0X07; break; }
case 8:{ PORTB=0X7F; break; }
case 9:{ PORTB=0X6F; break; }
}

}


i thnk u get from this code..............how to use 3 digit display

Added after 1 minutes:

Here SD1 , SD2 , SD3 are.. COM pins of 3 DIGITS

Added after 1 minutes:

in this code SD1, SD2 SD3 are the

COM1, COM2 , COM 3 of 3 DIGITs Supply pins through ULN

so understand the logic i hope u can do it.. by seeing this

hi sirnu . this is jameesha. now only i started to learning about the pic16f877 microcontroller interfacing .

i seen your program in this website. i had some doubt.

in this above program what is the need of count.

then what is the hex decimal code you written in the port b inside the switch case. wheather its hexdecimal code for 0-9 . where is that code available in the datasheet of pic or seven segment led.
 

Hello every one!!

Can any one give me c code of 0 to 100 counter program with 7 segment display.
I am using pic16f877a and mikroc program
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top