Jump to content


Photo

Adc With 16f887


4 replies to this topic

#1 mityeltu

mityeltu

    Regular

  • EstablishedMember
  • Pip
  • 81 posts
  • Gender:Male
  • Location:Tennessee
  • Interests:Communications

Posted 18 April 2010 - 08:57 PM

I'm stumped. I have been banging away at this project for more than 6 hours trying to get the sourceboost commands to work. They won't even compile. All I want ton do is read the ad result into a variable and then display it on an lcd. The lcd works fine. Here is the stripped down adc only code that won't copmpile. I compared it to what is done in the adc example, and everything is done the same, just not the same way... I am using the 16F887 with 8MHz internal oscillator. Can anyone please helkp me?

I get this error when compiling:
Error: Unresolved external function:'adc_measure(unsigned char)'

I tried declaring vartious combinations of variables locally and globally, but I frankly don't understand what thjat error even means.

#include <system.h>
#include <adc.h>

//short ad_res;
//unsigned char ch;
		
void main&#40;&#41;
{
//unsigned char ch
short ad_res;
char one, two, three;

unsigned char t = 500;
osccon = 0x71;

intcon = 0x00;
set_bit&#40;adcon0,0&#41;;
adcon1 = 0x80;
ansel = 0xe0;//channels 5,6,7 porte 0,1,2
anselh = 0x00;

trisa = 0x00;
porta = 0x00;
trisb = 0x00;
portb = 0x00;
trise = 0xff;

while&#40;1&#41;
{
	delay_ms&#40;t&#41;;
	ad_res = adc_measure&#40; 5 &#41;;
	ad_res = ad_res / 4;
	three = &#40;ad_res % 10&#41; + 48;
	ad_res /= 10;
	two = &#40;ad_res % 10&#41; + 48;
	ad_res /= 10;
	one = ad_res + 48;
}

}

Edited by mityeltu, 18 April 2010 - 08:59 PM.


#2 davidb

davidb

    Enthusiast

  • EstablishedMember
  • PipPip
  • 134 posts
  • Location:Essex, UK

Posted 18 April 2010 - 09:20 PM

I am guessing you haven't added the adc library file (adc.pic16.lib) to the workspace window.

Regards

davidb

#3 mityeltu

mityeltu

    Regular

  • EstablishedMember
  • Pip
  • 81 posts
  • Gender:Male
  • Location:Tennessee
  • Interests:Communications

Posted 19 April 2010 - 11:05 AM

I am guessing you haven't added the adc library file (adc.pic16.lib) to the workspace window.

Regards

davidb


That was it..... Thank you. Why is that not mentioned in the help file? I mean, it states that the function is declared in the .h and defined in the .lib, but there is no statement to the fact that this file has to be added to the project. Am I just supposed to know that?

Thanks again.... when I get back home, I'll test it out, but at least it compiles now.

#4 davidb

davidb

    Enthusiast

  • EstablishedMember
  • PipPip
  • 134 posts
  • Location:Essex, UK

Posted 19 April 2010 - 12:33 PM

That was it..... Thank you. Why is that not mentioned in the help file? I mean, it states that the function is declared in the .h and defined in the .lib, but there is no statement to the fact that this file has to be added to the project. Am I just supposed to know that?

The reference manuals (help) are not ideal and a sentence or so on creating projects with several files and the use of libraries would be helpful to newbies. There are a few references to this on the forum and also a mention about c and lib files in the Tip Of The Day.

Basically any library function used must have it's .lib file added to the project. The only exception to this is the libc file which SourceBoost IDE adds automatically when linking. If you use MPLAB instead of the SB IDE then the appropriate libc must be added to the project as well.

Despite the poor references and a few compiler quirks and ommisions I think you will find the overall package effective and very good value.

Good luck with the rest of your project.

Regards

davidb

#5 mityeltu

mityeltu

    Regular

  • EstablishedMember
  • Pip
  • 81 posts
  • Gender:Male
  • Location:Tennessee
  • Interests:Communications

Posted 20 April 2010 - 12:44 AM

The reference manuals (help) are not ideal and a sentence or so on creating projects with several files and the use of libraries would be helpful to newbies. There are a few references to this on the forum and also a mention about c and lib files in the Tip Of The Day.

Basically any library function used must have it's .lib file added to the project. The only exception to this is the libc file which SourceBoost IDE adds automatically when linking. If you use MPLAB instead of the SB IDE then the appropriate libc must be added to the project as well.

Despite the poor references and a few compiler quirks and ommisions I think you will find the overall package effective and very good value.

Good luck with the rest of your project.

Regards

davidb


Fair enough. But I don't have to include anythig but the lcd_driver.h file for that to work. I understand from reading the file that the functions have been both declared and defined within a single file, but that sort of inconsistency is not going to make it simpler. Not complaining at you, just complaining. Thank you for the help and the insight.

Sincerely,
Tim



Reply to this topic



  


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users