CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

PIC ADC

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
rezaf



Joined: 12 Oct 2008
Posts: 7

View user's profile Send private message

PIC ADC
PostPosted: Sat Mar 13, 2010 7:37 am     Reply with quote

Hello
How can I convert 10bit result of PIC16F877A ADC to BCD code or other methods to display on 7segment display?
I have written the code below to read ADC pin:
Code:

  #include <float.h>
  #include <math.h>
  #include <stdio.h>
  #include <string.h>
int32 value;
int32 value2;

void main()
{
   setup_adc_ports(AN0);
   setup_adc(ADC_CLOCK_DIV_2);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   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);
   SET_TRIS_B( 0 );
   // TODO: USER CODE!!
adccheck:
{
 OUTPUT_B(0x00);
 do {
     set_adc_channel(0);
     delay_ms(50);
     value = read_adc();
     value = (((int32)value*5000)/1024)+5;
     value = value/10;
    if (value!=value2){
     printf("\r\n\nCalibrated Result = %4.2Lw",value);
    }
     value2 = value;
  }while(true);
}
}

thanks.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Mar 14, 2010 1:20 am     Reply with quote

Look at the lcd_putd() function in this CCS example file:
Quote:

c:\program files\picc\examples\ex_zmd.c
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group