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);
}