- #include
- #defineucharunsignedchar
- #defineuintunsignedint
- sbit INPUT1=P1^0;//操控口
- sbit INPUT2=P1^1;
- sbit INPUT3=P1^2;
- sbit INPUT4=P1^3;
- sbit ENA=P1^4;//发生PWM波
- sbit ENB=P1^5;
- uint MA=0,MB=0;
- uint SpeedA=20;//50%占空比
- uint SpeedB=20;
- voiddelay(uint z){
- uint x,y;
- for(x=z;x>0;x–)
- for(y=125;y>0;y–);
- }
- voidmain(void)
- {
- L298N_init();
- while(1){}
- }
- voidL298N_init(void)
- {
- delay(1000);
- delay(1000);
- INPUT1=1;INPUT2=0;
- INPUT3=1;INPUT4=0;//电机停此
- TH0=0xF4;
- TL0=0x48;
- TH1=0xF4;
- TL1=0x48;
- TMOD=0x11;
- TR0=1;
- TR1=1;
- ET0=1;
- ET1=1;
- EA=1;
- }
- voidtime0_int()interrupt 1using1
- {
- TR0=0;
- TH0=0xF4;
- TL0=0x48;
- MA++;
- if(MA
- ENA=1;
- }
- elseENA=0;
- if(MA==40){
- MA=0;
- }
- TR0=1;
- }
- voidtime1_int()interrupt 3using1
- {
- TR1=0;
- TH1=0xF4;
- TL1=0x48;
- MB=MB+1;
- if(MB
- ENB=1;
- }
- elseENB=0;
- if(MB==40){
- MB=0;
- }
- TR1=1;
- }
L298N直流步进电机驱动直流电机程序
#includereg51.h>#defineucharunsignedchar#defineuintunsignedintsbitINPUT1=P1^0;//控制口sbitINPUT2=P1^
声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/qiche/275276.html