//=================================
//P3^0; forward and reverse
//P3^1; speed increase
//P3^2;
deceleration //P3^3; stop
#include
#define uint unsigned int
#define uchar unsigned char
sbit rl=P3^0;//forward and reverse
sbit add=P3^1;//speed increase
sbit sub=P3^2;//deceleration
sbit stop=P3^3;//stop
uchar num1,num2,flag1,flag2,flag3,n;
uchar code table1[]={0x08,0x0c,0x04,0x06,0x02,0x03,0x01,0x09};//forward table
uchar code table2[]={0x09,0x01,0x03,0x02,0x06,0x04,0x0c,0x08};//reversal table
//motor rotation table
void delay(uint z);
void keyscan();
void main()
{ uchar i;
n=50;
TMOD=0x01;
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
ET0=1;
EA=1;
TR0=1;
while(1)
{
keyscan();
if(!flag3)
{ if(flag1==1)
{flag1=0;
if(flag2==0)
P1=table1[i];
else
{P1=0;
P1=table2[i];}
i++;
if(i>8)
i=0;
}
}
}
}
//========================
void delay(uint z)
{
uint x;
uchar y;
for(x=0;x
}
//====================
void timer0() interrupt 1
{
TH0=(65536- 10000)/256;
TL0=(65536-10000)%256;
num1++;
if(num1==n)
{num1=0;flag1=1;}
}
//================
void keyscan()
{
if(rl==0)
delay(10);
if(rl==0)
{
while(!rl);
flag2++ ;
flag3=0;
if(flag2>1)
flag2=0;
}
if(add==0)
delay(10);
if(add==0)
{
while(!add);
n=n++;
if(n> 80)
n=80;
}
if(sub==0)
delay(10);
if(sub==0)
{
while(!sub);
n=n--;
if(n<10)
n=10;
}
if(stop==0)
delay(10);
if(stop==0)
{
while(!stop);
P1=0;
flag3=1;
}
}
Previous article:DC motor forward and reverse rotation and speed control
Next article:Digital clock program for microcontroller
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- FAQ Analog Front End and Sensors
- Disassembly of an eight-year-old laptop battery!
- Design of greenhouse temperature and humidity monitoring and alarm system based on zigbee
- Keysight Material Dielectric Constant Test Method - Just Read the Content
- Sound pressure, sound intensity and sound power
- Proteus MSP430 MCU simulation example 8-2-bit digital tube countdown
- The TouchGFX Designer is a real pain
- How to implement analog serial communication with TI MSP430
- ffmpeg port on at91sam9261ek
- How to understand the automatic reload function of the timer