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 » Clock time / keyboard / LED Marquee combined

December 10, 2009
by Guss
Guss's Avatar

Hi folks, I am trying to make a new twist on the LED Marquee.

Using two MCUs I want to use one to accept input from the keyboard, and send it to the second for output on the marquee. (marquee build to come later)

I have the first MCU running the time and the temperature. I use the LCD as the screen for the keyboard/clock. When I introduce the modules for the keyboard input, the clock no longer functions.

Before: clock and temperature display properly After: clock counts to one or two seconds, LCD goes blank, count starts over at 1 second.

The question (finally): Are the various interrupts doing too much?

I disabled the clock calculations, and now I can use the keyboard for input, and the temp stays displayed without flashing.

This is the modified interrupt code to calculate the time and read the temp:


 uint16_t last_sample = 0;

 // when Timer0 gets to its Output Compare value,
 // one one-hundredth of a second has elapsed (0.01 seconds).
 last_sample = adc_read();

  if (the_time > 99) {
   if (seconds == 59) {
  seconds = 0;
     if (minutes == 60) {
    minutes = 0;
       if (hours == 24) {
      hours = 0;
else {

   the_time = 0;
time_change = 1;

 this_temp = sampleToFahrenheit(last_sample);

This the while loop from main() which outputs to the lcd:

 while(1) {
   temp_avg = 0.0;
float cel;

if (time_change){
     temp_avg =  this_temp;
cel=(5.0/9.0)*(temp_avg-32.0);  // convert temp to celcius

     // write message to LCD
     lcd_write_string(PSTR(" "));
 //      lcd_write_int16(hours);
     fprintf_P(&lcd_stream, PSTR(" %2d"), hours);
 //      lcd_write_int16(minutes);
     fprintf_P(&lcd_stream, PSTR("%02d"), minutes);
 //      lcd_write_int16(seconds);
     fprintf_P(&lcd_stream, PSTR("%02d"), seconds);
     lcd_write_string(PSTR("   "));
     fprintf_P(&lcd_stream, PSTR(" %.2f"), cel);
     lcd_write_string(PSTR("C  "));

  time_change = 0;

   key_code = read_char();
   if(key_code == 0x5A){ // enter key, clear the line
     buf_pos = 0;   
   str_buf[0] = str_buf[1] = 0x00;
   } else if (key_code == 0x66){ //backspace
     str_buf[buf_pos] = 0x00;
   } else {
     str_buf[buf_pos] = render_scan_code(key_code);
     str_buf[buf_pos] = 0x00;


I have not modified the keyboard input module yet, and I disabled all output to the UART. (this will be enabled to pass data to the 2nd MCU for the marquee.)

Any help appreciated.


December 14, 2009
by hevans
(NerdKits Staff)

hevans's Avatar

Hi Gus,

It's hard for me to see what the flow of your program is without the full source code. The behaviour you are describing where LCD goes blank and time starts from 0 again, suggests that the chip is resetting due to a low battery. Perhaps your battery has enough juice to run the LCD/chip, but when it tried to run the keyboard too it just reset. Also make sure your keyboard is wired up correctly, and not causing a short.

If you put up some pictures of your setup, as well as possibly linking to the full source, I'm sure we can help your project move along.


Post a Reply

Please log in to post a reply.

Did you know that you can build a giant scrolling LED array with our microcontroller kit? Learn more...