* ======= PWM speed control program for DC motors ======== */
/*The crystal oscillator adopts 11.0592M, and the generated PWM frequency is about 91Hz */
#include
#include
#define uchar unsigned char
#define uint unsigned int
Sbit en1=P2^0; /* L298 Enable A */
Sbit en2=P2^1; /* L298's Enable B */
Sbit s1=P2^2; /* L298 Input 1 */
Sbit s2=P2^3; /* L298's Input 2 */
Sbit s3=P2^4; /* L298 Input 3 */
Sbit s4=P2^5; /* L298's Input 4 */
Uchar t=0; /* interrupt counter */
Uchar m1=0; /* Motor 1 speed value */
Uchar m2=0; /* Motor 2 speed value */
Uchar tmp1,tmp2; /* Current motor speed value*/
/* Motor control function index-motor number (1, 2); speed-motor speed (-100-100) */
Voidmotor(uchar index, char speed)
{
If(speed)=-100 && speed“=100)
{
If(index==1) /* Processing of motor 1*/
{
M1=abs(speed); /* Take the absolute value of speed*/
If(speed“0) /* The speed value is negative and reversed*/
{
S1=0;
S2=1;
}
Else /* is not negative, then forward */
{
S1=1;
S2=0;
}
}
If(index==2) /* Processing of motor 2*/
{
M2=abs(speed); /* Motor 2 speed control*/
If(speed“0) /* Direction control of motor 2*/
{
S3=0;
S4=1;
}
Else
{
S3=1;
S4=0;
}
}
}
}
Void delay(uint j) /* Simple delay function*/
{
For(j;j"0;j--);
}
Void main()
{
Char i;
TMOD=0x02; /* Set the working mode of T0 to 2 */
TH0=0x9B; /* Initial value of the loaded timer*/
TL0=0x9B;
EA=1; /* open interrupt*/
ET0=1; /* Timer 0 allows interrupt */
TR0=1; /* Start timer 0 */
While(1) /* motor actual control demo */
{
For(i=0;i"=100;i++) /* Forward acceleration*/
{
Motor(1,i);
Motor(2,i);
Delay(5000);
}
For(i=100;i"0;i--) /* Forward rotation deceleration*/
{
Motor(1,i);
Motor(2,i);
Delay(5000);
}
For(i=0;i"=100;i++) /* Inversion acceleration*/
{
Motor(1,-i);
Motor(2,-i);
Delay(5000);
}
For(i=100;i"0;i--) /* Reverse speed reduction*/
{
Motor(1,-i);
Motor(2,-i);
Delay(5000);
}
}
}
Void TImer0() interrupt 1 /* T0 interrupt service routine */
{
If(t==0) /* The new value will be accepted after 1 PWM cycle is completed*/
{
Tmp1=m1;
Tmp2=m2;
}
If(TIf(tt++;
If(t)=100) t=0; /* 1 PWM signal is generated by 100 interrupts*/
}
High efficient charging speed for Sony laptop, stable current outlet can offer power for the laptop at the same time charge the laptop battery. The best choice for your replacement adapter.We can meet your specific requirement of the products, like label design. The plug type is US/UK/AU/EU. The material of this product is PC+ABS. All condition of our product is 100% brand new.
Our products built with input/output overvoltage protection, input/output overcurrent protection, over temperature protection, over power protection and short circuit protection. You can send more details of this product, so that we can offer best service to you!
Adapter For Sony,Charger For Sony,Laptop Charger For Sony ,Sony Laptop Adapter
Shenzhen Waweis Technology Co., Ltd. , https://www.szwaweischarger.com