Discussion in "Software" started by    bhagirath    Jul 5, 2011.
Tue Jul 05 2011, 04:19 AM
#1
Hi all,

I am a newbie to Keil. I was just working in one demo project and stuck in between due to some access violation error. I tried googleing to various forums but didn't work, also tried applying map command but no success may be anyone could provide proper steps to do so. So could can one please help me in this regards? My code is as follows

//start
#include<reg51.h>

#include<string.h>


char var1[1];
char var2[1];
char var3[1];
char var4[5];
char var5[5];
char var6[1];
char var7[1];

void main()
{
    while(1)
    {
        char str[]= "123456789123456";
        int idx1 = 0;
        int index2 = 1;
        strncpy (var1,str+idx1,index2);
        idx1+=1;
        index2+=1;
        strncpy (var2,str+idx1,index2);
        idx1+=1;
        index2+=1;
        strncpy (var3,str+idx1,index2);
        idx1+=5;
        index2+=5;
        strncpy (var4,str+idx1,index2);
        idx1+=1;
        index2+=5;
        strncpy (var5,str+idx1,index2);
        idx1+=5;
        index2+=1;
        strncpy (var6,str+idx1,index2);
        idx1+=1;
        index2+=1;
        strncpy (var7,str+idx1,index2);
    }
}
//end


The error comes while debugging the code, here any where in between it stops debugging and throws error 65 access violation error.
If possible please reply me with steps to resolve this. Let me know if you want further information.

Thanks in advance

Info: Keil version 3.0 eval, hardware : AT89S52
Tue Jul 05 2011, 06:22 PM
#2
For a start,to find an error remove all the code you can until the error disappears.
In this case everything in your while loop.
Then put back a bit at a time until the error comes back .
This tells you where to look.

Your error(s) come from the use of strncpy.
Most of your target buffers are only one byte long and yet you are often trying to copy
more than one byte into them.
This means you are "violating" memory space you "don't own"



[ Edited Wed Jul 06 2011, 03:28 PM ]
Wed Jul 06 2011, 07:52 AM
#3
Hi ExperimenterUK,

Thank you very much for reply,

As per your advice I have removed all the multiple characters trimming, now I am doing only on single character, but then also I am getting the same error. I had googled on this error and some where it was mentioned to keep the code in single loop thats why i have kept it under while(1).

#include<reg51.h>

#include<string.h>


char var1[1];
char var2[1];
char var3[1];
char var4[1];
char var5[1];
char var6[1];
char var7[1];

void main()
{
    while(1)
    {
        char str[]= "123456789123456";
        unsigned char idx1 = 0;
        unsigned char index2 = 1;
        strncpy (var1,str+idx1,index2);
        idx1+=1;
        index2+=1;
        strncpy (var2,str+idx1,index2);
        idx1+=1;
        index2+=1;
        strncpy (var3,str+idx1,index2);
		idx1+=1;
        index2+=1;
        strncpy (var4,str+idx1,index2);
        idx1+=1;
        index2+=1;
        strncpy (var5,str+idx1,index2);// here the location of error..
        idx1+=1;
        index2+=1;
        strncpy (var6,str+idx1,index2);
        idx1+=1;
        index2+=1;
       	strncpy (var7,str+idx1,index2);
		break;
    }
}


I will be really grateful to you if you could try this in your environment.

According to my requirement I need to perform substring function on one string, thats why i have kept strncpy().

Thanks once again.
Wed Jul 06 2011, 08:31 AM
#4
I tried your code on My keil, it didnt showed any error,
Check your keil with other programs(simple one)
Wed Jul 06 2011, 09:16 AM
#5
Hi kirangowle,

I am getting error on debugging the code line by line. The code compiles fine with keil. the only issue
is while debugging it throws error for access violation.

Could you please try debugging the code?

Thanks
Bhagirath
Wed Jul 06 2011, 10:22 AM
#6
Hi,
I debugged your code, it was getting halt at strncpy(var3,)

In array declaration i increased the array length to 5(var[5]) and keep the local variable declaration outside of the while(1).
Wed Jul 06 2011, 11:31 AM
#7
Hi Kirangowle,

Thanks for reply,

I have changed the code as you have suggested, for performance and testing issue i have changed the capacity for each var to 1 byte. But no success, in debugging it stops at var5, after which i have noticed that all variables are cleared which were holding their values before error. here is my changed code

char var1[1];
char var2[1];
///...
char var7[1];
char str[]= "123456789123456";
char idx1 = 0;
char index2 = 1;

void main()
{

    while(1)
    {
        strncpy (var1,str+idx1,index2);
        idx1+=1;
        index2+=1;
        strncpy (var2,str+idx1,index2);
        idx1+=1;
        index2+=1;
        strncpy (var3,str+idx1,index2);
		idx1+=1;
        index2+=1;
        strncpy (var4,str+idx1,index2);
        idx1+=1;
        index2+=1;
        strncpy (var5,str+idx1,index2);
        idx1+=1;
        index2+=1;
        strncpy (var6,str+idx1,index2);
        idx1+=1;
        index2+=1;
       	strncpy (var7,str+idx1,index2);
		
    }
}


Wed Jul 06 2011, 12:26 PM
#8
You didnt change the array length from var[1] to var[5].
i am not understanding what basically u are try to achieve .
Wed Jul 06 2011, 01:34 PM
#9
Hi,

Let me describe my workflow here, I want to substring the "str" in different segments. Let say that segments would be like
var1 = first character
var2 = 2nd - 4th
var3 = 5th - 8th
like wise, it is my custom requirement.

