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

Bug in Printf() function!!

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



Joined: 17 Oct 2005
Posts: 68
Location: Brisbane

View user's profile Send private message

Bug in Printf() function!!
PostPosted: Thu Feb 09, 2006 12:59 am     Reply with quote

Can you believe this, the following functions gives wierd results with printf() function
Code:
void ADC_RESULT(void){
     //static char cnt;
   static int32 avgsum;
   static int16 adcval;
   static int8 tim_12_hr;
   struct time local_clock;   
   memcpy(&local_clock,&GLOB_clock, sizeof(struct time));
   avgsum+=local_clock.ADC_Results;
   adcval=avgsum/8;                                       //Average value- using/8 since in binary, this is quicker
   avgsum-=adcval;
   
   //Displaying time here
   if((local_clock.hrs)>=13)  tim_12_hr=(local_clock.hrs)-12;
   else tim_12_hr=local_clock.hrs;
   lcd_gotoxy(4, 1);   //lcd_putc("LCD Ready...");
   printf(LCD_PUTC,"%02d:%02d:%02d\n",tim_12_hr,local_clock.mins,local_clock.secs);

   lcd_gotoxy(12, 1);
   if(local_clock.hrs>11) lcd_putc("PM");

   else   lcd_putc("AM");
   
    //local_clock. ADC_Results=(local_clock.val/=10);
     lcd_gotoxy(4,2);
    local_clock.Temp_deg = ((adcval - 559L)/2);   //Temp_Kelvin = (Temp_degrees + 273.15); Temp_Kelvin =((((float)val*5)/1024)-273.15);
    printf(LCD_PUTC," %2ld %2.1f\n\r",adcval,local_clock.Temp_deg);
    //printf(LCD_PUTC," %2u %2.1f\n\r",local_clock.ADC_Results,local_clock.Temp_deg);
}


this one gives two dotes i,.e.
Code:
 temperature =20.05.0
from:
Code:
printf(LCD_PUTC," %2ld %2.1f\n\r",adcval,local_clock.Temp_deg);
Code:
The results are :local_clock.Temp_deg=20.07.0
instead of
Code:
20.1

please help me debug printf()
cheers...
kel



Joined: 17 Oct 2005
Posts: 68
Location: Brisbane

View user's profile Send private message

Did anyone meets this problem before?
PostPosted: Thu Feb 09, 2006 1:52 am     Reply with quote

Shocked
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Feb 09, 2006 2:01 am     Reply with quote

You didn't post a test program. What you posted is really just a
code fragment. You're referencing a structure but you didn't
post the declaration. There's no way to drop this program into
MPLAB and compile it. You didn't post your compiler version,
so who knows what version or what PIC you're using. Most of
the code that you did post is irrelevent to the problem.

So in a nutshell, I took a look at it and bailed.


Just letting you know why you don't get a prompt answer sometimes.
Ttelmah
Guest







PostPosted: Thu Feb 09, 2006 5:21 am     Reply with quote

He has posted the same question into another thread. It is not a bug in printf. There is nothing to clear away old results, so he is getting the new single digit result overwriting another longer result that was already there...

Best Wishes
kel



Joined: 17 Oct 2005
Posts: 68
Location: Brisbane

View user's profile Send private message

printf printing leaving garbadge
PostPosted: Thu Feb 09, 2006 8:17 pm     Reply with quote

Thanks alot Ttelmah & PCM programmer.I'm sorry i did not include the code and my version.I'm using ccs vs:3.24.Here is the code.Ttelmah has help me sped it up a lil bit though it still count up.
Ttelmah & PCM Programmer could u please help me fixed the garbadge problem i.e. the printing decimal like
Code:
 2..04.0.
from the following code.

Code:
#include <16f877a.h>
#device *=16
#device adc=10
#fuse HS,NOWDT,NOPROTECT,NOLVP,NOPUT
#use dleay(clock=20000000)
#include <lcd_driver.c>

