Code Vision Structure Problem

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

I made a structure in EEPROM using CodeVision :

eeprom unsigned int last_known_address; 
eeprom struct alarma{ 
unsigned char activ;// bit0 set hours; bit 1 set data; bit 2 set temp; bit 3 activate 
unsigned char h,m,s,zz,ll,aa;
float T1,T2,T3;
}alarm[10];

and access this structure from a pointer crated to structure alarma so i can work with alarm[1] the first block of structure array. and accessing elements like hours, minutes, seconds, etc , and activ byte.

struct alarma eeprom *ep;
ep=&alarm;
ep->h=10; 
ep->m=11;
ep->activ=0x07;

debuging in proteus simulator the entire code it's show me it was written in eeprom the values from above, and every thing works fine until i want to access the next block from structure.
so if i increment the pointer to get access to the next structure block alarm[2] the next element from the array structure;

++ep;

and nothing happens the pointer remains to the same block address like first one. it's not advancing !!

and i need to store this data in eeprom in case of power failure. so if the program starts back again get access to the last pointer;

So after finishing writing the structure i want to store the last pointer address so i can come back to structure if power get's down, after chip reset.

last_known_address=&ep;

last address of pointer to a block of memory;

So any body worked with this type of data !! any help is welcome !!

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

Quote:

and nothing happens the pointer remains to the same block address like first one. it's not advancing !!


Didja ever think it might be a Proteus situation?

Show some fragments of the .LST file corresponding with the posted code.

What version of CV are you using?

Is ep a global or local variable?

Lee

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'm using CV 1.24.6 Profesional so no code limitation.
And proteus 7.5 SP3 for simulation.

Yes ep it's a global variable, and i use'it in all functions.

I poste the entire code for accessing the ep pointer in the meniu "set alarm".

Attachment(s): 

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

eeprom struct alarma{ 
    unsigned char activ;
    unsigned char h,m,s,zz,ll,aa; 
    float T1,T2,T3; 
}alarm[10];

struct alarma eeprom *ep; 

void main(void)
{
    ep=&alarm; 
    ep->h=10; 
    ep->m=11; 
    ep->activ=0x07;
    ++ep;
    ep->h=12; 
    ep->m=13; 
    ep->activ=0x07;

    while (1);
}

...doesn't compile for me (CV 2.05.0).

Error: ...\foo\foo.c(13): a value of type 'eeprom struct alarma [10] *' can't be assigned to an entity of type 'eeprom struct alarma *'

Change to

    ep=&alarm[1];

...and it compiles and all seems good in the .LST around the ++ep; line

                 ; 0000 000D     ep=&alarm[1];
                +
00005a e1e3     +LDI R30 , LOW ( _alarm + ( 19 ) )
00005b e0f0     +LDI R31 , HIGH ( _alarm + ( 19 ) )
                 	__POINTW1MN _alarm,19
00005c 012f      	MOVW R4,R30
                 ; 0000 000E     ep->h=10;
00005d 01d2      	MOVW R26,R4
00005e 9611      	ADIW R26,1
00005f e0ea      	LDI  R30,LOW(10)
000060 940e 007e 	CALL __EEPROMWRB
                 ; 0000 000F     ep->m=11;
000062 01d2      	MOVW R26,R4
000063 9612      	ADIW R26,2
000064 e0eb      	LDI  R30,LOW(11)
000065 940e 007e 	CALL __EEPROMWRB
                 ; 0000 0010     ep->activ=0x07;
000067 01d2      	MOVW R26,R4
000068 e0e7      	LDI  R30,LOW(7)
000069 940e 007e 	CALL __EEPROMWRB
                 ; 0000 0011     ++ep;
00006b 01f2      	MOVW R30,R4
00006c 9673      	ADIW R30,19
00006d 012f      	MOVW R4,R30
                 ; 0000 0012     ep->h=12;
00006e 01d2      	MOVW R26,R4
00006f 9611      	ADIW R26,1
000070 e0ec      	LDI  R30,LOW(12)
000071 940e 007e 	CALL __EEPROMWRB
                 ; 0000 0013     ep->m=13;
000073 01d2      	MOVW R26,R4
000074 9612      	ADIW R26,2
000075 e0ed      	LDI  R30,LOW(13)
000076 940e 007e 	CALL __EEPROMWRB
                 ; 0000 0014     ep->activ=0x07;
000078 01d2      	MOVW R26,R4
000079 e0e7      	LDI  R30,LOW(7)
00007a 940e 007e 	CALL __EEPROMWRB
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i used atmega32 chip not 168. And second I modified ep=&alarm[1]; end nothing change in the program is working like old one.

I need when increment the pointer ++ep go to the next structure like ep=&alarm[2]; so it remains to same alarm[1] structure.

Last Edited: Wed. Mar 9, 2011 - 09:54 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Makes no difference. Have you tried

ep=&alarm[1];
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

MartinM57 wrote:
Makes no difference. Have you tried

ep=&alarm[1];