In given example i have created var1[1] - var7[1] just to check, because it was some times showing error in array with bigger ranges. Actually it will be as describe above.e.g.
var1[1], var2[3], var2[4], var4[1]....

Hope this clears it..

And in doing so keil is throwing the error of either access violation or it stops debugging.
Wed Jul 06 2011, 03:51 PM
#10


Hi ExperimenterUK,
As per your advice I have removed all the multiple characters trimming, now I am doing only on single character,

bhagirath


Actually I meant remove all the statements,then put back one statement at a time.


I had googled on this error and some where it was mentioned to keep the code in single
loop thats why i have kept it under while(1).

bhagirath


Whatever you Googled is not relevent here,remove the while() loop, or at least move it to the end

Remove this line for now " index2+=1; " it makes you copy more bytes each time


Try this
#include<reg51.h>
#include<string.h>
char var1[1];
char var2[1];
char var3[1];

void main()
{

    
        char str[]= "123456789123456";
        unsigned char idx1 = 0;
        unsigned char index2 = 1;
        strncpy (var1,str+idx1,index2);  //this should work
        idx1+=1;
 //;  index2+=1; don't do this as it copies 2 bytes next time

        strncpy (var2,str+idx1,index2);   //this should work
        idx1+=1;
        index2+=1;
        strncpy (var3,str+idx1,index2);   //this should not  work
//;		break;  // ??? not needed
    while(1);

}


Get Social

Information

Powered by e107 Forum System

Conversation

ExperimenterUK
Thu Oct 30 2014, 06:02 PM
This is a chat box..create a thread if you need help...but we don't do homework
Tue Oct 28 2014, 07:33 PM
vinni
hi rickey...anyone got the pgm...pls gimme now
Tue Oct 28 2014, 06:35 PM
potla
hi vinni even i need that program. help me if you get it
Tue Oct 28 2014, 03:22 PM
vinni
1. Using a look-up table in Flash ROM and accumulator offset indexed addressing mode, write a program that acts as a timer. The timer should count from 0 to 59 seconds. After reaching 59, it should go back to 0 on the next second and continue to count up. The timer should use the seven-segment display. The look-up table should contain information on how to display the digits 0 – 9 on the seven-segment display
Tue Oct 28 2014, 03:22 PM
vinni
hello Rickey..i need this pgm very urgently
Tue Oct 28 2014, 01:42 AM
Boy Donald
Dear sir, thanks before. i have some project urgent for my school and my project need this digital countdown timer using 7 segmen display. but your project only show ten minutes countdown, i need your help, can you show me more to change the minute or set the time manually. thank you, sorry for disturbing you.
Tue Oct 28 2014, 01:32 AM
Boy Donald
dear sir
Tue Oct 28 2014, 01:19 AM
Boy Donald
Rickey you inspired me a lot but why i can not change the time ( minute
Sun Oct 26 2014, 02:51 AM
sandeep bankar
dear sir I m facing problem about..how to read number of incoming call in gsm 900 a. pls help how to read it in atmel avr microcontroller.
ajay_bhargav
Mon Oct 20 2014, 11:22 AM
@skrishna, please post in forum so we can help you better.

Downloads

Comments

prash5054
Thu Oct 30 2014, 06:34 AM
Max.otto
Mon Oct 27 2014, 01:23 PM
toypoy
Sun Oct 26 2014, 01:06 AM
hiswe
Thu Oct 23 2014, 04:18 PM
pddung93
Sun Oct 19 2014, 01:56 PM
msideal
Thu Oct 16 2014, 08:48 AM
robotgirl
Tue Oct 14 2014, 06:23 PM
BRV64
Mon Oct 13 2014, 05:48 AM

Online

Guests: 65, Members: 0 ...

most ever online: 182184
(Members: , Guests: 182184) on 06 Aug 2010: 05:37 AM

Members: 37535
Newest member: prash5054
Forum Activity
rkodaganur Avatar
Posted By rkodaganur
Fri Oct 31 2014, 01:44 AM
Hi Ajay, I wanted to know can we use transformer ...
Max.otto Avatar
Posted By Max.otto
Thu Oct 30 2014, 11:09 AM
Hello all, before generating i have to give PWM p...
prash5054 Avatar
Posted By prash5054
Thu Oct 30 2014, 06:40 AM
can u post the updated code for the above problem ...
ExperimenterUK Avatar
Posted By ExperimenterUK
Wed Oct 29 2014, 05:36 PM
Thank you for the feedback.It's good to hear when ...
msideal Avatar
Posted By msideal
Tue Oct 28 2014, 05:34 PM
ExperimenterUK: Thankyou so much for helping me......
msideal Avatar
Posted By msideal
Tue Oct 28 2014, 05:18 PM
thanks ExperimenterUK for your help.... I will try...
ExperimenterUK Avatar
Posted By ExperimenterUK
Mon Oct 27 2014, 10:29 PM
Your error seems to be the use of PINC, which is f...
msideal Avatar
Posted By msideal
Mon Oct 27 2014, 05:45 PM
i want to extend my i/o's by writing this code. i ...
Max.otto Avatar
Posted By Max.otto
Mon Oct 27 2014, 01:30 PM
Hi all , i am working with PSoC 5LP. I have contin...
gaurav7577 Avatar
Posted By gaurav7577
Mon Oct 27 2014, 09:53 AM
hello everyone i wanna interface blood pressure se...