473,805 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C-AVR programming and saving to epprom

18 New Member
so i started learning avr-c programming a few weeks ago and i'm a little confused about using the eeprom so save values.
i've been working a snake game for my project, and i need to save everything at any point to the eeprom so that the user can load it from that spot again.
but first i've been receiving warnings in regard to the way i've been trying to save the the highscore
Expand|Select|Wrap|Line Numbers
  1. #include <avr/eeprom.h> 
  2. eeprom_write_word(1, hiscore);
  3. printf("Current High-Score: %d\n", eeprom_read_word(1));
  4.  
those are the only 2 instances where i've actually written to eeprom so far.
and it works so far, without any problems to the game, but the problem is i've been getting warnings saying.
Expand|Select|Wrap|Line Numbers
  1. warning: passing argument 1 of 'eeprom_read_word' makes pointer from integer without a cast
  2.  
  3. warning: passing argument 1 of 'eeprom_write_word' makes pointer from integer without a cast
  4.  
and i don't know how to fix the code.
any help would be appreciated
thanks,
phoenix1990
Oct 19 '09 #1
3 4084
newb16
687 Contributor
It wants cast? Ok, give it the cast -
eeprom_read_wor d((int*)1)
or something like, depending on declaration of eeprom_read_wor d.
Oct 19 '09 #2
Banfa
9,065 Recognized Expert Moderator Expert
@newb16
That is quite a bad mistake/assumption to make without further evidence that that is actually required. I know several people that had problems because they did that or something similar.

I think it is more likely that the function expected a pointer to a word(int) but you provided an int

Expand|Select|Wrap|Line Numbers
  1. const int *HIGHSCORE_ADDRESS = <someAddressInEEPROM>;
  2.  
  3. highscore = eeprom_read_word(HIGHSCORE_ADDRESS);
  4.  
The point is I suspect the function is expecting you to pass it a location in eeprom to save to, not a number cast to an address. Unless you were very very lucky (int *)1 is most unlikely to be an address in EEPROM.

OK I just Googled the AVR memory map and I take that back, it turns out that for AVR architecture (int *)1 is a valid EEPROM address. Which just goes to prove the point that you can't always generalise (particularly with micro-controllers) things that look dubious from a generalised Standard C point of view can be perfectly correct.

I would still recommend #defining (or using const ints) the locations of you stored parameters in EEPROM rather than hardcoding using magic numbers.
Oct 19 '09 #3
phoenix1990
18 New Member
thanks for the help guys, your comments saved me a lot of time.
Oct 20 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
958
by: Sam Fisher | last post by:
Hi @all I'm really new to programming, so please dont' lose patience. Now, I'm writing a VB .net application in which (as in most apps) the user shall setup a configuration (via checkboxes etc.). This whole configuration is stored in a structure. But of course, I need to save the configuration for next start: so, is there any simple way to do so I don't know if this is possible, but a solution would be exporting the structure to XML, saving...
7
5004
by: Philipp Lenssen | last post by:
How do I load and save a UTF-8 document in XML in ASP/VBS? Well, the loading* is not the problem actually -- the file is in UTF-8, and understood correctly -- but once saved, the UTF-8 is replaced by what seems to be iso-8859-1 (which Flash doesn't understand, but that's another problem). Any help greatly appreciated. * Something like this...
2
1613
by: Roy Gourgi | last post by:
Hi, Is it possible to save to a database as opposed to saving to a flat .txt file? It could be any database program, such as FoxPro (preferably), SQL Server, MySQL. Furthermore, I would also like to know if I would also be able to retrieve information from these databases? TIA Roy Gourgi
0
1432
by: soberhi | last post by:
I am new to Access (and Access programming) so kindly be gentle. I did try to search around before asking this question. I am simplifying my problem in the hopes that this scaled down version will mirror my current situation. Scenario: I have 5 clients in my customer table. My goal:
28
1952
by: marcpirat | last post by:
hi we create a real-time program on a embedded linux system. the program will run a few time by second i would like to know if it's better to create global variable or create the variable in the main and pass it to the function? thanks
1
6902
by: Dev | last post by:
Dear Friends, I am passing the image name, size (in bytes) and imgaeformat (like jpg or bmp or pdf) through the network. I want display the image into picturebox without saving image files into Hard disk. Just display the image into PictureBox.... Is it Possible? If so how do to this?
3
3628
by: cdj | last post by:
Hi all, I've got a picturebox on a form, and a save button. When I go to save, the app craps out with the following error: ================== An unhandled exception of type 'System.Runtime.InteropServices.ExternalException' occurred in system.drawing.dll
0
1037
by: Shiran | last post by:
hi, i'm programming in ASP.net and i'm having a problem saving the state of the session. all the parameters i save , primitive or not are not being save and get lost. does anybody have any idea? maybe something with the configuratio settings?
15
1523
by: Dan DeConinck | last post by:
Hello, I want to save the position of all the controls on my form. I would like to write them out to a preference file. I have done this in DOS BASIC like this: TO WRITE the preference open "c:\preferences.txt" for input as #1 input #1 ,a,b,c
0
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10363
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10109
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7649
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6876
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3847
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.