I sent the data to the Arduino Board by CSharp . But when i plug out the data i sent is reseted .Is there anyway to save the data to the file as library file ? Because i want to use this file to declare it in Arduino software.
if the data remain constant during runtime, you can store them in the flash memory together with your program. To do this, insert the line
#include "filename.h"
at the top of your program (probably there are already other #includes) replacing "filename" with the actual name, of course. Put the datafile in the project directory.
The catch is that you have to present the data in a way compatible with C. One way is to declare and initialize one or several arrays. If the amount of data is considerable, the most convenient way is to write a program which reads the raw data, and writes them into an ASCII file together with the necessary framework.
Hello Joerg Fricke , tkanks for your answer .It's very helpful but can you teach me how to save the data i input by C# into a file .h ? I tried many times but not success .
As an example, in AVR Studio, you have to insert the lines
#include
#include "filename.h"
into your program. The first include enables the allocation of your data to the program flash. Then your data in the file filename.h could be the elements of one or several arrays:
char somename[] PROGMEM =
{0x73, 0xF5, 0x01, ... };
PROGMEM tells the compiler/linker to merge the executable program and your data into one hex file which can be downloaded to the microcontroller. Instead of 8 bit integers you can use other data types as array elements as long as all elements of one array are of the same type. In your program, you can access the array elements using the function
pgm_read_byte_near(address), e.g.
value1 = pgm_read_byte_near(somename[17]);
Here you will find an overview of the functions provided by the library pgmspace:
So as you said, i code the Data Table in C# and then code in AVR Studio to save data to file .h ? Sorry if i reply late, i have to clean up my house because new year is coming.
If I understand correctly, the data are known beforehand and remain constant during run time. In your C# (plain C would suffice) program you write the data into an ASCII file named something.h ("something" being just a placeholder for any name you like) as described in my former answer. Then you copy this file into the project directory of AVR Studio where you develop the C program for the microcontroller, and include the *.h file in the *.c file.
If I misunderstood, and the data have to be generated during runtime then your program on the microcontroller had to write them into the EEPROM (restricted to 1 kByte, see chapter 8 of the datasheet of ATmega328P) or into the flash memory (32 kByte minus size of your program, see chapter 26 of the datasheet).