单片机采集小车往返运动的时间

[复制链接]
查看11 | 回复2 | 2010-8-15 20:12:02 | 显示全部楼层 |阅读模式
由单片机外部中断0和1控制小车的电机正反转,程序已经写好,但是采集小车运动一趟的时间不会请高手指点,最好各个程序,谢谢。
图片上ab两端有行程开关,小车碰到行程开关,产生下降沿脉冲,触发外部中断小车正反转。怎样用定时器采集小车运动的一趟的时间???
void interrupt0() interrupt 0
{
count0++;
if(count0==1)
{

a=1;
b=0;
count0=0;
}
}
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)

回复

使用道具 举报

千问 | 2010-8-15 20:12:02 | 显示全部楼层
做一个定时中断,规定t(ms)产生一次中断。中断一次标志计数器count加1.小车在a时刻记录下count值,b时刻几下count值,后者减去前者就是总时间。
回复

使用道具 举报

千问 | 2010-8-15 20:12:02 | 显示全部楼层
void interrupt0() interrupt 0{ count0++;
if(count0==1) {
a=1; b=0; count0=0; TR0=1;
//开计数器 }} void interrupt1() interr
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行