- helps you find a similar problem, you can read: https://ask.csdn.net/questions/7730104 < / font > < / a > < / li > < li > you also can refer to this article: Method principle of measuring capacitance value by 51 microcontroller and some solutions to the problems
-
51 MCU control 42 step motor -- program implementation(interrupt PWM/ delay function)
program part
part may be able to solve your problem, You can read the following carefully or jump to the source blog:
program implementation is keil software written in c language program, with two ideas written, can be realized, the following are posted out.
The first is the pulse with the delay function.#include < reg51.h>
#define uint unsigned intvoid delayms(uint);
sbit ENA=P1^0;
sbit DIR=P1^1;
sbit PWM=P1^2;void main()
{
ENA = 0;
DIR = 0;
PWM = 0;
while(1)
{
PWM = ~PWM;
delayms(1);
}
}void delayms(uint xms)
{
uint i,j;
for(i=xms; i> 0; I -) < br / > for(j=110; j> 0; J -);
}
The second, with 51 MCU T1 timer to achieve the pulse.
#include < reg51.h>
#define uint unsigned intunsigned char timer1;
sbit DIR=P1^0;
sbit ENA=P1^1;
sbit PWM=P1^2;void system_Ini()
{
TMOD = 0x00; / / 13 » I < br / > TH1 = 0xfd; //253
TL1 = 0x06; //6
EA = 1;
ET1 = 1;
TR1 = 1;
}/*********************************************************
2^13=8192
253 32=8096
8096+6=8102
8192-8102=90
12 (1/11059200)= 1.09us
*********************************************************/main()
{
system_Ini();
DIR = 0;
ENA = 0;
while(1)
{
if(timer1==40)
{
timer1=0;
}
if(timer1< 20)
{
PWM=0;
}
else
{
PWM=1;
}
}
}void Ti1(void) interrupt 3
{
TH1 = 0xfd;
TL1 = 0x06;
timer1++;
}
If you have solved the problem, I hope you can share the solution, write a blog about it, and put a link to it in the comments section to help more people. ^-^ /div>