struct time {
               int8  hrs;
               int8  mins;
               int8  secs;
               int16 mSec;
               int16 adcvalz;
               float Temp_deg;
               }GLOB_clock={15,58,45,0,0,0,0};

void ADC_RESULT(void);
#int_TBE
TBE_isr()
{

}

#int_RDA
RDA_isr()
{

}

#int_TIMER0
TIMER0_isr()
{
    static int16 tick=0;
    static int1 toggle=0;
     //set_timer0(96);
     tick+=256;   //   set_timer0(206); 20 mhz clock, no prescaler, set timer 0 to overflow in 35us
                    // 256-(.001024/(4*256/20000000))
   if(toggle) {
         toggle=0;
         GLOB_clock.adcvalz=read_adc(ADC_READ_ONLY);
         }
         else {
         toggle=1;
         read_adc(ADC_START_ONLY);
       }
   if(tick>3125) {  //2500){
         tick-=3125;
         if(++GLOB_clock.mSec>=25)  {    //1000){
            GLOB_clock.mSec-=25;        //1000;
            if(++GLOB_clock.secs>=60) {
               GLOB_clock.secs=0;
               if(++GLOB_clock.mins>=60) {
                  GLOB_clock.mins=0;
                  if(++GLOB_clock.hrs>=24) {
                  GLOB_clock.hrs=0;
                  }
               }
            }
         }
   }
}



void main()
{

   //char cnt;
   setup_adc_ports(AN0);
   setup_adc(ADC_CLOCK_DIV_32);    //ADC_CLOCK_INTERNAL//SET adc conversion clock speed
                                   //TAD(per bit)=1/20Mhz X 32 = 0.16us ;Requires min. 12 TAD for 10 bit
                                   //Min. conversion time approx. 2us
   set_adc_channel(0);             //Set ADC channel to port0(pin 2,AN0).
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_64);
   // setup_psp(PSP_DISABLED);setup_spi(FALSE);setup_timer_1(T1_DISABLED);setup_timer_2(T2_DISABLED,0,1);
  // setup_comparator(NC_NC_NC_NC);setup_vref(FALSE);enable_interrupts(INT_AD);/ enable_interrupts(INT_TBE);enable_interrupts(INT_RDA);

   lcd_init();
   enable_interrupts(INT_TIMER0);
   enable_interrupts(GLOBAL);             //printf("Sampling adc"

   lcd_gotoxy(2,1);
   lcd_putc("\fSampling....");
   delay_ms(1000);
   lcd_putc("\f");

while(1)
   {
   ADC_RESULT();
   delay_ms(200);
   }

}

void ADC_RESULT(void){
    static int1 first=true;
   static int32 avgsum;
   static int16 adcval;
   static int8 tim_12_hr;
   struct time local_clock;   
   memcpy(&local_clock,&GLOB_clock, sizeof(struct time));
if(first)
{
firts=false;
avgsum=local_clock.adcvalz*8;
}
else
{
   avgsum+=local_clock.adcvalz;
   adcval=avgsum/8;                                       //Average value- using/8 since in binary, this is quicker
   avgsum-=adcval;
}
    local_clock.Temp_deg = ((adcval - 559L)/2);   //Temp_Kelvin = (Temp_degrees + 273.15); Temp_Kelvin =((((float)val*5)/1024)-273.15); 

   //Displaying time here
   if((local_clock.hrs)>=13)  tim_12_hr=(local_clock.hrs)-12;
   else tim_12_hr=local_clock.hrs;
   lcd_gotoxy(4, 1);   //lcd_putc("LCD Ready...");
   printf(LCD_PUTC,"%02d:%02d:%02d\n",tim_12_hr,local_clock.mins,local_clock.secs);

   lcd_gotoxy(12, 1);
   if(local_clock.hrs>11) lcd_putc("PM");

   else   lcd_putc("AM");
   
    //local_clock. ADC_Results=(local_clock.val/=10);
     lcd_gotoxy(4,2);
   
    printf(LCD_PUTC," %2ld %2.1f\n\r",adcval,local_clock.Temp_deg);
    //printf(LCD_PUTC," %2u %2.1f\n\r",local_clock.ADC_Results,local_clock.Temp_deg);
}


