![]() |
![]() |
![]() |
|
|
|||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
|
|
Thread Tools | Display Modes |
|
|
(permalink) |
|
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);
}
|
|
|
|
|
|
|
(permalink) |
|
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.. |
|
|
|
|
|
|
(permalink) | |
|
Quote:
OP a schematic would be helpful. |
||
|
|
|
|
|
(permalink) |
|
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?
|
|
|
|
|
|
|
(permalink) |
|
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. |
|
|
|
|
|
|
(permalink) |
|
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..
|
|
|
|
|
|
|
(permalink) |
|
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);
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);
__________________
--- The days of the digital watch are numbered. --- Last edited by kchriste; 16th January 2008 at 04:54 AM. |
|
|
|
|
|
|
(permalink) |
|
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.. |
|
|
|
|
|
|
(permalink) |
|
btw.. im using two common anode 7 segments. will the figure above still be applicable or i have to create some modifications?
|
|
|
|
|
|
|
(permalink) |
|
Please post your schematic...
|
|
|
|
|
|
|
(permalink) |
|
The problem is the sendhex function.
|
|
|
|
|
|
|
(permalink) | |
|
Quote:
|
||
|
|
|
|
|
(permalink) | |
|
Quote:
|
||
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
|
|
||||
| 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 |