Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] how to call functions im MikroC

Status
Not open for further replies.

janosandi

Full Member level 4
Joined
Jan 23, 2010
Messages
210
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,298
Activity points
2,788
hello guys
i have a function which assigns values to varibles
Code:
void Dopen() {
     Digitt1 = 0;
     Digitt2 = 16;
     Digitt3 = 14;
     Digitt4 = 19;
it works when i call it from anywhere in the main function But when i call it from an If statement it gives me errors

Code:
if(PORTB.B0 == 0) {
Dopen()
}
when i put 'Dopen()' anywhere it works & get values fom there
but with if it gives me this error
(undeclared identifier'Dopen' in expression
what i should declare it? or is there is something like Gosub or call in mikroC?
thx for help

John
 

There should be a closing ' } ' at the end of the function definition and a semicolon ' ; ' after 'Dopen()' in the 'if' statement.

The { } enclose a group of instructions, in the 'if' statement you can optionally leave them out as there is one one line to execute.

The only other possible reason is 'Dopen();' is out of the scope of the program, it can happen if the function is in another source file or in a library but it shouldn't happen if you only have one source file. If fixing the punctuation doesn't solve the problem you will have to post the whole code for us to see.

Brian.
 

(undeclared identifier'Dopen' in expression
what i should declare it? or is there is something like Gosub or call in mikroC?

Initially I also encountered with such problem which was overcome by declaring all the functions at the beginning of code. Following is an example.

Code:
void Dopen();
void XXXXX();
void ####();
void $$$$$();


void Dopen() {
     Digitt1 = 0;
     Digitt2 = 16;
     Digitt3 = 14;
     Digitt4 = 19;
                }

if(PORTB.B0 == 0) {
Dopen();
}
 

here is my code
Code:
void Dopen;
char select = 0, Digitt1, Digitt2, Digitt3, Digitt4;
unsigned char common_cathode_mask[21] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F, 0x77, 0x7C, 0x39, 0x5E, 0x79, 0x71, 0x73, 0x50, 0x5C, 0x37, 0x40};
//                                      0      ,1    ,2    ,3    ,4    ,5    ,6    ,7    ,8    ,9    ,A    ,b    ,C    ,d    ,E    ,F    ,P    ,r    ,o    ,N    ,-
//char digit[2];
char digit[4];

//Timer1
//Prescaler 1:1; TMR1 Preload = 63536; Actual Interrupt Time : 2 ms
//Place/Copy this part in declaration section

void InitTimer1() {
    //T1CON = 0x01;
    T1CON = 0x01;
    TMR1IF_bit = 0;
    TMR1H = 0xF8;
    TMR1L = 0x30;
    TMR1IE_bit = 1;
    INTCON = 0xC0;
}

void Interrupt(){
    if(TMR1IF_bit) {
      TMR1H = 0xF8;
      TMR1L = 0x30;

      PORTD = 0x00;
}

      //Enter your code here
      switch(select) {
          case 0:
                PORTC = digit[0];
                PORTD = 0x01;
                break;
          case 1:
                PORTC = digit[1];
                PORTD = 0x02;
                break;
          case 2:
                PORTC = digit[2];
                PORTD = 0x04;
                break;
          case 3:
                PORTC = digit[3];
                PORTD = 0x08;
                break;
      };

      if(++select == 4)select = 0;

      TMR1IF_bit = 0;
      
      if(PORTB.B0 == 0) {
      Dopen();
      }
      else {
      PORTB = 0b11000000;
      }

    }
void machoff() {
     Digitt1 = 20;
     Digitt2 = 20;
     Digitt3 = 20;
     Digitt4 = 20;
}
void Dopen() {
     Digitt1 = 0;
     Digitt2 = 16;
     Digitt3 = 14;
     Digitt4 = 19;
     PORTB.RB5 = 1;
}
void main() {

    CMCON = 0x07;
    ADCON1 = 0x87;

    TRISA = 0x00;
    TRISB = 0x03;
    TRISC = 0x00;
    TRISD = 0x00;
    TRISE = 0x00;

    PORTA = 0x00;
    PORTB = 0x00;
    PORTC = 0x00;
    PORTD = 0x00;
    PORTE = 0x00;

    InitTimer1();
    machoff();

         digit[0] = common_cathode_mask[Digitt1];
         digit[1] = common_cathode_mask[Digitt2];
         digit[2] = common_cathode_mask[Digitt3];
         digit[3] = common_cathode_mask[Digitt4];
    }

thx for reply's
 

It could be a problem with function prototyping, the first three lines should be:

void Dopen();
void machoff();
void InitTimer1();

I find your line indentation confusing, it doesn't clearly show how instructions are grouped together.

Brian.
 

It could be a problem with function prototyping, the first three lines should be:

void Dopen();
void machoff();
void InitTimer1();

I find your line indentation confusing, it doesn't clearly show how instructions are grouped together.

Brian.

hello Brian
what do you suggest more i've already put 'void Dopen()' at the start

thx
 

It would help if you show the actual compiled code with the observed error message. Up to now, the posted code snippets had syntax errors. That's why we are talking about how the code should be instead how it is. Getting an answer that the actual code is different...
 

What do you mean by 'at the start' ? It will be better to you as well as other members if the entire code is posted.

- - - Updated - - -

Sorry. I did not notice your entire code at post #4. At the "start" does not mean at the top of your code, before defining PORT Bits and declaring variables. Please see the corrected code and notice the coloured portions. Do you use 16F887? In that case CMCON to be replaced with CM1CON0, otherwise you will get an error.

Code:
char select = 0, Digitt1, Digitt2, Digitt3, Digitt4;
unsigned char common_cathode_mask[21] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F, 0x77, 0x7C, 0x39, 0x5E, 0x79, 0x71, 0x73, 0x50, 0x5C, 0x37, 0x40};
//                                      0      ,1    ,2    ,3    ,4    ,5    ,6    ,7    ,8    ,9    ,A    ,b    ,C    ,d    ,E    ,F    ,P    ,r    ,o    ,N    ,-
//char digit[2];
char digit[4];
[COLOR="#FF0000"]void Dopen();
void machoff();
InitTimer1();[/COLOR]
//Timer1
//Prescaler 1:1; TMR1 Preload = 63536; Actual Interrupt Time : 2 ms
//Place/Copy this part in declaration section

void InitTimer1() {
    //T1CON = 0x01;
    T1CON = 0x01;
    TMR1IF_bit = 0;
    TMR1H = 0xF8;
    TMR1L = 0x30;
    TMR1IE_bit = 1;
    INTCON = 0xC0;
}

void Interrupt(){
    if(TMR1IF_bit) {
      TMR1H = 0xF8;
      TMR1L = 0x30;

      PORTD = 0x00;
}

      //Enter your code here
      switch(select) {
          case 0:
                PORTC = digit[0];
                PORTD = 0x01;
                break;
          case 1:
                PORTC = digit[1];
                PORTD = 0x02;
                break;
          case 2:
                PORTC = digit[2];
                PORTD = 0x04;
                break;
          case 3:
                PORTC = digit[3];
                PORTD = 0x08;
                break;
      };

      if(++select == 4)select = 0;

      TMR1IF_bit = 0;

      if(PORTB.B0 == 0) {
      Dopen();
      }
      else {
      PORTB = 0b11000000;
      }

    }
void machoff() {
     Digitt1 = 20;
     Digitt2 = 20;
     Digitt3 = 20;
     Digitt4 = 20;
}
void Dopen() {
     Digitt1 = 0;
     Digitt2 = 16;
     Digitt3 = 14;
     Digitt4 = 19;
     PORTB.RB5 = 1;
}
void main() {

    [COLOR="#FF0000"]CM1CON0 [/COLOR]= 0x07;
    ADCON1 = 0x87;

    TRISA = 0x00;
    TRISB = 0x03;
    TRISC = 0x00;
    TRISD = 0x00;
    TRISE = 0x00;

    PORTA = 0x00;
    PORTB = 0x00;
    PORTC = 0x00;
    PORTD = 0x00;
    PORTE = 0x00;

    InitTimer1();
    machoff();

         digit[0] = common_cathode_mask[Digitt1];
         digit[1] = common_cathode_mask[Digitt2];
         digit[2] = common_cathode_mask[Digitt3];
         digit[3] = common_cathode_mask[Digitt4];
    }
 

hello guys
its ok now i've declared Dopen again & its ok
i've did it before but it wasnt working i dont know why

thx for help
John
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top