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.

Support Forum » Trying to modify the Real Time Clock project

December 31, 2010
by Ralphxyz
Ralphxyz's Avatar

I am trying to capture a 1 second block of time (count).

volatile int32_t the_time;
volatile int32_t count;
  // when Timer0 gets to its Output Compare value,
  // one one-hundredth of a second has elapsed (0.01 seconds).
  if (the_time = 100) {

int main() {
  lcd_init();               // init lcd
  FILE lcd_stream = FDEV_SETUP_STREAM(lcd_putchar, 0, _FDEV_SETUP_WRITE);
  uart_init();              // init serial port
  FILE uart_stream = FDEV_SETUP_STREAM(uart_putchar, uart_getchar, _FDEV_SETUP_RW);
  stdin = stdout = &uart_stream;
  sei();                    // turn on interrupt handler

  while(1) {
    fprintf_P(&lcd_stream, PSTR("%16.2f sec"), (double) the_time / 100.0);
    fprintf_P(&lcd_stream, PSTR("Count: %.0f"), count);   
    if (count = 10)         // 10 second block
        count=0;            // Start over
  return 0;

Time stands still.

I get 1.00 sec and Count: 0

frozen nothing more.

It seems logical (doesn't it) that the the_time counts up to 100 then count is incremented by 1. Then do it again.

Why does it freeze (or more concisely why doesn't it work)?


December 31, 2010
by Rick_S
Rick_S's Avatar

= is the assignment operator == is for checking a variable against another.

So when you said on line 7 if (the_time = 100) you assigned the_time the value of 100. To check against 100 it should read if (the_time == 100)

The same is true for the if statement on line 29.

Hope that helps out, I still catch myself doing this on occasion,


Post a Reply

Please log in to post a reply.

Did you know that negative numbers are represented in two's complement notation in binary? Learn more...