#include
// Define new types
typedef unsigned char uchar;
typedef unsigned int uint;
// Define P3 pins
sbit Inc = P3^4;
sbit Dec = P3^5;
sbit Dir = P3^6;
sbit PWM = P3^7;
void delay(uint);
void main(void)
{
int speed;
// Select initial direction and speed.
if (Dir) //Dir = 1 anti clockwise;Dir = 0 clockwise speed = 400; //T(PWM) = 0.012s,f = 83.3Hz else
speed = 100;
// Main control loop
while(1)
{
if(Dir) //anti_clockwise
{
if(!Inc)
// Increase speed
speed = speed > 0 ? speed - 1 : 0;
if(!Dec)
// Decrease speed
speed = speed
// Drive a PWM signal out.
PWM=1;
delay(speed);
PWM=0;
delay(500-speed);
}
else //clockwise
{
if(!Inc)
// Increase speed
speed = speed
// Decrease speed
speed = speed > 0 ? speed - 1 : 0;
// Drive a PWM signal out.
PWM=1;
delay(speed);
PWM=0;
delay(500-speed);
}
}
}
void delay(uint j)
{ for(; j>0; j--)
{
//__no_operation();
}
}
#include
// Define new types
typedef unsigned char uchar;
typedef unsigned int uint;
// Define P3 pins
sbit Inc = P3^4;
sbit Dec = P3^5;
sbit Dir = P3^6;
sbit PWM = P3^7;
void delay(uint);
void main(void)
{
int speed;
// Select initial direction and speed.
if (Dir) //Dir = 1 anti clockwise;Dir = 0 clockwise speed = 400; //T(PWM) = 0.012s,f = 83.3Hz else
speed = 100;
// Main control loop
while(1)
{
if(Dir) //anti_clockwise
{
if(!Inc)
// Increase speed
speed = speed > 0 ? speed - 1 : 0;
if(!Dec)
// Decrease speed
speed = speed
// Drive a PWM signal out.
PWM=1;
delay(speed);
PWM=0;
delay(500-speed);
}
else //clockwise
{
if(!Inc)
// Increase speed
speed = speed
// Decrease speed
speed = speed > 0 ? speed - 1 : 0;
// Drive a PWM signal out.
PWM=1;
delay(speed);
PWM=0;
delay(500-speed);
}
}
}
void delay(uint j)
{ for(; j>0; j--)
{
//__no_operation();
}
}