NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » counting

January 27, 2011
by Jalex
Jalex's Avatar

Hi I am having trouble displaying my variables. You can see where I moved the Rain++ out of the while but it still shows 000's.

    // Turn on PC4 
    PORTC |= (1<<PC4);
    //turn PC4 back off
    PORTC &= ~(1<<PC4);
    while (PINC &= (1<<PC3) && ((Rain < 60))) {

Here is a clip of the display code. It all inside the while(1) loop

    // Write Info to LCD

  fprintf_P(&lcd_stream, PSTR("Temperature: %.2f"), temp_avg);
  // lcd_write_data(0xdf);
  fprintf_P(&lcd_stream, PSTR("Degrees : %.3f"), Direct);
  fprintf_P(&lcd_stream, PSTR("Wind Speed : %.2f"), WindCnt);
  fprintf_P(&lcd_stream, PSTR("Rain Fall: %.3f"), Rain);
January 27, 2011
by Jalex
Jalex's Avatar

It has something to do with inisializing the variables. I chaneged them from uint16_t to double and I seems to work now. I guess I will have to study that some more.

January 27, 2011
by hevans
(NerdKits Staff)

hevans's Avatar

Hi Jalex,

I think I know what the problem was now. Since you are declaring an integer you need to use %d instead of %f in the format string. Take a look at our tutorial on printf and scanf for more on format strings.


January 28, 2011
by Jalex
Jalex's Avatar

Thanks Humberto That's cool. I guess I have been using Visual Basic too long. LOL Now that it counts there is another problem. Now it won't stop. LOL I have Rain = 0; just before the count code above and it just keeps adding 60 to the count. By the looks of the code it should keep reading 60 if PC3 is high. That Rain++; has been changed to Rain = 0; above the while.... I will studdy your tutorial. Jim

Post a Reply

Please log in to post a reply.

Did you know that the Timer/Counter modules on the microcontroller can be configured to output a PWM (Pulse Width Modulation) signal? Learn more...