附上我编的程序
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit a=P1^0;//直流电机的两端
sbit b=P1^1;
uchar count0,count1;//中断标志
uint aa,dat, t0_count;
uchar code table[]={ //数码管显示编码 //共阴极,高电平有效
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
void display(uint); //函数声明显示小车运动周期
delay(uchar x)
{
uchar a,b;
for(a=x;a>0;a--)
for(b=255;b>0;b--);
}
void inti()
{
EA=1;
EX0=1;
EX1=1;
IT0=1;//边沿触发
IT1=1;
a=0;
b=0;
TMOD=0x01;
TH0=(65536-10000)/256;;
TL0=(65536-10000)%256;//定时1mS
ET0=1;
TR0=0; //关计数器0
t0_count=0;
}
void main ()
{ inti();
display(12345);//初始化显示
while(1)
{ display(???);
}
}
void interrupt0() interrupt 0
{
count0++;
if(count0==1)//正传
{
a=1;
b=0;
count0=0;
TR0=1;//开始计时
}
}
void interrupt1() interrupt 2)//反传
{
count1++;
if(count1==1)
{
a=0;
b=1;
count1=0;
}
}
void time0() interrupt 1 //采集小车一趟或一个周期的时间
{
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;//定时10mS
t0_count++;
}
void display(uint a)
|