PIC16F628 code

Help
Alex Roman
2005-08-28
2013-03-12
  • Alex Roman
    Alex Roman
    2005-08-28

    Hi,

    I am trying to code a program in C using SDCC for the microcontroller PIC16F628. I am having troubles...

    motor.h (important bits):
    #define __MOTOR_TRISB 0xF0

    motor.c (important bits):
    void leftMotorFwd (int steps) {
        int motor;
        motor = PORTB & __MOTOR_LEFT_MASK;

        /* for every step */
        int i;                           // this is line 40
        for (i=0; i<steps; i++) { // this is line 41
    ...

    I get compile-time error messages:
    $ sdcc -mpic14 -p16f628 -c src/motor.c -o obj/
    Processor: 16f628

    src/motor.c:40: syntax error: token -> 'int' ; column 11
    src/motor.c:41: error 20: Undefined identifier 'i'
    src/motor.c:41: error 20: Undefined identifier 'i'
    src/motor.c:41: error 20: Undefined identifier 'i'
    -:0: error 103: code not generated for 'leftMotorFwd' due to previous errors

    src/motor.c:70: syntax error: token -> 'int' ; column 11
    src/motor.c:71: error 20: Undefined identifier 'i'
    src/motor.c:71: error 20: Undefined identifier 'i'
    src/motor.c:71: error 20: Undefined identifier 'i'
    -:0: error 103: code not generated for 'leftMotorBck' due to previous errors

    src/motor.c:92: syntax error: token -> 'int' ; column 11
    src/motor.c:93: error 20: Undefined identifier 'i'
    src/motor.c:93: error 20: Undefined identifier 'i'
    src/motor.c:93: error 20: Undefined identifier 'i'
    -:0: error 103: code not generated for 'rightMotorFwd' due to previous errors

    src/motor.c:114: syntax error: token -> 'int' ; column 11
    src/motor.c:115: error 20: Undefined identifier 'i'
    src/motor.c:115: error 20: Undefined identifier 'i'
    src/motor.c:115: error 20: Undefined identifier 'i'
    -:0: error 103: code not generated for 'rightMotorBck' due to previous errors

    I am clueless, what is going on?
    Any help would be greatly appreciated. Thank you!

     
    • Maarten Brock
      Maarten Brock
      2005-08-28

      It's not allowed in C to declare a new variable in the middle of a block { }, but only at the beginning.

      void leftMotorFwd (int steps) {
      int motor;
      int i;

      motor = PORTB & __MOTOR_LEFT_MASK;

       
    • Alex Roman
      Alex Roman
      2005-08-28

      :( I feel ashamed... I guess I've been programming extended versions of C all along...

      Thank you very much for the insight! :)