need Pic 16f873A 4 digit seven segment display code

HI any one help me code for seven segment display 4 digit with pic16f873A

a-RB1 t0 g-RB7
dot-RBO

common cathode -dig1-RC7
dig2-RC6
dig3-RC5
dig4-RC4
complier ccs c

i tried this code 2 digit but not working
#include <16F873A.h>
#device adc=8

#FUSES NOWDT //No Watch Dog Timer
#FUSES XT //Crystal osc <= 4mhz for PCM/PCH , 3mhz to 10 mhz for PCD
#FUSES NOPUT //No Power Up Timer
#FUSES PROTECT //Code protected from reads
#FUSES NODEBUG //No Debug mode for ICD
#FUSES BROWNOUT //Reset when brownout detected
#FUSES LVP //Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected

#use delay(clock=4000000)

Void init_peripheral();
Void Referesh();
#bit sel1 =0x07.7
#bit sel2 =0x07.6
#bit sel3 =0x07.5
#bit sel4 =0x07.4
#byte portb=0x06
#bit menu =0x07.0
#bit up = 0x07.1
#bit down =0x07.2
#bit enter =0x7.3
#bit relay1=0x05.4
#byte trisb=0x86
#byte trisa=0x85
#byte trisc =0x87
const int8 seg[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
int8 d;
void main()
{

//setup_adc_ports(sANO_ANALOGS);
//setup_adc(ADC_OFF);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
//enable_interrupts(global);

init_peripheral();
while(1)
{


set_adc_channel(AN0);
delay_ms(100);
d=read_adc();
referesh();
}
}
void init_peripheral()
{
trisb=0;trisa=0xff;trisc=0x0f;
}
void referesh()
{
int8 d2,d3;
d2=(d/10)%10;//second digit
d3= d/100; //first disgit
portb=seg[d3];sel4=1;delay_ms(50);sel4=0;
portb=seg[d2];sel3=1;delay_ms(50);sel3=0;

}
 
I guess CCS... Hi John.. Havent seen you in a while...


Yeah...been workin' like crazy and we just added a little one to the family. He was born April 25th @ 2:59AM Pacific Time. 8lbs 1oz and 20 inches. He's totally got the hands of a guitar player for sure. Hoping to expose him to it and have him develop an interest in it.
 
now displays the segment but i need conversion from adc to 0 t0 500 (only three digit enough
what is the procedure
portb configure as dot,a,b,c,d,e,f,g,h
portc as enble digit

const int8 seg[]={0x7e,0x0c,0xb6,0x9e,0xcc,0xda,0xfa,0x0e,0xfe,0xce};
portb adress for 0-9

how to displays this adc to 0-500
any help
 
thanks for reply roger ,i want to conversion value to display ,
0v to 0.00
5V to 5.00 or 4.99

result=adc value /51*100
if 0=0.00
255=5.00
i want display function like first digit result/100
second digit result/10
like that how this function working?
urgent plz
 
0 to 5v represents 0 to 255 on an 8 bit ADC... This is called "mapping"


If you have said voltage at 2.5 volts, then you would expect to see 128 digitally..

Volts in * ADC max resolution / max volts

2.5 * 256 / 5 = 128... We can use 9 bits to our benifit.... 2.5v * 512 / 5 = 256 put in the decimal place and it represents 2.56 volts

But you haven't got 9 bits so you can "oversample" Read the ADC 10 times in succession.. 255 * 10 = 2550 then divide by 5 = 510..


I, personally, read the ADC 24 times then I can then divide to get my results.... Oversampling gives slightly better results as it does two things

a) Acts as a digital filter to smooth the ADC result..
b) Gives, ever so slightly, a better resolution..
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…