Discussion in "General help Guidance and Discussion" started by    Amit Radha    Feb 10, 2008.
Sun Feb 10 2008, 11:12 pm
#1
Facing trouble with coding in c. I am farely good in assembley but am trying to sharpen my c skills for 8051. I am trying to toggle P0. No matter what I try, only P0is toggling but the Pins dont toggle. They remain as 0000000 only. Pls correct me. This is one of the codes i tried. Wat is the difference can u explain and wil it have any impact while using such a code physically in a microcontroller?
#include<reg51.h>

void main(void)
{
unsigned int x;

for(x=0;x<10;x++)
{
// for(y=0;y<10000;y++)
P0=0x00;
// for(y=0;y<10000;y++)
P0=0xff;
}
}

Also I am encountering an error at the completeion of al my codes(in assembley and c)
"error 65: access violation at C:0x.... : 'execute/read' permission"
(i have used .... to indicate that different values are shown here for differnt codes i have tried)
Thanks
Mon Feb 11 2008, 01:31 am
#2
please correct and try..
for(x=0;x<10;x++)
{
// for(y=0;y<10000;y++)
P0=0x00;
// for(y=0;y<10000;y++)
P0=0xff;
}


unsigned int y;
for(x=0;x<10;x++)
{
 for(y=0;y<10000;y++);
P0=0x00;
 for(y=0;y<10000;y++);
P0=0xff;
}


also didnt get what u mean by

No matter what I try, only P0is toggling but the Pins dont toggle




for the error part ...
try by not passing any argument to main fun...
ex. use void main() ....


[ Edited Mon Feb 11 2008, 01:33 am ]
Mon Feb 11 2008, 07:28 pm
#3
Hi Shyam,
1. I tried it with void main() but i stil got the access violation error after al the instructions were executed.
2. I am not using for(y=0;y<10000;y++); because i am debugging it and doing "step" to see the result of each instruction. (such a huge delay will take me ages!!!)
3. By the P0 toggling and Pins not toggling I mean that when u open the peripheral window to check the P0 value it shows P0 and Pins.

Il upload the screenshot to show you.


[ Edited Mon Feb 11 2008, 09:34 pm ]
Mon Feb 11 2008, 09:40 pm
#4
you forgot to add one statement in your code..

while (1){
//your for loop here :)
}


after editing your code, do not forget to recompile it.
Mon Feb 11 2008, 10:13 pm
#5
Hi ajay,
That solves the prolem of that access violation error. Thanks.
But wat do i do for the no change in "Pins" value which remains null ater the 1st time it is reset. as u can see in my screenshot?
And any help on my sensor problem? shall i start another thread for that?
Mon Feb 11 2008, 10:47 pm
#6
Pins value wont change because.. Pins are actually for input. you should not forget that you are using a debugger. So when you write something to port it goes to P0 not to pins. when you want to enter something to port then you have enter value through pins thats why they have given both pins and port register differently.
I don't know how to explain this question has got a logical answer.
 Amit Radha like this.
Mon Feb 11 2008, 10:51 pm
#7
hey Ajay,
I understood thanks

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

KevinTab
Sun Apr 28 2024, 05:35 am
Tumergix
Sun Apr 28 2024, 12:59 am
StevenDrulk
Sat Apr 27 2024, 08:47 pm
StephenHauct
Sat Apr 27 2024, 09:38 am
Adamsaf
Sat Apr 27 2024, 07:12 am
Robertphype
Sat Apr 27 2024, 12:23 am
ktaletrryp
Fri Apr 26 2024, 10:55 pm
Robertrip
Fri Apr 26 2024, 11:20 am