View previous topic :: View next topic |
Author |
Message |
angel
Joined: 19 Oct 2004 Posts: 40
|
more problems with printf!!! |
Posted: Wed Nov 10, 2004 11:46 am |
|
|
I use a PIC 16F872 and a Max 232 CPE.
I have some problems with the printf function.
For exemple :
1)
..........................
printf ("f1,\n\r");
delay_ms(100);
value=Read_ADC();
printf("A/D value=%2x \n\r",value);
printf("f2,\n\r");
What happen? I read in my computer only f1. It doesn't appear A/D... and f2. The program jumps all the printf afther the first!!!
2)
....................................
printf ("f1,\n\r");
printf ("f2,\n\r");
What happen? In this case the answer is correct. I read in my computer f1 and f2.
3) Between printf f1 and printf f2 I changed the lines. Before I wanted to read a value after a ADC and now I use some lines from the DS1624.c driver of CCS. I want to read a temperature value.
..................................
printf ("f1,\n\r");
init_temp();
temp=read_temp();
printf("Temp(F):%6.4f\r\n",temp);
printf ("f2,\n\r");
what happen? the same that 1). Only I read in my computer f1.
Conclusion : When I try to read a value from out the PIC I can't read it using the function printf.
What happen? Does anyone know the solution of this problem?
Thanks for your answer. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Wed Nov 10, 2004 12:55 pm |
|
|
My conclusion you didn't setup the ADC correctly and its waiting for the value. Nothing to do with printf. |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Wed Nov 10, 2004 2:35 pm |
|
|
From what you have told us Mark's conclusion seems right. Try commenting out one line at a time to see what the effect of each one is. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Wed Nov 10, 2004 2:47 pm |
|
|
To prove me right angel could add
Code: | printf ("f1,\n\r");
|
after the ADC call since we know that this printf works correctly. |
|
|
angel
Joined: 19 Oct 2004 Posts: 40
|
OK it is the ADC!!! |
Posted: Mon Nov 15, 2004 1:15 pm |
|
|
hi
Ok it seems it is the ADC.
My software is :
...........................
main(){
int value;
setup_port_a(ALL_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(2);
while(1) {
if (kbhit) {
printf("f1 \n\r");
delay_ms(100);
value=Read_ADC();
printf ( "A/D value =%2x \n\r");
printf("f2 \n\r");
}
}
}
--------------------------------------------
--------------------------------------------
I try to read the out from a CNY70 sensor. It works correctly.
is "set_adc_channel(2);" the pin_A2?
is the software correct?
My PIC is a 16F872 and my quartz is 4 MHz. |
|
|
|