Potřebujete pomoci zkrátit program spustit servomotoru.

D

darrellc

Guest
Snažím se spustit servo motor s tímto programem kód.Jsem pomocí mikroC základní kompilátor pro PIC.Je to nad limit, nemůže najít nějaký způsob, jak zkrátit program.Může někdo pomoci mne?Chtěl bych ocenit všechny nápovědy.

Kód:

/ / Servomotoru Auto-Mode Testint i;void main () (

TRISB = 0;

ADCON1 = 0x07;

PORTB = 0;do (

pro (i = 0; i <= 25; i ) (

PORTB = 0x01;

Delay_us (1300);

PORTB = 0x00;

Delay_us (18700);

)

pro (i = 0; i <= 25; i ) (

PORTB = 0x01;

Delay_us (1310);

PORTB = 0x00;

Delay_us (18690);

)

pro (i = 0; i <= 25; i ) (

PORTB = 0x01;

Delay_us (1320);

PORTB = 0x00;

Delay_us (18680);

)

pro (i = 0; i <= 25; i ) (

PORTB = 0x01;

Delay_us (1330);

PORTB = 0x00;

Delay_us (18670);

)

pro (i = 0; i <= 25; i ) (

PORTB = 0x01;

Delay_us (1340);

PORTB = 0x00;

Delay_us (18660);

)

pro (i = 0; i <= 25; i ) (

PORTB = 0x01;

Delay_us (1350);

PORTB = 0x00;

Delay_us (18650);

)

pro (i = 0; i <= 25; i ) (

PORTB = 0x01;

Delay_us (1360);

PORTB = 0x00;

Delay_us (18640);

)

pro (i = 0; i <= 25; i ) (

PORTB = 0x01;

Delay_us (1370);

PORTB = 0x00;

Delay_us (18630);

)

pro (i = 0; i <= 25; i ) (

PORTB = 0x01;

Delay_us (1380);

PORTB = 0x00;

Delay_us (18620);

)

pro (i = 0; i <= 25; i ) (

PORTB = 0x01;

Delay_us (1390);

PORTB = 0x00;

Delay_us (18610);

)

pro (i = 0; i <= 25; i ) (

PORTB = 0x01;

Delay_us (1400);

PORTB = 0x00;

Delay_us (18600);

)

pro (i = 0; i <= 25; i ) (

PORTB = 0x01;

Delay_us (1410);

PORTB = 0x00;

Delay_us (18590);

)

pro (i = 0; i <= 25; i ) (

PORTB = 0x01;

Delay_us (1420);

PORTB = 0x00;

Delay_us (18580);

)

pro (i = 0; i <= 25; i ) (

PORTB = 0x01;

Delay_us (1430);

PORTB = 0x00;

Delay_us (18570);

)

pro (i = 0; i <= 25; i ) (

PORTB = 0x01;

Delay_us (1440);

PORTB = 0x00;

Delay_us (18560);

)

pro (i = 0; i <= 25; i ) (

PORTB = 0x01;

Delay_us (1450);

PORTB = 0x00;

Delay_us (18550);

)

pro (i = 0; i <= 25; i ) (

PORTB = 0x01;

Delay_us (1460);

PORTB = 0x00;

Delay_us (18540);

)

pro (i = 0; i <= 25; i ) (

PORTB = 0x01;

Delay_us (1470);

PORTB = 0x00;

Delay_us (18530);

)

pro (i = 0; i <= 25; i ) (

PORTB = 0x01;

Delay_us (1480);

PORTB = 0x00;

Delay_us (18520);

)

pro (i = 0; i <= 25; i ) (

PORTB = 0x01;

Delay_us (1490);

PORTB = 0x00;

Delay_us (18510);

)

pro (i = 0; i <= 25; i ) (

PORTB = 0x01;

Delay_us (1500);

PORTB = 0x00;

Delay_us (18500);

)

pro (i = 0; i <= 25; i ) (

PORTB = 0x01;

Delay_us (1510);

PORTB = 0x00;

Delay_us (18490);

)

pro (i = 0; i <= 25; i ) (

PORTB = 0x01;

Delay_us (1520);

PORTB = 0x00;

Delay_us (18480);

)

pro (i = 0; i <= 25; i ) (

PORTB = 0x01;

Delay_us (1530);

PORTB = 0x00;

Delay_us (18470);

)

pro (i = 0; i <= 25; i ) (

PORTB = 0x01;

Delay_us (1540);

PORTB = 0x00;

Delay_us (18460);

)

pro (i = 0; i <= 25; i ) (

PORTB = 0x01;

Delay_us (1550);

PORTB = 0x00;

Delay_us (18450);

)

pro (i = 0; i <= 25; i ) (

PORTB = 0x01;

Delay_us (1560);

PORTB = 0x00;

Delay_us (18440);

)

pro (i = 0; i <= 25; i ) (

PORTB = 0x01;

Delay_us (1570);

PORTB = 0x00;

Delay_us (18430);

)

pro (i = 0; i <= 25; i ) (

PORTB = 0x01;

Delay_us (1580);

PORTB = 0x00;

Delay_us (18420);

)

pro (i = 0; i <= 25; i ) (

PORTB = 0x01;

Delay_us (1590);

PORTB = 0x00;

Delay_us (18410);

)

pro (i = 0; i <= 25; i ) (

PORTB = 0x01;

Delay_us (1600);

PORTB = 0x00;

Delay_us (18400);

)

pro (i = 0; i <= 25; i ) (

PORTB = 0x01;

Delay_us (1610);

PORTB = 0x00;

Delay_us (18390);

)

pro (i = 0; i <= 25; i ) (

PORTB = 0x01;

Delay_us (1620);

PORTB = 0x00;

Delay_us (18380);

)

pro (i = 0; i <= 25; i ) (

PORTB = 0x01;

Delay_us (1630);

PORTB = 0x00;

Delay_us (18370);

)

pro (i = 0; i <= 25; i ) (

PORTB = 0x01;

Delay_us (1640);

PORTB = 0x00;

Delay_us (18360);

)

pro (i = 0; i <= 25; i ) (

PORTB = 0x01;

Delay_us (1650);

PORTB = 0x00;

Delay_us (18350);

)

pro (i = 0; i <= 25; i ) (

PORTB = 0x01;

Delay_us (1660);

PORTB = 0x00;

Delay_us (18340);

)

pro (i = 0; i <= 25; i ) (

PORTB = 0x01;

Delay_us (1670);

PORTB = 0x00;

Delay_us (18330);

)

pro (i = 0; i <= 25; i ) (

PORTB = 0x01;

Delay_us (1680);

PORTB = 0x00;

Delay_us (18320);

)

pro (i = 0; i <= 25; i ) (

PORTB = 0x01;

Delay_us (1690);

PORTB = 0x00;

Delay_us (18310);

)

pro (i = 0; i <= 25; i ) (

PORTB = 0x01;

Delay_us (1700);

PORTB = 0x00;

Delay_us (18300);

)

) While (1);

)
 
