Single chip microcomputer four-wire stepper motor driver

Publisher:AsawenLatest update time:2022-01-15 Source: eefocusKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

MCU four-wire stepper motor driver function:


When SW1 is pressed, the stepper motor rotates forward, and when SW2 is pressed, the stepper motor rotates reversely. The rotation speed and rotation angle of each pulse can be adjusted arbitrarily according to the source code.

insert image description here
insert image description here

insert image description here

The program reference source code is as follows:


/C language program:/

#include // Available very successfully.

#define uchar unsigned char

#define uint unsigned int


uchar table_begin;

uint maichong; //pulse

uchar zhuansu; //speed

uchar flag; //direction

sbit key_fuwei=P3^0; //Reset key

sbit key_z=P3^1; //Forward key

sbit key_f=P3^2; //Reverse key

sbit key_jia=P3^3; //Accelerator key

sbit key_jian=P3^6; //deceleration key


sbit A1=P2^0;

sbit A2=P2^1;

sbit A3=P2^2;

sbit A4=P2^3;

void display();

void delayms(xms);


void delay(uchar x)

{undefined

uchar i,j; //delay

for(i=0;ifor(j=100;j>0;j–);

}

void fuwei(void) //reset

{undefined

flag=2;

zhuansu=0;

}

/*void Display(void) //display

{undefined

unsigned char b1, b2;

b1=zhuansu/10;

b2=zhuansu%10;

if(flag == 0) //0

P0=0x71; //Display F

else

P0=0x79;

A1=0;

delayms(3);

A1=1;


    P0=0x40;

    A2=0; //Display--

    delayms(3);

    A2=1;


    P0=table2[b1];

    A3=0; //Display tens digit

    delayms(3);

    A3=1;


    P0=table2[b2];

    A4=0;

    delayms(3); //display the units digit

    A4=1;

1

2

3

4

5

6

7

8

9

10

11

12

13

14

} */


void display()

{undefined

uchar b1,b2,b3,b4;

if(flag0)

P0=0x71; //Display F

else

P0=0x79;

if(flag1)

P0=0x7c; //display b

else

P0=0x71;

b1=10;

b2=0x3f;

b3=zhuansu/10;

b4=zhuansu%10;

//P0=table2;

A1=0; //P2.0

delay(1);

A1=1;

P0=b2;

A2=0; //P2.1

delay(1);

A2=1;

P0=table2[b3];

A3=0; //P2.3

delay(1);

A3=1;

P0=table2[b4];

A4=0; //P2.4

delay(1);

A4=1;

}


void key() //Key scan

{undefined

if(key_fuwei0)

{

delay(5);

if(key_fuwei0)

fuwei();

}

if(key_z0)

{

delay(5);

if(key_z0)

{undefined

flag=0;

zhuansu=10;

while(key_z0);

}

}

if(key_f0)

{undefined


delay(5);

if(key_f0)

{

flag=1;

zhuansu=10;

while(key_f0);

}

}

if(key_jia0)

{

delay(5);

if(key_jia0)

{undefined

zhuansu++;

if(zhuansu21)

zhuansu=20;

while(key_jia0);

}

}

if(key_jian0)

{

delay(5);

if(key_jian0)

{undefined

zhuansu–;

if(zhuansu<=0)

zhuansu=0;

while(key_jian==0);

}

}

}

void dispose() //Pulse function

{undefined

switch (zhuansu)

{undefined


case 0: flag=2; break;

case 1: maichong=300; break;

case 2: maichong=295; break;

case 3: maichong=290; break;

case 4: maichong=280; break;

case 5: maichong=260; break;

case 6: maichong=240; break;

case 7: maichong=200; break;

case 8: maichong=180; break;

case 9: maichong=160; break;

case 10: maichong=120; break;

case 11: maichong=80; break;

case 12: maichong=70; break;

case 13: maichong=60; break;

case 14: maichong=40; break;

case 15: maichong=35; break;

case 16: maichong=30; break;

case 17: maichong=25; break;

case 18: maichong=20; break;

case 19: maichong=15; ​​break;

case 20: maichong=10; break;


}

if(flag0)

table_begin=0;

else

if(flag1)

table_begin=4;

}

void zhuandong(void)

{undefined

uint i,j;

if(zhuansu>0&&zhuansu<=20)

{undefined

for(j=0+table_begin;j<4+table_begin;j++)

{undefined

P1=table1[j];

for(i=0;idisplay();

}

}

}

……………………


Keywords:MCU Reference address:Single chip microcomputer four-wire stepper motor driver

Previous article:51 MCU 12864 large LCD screen Tetris
Next article:MCU drives DS1302 clock + 1602 LCD

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号