C programming problem

Thread Starter

Prinz

Joined Nov 16, 2014
16
Hello guys I'm kinda still finding my way around c programming language, I tried the code below and got a "too many actual parameter" error
Code:
Char *text = "welcome aboard";
Void main() {
Lcd_Init;-------got d error code on this line
Lcd_Out(1,1,text);
}
Anyone with useful information should pls help..
 

bertus

Joined Apr 5, 2008
22,270
Hello,

I moved your post from the line following robot thread, as it seems to me a completely different problem and it also was a hyjack.

Bertus
 

shteii01

Joined Feb 19, 2010
4,644
Char *text = "welcome aboard";
Two problems for me.
- Char, should it start with capital c? Normally when I declare character in C I just use: char.
- *text, that is pointer of some kind? Since I have a string of characters (welcome aboard), I would just use array: text[]="welcome aboard".

Lcd_Init
One problem here.
I assume that Lcd_Init is a function. Function needs prentecies. I would have used: Lcd_Init().
 

ErnieM

Joined Apr 24, 2011
8,377
"Void main()" can never be correct.

Try "void main()" Lower case.

When presented by many errors in C always tackle the first one first... it may be causing everything that fails below.

Also helps to check the line just before the error... it oft is the cause of something failing directly below it.
 

Thread Starter

Prinz

Joined Nov 16, 2014
16
Thanks guys for your suggestions, I hav tried the code dis way,
char *text = "welcome aboard";
void main(){
Lcd_Init(&PORTB);
Lcd_Out(1,1,text);
}
...But it still shows d "too many actual parameters" error on line 3, could it be that the code on line 3 is a function call?
 

JohnInTX

Joined Jun 26, 2012
4,787
This looks like MicroC.

For any compiler, you need to spec the LCD IO before using any LCD functions. A sample pasted from the MicroC manual for a PIC16F877A is shown.

In any C, 'too many formal parameters' means that the function can't take what you are passing it. Review the prototype of the function (in the IO library sections of the manual or a header file LCD.h etc.) to see what it wants. For MicroC, Lcd_Init() wants NO parameters so passing the address of PORTB will flag an error (or warning - which should be considered a problem as well).

I like declaring the string as shown but both compiled OK, at least on MicroC. You might have issues with another compiler though.

Note that MicroC is very forgiving and by default includes the header files for LCD and everything else it does. Other compilers (HiTech et al) will require specifically including the header file that has the prototypes of the various library routines.

MicroC also handles PIC fuzes in a separate window. Hitech, XC8 require them to be set in the code using pragmas. A very common error is leaving the config fuses out out when moving from a simulation to actual hardware.

Have fun.
Code:
 // Lcd pinout settings - You need to specify these before using any of the LCD functions
// See  chapter 7 of the MicroC manual. pp 351
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D4 at RB0_bit;
// Pin direction
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D7_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB0_bit;
//char *text = "welcome aboard";
char text[] = "welcome aboard";   // probably a better way to declare it but both compile OK
                                     // Note that 'text' IS a char* as its the name of a single dim array.
void main(){
     Lcd_Init();
     Lcd_Out(1,1,text);

     while(1);
}
 
Last edited:

ErnieM

Joined Apr 24, 2011
8,377
Thanks guys for your suggestions, I hav tried the code dis way...
But have you tried it dat way, the way that shteii01 suggested to init the LCD, which just happens to coincide with the way MikroC says to use that library function.

Of course, I am making an assumption about your compiler as you never stated which one you are using on this project.
 

ErnieM

Joined Apr 24, 2011
8,377
Char *text = "welcome aboard";
Two problems for me.
- Char, should it start with capital c? Normally when I declare character in C I just use: char.
- *text, that is pointer of some kind? Since I have a string of characters (welcome aboard), I would just use array: text[]="welcome aboard".
That is actually only one problrm. "char text[] = "welcome aboard" and . "char *text = "welcome aboard" are equivalent expressions. K&R actually states they prefer the latter way "because it says explicitly that the parameter is a pointer" (section 5.3).
 

shteii01

