/*Schrittmotor Vollschritt
01
*/
#include
<stdio.h>
#include <reg517.h>
void wait1ms(unsigned int
time); //Prototyp
Wartezeit
void main() //Anfang Hauptprogramm
{
int rechts[4]; // Feldvariable für 4 Werte
int links[4]; // Feldvariable für 4 Werte
int wartezeit=5; // Zeit zwischen den Schritten in ms
int i;
rechts[0]=0x05; // Werte für
Ausgabe an Port 4.0 … 4.3
rechts[1]=0x09; // rechtlauf
rechts[2]=0x0a;
rechts[3]=0x06;
links[0]=0x06; // Werte für Ausgabe an Port 4.0 … 4.3
links[1]=0x0a; // linkslauf
links[2]=0x09;
links[3]=0x05;
while(1) {
if
(P50==0) { // umschaltung
recht, links, abfrage Port 5
for(i=0;i<=4;i++) {
P4=rechts[i]; // ausgabe auf Port4
wait1ms(wartezeit);
}
}
Else {
for(i=0;i<=4;i++) {
P4=links[i]; // ausgabe auf Port4
wait1ms(wartezeit);
}
}
} // Ende While
} //Ende Hauptprogramm
void wait1ms(unsigned int time) { //Funktion
Wartezeit
int k,i;
for(k=0;k<time;k++) //Schleife Anzahl ms
{
for(i=0;i<480;i++); //Schleife läuft 1ms
}
}