Jump to content
Sign in to follow this  
james :-)

"Unreliable" code???

Recommended Posts

I set up this code to clear line 0 or 1 on an lcd - it works ok for just the first time I call it and after that does nothing????

 

Any ideas???

 

// clear line 0

 

unsigned char zx ;

 

char clr_line0 (void)

 

{

   cursor_pos ( 0,0 ) ;   // sets line to be cleared

 

for( zx== 0; zx < 16; zx++ )

     {

         lcd_print_ch (' ') ;

     }

   cursor_home () ;    // sends cursor home ( 0,0 )

}

 

// clear line 1

 

unsigned char cx ;

 

char clr_line1 (void)

 

{

   cursor_pos ( 0,1 ) ;     // sets line to be cleared

 

for( cx== 0; cx < 16; cx++ )

   {

lcd_print_ch (' ') ;

   }

   cursor_home () ;     // sends cursor home ( 0,0 )

}

 

 

I dont know if it's a bug in the code and while I'm here why does the compiler require ' == ' as the equals in the loop bits but not outside a loop??

 

best regards,

 

 

James Dexter :-)

???  ???

Share this post


Link to post
Share on other sites
Guest Dave

James

 

Your mistake look like you don't understand the C languge.

 

When you use '=', it means an assignment.

That means you want to give whatever is on the left of the = the value of whats on the right.

eg

a = 1;

or

b = 3 * a;

 

When you used '==' it means equality test, and returns true if the value of the item on the left is equal to the item on the right.

eg

1 == 2 // always false

1 == 1 // always true

a == b // depends on values of a and b

 

Change the == to = in you loops and the code should work :)

 

Regards

Dave

Share this post


Link to post
Share on other sites

Hi Dave,

 

Being a veteran of about 4 weeks I'm really struggling here but things are going well!

 

It works fine now that I've altered the == to = .

 

Thanks for that.

 

Back to "C for Dummies" I think.

 

 

Best regards,

 

 

James Dexter

Share this post


Link to post
Share on other sites
Guest Dave

James,

 

You are most wecome  :cool:

 

At one time we were all beginners, and struggled with the same problems.

 

Regards

Dave

Share this post


Link to post
Share on other sites
Guest Jim Franklin

James,

 

if it's any consolation, when I started programming the 8051 in C, i did exactly the opposite. I used

if (a=1)

 {

  .....

  }

 

and spent WEEKS trying to figure out why the code didn't work. exactly the opposite problem that you have here..

Good Luck.

(incidentally - Iam just getting back into programming the PICs and using C, having been on various M$ Basics for 6 years+) If you want to share experiences and learn together, i'd be more than willing to share my (generally bad) code.

 

All the best,

Jim

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...