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);
    delay_ms(5);
    //turn PC4 back off
    PORTC &= ~(1<<PC4);
    Rain++;
    while (PINC &= (1<<PC3) && ((Rain < 60))) {
    delay_us(1); 
    Rain++;
       }

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

    // Write Info to LCD

    lcd_home();
  fprintf_P(&lcd_stream, PSTR("Temperature: %.2f"), temp_avg);
  // lcd_write_data(0xdf);
  lcd_write_string(PSTR("F"));
  lcd_line_two();
  fprintf_P(&lcd_stream, PSTR("Degrees : %.3f"), Direct);
  lcd_line_three();
  fprintf_P(&lcd_stream, PSTR("Wind Speed : %.2f"), WindCnt);
  lcd_line_four();
  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.

Humberto

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 NerdKits also has extra parts available for its customers? Learn more...