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.

Mikro c : varialble decleration problem

Status
Not open for further replies.

dashkil

Member level 2
Member level 2
Joined
Mar 3, 2012
Messages
45
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,286
Activity points
1,620
i have some problem in this code;
this one is correct. but having problem as mentioned below:

Code:
char text[]="kkkkk";
     
void main()
{
    ADCON1=0x06;
    TRISA=0xFF;
    TRISB=0;
    PORTA=0;
    PORTB=0;

     while(1){
     char z;

                       if(PORTA.F0==1)
                       {                      
                        for(z=0;z<5;z++)
                        PORTB=text[z];
                       }

                               else
                              {
                               ;
                               }
  }
    }

problems:
1) when i declare char text[] in the void main() it shows error; it shows no error when declare outside the void main as global variable.

2) Again declaring char z within void main or outside shows error; but no error when decelerated within while loop.

i need explanation about this kind of problem.
 
Last edited:

Which compiler are you using? Which version? Can you post the screenshot of error message.
 

Which compiler are you using? Which version? Can you post the screenshot of error message.

mikro c pro v 4.60

error.PNG
 

You need a semicolon at the end of the first statement.
 

Try this code. If it gives error again then reinstall your compiler and check.

Code:
void main()
{

     char text[]="kkkkk";
     char z;

     ADCON1=0x06;
     TRISA=0xFF;
     TRISB=0x00;
     PORTA=0x00;
     PORTB=0x00;

     while(1){
     

              if(PORTA.F0==1)
              {                      
                  for(z=0;z<5;z++)
                        PORTB=text[z];
              }

              else
              {
                  ;
              }
     }
}

Why are you trying to assign string to PORT?
 
i have some problem in this code;
this one is correct. but having problem as mentioned below:

Code:
char text[]="kkkkk";
     
void main()
{
    ADCON1=0x06;
    TRISA=0xFF;
    TRISB=0;
    PORTA=0;
    PORTB=0;

     while(1){
     char z;

                       if(PORTA.F0==1)
                       {                      
                        for(z=0;z<5;z++)
                        PORTB=text[z];
                       }

                               else
                              {
                               ;
                               }
  }
    }

problems:
1) when i declare char text[] in the void main() it shows error; it shows no error when declare outside the void main as global variable.

2) Again declaring char z within void main or outside shows error; but no error when decelerated within while loop.

i need explanation about this kind of problem.

Declare both at the beginning of the main loop - before everything else. Declarations must be done at the beginning. You'll see that it's all okay, then.

Code:
//char text[]="kkkkk";

void main()
{
    char z;
    char text[]="kkkkk";
     
    ADCON1=0x06;
    TRISA=0xFF;
    TRISB=0;
    PORTA=0;
    PORTB=0;
    
     while(1){

                       if(PORTA.F0==1)
                       {
                        for(z=0;z<5;z++)
                        PORTB=text[z];
                       }

                               else
                              {
                               ;
                               }
  }
    }

Hope this helps.
Tahmid.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top