|
#include <REGX52.H>
typedef unsigned int u16;
typedef unsigned char u8;
u8 ReceiveData=0;
sbit Motor = P2^7;
void UartInit()
{
SCON=0x50;
TMOD=0x20;
PCON=0x80;
TH1=0xF3;
TL1=0xF3;
ES=1;
EA=1;
TR1=1;
}
void Delay(u8 n)
{
unsigned int i,j;
for(j=n;j>0;j--)
for(i=112;i>0;i--);
}
void main()
{
UartInit();
Motor = 0;
while(1)
{
while(ReceiveData == 0)
{
Motor = 0;
}
else
{
Motor = 1;
Delay(20000);
Motor = 0;
Delay(10000 - ReceiveData*100);
}
}
}
void Uart() interrupt 4
{
ReceiveData = SBUF;
RI = 0;
SBUF = ReceiveData;
while(!TI);
TI = 0;
}
哪位佬能够解答一下吗?按理来说,我的程序应该是一开始motor为0电机为0,不转动的。但是这个程序一烧录进去就开始转动,还有就是为什么我串口发送数据没有任何反应?
连线如下:
P2.7与IN1相连,直流电机与OUT1和VCC相连接。 |
|