|
#include <intrins.h>
#include <REGX51.H>
sbit PWM = P1^0;
sbit PWM2 = P0^1;
unsigned char counter,angle,counter2,angle2;
void Delay3000ms() //@11.0592MHz
{
unsigned char i, j, k;
_nop_();
_nop_();
i = 127;
j = 18;
k = 107;
do
{
do
{
while (--k);
} while (--j);
} while (--i);
}
void delay(unsigned char i)
{
unsigned char j,k;
for(j=i;j>0;j--)
for(k=125;k>0;k--);
}
void Timer1_Init()
{
TMOD = 0x10;
TL1 = 0x33;
TH1 = 0xFE;
TF1 = 0;
TR1 = 1;
ET1 = 1;
EA = 1;
PT1 = 1;
}
void Timer1_Routine() interrupt 3
{
TL1 = 0x33;
TH1 = 0xFE;
counter++;
counter2++;
if (counter >= 40)
{
counter = 0;
}
if (counter2 >= 40)
{
counter2 = 0;
}
if (counter < angle)
{
PWM = 1;
}
else
{
PWM = 0;
}
if (counter2 < angle2)
{
PWM2 = 1;
}
else
{
PWM2 = 0;
}
}
void control ()
{
counter = 0;
angle = 1;
counter2 = 0;
angle2 = 5;
}
void stop ()
{
angle = 0;
angle2 = 0;
}
#endif
#include "control.h"
void main ()
{
Timer1_Init();
control ();
delay(100);
stop();
}
|
|