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 » Random Questions

November 15, 2009
by n3ueaEMTP
n3ueaEMTP's Avatar

I have 2 questions for anybody willing to answer.

Q1. His or her way to get the program from the MCU back on your computer? Consider this scenario: you're sitting at your workbench, admiring all of the 10 projects you just completed when all of a sudden all 10 MCUs jump out of the breadboards and land in a pile. is there a way to determine which MCU goes on, which breadboard without using a trial and error method?

Q2. I was looking through the forums and I found in this thread: Chaser Thread. I wanted to increase the number of LEDs and configure them into a circle. So it appears that the LED never stops. That didn't seem to be a problem until I decided to add the LCD so to count the number of loops. I used the code below. After counting to approximately 32,000, the counter (at least on the LCD) started to count backwards and was a negative integer. I believe I define the variable correctly (uint64_t counter=0;). so my question is: did I code my variable wrong or is there a limitation of the LCD?

main() { uint8_t i; uint16_t speed=50; uint64_t counter=0; uint64_t tenK=0; DDRC = 0x3F; DDRB = 0x3F; PORTD |= (1<<PD7) | (1<<PD6); // start up the LCD lcd_init(); lcd_home();

while(1)
{
  lcd_home();
  lcd_write_string(PSTR("# of loops:"));
  lcd_write_int16(counter);

//clears the rest of the line lcd_write_string(PSTR(" ")); counter++;

     for (i=0; i <= 5; i++)
            {
               PORTC = (1 << i); // so PORTC = 0,1,2,4
               delay_ms(speed);
               PORTC &= ~(1 << i); // LED off
            }
     for (i=0; i <= 5; i++)
            {
               PORTB = (1 << i); // so PORTB = 0,1,2,4
               delay_ms(speed);
               PORTB &= ~(1 << i); // LED off
            }
}

}

Thanks for any answers you can provide.

Chris B. n3ueaEMTP

November 15, 2009
by pbfy0
pbfy0's Avatar

I think, to get the code off the chip, you'd do something like this:

cp main.hex code_from_mcu.hex
avrdude -c avr109 -p m168 -b 115200 -P /dev/cu.PL2303-0000201A -U flash:r:code_from_mcu.hex:a

you need to copy another hex so avrdude can autodetect it as an intel hex

November 15, 2009
by pbfy0
pbfy0's Avatar

I also wrote a circular light chaser, it uses ALL the pins(even the LED ones), here

November 15, 2009
by pbfy0
pbfy0's Avatar

make that LCD

November 15, 2009
by pbfy0
pbfy0's Avatar

you can use vavrdisasm for turning hex to asm.

November 15, 2009
by hevans
(NerdKits Staff)

hevans's Avatar

Hi,

I think your counting backwards problem is caused by your call to lcd_write_int16(); This expects a 16 bit int and even though you are passing it a 32 bit int it is demoting back to a 16 bit signed int. You can use an fprintf statement like

fprintf_P(&lcd_stream,PSTR("Count: %ld"),counter);

As for your other question. I think pbfy0 has it right. That command will dump the hex file back from the chip. You can use :i instead of :a at the end to tell avrdude to expect an intel hex file so you don't have to start from another hex file.

avrdude -c avr109 -p m168 -b 115200 -P /dev/cu.PL2303-0000201A -U flash:r:code_from_mcu.hex:i

will do what you are looking for.

Humberto

November 15, 2009
by mikedoug
mikedoug's Avatar

You may want to try %lu -- %u indicates UNSIGNED and the L indicates that it's a LONG.

MikeDoug

November 17, 2009
by mcai8sh4
mcai8sh4's Avatar

Isn't this counting problem similar to the problem with the Ariane 5 initial rocket launch, that was an expensive 'Oops!'

November 23, 2009
by BobaMosfet
BobaMosfet's Avatar

hevans is correct. INT values are 16-bit. This means they are from -32768 to +32768 (65,535 values). ALWAYS be mindful of values like 8, 16, 32, 64, 128, 512, 1024, and any larger scale values (eg. 4096, 8192, 16384, etc) because whenever you see things like sign rolls (+ to - or = to +), likely it's because your chosen word isn't long enough to hold the value in it.

November 24, 2009
by n3ueaEMTP
n3ueaEMTP's Avatar

Thanks for all the help gang!!!

Chris B, n3ueaEMTP

Post a Reply

Please log in to post a reply.

Did you know that you can make a huge, multi-panel LED display? Learn more...