Define a name to I/O pin in MikroC V8

Status
Not open for further replies.

mm_pk1

Newbie level 6
Joined
Jan 9, 2009
Messages
12
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,372
I have written the following code to run the stepper motor forward and backward. I am using MikroC V8.0. But after build process, following error appears:
Undeclared identifier [PORTB] in expression
At line36, ')' expected but ; found
. And many more errors, can someone help plz.

Complete Project is also attached:

#define Switch PORTC.F0; // Switch for Stepper Motor
#define X1 PORTB.F0;
#define X2 PORTB.F1;
#define X3 PORTB.F2;
#define X4 PORTB.F3;

//I have also tried with the following
//sbit Switch at RC0_bit; // Switch for Stepper Motor
//sbit X1 at RB0_bit;
//sbit X2 at RB1_bit;
//sbit X3 at RB2_bit;
//sbit X4 at RB3_bit;

//But both ways are not working fine
//Following error appears during build all process:
// Undeclared identifier [PORTB] in expression
// At line36, ')' expected but ; found
// and many more errors, can someone help plz

void MoveX_F(void); // Move Motor Forward
void MoveX_B(void); // Move Motor Backward

void main(void)
{
TRISB = 0x00;
TRISC = 0xFF;
P0RTB = 0x00;
PORTC = 0x00;

while(1)
{
if(Switch == 0);
MoveX_F();

else
MoveX_B();
}
}

void MoveX_F(void)
{ //Start Move X Motor to Forward Direction
unsigned int j;
X1=1;
for(j=0;j<1500;j++);
X1=0;
X2=1;
for(j=0;j<1500;j++);
X2=0;
X3=1;
for(j=0;j<1500;j++);
X3=0;
X4=1;
for(j=0;j<1500;j++);
X4=0;

} //End Move X Motor Forward

void MoveX_B(void)
{ //Start Move X Motor to Bacrkward Direction
unsigned int j;
X4=1;
for(j=0;j<1500;j++);
X4=0;
X3=1;
for(j=0;j<1500;j++);
X3=0;
X2=1;
for(j=0;j<1500;j++);
X2=0;
X1=1;
for(j=0;j<1500;j++);
X1=0;

} //End Move X Motor Backward
 

Attachments

  • Drive Stepper Motor.rar
    1.4 KB · Views: 117

Dear Friend

the very first thing is that i would like to point out is that you should not use comma (";") in # define directive in C.

try your code with the following modifications

#define Switch PORTC.F0
#define X1 PORTB.F0
#define X2 PORTB.F1
#define X3 PORTB.F2
#define X4 PORTB.F3

see i just removed the comma that you used.

secondly is there a PORTB in your controller? there are many controllers without PORTB(like 16F676).but i don't think that it's the problem,you must had checked the same before writing the software. i thing the first modification will solve your problem

regards

ML
 
Thank you so much microlab, by removing the " ; " after the #define statement my problems have been resolved. Thanks a lot
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…