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.

Project Help and Ideas » Arrays....

July 18, 2010
by Master_Programmer
Master_Programmer's Avatar

hey, i'm using this code to make an array

 uint8_t ENEMYST[6][4]={{10,3,0,4},
                        {16,5,3,7},
                        {22,7,4,13},
                        {29,12,1,19},
                        {29,12,1,19},
                        {29,12,1,19} };

and i use this code to return a value from it....

      lcd_write_string(PSTR(" O:"));
  lcd_write_int16(ENEMYST[r][1]);
  lcd_write_string(PSTR(" D:"));
  lcd_write_int16(ENEMYST[r][2]);
  lcd_write_string(PSTR(" E:"));
  lcd_write_int16(ENEMYST[r][3]);

But every time i even so much as put a STATEMENT in that modifies "r", the entire array screws up completely. i'm using AVRDUDE 5.6

July 18, 2010
by Master_Programmer
Master_Programmer's Avatar

by the way, by screws up, i mean if it's an 8-bit array, all the values read "255", and if it's a 16-bit array it reads "-1"

July 19, 2010
by bretm
bretm's Avatar

When you don't modify the array, the compiler is just optimizing it away completely and replacing array references with constant values.

When you do modify the array, the compiler can no longer make this optimization, and instead emits code for the array accesses.

But the default makefile that comes with the Nerdkit doesn't copy constant initializer values to the chip--it only copies program code. I think this is generally a good default position to take, but it does cause this problem to be a FAQ. See http://www.nerdkits.com/forum/thread/100/ for a discussion of the issue, and a couple of different choices for fixing it.

July 19, 2010
by Master_Programmer
Master_Programmer's Avatar

thank you a lot.

now i can make some games i couldn't due to bad arrays.......

thank you VERY much. :D

July 20, 2010
by Master_Programmer
Master_Programmer's Avatar

odd...i'm trying to make my array be put in the "PROGMEM" thing... and i get a "ROM.c:39: warning: 'progmem' attribute ignored"

July 21, 2010
by hevans
(NerdKits Staff)

hevans's Avatar

Hi Master_Programmer,

Are you by any chance trying to declare this string inside of a method. You will get this error if you have a static declaration inside a method. This is because strings defined inside methods by definition would be allocated at runtime when the function gets called, which doesn't really make sense on for static string that lives on the flash memory. Try declaring the string outside of any method, usually towards the top after all the include statements. Let us know if that was the problem.

Humberto

September 02, 2010
by Master_Programmer
Master_Programmer's Avatar

okay....i have a tiny question......

there is an atmega i'm looking at, and when i look in the data-sheet, it says:

– Byte-oriented Two-wire Serial Interface
– Two Programmable Serial USART
– Master/Slave SPI Serial Interface

does that mean it doesn't need a programmer??

September 02, 2010
by hevans
(NerdKits Staff)

hevans's Avatar

Hi Master_Programmer,

This chip would definitely still need a programmer to be able to talk to it (and program it) over the serial interface. In general, you will always need some type of special interface in order to program the chip, be it an ISP programmer, or some sort of bootloader to program the chip over a different interface.

The ATmega168 has a Two-wire serial interface, as well as the SPI Serial Interface. What this chip does have that the ATmega168 we use does not have is two separate UART modules, which means you could hook up say a bluetooth module, or a radio transmitter and still be able to have the chip hooked up to the serial port to communicate with the PC. The 168 has only one UART module.

Hope that clears things up.

Humberto

September 02, 2010
by Master_Programmer
Master_Programmer's Avatar

okay.... i'm looking at an atmega 128p and just wondered if the whole jtag or uart thing meant it didn't need a programmer..... DX

September 02, 2010
by Rick_S
Rick_S's Avatar

You would definately need a programmer. The features built into the chip you are mentioning are for the following.

The Two Wire Serial Interface is for connectingt the chip to TWI or I2C devices such as a DS1307 real time clock chip.

The "Two Programmable Serial UART" simply means the chip has two independant "Serial Ports" That would be like a windows PC Having a COM1 and COM2.

SPI is simply another type of serial communication channel used commonly on external memories or display driver ic's.

JTAG is an interface for connecting testing equipment to troubleshoot and debug the chip live.

Hope that helps some,

Rick

September 03, 2010
by Master_Programmer
Master_Programmer's Avatar

thanks!

i will order parts and make my own programmer soon.....then i can make 128kb games!!! >:D

Post a Reply

Please log in to post a reply.

Did you know that two resistors plus a transistor can be used to make a better voltage supply? Learn more...