Joined Feb 19, 2010
4,644
That is actually only one problrm. "char text[] = "welcome aboard" and . "char *text = "welcome aboard" are equivalent expressions. K&R actually states they prefer the latter way "because it says explicitly that the parameter is a pointer" (section 5.3).
Pointers were never my strong point. (Is that a pun?)
I mean I have used it/done it in my C classes, on as needed basis (meanint when material that we were covering was about pointers and all the assignments/homework was to show that yes, I know how to use pointers). But I normally prefer more direct representation, so array is my first choice when it comes to putting text on the screen.

Mind, I am not some kind of great programmer or C specialist. My degree is EE, not CS.
 

ErnieM

Joined Apr 24, 2011
8,377
I sometimes use one way, sometimes the other. I got a good grounding in pointers writing libraries on a PC to create COM objects in assembly. Objects are collections of pointers to pointers, all of which is pointer to by the object pointer.

My degree is also an EE. CS was for the weenies afraid of the 2nd semester of Maxwell's equations.
 

Thread Starter

Prinz

Joined Nov 16, 2014
16
Thanks too @ Ernie, guys I've got another issue,

Code:
#include <16f877a.h>
#fuses hs, noprotect, nowdt, nolvp
#use delay (clock=20000000)
#byte portc=7
#byte portd=8
#byte porte=9

void main()
{
  set_tris_e(0x07);
  set_tris_d(0);
  setup_ccp1(ccp_pwm);
  setup_ccp2(ccp_pwm);
  setup_timer_2(t2_div_by_4,100,1);
And d code continues, I got a "main function not declared" error @ d 'void main()' line
What's your suggestion guys?

Moderators note: please use code tags for pieces of code.
 
Last edited by a moderator:

ErnieM

Joined Apr 24, 2011
8,377
Probably you have defined main incorrectly.

The correct definition depends on the exact compiler you use.

Would you care to share that with us?
 

tshuck

Joined Oct 18, 2012
3,534
Possibly a lack of the closing bracket:
Code:
#include <16f877a.h>
#fuses hs, noprotect, nowdt, nolvp
#use delay (clock=20000000)
#byte portc=7
#byte portd=8
#byte porte=9

void main()
{
set_tris_e(0x07);
set_tris_d(0);
setup_ccp1(ccp_pwm);
setup_ccp2(ccp_pwm);
setup_timer_2(t2_div_by_4,100,1);
}
 

Thread Starter

Prinz

Joined Nov 16, 2014
16
Code:
#include <16f877a.h>
#fuses hs, noprotect, nowdt, nolvp
#use delay (clock=20000000)

#byte portc=7
#byte portd=8
#byte porte=9

void main()
{
   set_tris_e(0x07);
   set_tris_d(0);
   setup_ccp1(ccp_pwm);
   setup_ccp2(ccp_pwm);
   setup_timer_2(t2_div_by_4,100,1);
  
   //white = 1; black =0
  
   while(true)
   {
      if(!input(pin_E2) && !input(pin_E1) && input(pin_E0))    //Turn Left (001)
      {
         portd=0x0A;
         set_pwm1_duty(40);      //pwm1 control left motor
         set_pwm2_duty(90);      //pwm2 control right motor
      }
     
      if(!input(pin_E2) && input(pin_E1) && input(pin_E0))     //Turn Left 2 (011)
      {
         portd=0x0A;
         set_pwm1_duty(40);
         set_pwm2_duty(90);
      }

      if(input(pin_E2) && !input(pin_E1) && !input(pin_E0))    //Turn Right (100)
      {
         portd=0x0A;
         set_pwm1_duty(90);
         set_pwm2_duty(40);
      }
  
      if(input(pin_E2) && input(pin_E1) && !input(pin_E0))     //Turn Right 2 (110)
      {
         portd=0x0A;
         set_pwm1_duty(90);
         set_pwm2_duty(40);
      }
  
     
     if(!input(pin_E2) && !input(pin_E1) && !input(pin_E0))    //Forward (000)
      {
         portd=0x0A;
         set_pwm1_duty(85);
         set_pwm2_duty(85);
      }
  
     if(input(pin_E2) && input(pin_E1) && input(pin_E0))       //backward(111)
      {
         portd=0x14;
         set_pwm1_duty(85);
         set_pwm2_duty(85);
      }
   }
}
Dats d whole code

Moderators note: please use code tags for pieces of code.
 
Last edited by a moderator:
Top