guys i will appreciate your help... Embarassed
Code:
lastly how do i put a degree symbol(oC) on the LCD?Any idea?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Feb 09, 2006 10:03 pm     Reply with quote

Quote:
could u please help me fixed the garbadge problem i.e. the printing decimal like


Ttelmah told you exactly what to do:
Quote:

You need to either clear the screen, use a fixed width numeric
output, or have the value written with a few trailing zeros,
to get rid of the remaining data on the display.

If you don't know how to clear the screen (the LCD), then read
the LCD.C file, which is in c:\Program Files\Picc\Drivers, and
notice the command that is used to clear the LCD screen.
(The command is listed right at the start of the file.)
Then put it into your own program.

The purpose of this forum is not to do your school work for you.
We'll help you, but you must do some of the work yourself.
kel



Joined: 17 Oct 2005
Posts: 68
Location: Brisbane

View user's profile Send private message

Display flickering!!
PostPosted: Thu Feb 09, 2006 10:41 pm     Reply with quote

Thanks for your advice...I appreciate..
It's not that i donnot know how to clear the screen but that it flickers the screen wshen it's include in the
Code:
while(true)
loop...
here is what i have done.
Code:
lcp_putc("\f");

What then can i do to stop the flickering of the Display?
newguy



Joined: 24 Jun 2004
Posts: 1907

View user's profile Send private message

Re: Display flickering!!
PostPosted: Thu Feb 09, 2006 10:50 pm     Reply with quote

kel wrote:
What then can i do to stop the flickering of the Display?


The obvious answer is to slow the whole thing down. Also add a check to your print routine. Only print a temperature if it is different from that already shown.
kel



Joined: 17 Oct 2005
Posts: 68
Location: Brisbane

View user's profile Send private message

Adding check does not print anything
PostPosted: Thu Feb 09, 2006 11:35 pm     Reply with quote

The following is code i added to check for any new values but for some rerasons does seem to print nothing.Slowing down work fine.What is the problem with the code below.
[code]void ADC_RESULT(void){
static int1 first=true;
static int32 avgsum;
static int16 adcval;
Quote:
static float prev_temp=0.0

static int8 tim_12_hr;
struct time local_clock;
memcpy(&local_clock,&GLOB_clock, sizeof(struct time));
if(first)
{
firts=false;
avgsum=local_clock.adcvalz*8;
}
else
{
avgsum+=local_clock.adcvalz;
adcval=avgsum/8; //Average value- using/8 since in binary, this is quicker
avgsum-=adcval;
}
local_clock.Temp_deg = ((adcval - 559L)/2); //Temp_Kelvin = (Temp_degrees + 273.15); Temp_Kelvin =((((float)val*5)/1024)-273.15);

//Displaying time here
if((local_clock.hrs)>=13) tim_12_hr=(local_clock.hrs)-12;
else tim_12_hr=local_clock.hrs;
lcd_gotoxy(4, 1); //lcd_putc("LCD Ready...");
printf(LCD_PUTC,"%02d:%02d:%02d\n",tim_12_hr,local_clock.mins,local_clock.secs);

lcd_gotoxy(12, 1);
if(local_clock.hrs>11) lcd_putc("PM");

else lcd_putc("AM");

//local_clock. ADC_Results=(local_clock.val/=10);
lcd_gotoxy(4,2);
Quote:
if(local_clock.Temp_deg>prev_temp)
{
prev_temp=local_clock.Temp_deg;
printf(LCD_PUTC," %2ld %2.1f\n\r",adcval,local_clock.Temp_deg);
//printf(LCD_PUTC," %2u %2.1f\n\r",local_clock.ADC_Results,local_clock.Temp_deg);
}
else {}
} Rolling Eyes
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