aviator3679
Starting Member
- Total Posts : 36
- Reward points : 0
- Joined: 2019/08/22 13:32:23
- Location: 0
- Status: offline
ADC interface doesnt work
Hello, i am using PIC18F2580 and the XC8 v1.34 compiler and trying to interface an ADC but doesnt compile.Does anyone know whats happening? The code im using is below: #include <stdio.h> #include <stdlib.h> #include "adc.h" #include <delays.h> void Initialize_ADC(void); void Initialize_XLCD(void); void DelayFor18TCY(void); void DelayPORXLCD(void); void DelayXLCD(void); unsigned int ADCResult=0; float voltage; unsigned char ResultString[10]; void main(void) { OSCCON=0x76; Initialize_ADC(); Initialize_XLCD(); putrsXLCD("ADC"); SetDDRamAddr(0x40); putrsXLCD("Display Voltage"); for(int x=0;x<=20;x++)__delay_ms(50); WriteCmdXLCD(0x01); while(1) { ADCResult=0; ConvertADC(); while(BusyADC()); ADCResult=ReadADC(); voltage=(ADCResult*5.0)/1024; putrsXLCD("Voltage="); sprintf(ResultString, "%.3", voltage); putsXLCD(ResultString); putrsXLCD("V"); putrsXLCD(" "); WriteCmdXLCD(0x02); } } void DelayFor18TCY(void) { Delay10TCYx(2); } void DelayPORXLCD(void) { Delay1KTCYx(60); return; } void DelayXLCD(void) { Delay1KTCYx(20); return; } void Initialize_ADC(void) { OpenADC(ADC_FOSC_2 & ADC_RIGHT_JUST & ADC_2_TAD, ADC_CH0 & ADC_INT_ON & ADC_REF_VDD_VSS, ADC_1ANA); } void Initialize_XLCD(void) { OpenXLCD(FOUR_BIT & LINES_5X7); while(BusyXLCD()); WriteCmdXLCD(0x06); WriteCmdXLCD(0x0C); WriteCmdXLCD(0x01); }
|
ric
Super Member
- Total Posts : 24605
- Reward points : 0
- Joined: 2003/11/07 12:41:26
- Location: Australia, Melbourne
- Status: offline
Re: ADC interface doesnt work
2019/08/28 22:06:44
(permalink)
"Doesn't compile" is not very informative. What error message do you get? Post the whole build log if you don't know which bit is relevant.
To get a useful answer, always state which PIC you are using!
|
aviator3679
Starting Member
- Total Posts : 36
- Reward points : 0
- Joined: 2019/08/22 13:32:23
- Location: 0
- Status: offline
Re: ADC interface doesnt work
2019/08/28 22:11:37
(permalink)
Yeah sorry about that haha.....the whole build log is below: make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf make[1]: Entering directory 'C:/Users/aeros/MPLABXProjects/adc.X' make -f nbproject/Makefile-default.mk dist/default/production/adc.X.production.hex make[2]: Entering directory 'C:/Users/aeros/MPLABXProjects/adc.X' "C:\Program Files (x86)\Microchip\xc8\v1.34\bin\xc8.exe" --pass1 --chip=18F2580 -Q -G --double=24 --float=24 --emi=wordwrite --opt=+asm,+asmfile,-speed,+space,-debug --addrqual=ignore --mode=free -P -N255 --warn=-3 --asmlist -DXPRJ_default=default --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,+plib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto:auto "--errformat=%f:%l: error: (%n) %s" "--warnformat=%f:%l: warning: (%n) %s" "--msgformat=%f:%l: advisory: (%n) %s" -obuild/default/production/adc.p1 adc.c adc.c:45: error: (969) end of string in format specifier adc.c:45: warning: (325) error in printf-style format string (908) exit status = 1 nbproject/Makefile-default.mk:107: recipe for target 'build/default/production/adc.p1' failed make[2]: Leaving directory 'C:/Users/aeros/MPLABXProjects/adc.X' nbproject/Makefile-default.mk:91: recipe for target '.build-conf' failed make[1]: Leaving directory 'C:/Users/aeros/MPLABXProjects/adc.X' nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed make[2]: *** [build/default/production/adc.p1] Error 1 make[1]: *** [.build-conf] Error 2 make: *** [.build-impl] Error 2 BUILD FAILED (exit value 2, total time: 2s)
|
ric
Super Member
- Total Posts : 24605
- Reward points : 0
- Joined: 2003/11/07 12:41:26
- Location: Australia, Melbourne
- Status: offline
Re: ADC interface doesnt work
2019/08/28 22:29:17
(permalink)
Here's the first error adc.c:45: error: (969) end of string in format specifier What is on line 45 of your copy of adc.c ? Possibly that file is corrupt.
To get a useful answer, always state which PIC you are using!
|
aviator3679
Starting Member
- Total Posts : 36
- Reward points : 0
- Joined: 2019/08/22 13:32:23
- Location: 0
- Status: offline
Re: ADC interface doesnt work
2019/08/28 22:49:06
(permalink)
On line 45 i have: sprintf(ResultString, "%.3", voltage); But still this should work
|
ric
Super Member
- Total Posts : 24605
- Reward points : 0
- Joined: 2003/11/07 12:41:26
- Location: Australia, Melbourne
- Status: offline
Re: ADC interface doesnt work
2019/08/28 23:22:36
(permalink)
aviator3679 On line 45 i have: sprintf(ResultString, "%.3", voltage); But still this should work
It would if you had remembered the format character. I assume there's meant to be an "f" in there!
To get a useful answer, always state which PIC you are using!
|
aviator3679
Starting Member
- Total Posts : 36
- Reward points : 0
- Joined: 2019/08/22 13:32:23
- Location: 0
- Status: offline
Re: ADC interface doesnt work
2019/08/28 23:27:35
(permalink)
I am watching a youtube tutorial the he has it exactly like that and it works
|
aviator3679
Starting Member
- Total Posts : 36
- Reward points : 0
- Joined: 2019/08/22 13:32:23
- Location: 0
- Status: offline
Re: ADC interface doesnt work
2019/08/28 23:28:54
(permalink)
how is it with an f ?......I am a student, its not like i have much experience with this kind of stuff
|
ric
Super Member
- Total Posts : 24605
- Reward points : 0
- Joined: 2003/11/07 12:41:26
- Location: Australia, Melbourne
- Status: offline
Re: ADC interface doesnt work
2019/08/28 23:29:32
(permalink)
It is invalid C syntax, so he's using some sort of non compliant compiler then. I can't comment any further as you failed to reveal the address of this "Youtube video".
To get a useful answer, always state which PIC you are using!
|
ric
Super Member
- Total Posts : 24605
- Reward points : 0
- Joined: 2003/11/07 12:41:26
- Location: Australia, Melbourne
- Status: offline
Re: ADC interface doesnt work
2019/08/28 23:32:40
(permalink)
aviator3679 how is it with an f ?......I am a student, its not like i have much experience with this kind of stuff
So how much C learning have you done? "format specifiers" in printf() statements are something you should learn how to use in the first week, before you start playing with exotic hardware...
To get a useful answer, always state which PIC you are using!
|
aviator3679
Starting Member
- Total Posts : 36
- Reward points : 0
- Joined: 2019/08/22 13:32:23
- Location: 0
- Status: offline
Re: ADC interface doesnt work
2019/08/29 00:05:13
(permalink)
Yeah i know,i supposed that since its a tutorial he may be using something i dont know ,so it should be alright,i am almost done with embedded C,only some final theoritical stuff remain about the better structure of the code and some practice in assignments,thats it....unfortunately for some reason the forum doesnt allow me to include a link...
|
aviator3679
Starting Member
- Total Posts : 36
- Reward points : 0
- Joined: 2019/08/22 13:32:23
- Location: 0
- Status: offline
Re: ADC interface doesnt work
2019/08/29 00:06:29
(permalink)
I tried what you said about the f in the code and works,it compiles....THANK YOU !!!!!
|
Aussie Susan
Super Member
- Total Posts : 3637
- Reward points : 0
- Joined: 2008/08/18 22:20:40
- Location: Melbourne, Australia
- Status: offline
Re: ADC interface doesnt work
2019/08/29 19:04:08
(permalink)
I'm not totally sure but I do know that the XC8 compiler parses the format specifier when it is a string literal so that it can optimise what modules need to be included in the app (rather than including everything and leaving it to runtime to do the parsing and interpreting). If the compiler can't interpret the format specifier string according to the 'rules', then it looks like it treats it as a compile error. Susan
|
aviator3679
Starting Member
- Total Posts : 36
- Reward points : 0
- Joined: 2019/08/22 13:32:23
- Location: 0
- Status: offline
Re: ADC interface doesnt work
2019/08/29 20:58:26
(permalink)
Maybe, because this project seems to work now but in another i think that everything is alright except the adc conversion, resulting in displaying black boxes on my lcd display simulation on proteus....For more info : https://www.microchip.com/forums/m1110825.aspx with title : lcd / black vertical bars [font="verdana; font-size: 14px; font-weight: normal"]
|