|
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
bit D_electrical_1;
sbit D_ctrl_1=P0^0;
sbit input_6=P2^6;
uint init_v_H;
uint init_v_L;
uint init_v;
uchar *p;
uchar TH,TL;
#define i 1950.0/180.0
void delay(uint x)
{
uint y;
while(x--)
{
for(y=112;y>0;y--);
}
}
uint T0_Init_Value_H(float degree,float us_per_degree)
{
uint width=(unsigned int)(degree*us_per_degree);
uint init_v_H=65536-width;
return init_v_H;
}
uint T0_Init_Value_L(uint init_v_H)
{
unsigned int init_v_L=65536-init_v_H+45536;
return init_v_L;
}
void Init_T0()
{
TMOD=0x01;
ET0=1;
EA=1;
}
void PWM_duoji_1(float pwm1)
{
init_v_H=T0_Init_Value_H(pwm1,i);
init_v_L=T0_Init_Value_L(init_v_H);
p=(uchar*)(&init_v_H);
TH0=*P;
TH1=*P;
P++;
TL0=*P;
TL1=*P;
D_ctrl_1=D_electrical_1=1;
TR0=1;
}
void main()
{
Init_T0();
while(1);
{
if(!input_6)
{
PWM_duoji_1(180.0);
}
}
}
void T0_Server_1() interrupt 1
{
D_electrical_1=!D_electrical_1;
if(D_electrical_1)
{
init_v=init_v_H;
}
else
{
init_v=init_v_L;
}
p=(uchar*)(&init_v);
TH=*p;
p++;
TL=*p;
D_ctrl_1=D_electrical_1;
TH0=TH;
TL0=TL;
}
|
-
1.png
(35.63 KB, 下載次數: 36)
下載附件
2020-5-5 11:55 上傳
|