darrellc
Newbie level 3
delay_us on mikroc
I'm trying to run a servo motor with this program code. I'm using the mikroC basic compiler for PIC. It's over the limit, can't find any way to shorten the program. Can somebody help me? Would appreciate all help.
I tried with Vdelay_ms() and doing it like Vdelay_ms(j), where j = 1.3. Then use j = j + count, where count = 0.01. However it's unable to calculate decimals. I'm just a rookie, don't know much. Hope someone would be able to help. Thanks.
I'm trying to run a servo motor with this program code. I'm using the mikroC basic compiler for PIC. It's over the limit, can't find any way to shorten the program. Can somebody help me? Would appreciate all help.
Code:
//Servo Motor Auto-Mode Test
int i;
void main() {
TRISB = 0;
ADCON1= 0x07;
PORTB = 0;
do {
for(i=0;i<=25;i++){
PORTB = 0x01;
Delay_us(1300);
PORTB = 0x00;
Delay_us(18700);
}
for(i=0;i<=25;i++){
PORTB = 0x01;
Delay_us(1310);
PORTB = 0x00;
Delay_us(18690);
}
for(i=0;i<=25;i++){
PORTB = 0x01;
Delay_us(1320);
PORTB = 0x00;
Delay_us(18680);
}
for(i=0;i<=25;i++){
PORTB = 0x01;
Delay_us(1330);
PORTB = 0x00;
Delay_us(18670);
}
for(i=0;i<=25;i++){
PORTB = 0x01;
Delay_us(1340);
PORTB = 0x00;
Delay_us(18660);
}
for(i=0;i<=25;i++){
PORTB = 0x01;
Delay_us(1350);
PORTB = 0x00;
Delay_us(18650);
}
for(i=0;i<=25;i++){
PORTB = 0x01;
Delay_us(1360);
PORTB = 0x00;
Delay_us(18640);
}
for(i=0;i<=25;i++){
PORTB = 0x01;
Delay_us(1370);
PORTB = 0x00;
Delay_us(18630);
}
for(i=0;i<=25;i++){
PORTB = 0x01;
Delay_us(1380);
PORTB = 0x00;
Delay_us(18620);
}
for(i=0;i<=25;i++){
PORTB = 0x01;
Delay_us(1390);
PORTB = 0x00;
Delay_us(18610);
}
for(i=0;i<=25;i++){
PORTB = 0x01;
Delay_us(1400);
PORTB = 0x00;
Delay_us(18600);
}
for(i=0;i<=25;i++){
PORTB = 0x01;
Delay_us(1410);
PORTB = 0x00;
Delay_us(18590);
}
for(i=0;i<=25;i++){
PORTB = 0x01;
Delay_us(1420);
PORTB = 0x00;
Delay_us(18580);
}
for(i=0;i<=25;i++){
PORTB = 0x01;
Delay_us(1430);
PORTB = 0x00;
Delay_us(18570);
}
for(i=0;i<=25;i++){
PORTB = 0x01;
Delay_us(1440);
PORTB = 0x00;
Delay_us(18560);
}
for(i=0;i<=25;i++){
PORTB = 0x01;
Delay_us(1450);
PORTB = 0x00;
Delay_us(18550);
}
for(i=0;i<=25;i++){
PORTB = 0x01;
Delay_us(1460);
PORTB = 0x00;
Delay_us(18540);
}
for(i=0;i<=25;i++){
PORTB = 0x01;
Delay_us(1470);
PORTB = 0x00;
Delay_us(18530);
}
for(i=0;i<=25;i++){
PORTB = 0x01;
Delay_us(1480);
PORTB = 0x00;
Delay_us(18520);
}
for(i=0;i<=25;i++){
PORTB = 0x01;
Delay_us(1490);
PORTB = 0x00;
Delay_us(18510);
}
for(i=0;i<=25;i++){
PORTB = 0x01;
Delay_us(1500);
PORTB = 0x00;
Delay_us(18500);
}
for(i=0;i<=25;i++){
PORTB = 0x01;
Delay_us(1510);
PORTB = 0x00;
Delay_us(18490);
}
for(i=0;i<=25;i++){
PORTB = 0x01;
Delay_us(1520);
PORTB = 0x00;
Delay_us(18480);
}
for(i=0;i<=25;i++){
PORTB = 0x01;
Delay_us(1530);
PORTB = 0x00;
Delay_us(18470);
}
for(i=0;i<=25;i++){
PORTB = 0x01;
Delay_us(1540);
PORTB = 0x00;
Delay_us(18460);
}
for(i=0;i<=25;i++){
PORTB = 0x01;
Delay_us(1550);
PORTB = 0x00;
Delay_us(18450);
}
for(i=0;i<=25;i++){
PORTB = 0x01;
Delay_us(1560);
PORTB = 0x00;
Delay_us(18440);
}
for(i=0;i<=25;i++){
PORTB = 0x01;
Delay_us(1570);
PORTB = 0x00;
Delay_us(18430);
}
for(i=0;i<=25;i++){
PORTB = 0x01;
Delay_us(1580);
PORTB = 0x00;
Delay_us(18420);
}
for(i=0;i<=25;i++){
PORTB = 0x01;
Delay_us(1590);
PORTB = 0x00;
Delay_us(18410);
}
for(i=0;i<=25;i++){
PORTB = 0x01;
Delay_us(1600);
PORTB = 0x00;
Delay_us(18400);
}
for(i=0;i<=25;i++){
PORTB = 0x01;
Delay_us(1610);
PORTB = 0x00;
Delay_us(18390);
}
for(i=0;i<=25;i++){
PORTB = 0x01;
Delay_us(1620);
PORTB = 0x00;
Delay_us(18380);
}
for(i=0;i<=25;i++){
PORTB = 0x01;
Delay_us(1630);
PORTB = 0x00;
Delay_us(18370);
}
for(i=0;i<=25;i++){
PORTB = 0x01;
Delay_us(1640);
PORTB = 0x00;
Delay_us(18360);
}
for(i=0;i<=25;i++){
PORTB = 0x01;
Delay_us(1650);
PORTB = 0x00;
Delay_us(18350);
}
for(i=0;i<=25;i++){
PORTB = 0x01;
Delay_us(1660);
PORTB = 0x00;
Delay_us(18340);
}
for(i=0;i<=25;i++){
PORTB = 0x01;
Delay_us(1670);
PORTB = 0x00;
Delay_us(18330);
}
for(i=0;i<=25;i++){
PORTB = 0x01;
Delay_us(1680);
PORTB = 0x00;
Delay_us(18320);
}
for(i=0;i<=25;i++){
PORTB = 0x01;
Delay_us(1690);
PORTB = 0x00;
Delay_us(18310);
}
for(i=0;i<=25;i++){
PORTB = 0x01;
Delay_us(1700);
PORTB = 0x00;
Delay_us(18300);
}
} while(1);
}
I tried with Vdelay_ms() and doing it like Vdelay_ms(j), where j = 1.3. Then use j = j + count, where count = 0.01. However it's unable to calculate decimals. I'm just a rookie, don't know much. Hope someone would be able to help. Thanks.