Atmega32 internal EEPROM codevisionavr

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i'm trying to worke with eeprom  but i think anything i write to the eeprom keeps writing in the same addres 

 

 

i have read  a lot of tutorials but i cant understand how to use eeprom

please give me a link to a good tutorial 

thanks in advance

 

proteus 8 simulation log:

 

PROSPICE 8.04.00 (Build 21720) (C) Labcenter Electronics 1993-2017.
Loaded netlist 'C:\Users\***\AppData\Local\Temp\LISA8111.SDF' for design 'sym.pdsprj'
AVR Release 7.5SP0 build 6751 for ATMEGA32. [U1]
[AVR EEPROM] Loaded 1024 bytes of persistent data. [U1]
[AVR EEPROM] Interrupt Vector: Address=0x0022, EE_RDY. [U1]
Loading HEX file 'Debug\Exe\asdsa.hex'. [U1]
Read total of 1808 bytes from file 'Debug\Exe\asdsa.hex'. [U1]
PC=0x06E2. [AVR EEPROM] Read operation from address 00: data = 2D [U1]
PC=0x06EC. [AVR EEPROM] Master Program Enable is set and will be cleared at 0.028689125s. [U1]
PC=0x06EE. [AVR EEPROM] Erase and Write operation started. [U1]
PC=0x06F0. [AVR EEPROM] EEMPE is cleared by hardware. [U1]
PC=0x06D2. [AVR EEPROM] Erase and Write operation complete at address 00: data = 0A. [U1]
PC=0x06E2. [AVR EEPROM] Read operation from address 00: data = 0A [U1]
PC=0x06EC. [AVR EEPROM] Master Program Enable is set and will be cleared at 0.031891875s. [U1]
PC=0x06EE. [AVR EEPROM] Erase and Write operation started. [U1]
PC=0x06F0. [AVR EEPROM] EEMPE is cleared by hardware. [U1]
PC=0x06D2. [AVR EEPROM] Erase and Write operation complete at address 00: data = 14. [U1]
PC=0x06E2. [AVR EEPROM] Read operation from address 00: data = 14 [U1]
PC=0x06EC. [AVR EEPROM] Master Program Enable is set and will be cleared at 0.035094625s. [U1]
PC=0x06EE. [AVR EEPROM] Erase and Write operation started. [U1]
PC=0x06F0. [AVR EEPROM] EEMPE is cleared by hardware. [U1]
PC=0x06BA. [AVR EEPROM] Erase and Write operation complete at address 00: data = 1E. [U1]
PC=0x06C8. [AVR EEPROM] Read operation from address 00: data = 1E [U1]
PC=0x06C8. [AVR EEPROM] Read operation from address 00: data = 1E [U1]
PC=0x06C8. [AVR EEPROM] Read operation from address 00: data = 1E [U1]
PC=0x06C8. [AVR EEPROM] Read operation from address 00: data = 1E [U1]
PC=0x06C8. [AVR EEPROM] Read operation from address 00: data = 1E [U1]
PC=0x06C8. [AVR EEPROM] Read operation from address 00: data = 1E [U1]

>>>>

 

 "<

#include <mega32.h>
#include <alcd.h>
#include <stdio.h>
#include <string.h>
#include <delay.h>
#include <eeprom.h>

unsigned char EEPROM_read(unsigned int uiAddress);
void EEPROM_write(unsigned int uiAddress, unsigned char ucData);

char st[80];
int x,c,b;

void main(void)
{
lcd_init(16);

eeprom_write_byte(0x35,10);
eeprom_write_byte(0x55,20);
eeprom_write_byte(0x65,30);

while (1)
      {   
      
      x=eeprom_read_byte(0x35);
      c=eeprom_read_byte(0x55);
      b=eeprom_read_byte(0x65);
                     
      sprintf(st," %d \n%d \n%d",x,c,b);
      lcd_gotoxy(0,0);
      lcd_puts(st);

        
        }
      
}

>"

 

Last Edited: Sun. Aug 11, 2019 - 02:23 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, certainly we would need to see all the code for eeprom.h routines, as well as for your primitives that you prototyped:

unsigned char EEPROM_read(unsigned int uiAddress);
void EEPROM_write(unsigned int uiAddress, unsigned char ucData);

 

Did you ever think that it could be part of the simulation?  Did you ask Proteus?

 

But why are you trying to apply the contortions that were needed when using the infinite-value toolchain when CodeVision has always had transparent access?

 

If, for some reason, you really really need a particular address then CV has facilities for that.

 

Aaah, I see:

 

For compatibility with AVR GCC programs, the eeprom.h header file is supplied with CodeVisionAVR.

It contains the following macros and functions:

 

eeprom_read_byte(addr)

 

            Reads an unsigned char value from EEPROM address addr.

Are you really porting a program from GCC?

 

#include <mega32a.h>
#include <alcd.h>
#include <stdio.h>


char st[80];

int x,c,b;

__eeprom int x_in_eeprom @0x35;
__eeprom int c_in_eeprom @0x55;
__eeprom int b_in_eeprom @0x65;

void main(void)
{
// better put a 100ms delay here; character LCDs are slow to start...
lcd_init(16);

x_in_eeprom = 10;
c_in_eeprom = 20;
b_in_eeprom = 30;

while (1)
      {   
      
      x = x_in_eeprom;
      c = c_in_eeprom;
      b = b_in_eeprom;

// I don't remember whether (s)printf() %d will pull directly from EEPROM or not                     
      sprintf(st," %d \n%d \n%d",x,c,b);
      lcd_gotoxy(0,0);
      lcd_puts(st);

// do LCD operations really support \n? I don't think so; otherwise how do you display 0x10 from the character set?

        
        }
      
}

 

 

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i just need to store some variables in eeprom (keypad lock)

i read  CodeVision help so many times i just don't understand how to use eeprom (my English  is not so great)  and somehow missed this some how tank you

::

(CodeVision help: For compatibility with AVR GCC programs, the eeprom.h header file is supplied with CodeVisionAVR)

 

so if eeprom,h is for For AVR GCC compatibility what shuld i do

also if the problem is  proteus 8 , what other simulators can i use?

also what ascii code  is 0x10 

      sprintf(st,"xx\nxx  \nxx%dxx%cxx",0x10,0x10);
      lcd_gotoxy(0,0);
      lcd_puts(st);

simulation pic

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In Code vision you don't need functions like eeprom_read_byte() just define variables with the "eeprom" modifier then read/write them as if RAM.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hossein12DarthVader wrote:

 

also what ascii code  is 0x10 

 

 

So, you show a screen display with dummy data, and not with the real data from your posted program?

 

Asking what ASCII code is 0x10 is a trick question in this context.  [Can't you do a Google search for an ASCII chart?  You don't have one with your ready-reference materials?!?]

 

Anyway, it is line feed.  But that doesn't matter here -- what does it show up as in your LCD's character set?

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.