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

PIC16F877A data acquisition

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







PIC16F877A data acquisition
PostPosted: Thu Apr 21, 2005 9:49 am     Reply with quote

Hi all,

I’ve just started learning PIC16F877A, before this I experienced a lot with 16F84A using CCS PIC C. I had never used A/D converter uC before this. Basically I want to read analog signal by A/D converter and display the result on RS232 terminal software at an interval of say 1sec. So can anybody please give me source code, so as to learn how to program it?

Thanks a lot
DragonPIC



Joined: 11 Nov 2003
Posts: 118

View user's profile Send private message

PostPosted: Thu Apr 21, 2005 12:24 pm     Reply with quote

Code:
void init(void)         //initialization
{
   port_a = a_start;

   setup_adc_ports(RA0_ANALOG_RA3_RA2_REF);
   setup_adc(ADC_CLOCK_DIV_2);         //MIGHT HAVE TO BE DIV_32 OR DIV_64
   set_adc_channel(0);

   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);

   sleep_timer = 0x0000;
   set_timer1(0);
   setup_timer_1(t1_internal|t1_div_by_1);
   enable_interrupts(int_timer1);
   enable_interrupts(global);

   set_tris_a(a_dirs);
   set_tris_b(b_dirs);
   port_b_pullups(TRUE);
   set_tris_c(c_dirs);

   port_a = a_def;
   port_b = b_def;
   port_c = c_def;

//   while((port_b & 0xF1) != 0xF1);      //make sure int pin is in default state before continueing

   delay_ms(900);
}

void battery_test(void)
{
   battery = read_adc();
   if (battery > full)
      battery = full;
   if (battery > dead)
      percent = ((battery-dead) * 10) / bat_div;         //compute battery charge
   else
      percent = 0;

      printf("\r\nBattery = %lu%%\r\n", percent);   //display charge percentage
}


here is a quick chunk of some of my code on a 876A.

don't forget the #device adc=10 (#device adc=8 if you are doing 8bit conversion) in your *.h file.

Hope this helps..
_________________
-Matt
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