Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int lastState[2]={0,0};
- int words[4]={0x08,0x02,0x01,0x04};
- //int Owords[1][4]={0x04,0x02,0x01};
- //MoveMotor(x or y, number of 90d steps to make, + or - right up or left down)
- void moveMotor(char motor,int steps,char direction){
- int i;
- int axis=0;
- int dir=1;
- // if(motor=='y')
- if(direction=='-')
- dir=-1;
- for(i=0;i<steps;i++){
- if(motor=='x'){
- int nextState= (dir+lastState[0]+4)%4;
- PORTB=words[nextState];
- lastState[0]=nextState;
- }
- else{
- int nextState= (dir+lastState[1]+4)%4;
- PORTA=words[nextState];
- lastState[1]=nextState;
- }
- delay_ms(100);
- }
- }
- void main() {
- int i;
- TRISB=0X00;
- TRISA=0X00;
- PORTB=0X00;
- PORTA=0x00;
- while(1 ){
- moveMotor('x',8,'+');
- delay_ms(500);
- moveMotor('y',8,'+');
- delay_ms(500);
- moveMotor('x',8,'-');
- delay_ms(500);
- moveMotor('y',8,'-');
- delay_ms(500);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement