51单片机和l298n控制步进电机想实现(收到几个脉冲步进电机转过几个固定角度)


#include
#include"delay.h"
#define uchar unsigned char
#define uint unsigned int
uchar upstep_table[]={0x07,0x0b,0x0d,0x0e};

 void upturn(uint,uint);

uint read()
{uint N;

                                                                                                                                                                    uchar tl, th1, th2;
                                                                                                                                                                    while(1)
                                                                                                                                                                   {                                  
                                                                                                                                                                    th1=TH0;                       //读出数据手套所收集的数据
                                                                                                                                                                    tl=TL0;

                                                                                                                                                                    th2=TH0;

                                                                                                                                                                    if(th1==th2)  break;
                                                                                                                                                                                        }


                                                                                                                                                                     N=th1*256+tl;

                                                                                                                                                                     return N;
                                                                                                                                                                           }                                    

void upturn( uint i, uint j)
{

    while(j--)
     {
        for(i=0;i<8;i++)
         {
              P1=upstep_table[i];
                 delay(5);
                                                 }
                                                         }
                     while(1);
                                    }

void main()
{ uint num;

TMOD=0x05;
 TH0=0; 
 TL0=0;
 TR0=1;

                                                                                                                                                                                                                                                                                                                              { 

 num=read();

while(1)
{             read();
  delay(5);
                upturn(0,num);}

                                                                             }
                                                                                             }

https://zhidao.baidu.com/question/1703604028968704340.html