Embedded C/C++

Moderators: Lundin
Number of threads: 209
Number of posts: 392

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
AT89c4051 problem in using string functions Posted by kirankumar on 2 Oct 2007 at 11:16 PM
Hai,
Iam new to Embedded systems.iam using at89c4051
i have a problem. Problem: P3.3 is connected to a bulb.

and my program is
sbit sw1 P3^3
void main()
{ P3=0xff;
for(i=0;i<10000;i++);
SW1=0;
while(1);
} output; Bulb conneted to p3.3, turned on
this program is working fine.

but when the same main()

void main()
{ int flag;
P3=0xff;
for(i=0;i<10000;i++);

flag=strcmp("INFOLINE","INFOLINE");

if(flag==0)
sw1=0;

while(1);
} when is dumped, its not working,
iam unable to understand, why this is not working.

please assist me in solving this.

Cordially,
Kiran Kumar D
Report
Re: AT89c4051 problem in using string functions Posted by Lundin on 3 Oct 2007 at 12:00 AM
If you don't have a debugger, you should get one. You would likely detect the problem within five minutes.

Without a debugger, I see nothing wrong with the program, the only safety risk in it is that you are using "int" rather than "signed int". int can either signed or unsigned, it isn't specified by ANSI C but determined by the compiler. Since strcmp() returns a signed int, you will get problems if int is treated as unsigned int.

Also, where is "i" allocated? Please post the whole code.


A tip: when writing dummy for-loops, write like this:

for(i=0; i<10000; i++)
  ;

To show that you are explicitly doing nothing, and not that you accidently added a semicolon at the end of the line.
Report
Re: AT89c4051 problem in using string functions Posted by stars_625 on 18 Jul 2008 at 10:48 PM
: Hai,
: Iam new to Embedded systems.iam using at89c4051
: i have a problem. Problem: P3.3 is connected to a bulb.
:
: and my program is
: sbit sw1 P3^3
: void main()
: { P3=0xff;
: for(i=0;i<10000;i++);
: SW1=0;
: while(1);
: } output; Bulb conneted to p3.3, turned on
: this program is working fine.
:
: but when the same main()
:
: void main()
: { int flag;
: P3=0xff;
: for(i=0;i<10000;i++);
:
: flag=strcmp("INFOLINE","INFOLINE");
:
: if(flag==0)
: sw1=0;
:
: while(1);
: } when is dumped, its not working,
: iam unable to understand, why this is not working.
:
: please assist me in solving this.
:
: Cordially,
: Kiran Kumar D
:

sbit sw1 P3^3 <==> sbit sw1 = P3^3

sw1 <==> SW1



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.