Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

2 digit 7 segment display..

Status
Not open for further replies.

overmind

New Member
hi everyone.. what im trying to do is that when i type a 1 or 2 digit no., it will appear on the 7 segment display.. i really cant figure out why its not working.. can anybody tell me whats wrong with my code? thanks..im using a 16f877.h pic.. here it is
Code:
#if defined(__PCM__)
#include <16F877.h>
#include <stdio.h>
#include <stdlib.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)  

void findnumbers(int temp);
void sendhex(int number, int digit);
void displaynumbers(int tens, int ones);
int getavgtemp(); 




void main() {
  int temp;
   int i=0;
  set_tris_b(0);
  
  temp = 0;
  output_b (0x00);
  while(TRUE) {
    if(kbhit()) {
        temp=getc();
        delay_ms(500);
            findnumbers(temp);
    }
  }
}




// function to find number
void findnumbers(int temp) 
   {

   int tens = 0; // tens position
   int ones = 0; // ones position
   
   output_high(PIN_D0); 
   if (temp < 100) // temp should never be over 100
   {
    tens = (temp/10)%(10);
    ones = (temp%10);
   }else{tens, ones = 2;}
   displaynumbers(tens,ones);
}

// this converts a number to the desired high/low combination
// for the 7 seg led display
void sendhex(int number, int digit)
   {
   output_high(PIN_D1);
   output_e (0x00);
   // send hex to port b to make number
   
   if (number == 0){output_b (0xC0);} // output 0 to port b
   if (number == 1){output_b (0xF9);} // 1
   if (number == 2){output_b (0xA4);}
   if (number == 3){output_b (0xB0);}
   if (number == 4){output_b (0x99);}
   if (number == 5){output_b (0x92);}
   if (number == 6){output_b (0x82);}
   if (number == 7){output_b (0xF8);}
   if (number == 8){output_b (0x80);}
   if (number == 9){output_b (0x90);}

   
   //turn on the digit(send high to common cathode via transistor)
   if (digit == 1){output_high(PIN_E0);}
   if (digit == 2){output_high(PIN_E1);}
   output_low(PIN_D1);
   
   }
   
void displaynumbers(int tens, int ones)// send to led
   {
   int i = 0;
   output_high(PIN_D2); 
   
   
   if(tens > 0)
   {
   sendhex(tens, 2);
   sendhex(ones, 1);
   }else{
   sendhex(ones, 2);
   }
   output_low(PIN_D2);
   }
 
Well...

Well,

I suggest you to use IC 7447 or 7448 ... then your code will be as small as two or three lines...

| microcontroller | --- > | 7447 | --- > | Seven Seg. |

Regards,

Simran..:)
 
simrantogether said:
Well,

I suggest you to use IC 7447 or 7448 ... then your code will be as small as two or three lines...

| microcontroller | --- > | 7447 | --- > | Seven Seg. |

Regards,

Simran..:)

It's good practice to avoid using "glue" logic if you can. The 16F877 is a big chip, lots of I/O and can drive a seven-segment display.

OP a schematic would be helpful.
 
hi.. actually i just based my code on a post here somewhere.. however in his schematic diagram, he placed transistors between the input of the 7 segments going to the microcontroller. but i didnt placed any transistor in my project.. will it matter?
 
Well the PIC can only sink or source 20 to 25ma. Generally the transistors are there to drive the CA or CC pins.
**broken link removed**
Funny thing this schematic is from an 8051 site.
 
hi.. i followed the schematic diagram and placed a temperature transducer at port A1. so what i want to do now is to display the temperature transducer in the two 7 segments.. however when i get a reading of 20 C. what happens is that it displays the digit 2 on the first 7 segment and the segments on the first 7 segment that did not light (segments f,c and dp) will light on the second 7 segment and then the digit 0 will be displayed on the first 7 segment and segments g and dp will light on the second seven segment.. its like it displays the digit 20 on two occasions.. can anybody tell me why is this happening? (i hope you understand the way i explain my problem..) please help..
 
One problem is the following code:
Code:
//turn on the digit(send high to common cathode via transistor)
   if (digit == 1){output_high(PIN_E0);}
   if (digit == 2){output_high(PIN_E1);}
   output_low(PIN_D1);
You really need to turn off one digit before turning on the other:
Code:
//turn on the digit(send high to common cathode via transistor)
   if (digit == 1){output_low(PIN_E1); output_high(PIN_E0);}
   if (digit == 2){output_low(PIN_E0); output_high(PIN_E1);}
   output_low(PIN_D1);
BTW, what are you doing with PIN_D1?
 
Last edited:
thanks for the reply.. actually, i have a customized kit.. and port d is connected to 8 LED's.. one for each pin..

the code you gave me still doesn't solve my problem.. anymore ideas? please help.. thanks..
 
btw.. im using two common anode 7 segments. will the figure above still be applicable or i have to create some modifications?
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top