Yes, i tried. And now have bigger problems discovered to my code, i add ADC function to measure a temperature from a LM35, if i want to read first channel is ok, if i try to read second adc channel from a second sensor is working adc and display but is not working external interrupt anymore. :shock:

Attachment(s): 

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

Well

#include 

eeprom struct alarma{ 
    unsigned char activ;
    unsigned char h,m,s,zz,ll,aa; 
    float T1,T2,T3; 
}alarm[10];

struct alarma eeprom *ep; 

void main(void)
{
    ep=&alarm[1]; 
    ep->h=10; 
    ep->m=11; 
    ep->activ=0x07;
    ++ep;
    ep->h=12; 
    ep->m=13; 
    ep->activ=0x07;

    while (1);
}

compiles in CV 2.05.0 and runs perfectly using AVR simulator inside AVR Studio 4.18.

Suggest you try this rather than using the Proteus simulator.

Maybe you should call the Labcenter support desk - you've paid a lot of money for Proteus after all...

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

MartinM57 wrote:
Well

#include 

eeprom struct alarma{ 
    unsigned char activ;
    unsigned char h,m,s,zz,ll,aa; 
    float T1,T2,T3; 
}alarm[10];

struct alarma eeprom *ep; 

void main(void)
{
    ep=&alarm[1]; 
    ep->h=10; 
    ep->m=11; 
    ep->activ=0x07;
    ++ep;
    ep->h=12; 
    ep->m=13; 
    ep->activ=0x07;

    while (1);
}

compiles in CV 2.05.0 and runs perfectly using AVR simulator inside AVR Studio 4.18.

Suggest you try this rather than using the Proteus simulator.

Maybe you should call the Labcenter support desk - you've paid a lot of money for Proteus after all...

i test your code it's working just fine in proteus too. I believe i found the bug in my code. I reinitialize pointer to ep=&alarm[1] in every function when i call the function in main program. Hope this work, and fix the problem with the adc. Thx for help MartinM57 !!

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

Quote:
you've paid a lot of money for Proteus after all...
Labcenter must be making a load of money, judging by how many people on this forum have purchased a copy :) After all, it is quite expensive!

--greg
Still learning, don't shout at me, educate me.
Starting the fire is easy; the hardest part is learning how to keep the flame!

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

Good news.

So how often does ep and the alarm structures get updated (100 times a second, ..., 1 time a year?)

Remember EEPROM ony has a limited number of writes before it fails...

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

MartinM57 wrote:
Good news.

So how often does ep and the alarm structures get updated (100 times a second, ..., 1 time a year?)

Remember EEPROM ony has a limited number of writes before it fails...

I know, EEPROM is written only when user set one alarm, So i believe this happen maybe 1-2 times a day.

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

Excellent :)

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

Quote:
I'm using CV 1.24.6 Profesional so no code limitation.

Yes, of course there's no code limitation because it's PIRATED software, like the Proteus "license" that you are also using. You have stolen other people's work.
There is no such "Profesional" version for CVAVR.

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

Oops - bye bye enter666...

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

Quote:

Oops - bye bye enter666...

Martin--notice that I had no further responses after getting the "version" information? :twisted:

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 only joined in as I'm a C newbie still, and a CV (registered :)) user and was interested in the technique being used. I might find a use for it some day...

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

Quote:

I only joined in as I'm a C newbie still, ...

As you found out, the syntax for EEPROM (and flash) structures and pointers changed a bit between CV 1.x and 2.x. Hence my original question, but the answer gave me pause as there are "favourite" cracked versions out there.

Lee

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

The 666 in his handle was Prophetic wasn't it? Computer programming cleverness seems to be a wide spectrum from clueless to Godlike. Somewhere on the Subcontinent is a guy that can read pentium assembler like a book and can unprotect Pavel's compiler, but within 100 miles of him are millions of untouchables yearning to learn how to simulate lcd initialization on yet another cracked version of proteus. If the cracker dude would set up a mail order microcontroller programming online school, he could probably make an honest living, AND elevate the microcontroller skills of all the graduates of the Indian Institute of Technology, and further the entrepreneurial juggernaut of the Indian Democracy.

Imagecraft compiler user

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

now i'm heaving a new problem
I'm trying to make a function to work whith the structure like "test()" and this function must return me the pointer to the next structure block;

eeprom  struct alarma{
    unsigned char activ;
    unsigned char h,m,s,zz,ll,aa;
    float T1,T2,T3;
}alarm;
 unsigned char i;
void test(struct alarma eeprom *app)
{   app->h=i;
    app->m=i+1;
    app->activ=0x07;
    i++; 
    ++app;
    }
struct alarma eeprom *ep;

void main(void)
{  
    ep=&alarm;
    
    ep->h=12;
    ep->m=13;
    ep->activ=0x07;
    i=0;

    while (i<10)
    {
    test(&ep); <- this is not working to return the next pointer structure address
    }
}

the function works if i called test(ep); but i can't make it to advance to next structure in function test.

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

It seems that you don't understand that we do not support pirated software. You must go and ask questions to the pirates from whom you have obtained the crack.