这个程序怎么调速,希望大神们可以帮我写一下。。。不会在这个红外控制里面加,自己写的无法进入中断
时间:10-02
整理:3721RD
点击:
#include "REG52.H"
#define const_interrupt_time 792
#define uchar unsigned char
#define uint unsigned int
void initial_myself();
void initial_peripheral();
void delay_short(uint uiDelayShort);
void delay_long(uint uiDelaylong);
void Int0();
void detectorIR();
void run();
sbit IR_sr=P3^2;
sbit P1_0=P1^0;
sbit P1_1=P1^1;
sbit P1_2=P1^2;
sbit P1_3=P1^3;
uchar ucMotorStep=0;
uchar ucdata;
void main()
{
initial_myself();
delay_long(100);
initial_peripheral();
while(1)
{
detectorIR();
run();
}
}
void detectorIR()
{
if(ucdata==0x73) ucMotorStep=1;
else if(ucdata==0x56) ucMotorStep=2;
else if(ucdata==0x7b) ucMotorStep=3;
else if(ucdata==0x52) ucMotorStep=4;
else if(ucdata==0x71) ucMotorStep=5;
else ucMotorStep=5;
}
void run()
{
switch(ucMotorStep)
{
case 1:
P1_0=1;
P1_1=0;
P1_2=1;
P1_3=0;
break;
case 2:
P1_0=0;
P1_1=1;
P1_2=0;
P1_3=1;
break;
case 3:
P1_0=0;
P1_1=0;
P1_2=1;
P1_3=0;
break;
case 4:
P1_0=1;
P1_1=0;
P1_2=0;
P1_3=0;
break;
case 5:
P1_0=0;
P1_1=0;
P1_2=0;
P1_3=0;
break;
}
}
void Int0() interrupt 0
{
uchar i,j;
EX0=0;
i=10;
while(i--)
{
TH0=(65535-const_interrupt_time)/256;
TL0=(65535-const_interrupt_time)%256;
TR0=1;
while(!TF0);
TF0=0;
TR0=0;
while(IR_sr)
{
EX0=1;
return;
}
}
while(!IR_sr);
j=5;
while(j--)
{
TH0=(65535-const_interrupt_time)/256;
TL0=(65535-const_interrupt_time)%256;
TR0=1;
while(!TF0);
TF0=0;
TR0=0;
while(!IR_sr)
{
EX0=1;
return;
}
}
while(IR_sr);
for(i=0;i<4;i++)
{
for(j=0;j<8;j++)
{
while(!IR_sr);
TH0=(65535-const_interrupt_time)/256;
TL0=(65535-const_interrupt_time)%256;
TR0=1;
while(!TF0);
TF0=0;
TR0=0;
if(IR_sr)
{
ucdata|=0x80;
while(IR_sr);
}
ucdata>>=1;
}
}
EX0=1;
return;
}
void delay_long(unsigned int uiDelayLong)
{
unsigned int i;
unsigned int j;
for(i=0;i<uiDelayLong;i++)
{
for(j=0;j<500;j++)
{
;
}
}
}
void initial_myself()
{
TMOD=0x01;
}
void initial_peripheral()
{
ET0=1;
IT0=1;
EX0=1;
EA=1;
}
#define const_interrupt_time 792
#define uchar unsigned char
#define uint unsigned int
void initial_myself();
void initial_peripheral();
void delay_short(uint uiDelayShort);
void delay_long(uint uiDelaylong);
void Int0();
void detectorIR();
void run();
sbit IR_sr=P3^2;
sbit P1_0=P1^0;
sbit P1_1=P1^1;
sbit P1_2=P1^2;
sbit P1_3=P1^3;
uchar ucMotorStep=0;
uchar ucdata;
void main()
{
initial_myself();
delay_long(100);
initial_peripheral();
while(1)
{
detectorIR();
run();
}
}
void detectorIR()
{
if(ucdata==0x73) ucMotorStep=1;
else if(ucdata==0x56) ucMotorStep=2;
else if(ucdata==0x7b) ucMotorStep=3;
else if(ucdata==0x52) ucMotorStep=4;
else if(ucdata==0x71) ucMotorStep=5;
else ucMotorStep=5;
}
void run()
{
switch(ucMotorStep)
{
case 1:
P1_0=1;
P1_1=0;
P1_2=1;
P1_3=0;
break;
case 2:
P1_0=0;
P1_1=1;
P1_2=0;
P1_3=1;
break;
case 3:
P1_0=0;
P1_1=0;
P1_2=1;
P1_3=0;
break;
case 4:
P1_0=1;
P1_1=0;
P1_2=0;
P1_3=0;
break;
case 5:
P1_0=0;
P1_1=0;
P1_2=0;
P1_3=0;
break;
}
}
void Int0() interrupt 0
{
uchar i,j;
EX0=0;
i=10;
while(i--)
{
TH0=(65535-const_interrupt_time)/256;
TL0=(65535-const_interrupt_time)%256;
TR0=1;
while(!TF0);
TF0=0;
TR0=0;
while(IR_sr)
{
EX0=1;
return;
}
}
while(!IR_sr);
j=5;
while(j--)
{
TH0=(65535-const_interrupt_time)/256;
TL0=(65535-const_interrupt_time)%256;
TR0=1;
while(!TF0);
TF0=0;
TR0=0;
while(!IR_sr)
{
EX0=1;
return;
}
}
while(IR_sr);
for(i=0;i<4;i++)
{
for(j=0;j<8;j++)
{
while(!IR_sr);
TH0=(65535-const_interrupt_time)/256;
TL0=(65535-const_interrupt_time)%256;
TR0=1;
while(!TF0);
TF0=0;
TR0=0;
if(IR_sr)
{
ucdata|=0x80;
while(IR_sr);
}
ucdata>>=1;
}
}
EX0=1;
return;
}
void delay_long(unsigned int uiDelayLong)
{
unsigned int i;
unsigned int j;
for(i=0;i<uiDelayLong;i++)
{
for(j=0;j<500;j++)
{
;
}
}
}
void initial_myself()
{
TMOD=0x01;
}
void initial_peripheral()
{
ET0=1;
IT0=1;
EX0=1;
EA=1;
}
大神们帮个忙,不会写了
这么给程序谁给你改啊? 还不如你说什么要求,大家给你写新的方便