Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

problem in countdown timer coding in mikroC PRO

Status
Not open for further replies.

lazyhut

Member level 1
Joined
Feb 14, 2011
Messages
33
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,467
ic:pIC16F877A
compiler: mikroC PRO
problem: Countdown timer showing unknown word in LCD display..3rd digit showing unknown word..

i just show declaration and function

Code:
char txt[6]; //declaration
char sec;//declaration

  while(sec<=30)                          //wait 30sec
   {
    timer=30-sec;
    countdown();                           //display timer
    delay_ms(1000);
    sec++;                                 //sec+1
    if(reset_1)                          //if reset press
    {                                      //then stop
     reset();
     break;
    }
   }

void countdown()
{
 floattostr(timer,txt);       
 lcd_chr(1,14,txt[0]);       //display lcd
 lcd_chr_cp(txt[1]);
 lcd_chr_cp(txt[2]);
}

**broken link removed**
3rd digit shown unknow word
 
Last edited:

Please upload your whole project, instead of just posting small snippets. Sometimes the errors in the least likely places can cause problems elsewhere in the program.

Is "timer" declared as a float? Is it a integer? Is it a short? Is it a char?

If it is declared as a float, try this code snippet:

Code:
void countdown()
{
  LCD_Out(1,14, FloatToStr(timer));  //display lcd
}

Instead of your original code snippet:

Code:
void countdown()
{
 floattostr(timer,txt);       
 lcd_chr(1,14,txt[0]);       //display lcd
 lcd_chr_cp(txt[1]);
 lcd_chr_cp(txt[2]);
}

If "timer" is not declared as a float then use the IntToStr() instead.

Actually here's a much more efficient code snippet:

Code:
int timer = 30;

 while(timer)                          //wait 30sec
 {
    countdown();                           //display timer
    delay_ms(1000);
    timer--;                                  // decrement timer 
                               
    if(reset_1)                          //if reset press
    {                                      //then stop
      reset();
     break;
    }
 }

void countdown()
{
   LCD_Out(1,14, IntToStr(timer));  //display lcd
}


---------- Post added at 12:02 ---------- Previous post was at 11:17 ----------

Your problem with displaying character on the LCD stems from the fact you are passing a "char" to a function which expects a "float".

You should always pass the correct "type" to a function call.

There are numerous reports of strange output caused by passing the incorrect "type" to either FloatToStr() or IntToStr(). To keep things simple I would just declare timer an Integer type and use IntToStr(). If you want that decimal point in your display, then cast the timer variable into a "float", FloatToStr((float)timer).
 
Last edited:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top