john120
Banned
- Joined
- Aug 13, 2011
- Messages
- 257
- Helped
- 11
- Reputation
- 22
- Reaction score
- 10
- Trophy points
- 1,298
- Activity points
- 0
Hello there,I am design a digital voltmeter 0-30V I am using PIC16F876A and ccs c for coding but I am having great problem with the conversion of adc value read to be converted into decimal for displaying on seven segment .
Please see the codes and let me know what I can change.
I am always reading 0s in the 3 seven segment display.
see the code here;please help.
Please see the codes and let me know what I can change.
I am always reading 0s in the 3 seven segment display.
see the code here;please help.
PHP:
#include "16f876a.h"
#DEVICE ADC=10
#fuses HS,NOWDT
#use delay(clock=12000000)
#include<stdio.h>
#include<STDLIB.H>
#use standard_io(A)
#use standard_io(B)
#DEFINE PORTB
#DEFINE PORTC
#DEFINE PORTA
byte const digit[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
char display[3];
int value;
unsigned long value1;
unsigned int value2;
void main()
{
set_tris_a(0xff);
set_tris_b(0x00);
set_tris_c(0x00);
output_b(0xff);
output_c(0xff);
setup_comparator(NC_NC_NC_NC);
setup_adc(ADC_CLOCK_INTERNAL);
setup_adc_ports(AN0);
set_adc_channel(0);
setup_vref(FALSE);
while(TRUE)
{
delay_us(100);
read_adc(ADC_read_only);
delay_us(100);
value=read_adc(ADC_read_only);
value1=(value*5*6)/1023;
value2=value1;
delay_ms(5);
output_low(PIN_b2);
display[0]=(value2%10);
output_high(PIN_b4);
output_high(PIN_b5);
output_c(digit[display[0]]);
delay_ms(5);
output_low(PIN_b4);
display[1]=(value2%10) ;
output_high(PIN_B5);
output_high(PIN_b2);
output_c(digit[display[1]]);
delay_ms(5);
delay_ms(5);
output_low(PIN_b5);
display[2]=(value2%100) ;
output_high(PIN_B2);
output_high(PIN_b2);
output_c(digit[display[2]]);
delay_ms(5);
}
}