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.

calling subroutine problem in mikroC

Status
Not open for further replies.

bbgil

Full Member level 2
Full Member level 2
Joined
Mar 11, 2006
Messages
135
Helped
13
Reputation
26
Reaction score
9
Trophy points
1,298
Activity points
2,321
too many actual parameters mikroc

hi. i got this code in which i want to call a subroutine. It got error that it has too many actual parameters. What is that error? How do you create and call a subroutine in the main program? any sample will help. or link? Needless to say, i'm a newbie in c. thnx in advance.

//
char n;
void flash () ;
void main()
{
while(1)
{
flash(5);//this is the error line
delay_ms(3000);
}
}
void flash(n)
{ for (n=0; n < 5; n++)
{
trisb = 0;
portb.f0 = 1;
Delay_ms(500);
portb.f0 = 0;
Delay_ms(500);
}
}
 

for loop mikroc

Your declearation of the function flash should specify that it passes an int.

void flash (int n);
void main();

....
 

    bbgil

    Points: 2
    Helpful Answer Positive Rating
mikroc portb input

thanks for the reply. helped a lot. now i have another one, i want to run this such that RB7 act like a switch. when its on, it performs the task. Problem is, it doesn't work that way i tried with == and =. both not working. help is much appreciated. here is the code. another thing, how to simulate switch in MikroC IDE?

unsigned int i=1;

void main() {if (PORTB.F7=1)
{
PORTB = 0;
TRISB = 0;

while(1) {
for(i=1;i<=63;i=i++)
{

PORTB.f0 = 1;
Delay_ms(1000);
PORTB.f1 = 1;
Delay_ms (1000);
PORTB.f2 = 1;
Delay_ms (1000);
PORTB.f3 = 1;
Delay_ms(1000);
PORTB.f4 = 1;
Delay_ms (1000);
PORTB.f5 = 1;
Delay_ms(1000);


for(i=63;i>1;i=i--)
{
PORTB.f5 = 0;
Delay_ms(1000);
PORTB.f4 = 0;
Delay_ms (1000);
PORTB.f3 = 0;
Delay_ms (1000);
PORTB.f2 = 0;
Delay_ms(1000);
PORTB.f1 = 0;
Delay_ms (1000);
PORTB.f0 = 0;
Delay_ms (1000) ;
}
} } }
} //~!
 

too many actual parameters microc

you should set TRISB to 1000 0000 so RB7 is input... and then it will work... I supposed if you press RB7 it will make a secuence of turning on leds, and then turning them off... i dont understand what's up with the 63 loop...(so I took it out!)
maybe you could explain your code a little more...

void main(void)
{
PORTB = 0;
TRISB = 0b10000000;
while(1) {
if (PORTB.F7==1)
{
{
PORTB.f0 = 1;
Delay_ms(1000);
PORTB.f1 = 1;
Delay_ms (1000);
PORTB.f2 = 1;
Delay_ms (1000);
PORTB.f3 = 1;
Delay_ms(1000);
PORTB.f4 = 1;
Delay_ms (1000);
PORTB.f5 = 1;
Delay_ms(1000);
}
{
PORTB.f5 = 0;
Delay_ms(1000);
PORTB.f4 = 0;
Delay_ms (1000);
PORTB.f3 = 0;
Delay_ms (1000);
PORTB.f2 = 0;
Delay_ms(1000);
PORTB.f1 = 0;
Delay_ms (1000);
PORTB.f0 = 0;
Delay_ms (1000) ;
}
}
}
} //~!
 

    bbgil

    Points: 2
    Helpful Answer Positive Rating
mikroc subrotina

tnx for the help. silly me, forgot to set the input. it worked already. the 63 count is just for me to practice on the use of the for loop. nothing to it, though the effect is different coz it doesn't allow the sequence to repeat. How to simulate now the switch/button in MikroC simulator? in MPLAB, i used the stimulus editor? MikroC got one or its equivalent? tnx for any help again.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top