|
|
#include<reg52.h>
sbit hui = P1^0;
sbit dir = P1^1; //這是電機(jī)的正反轉(zhuǎn)
sbit shineng = P1^2; //電機(jī)使能端
int qw =9;
char quanshu = 0; //保存旋轉(zhuǎn)的圈數(shù)
int main()
{
int counter = 0;
int i; int j;
for( i = 0;i<200;i++)
{
for( j= 0;j<100;j++)
{
;;
}
}
TMOD = 0x21;
TH0 = (65535-qw)/256;
TL0 = (65535-qw)%256;
TH1 = 0xfd;
TL1 = 0xfd;
SM0 = 0; //串口SM0和SM1是工作方式選擇位
SM1 = 1;
REN = 1; //串口允許接受
EA = 1; //總中斷
ES = 1; //串口中斷
TR1 = 1; //打開定時(shí)器1
TR0 = 1;
shineng = 0;
while(1)
{
if(TF0 == 1)
{
TF0 = 0;
TH0 = (65535-qw)/256;
TL0 = (65535-qw)%256;
hui = !hui;
}
;
}
while(1)
{
if(quanshu != 0)
{
if(TF0 == 1)
{
TF0 = 0;
TH0 = (65535-qw)/256;
TL0 = (65535-qw)%256;
hui = !hui;
counter++;
}
if(counter == 396)
{
counter = 0;
quanshu--;
;
}
}
else
{
TR0 = 0;
hui = 0;
shineng = 1;
}
}
}
void asd() interrupt 4
{
RI = 0;
quanshu = SBUF;
TR0 = 1; //如果接受的到了數(shù)據(jù)就把計(jì)數(shù)器打開
shineng = 0;
}
|
|