Dobrý den.

Nemám tušení, co tento program je dobrý, ale já si navrhuje malou velikost optimalizaci, jako je tento:
Kód:/ / Servomotoru Auto-Mode Testint i, j;void main ()

(

TRISB = 0;

ADCON1 = 0x07;

PORTB = 0;dělat

(

pro (j = 1300; j <= 1700; j = 10)

(

pro (i = 0, i <= 25; i )

(

PORTB = 0x01;

Delay_us (j);

PORTB = 0x00;

Delay_us (20000-j);

)

)

) While (1);

)

 
Věc je, že jsem schopen dát do proměnné 'Delay_us ()'.Jsem pomocí mikroC PIC kompilátor.

 
Jak 'bout to pak:
Kód:

/ / Servomotoru Auto-Mode Testint i, j;neplatné Delay_10us (int dly)

(

while (- dly> 0)

(

Delay_us (10);

)

)void main ()

(

TRISB = 0;

ADCON1 = 0x07;

PORTB = 0;dělat

(

pro (j = 130; j <= 170; j )

(

pro (i = 0; i <= 25; i )

(

PORTB = 0x01;

Delay_10us (j);

PORTB = 0x00;

Delay_10us (2000-j);

)

)

) While (1);

)
 
Hmm, chybové hlášení 'Delay_10us Identifikátor znovu definovat'.Nicméně jsem se snažil změnit název funkce a to se podařilo sestavit!Teď budu muset vyzkoušet si to na můj motor později.

<img src="http://www.edaboard.com/images/smiles/icon_biggrin.gif" alt="Very Happy" border="0" />

Díky!

 

Welcome to EDABoard.com

Sponsor

Back
Top