C programming problem

Discussion in 'Embedded Systems and Microcontrollers' started by Prinz, Nov 16, 2014.

  1. Prinz

    Thread Starter New Member

    Nov 16, 2014
    16
    0
    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 (Text):
    1.  
    2. Char *text = "welcome aboard";
    3. Void main() {
    4. Lcd_Init;-------got d error code on this line
    5. Lcd_Out(1,1,text);
    6. }
    7.  
    Anyone with useful information should pls help..
     
  2. bertus

    Administrator

    Apr 5, 2008
    15,634
    2,342
    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
     
  3. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,373
    494
    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().
     
  4. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    "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.
     
  5. Prinz

    Thread Starter New Member

    Nov 16, 2014
    16
    0
    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?
     
  6. JohnInTX

    Moderator

    Jun 26, 2012
    2,338
    1,016
    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 (Text):
    1.  // Lcd pinout settings - You need to specify these before using any of the LCD functions
    2. // See  chapter 7 of the MicroC manual. pp 351
    3. sbit LCD_RS at RB4_bit;
    4. sbit LCD_EN at RB5_bit;
    5. sbit LCD_D7 at RB3_bit;
    6. sbit LCD_D6 at RB2_bit;
    7. sbit LCD_D5 at RB1_bit;
    8. sbit LCD_D4 at RB0_bit;
    9. // Pin direction
    10. sbit LCD_RS_Direction at TRISB4_bit;
    11. sbit LCD_EN_Direction at TRISB5_bit;
    12. sbit LCD_D7_Direction at TRISB3_bit;
    13. sbit LCD_D6_Direction at TRISB2_bit;
    14. sbit LCD_D5_Direction at TRISB1_bit;
    15. sbit LCD_D4_Direction at TRISB0_bit;
    16. //char *text = "welcome aboard";
    17. char text[] = "welcome aboard";   // probably a better way to declare it but both compile OK
    18.                                      // Note that 'text' IS a char* as its the name of a single dim array.
    19. void main(){
    20.      Lcd_Init();
    21.      Lcd_Out(1,1,text);
    22.  
    23.      while(1);
    24. }
     
    Last edited: Nov 17, 2014
  7. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    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.
     
  8. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    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).
     
    JohnInTX likes this.
  9. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,373
    494
    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.
     
  10. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    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.
     
  11. Prinz

    Thread Starter New Member

    Nov 16, 2014
    16
    0
    Thanks John,
     
  12. Prinz

    Thread Starter New Member

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

    Code (Text):
    1.  
    2. #include <16f877a.h>
    3. #fuses hs, noprotect, nowdt, nolvp
    4. #use delay (clock=20000000)
    5. #byte portc=7
    6. #byte portd=8
    7. #byte porte=9
    8.  
    9. void main()
    10. {
    11.   set_tris_e(0x07);
    12.   set_tris_d(0);
    13.   setup_ccp1(ccp_pwm);
    14.   setup_ccp2(ccp_pwm);
    15.   setup_timer_2(t2_div_by_4,100,1);
    16.  
    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: Nov 19, 2014
  13. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    Probably you have defined main incorrectly.

    The correct definition depends on the exact compiler you use.

    Would you care to share that with us?
     
  14. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    Possibly a lack of the closing bracket:
    Code (Text):
    1. #include <16f877a.h>
    2. #fuses hs, noprotect, nowdt, nolvp
    3. #use delay (clock=20000000)
    4. #byte portc=7
    5. #byte portd=8
    6. #byte porte=9
    7.  
    8. void main()
    9. {
    10. set_tris_e(0x07);
    11. set_tris_d(0);
    12. setup_ccp1(ccp_pwm);
    13. setup_ccp2(ccp_pwm);
    14. setup_timer_2(t2_div_by_4,100,1);
    15. }
     
  15. Prinz

    Thread Starter New Member

    Nov 16, 2014
    16
    0
    I'm using mikroC compiler @ ErnieM
     
  16. Prinz

    Thread Starter New Member

    Nov 16, 2014
    16
    0
    Its definitely not a bracket issue, I think it could be some other omission I'm yet to decifer
     
  17. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    Is this your whole code, then? If not, post it.
     
  18. Prinz

    Thread Starter New Member

    Nov 16, 2014
    16
    0
    Code (Text):
    1.  
    2. #include <16f877a.h>
    3. #fuses hs, noprotect, nowdt, nolvp
    4. #use delay (clock=20000000)
    5.  
    6. #byte portc=7
    7. #byte portd=8
    8. #byte porte=9
    9.  
    10. void main()
    11. {
    12.    set_tris_e(0x07);
    13.    set_tris_d(0);
    14.    setup_ccp1(ccp_pwm);
    15.    setup_ccp2(ccp_pwm);
    16.    setup_timer_2(t2_div_by_4,100,1);
    17.  
    18.    //white = 1; black =0
    19.  
    20.    while(true)
    21.    {
    22.       if(!input(pin_E2) && !input(pin_E1) && input(pin_E0))    //Turn Left (001)
    23.       {
    24.          portd=0x0A;
    25.          set_pwm1_duty(40);      //pwm1 control left motor
    26.          set_pwm2_duty(90);      //pwm2 control right motor
    27.       }
    28.      
    29.       if(!input(pin_E2) && input(pin_E1) && input(pin_E0))     //Turn Left 2 (011)
    30.       {
    31.          portd=0x0A;
    32.          set_pwm1_duty(40);
    33.          set_pwm2_duty(90);
    34.       }
    35.  
    36.       if(input(pin_E2) && !input(pin_E1) && !input(pin_E0))    //Turn Right (100)
    37.       {
    38.          portd=0x0A;
    39.          set_pwm1_duty(90);
    40.          set_pwm2_duty(40);
    41.       }
    42.  
    43.       if(input(pin_E2) && input(pin_E1) && !input(pin_E0))     //Turn Right 2 (110)
    44.       {
    45.          portd=0x0A;
    46.          set_pwm1_duty(90);
    47.          set_pwm2_duty(40);
    48.       }
    49.  
    50.      
    51.      if(!input(pin_E2) && !input(pin_E1) && !input(pin_E0))    //Forward (000)
    52.       {
    53.          portd=0x0A;
    54.          set_pwm1_duty(85);
    55.          set_pwm2_duty(85);
    56.       }
    57.  
    58.      if(input(pin_E2) && input(pin_E1) && input(pin_E0))       //backward(111)
    59.       {
    60.          portd=0x14;
    61.          set_pwm1_duty(85);
    62.          set_pwm2_duty(85);
    63.       }
    64.    }
    65. }
    66.  
    Dats d whole code

    Moderators note: please use code tags for pieces of code.
     
    Last edited by a moderator: Nov 19, 2014
  19. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    Did you remember to add the *.c file to your project?
     
  20. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    Did you remember to post your code using the [code ] [/code ] tags?

    Oh, I see.
     
Loading...