Jump to content
Sign in to follow this  
GeekDoc

Some help with my C?

Recommended Posts

I'm working on driving a parallel LCD using a 74HC595 shift register. I've hacked together bits of code from around the web and on these forums (thanks, gatesphere!). I'm getting close to having basic functionality, but I have some compiler (CCS) errors I don't understand.

 

EDIT: Solved the original code I put here. Here's another problem:

 

Here's the code with the errors as comments:

//-----------------------------------------------------------------------------
// Module:   LCD_inst
// Description: Send instruction to LCD module
//-----------------------------------------------------------------------------

void LCD_inst(unsigned char data){
   LCD_via_595(data, LCD_RS);      //*****expected an expression AND expected a ")"
}



//-----------------------------------------------------------------------------
// Module:   LCD_data
// Description: Display value
//-----------------------------------------------------------------------------
void LCD_data(unsigned char data)
{
   LCD_via_595(data, ~LCD_RS);     //*****expected an expression AND expected a ")"
}

 

LCD_via_595 takes two unsigned char arguments. LCD_RS is a defined unsigned char constant.

 

Can anyone help? Visual Studio's code completion has made me soft! :oops:

Share this post


Link to post
Share on other sites

Hmm... I don't rightfully know what's going on here. However, trying to compile the section you've provided, I only get an error on the first line. Taking out the default value seems to fix it, but makes things more difficult to implement cleanly.

 

Doing some research, it seems that default parameter values are not in the ANSI C standard, they were introduced with C++, and later adopted into the C99 standard. I don't think CCS uses the C99 standard, so you might be SOL. If you take out that default value, your code might just compile fine.

 

If you'd still like to have it able to be called without the second parameter, you could write a helper function with the following definition:

inline void LDC_via_595(unsigned char data) { LCD_via_595(data, 0x00);}

 

This is called function overloading. It allows the same function name (with different parameter lists) to be used for multiple implementations. The inline keyword tells the compiler replace any instance of the function call with the code directly, kind of like a pre-processor #define statement, except handled by the processor, not the pre-processor.

 

Think of it as a "helper" function.

 

Hope this helps. Let me know if that resolves your other issues, if not, I'll take a crack at those too.

Share this post


Link to post
Share on other sites

Thanks for the help. I did end up taking out the default value (I learned mostly C++) and doing the OR operations before I called the other function.

 

While you were so graciously researching my problem, I changed the code I was requesting help with. I have no clue as to the origin of these other errors!

Share this post


Link to post
Share on other sites

Okay, solved these... kinda.

 

It seems the function calls did not like the constant (defined as 0x04) in the call. I just added a local variable and set it to the constant. It works, but I don't know why it didn't work before.

 

//-----------------------------------------------------------------------------
// Module:   LCD_inst
// Description: Send instruction to LCD module
//-----------------------------------------------------------------------------

void LCD_inst(unsigned char data){
   unsigned char LCDreg = LCD_RS;
   LCD_via_595(data, LCDreg);
}

//-----------------------------------------------------------------------------
// Module:   LCD_data
// Description: Display value
//-----------------------------------------------------------------------------
void LCD_data(unsigned char data)
{
   unsigned char LCDreg = ~LCD_RS;
   LCD_via_595(data, LCDreg);
}

Share this post


Link to post
Share on other sites

*shrug* As long as you've got it working. Strange about not liking the or of the constant and the variable though... there's no valid reason it shouldn't like that.

 

Glad you're still working on it, though! :D

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

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.

Sign in to follow this  

×
×
  • Create New...