Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] how to save a variable's value permanently in memory of atmega16

Status
Not open for further replies.
It was already discussed many times here..

Search the board you will find it

is nobody interested to support me???????????
You already got replies..

Nobody here will give you code for your project..

We can guide you, you have to do your work..
 
is something wrong with me or my account?????????
if this then tell what should i do for removing that fault for that

- - - Updated - - -

ok thanks for reply
i was thinking that i have some problem with my account!!!!!

- - - Updated - - -

dear sir
i am confused in this.
ok please just tell me only that may i save any variable in eeprom from initialization or not
if yes then what should be the content of that statement. as for generally initialization of a simple variable can be done as
Code:
unsigned char i;
in same manner what should be written for storing it in eeprom, is it-
Code:
eeprom unsigned char i;
or anything else?

- - - Updated - - -

please tell me that am i right or not?
if not then how to define a variable in eeprom
 
Did you read the blog link I have posted?

Code:
//

#include <avr/eeprom.h>
// defines for eeprom access	
#define read_eeprom_byte(address) eeprom_read_byte ((const uint8_t*)address)
#define write_eeprom_byte(address,value) eeprom_write_byte ((uint8_t*)address,(uint8_t)value)
#define read_eeprom_word(address) eeprom_read_word ((const uint16_t*)address)
#define write_eeprom_word(address,value) eeprom_write_word ((uint16_t*)address,(uint16_t)value)
#define read_eeprom_dword(address) eeprom_read_dword ((const uint32_t*)address)
#define write_eeprom_dword(address,value) eeprom_write_dword ((uint32_t*)address,(uint32_t)value)
#define read_eeprom_array(address,value_p,length) eeprom_read_block ((void *)value_p, (const void *)address, length)
#define write_eeprom_array(address,value_p,length) eeprom_write_block ((const void *)value_p, (void *)address, length)

uint8_t EEMEM eeprombyte=0x10;		[COLOR="red"]//store initial byte to eeprom, eep file will include this[/COLOR]

uint16_t EEMEM eepromword=0x5555;	[COLOR="red"]//store initial word to eeprom, eep file will include this[/COLOR]

uint8_t EEMEM eepromstring[5]={"Test\0"}; 	[COLOR="red"]//store string to eeprom, eep file will include this[/COLOR]

int main(void)
{
 uint8_t RAMbyte;		//RAM byte variable
 uint16_t RAMword;		//RAM word variable
 uint8_t RAMstring[5];		//RAM array of bytes

 RAMbyte = read_eeprom_byte(&eeprombyte);	    //read byte from EEPROM and store to RAM 
 RAMword = read_eeprom_word(&eepromword);	    //read word from EEPROM and store to RAM
 read_eeprom_array(eepromstring,RAMstring,5);		//copy string from EEPROM to RAM
}
 
thanks a lot
i'll use it in my project & then inform you about the result
 

dear all
this is my code for controlling rgb led with the help of atmega16 using interrupt (INT0).

Code:
#define F_CPU 16000000UL
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include <avr/eeprom.h>



#define read_eeprom_byte(address) eeprom_read_byte ((const uint8_t*)address)
#define write_eeprom_byte(address,value) eeprom_write_byte ((uint8_t*)address,(uint8_t)value)
unsigned char l=0,m=1;
unsigned char i,j,k;
uint8_t EEMEM eeprombyte=1;
int main()

{
	
	
	DDRB = 0x08;
	DDRD = 0x30;
	
		OCR0 = 255;   //blue  pb3
 		OCR1AH = 00;
		OCR1AL = 255;  //red  pd5
		OCR1BH = 00;
		OCR1BL = 255;  //green  pd4
		TCCR0 = 0x63;
		TCCR1B = 0x03;
		TCCR1A = 0xA1;
	


	PORTD = 0x08;	//make the PD3 input pin
	GICR = (1<<INT0);
	sei();
	

	
	while(1);
	return 0;
}

ISR(INT0_vect)
{
	_delay_ms(100);
	if((PIND & (1<<3))==0)	//check that the intrupt is activated or not
	{
	l=read_eeprom_byte(eeprombyte);	//store the eeprom data into variable l
	l++;
	write_eeprom_byte(eeprombyte,l);
	if(l==4)	//as we have 4 cases so when we press key again then it will 
							//go to case 1 autometically 
			write_eeprom_byte(eeprombyte,1);    // save 1 to eeprom variable
	switch(l)
	{
		case 1:
		{			
			{
				blue();
				_delay_ms(200);				
			}
			break;
		}
		case 2:
		{		
			{				
				green();
				_delay_ms(200);
			}
			break;
		}
		case 3:
		{			
			{				
				red();
				_delay_ms(200);	
			}
			break;
		}
		case 4:
		{			
			{				
				white();
				_delay_ms(200);							
			}
			break;
		}
	}
								
	}
}

white(void)
{
	char i=0;
	OCR0 = i;
	OCR1AL = i;
	OCR1BL = i;
}

red(void)
{
	char i=0;
	OCR0 = 255;
	OCR1AL = i;
	OCR1BL = 255;	
}

blue(void)
{
	char i=20;
	OCR0 = i;
	OCR1AL = 255;
	OCR1BL = 255;
}

green(void)
{
	char i=20;
	OCR0 = 255;
	OCR1AL = 255;
	OCR1BL = i;
}
voilet(void)
{
	char i=0;
	OCR0 = i;
	OCR1AL = i;
	OCR1BL = 255;
}

here i made some functions for different colors.
i call them using switch-case.
i just want that let initially first time i press interrupt button the value of l will go to 1, blue will glow.
again press then l will go to 2 & also save this value to eeprom, green will glow. and so on...
i used eeprom here for saving the current value of variable "l", as if power has gone then it should again start from that location at which it gone to off condition.

but when i run this program,
it goes upto l=4 very well.
ialso made the power off for checking it & it was working ok.
but when it reach at l=4, i. e. at white color & then i press the intrupt button but it is not changing the state from l=4 to 1 i.e. white to blue color
please help me to investigate the actual error.
 
Your write/read eeprom call is not correct

Code:
l = read_eeprom_byte(eeprombyte);	//store the eeprom data into variable l
        l++;
        write_eeprom_byte(eeprombyte, l);

The read and write functions need the variable address so you need to add & in front of the variable

Code:
l = read_eeprom_byte([COLOR="#FF0000"]&[/COLOR]eeprombyte);	//store the eeprom data into variable l
        l++;
        write_eeprom_byte([COLOR="#FF0000"]&[/COLOR]eeprombyte, l);
 

ok thanks for suggestion
i'll implement it in my code & inform you soon.
but one thing which i didn't get is-
initially first time when i press the button then upto 4 press it works ok
as first press it glow in blue color then i switched off power & made it on again, then it shows the accurate sequence i.e. after next press it comes on next color which is green!!!!!!!!
 

Your code depends on
Code:
if(l == 4)	//as we have 4 cases so when we press key again then it will
            //go to case 1 autometically
        {
            write_eeprom_byte(eeprombyte, 1);    // save 1 to eeprom variable
        }

to rollover l and this part doesn't write the value correctly unless you use & as shown in the previous post
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top