Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 15th January 2008, 10:09 AM   (permalink)
Default 2 digit 7 segment display..

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);
   }
overmind is offline  
Reply With Quote
Old 15th January 2008, 11:30 AM   (permalink)
Smile 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..
__________________
Simran..
8051 Specialist..
simrantogether is offline  
Reply With Quote
Old 15th January 2008, 03:05 PM   (permalink)
Default

Quote:
Originally Posted by simrantogether
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.
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com
blueroomelectronics is offline  
Reply With Quote
Old 16th January 2008, 02:45 AM   (permalink)
Default

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?
overmind is offline  
Reply With Quote
Old 16th January 2008, 03:05 AM   (permalink)
Default

Well the PIC can only sink or source 20 to 25ma. Generally the transistors are there to drive the CA or CC pins.

Funny thing this schematic is from an 8051 site.
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com
blueroomelectronics is offline  
Reply With Quote
Old 16th January 2008, 03:47 AM   (permalink)
Default

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..
overmind is offline  
Reply With Quote
Old 16th January 2008, 04:51 AM   (permalink)
Default

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?
__________________
--- The days of the digital watch are numbered. ---

Last edited by kchriste; 16th January 2008 at 04:54 AM.
kchriste is offline  
Reply With Quote
Old 16th January 2008, 05:22 AM   (permalink)
Default

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..
overmind is offline  
Reply With Quote
Old 16th January 2008, 05:40 AM   (permalink)
Default

btw.. im using two common anode 7 segments. will the figure above still be applicable or i have to create some modifications?
overmind is offline  
Reply With Quote
Old 16th January 2008, 11:18 PM   (permalink)
Default

Please post your schematic...
Mike, K8LH is online now  
Reply With Quote
Old 17th January 2008, 12:27 AM   (permalink)
Default

The problem is the sendhex function.
penoy_balut is offline  
Reply With Quote
Old 17th January 2008, 03:32 AM   (permalink)
Default

Quote:
Originally Posted by Mike, K8LH
Please post your schematic...
hi mike... i followed the one shown above..
overmind is offline  
Reply With Quote
Old 17th January 2008, 03:34 AM   (permalink)
Default

Quote:
Originally Posted by penoy_balut
The problem is the sendhex function.
hi there.. can you please tell me whats wrong with my code? i really cant figure it out.. thanks..
overmind is offline  
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Latest
Problem with LCD code? spondootre Micro Controllers 15 29th April 2008 09:15 AM
asm attachments eng1 Feedback/Comments 6 14th September 2007 03:01 PM
driving multiplexed 7 segment display mathur2000 Micro Controllers 7 24th June 2007 10:07 PM
microchip application A590 /display is ok now prosound90 Micro Controllers 20 18th November 2006 09:44 PM
simple 3 digit, large 7 segment LED display tgator Electronic Projects Design/Ideas/Reviews 3 11th August 2005 10:37 PM



All times are GMT. The time now is 01:30 PM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.