|
|

楼主 |
发表于 2015-9-13 19:41:06
|
显示全部楼层
基本上搞定了,用的AVR编程,1us脉宽的脉冲都能够扑捉到了。
谢谢各位的帮助。
#include <avr/io.h>
#include <util/delay.h>
#define PORT_LOW PORTB &= ~(1 << PB7) // leonardo 引脚11=PB7
#define PORT_HIGH PORTB |= (1 << PB7)
void setup()
{
DDRB |= (1<<PB7);//DDRB寄存器置位写状态
}
void loop()
{
// 发送脉宽1us的脉冲:
PORT_HIGH;
delayMicroseconds(1);
PORT_LOW;
delay(1000);
}
上面是发脉冲的代码,下面是接收脉冲的代码,用了两个leonardo调试
#include <avr/io.h>
#include <util/delay.h>
unsigned long starttime;
unsigned long stoptime;
void setup()
{
Serial.begin(9600);
while (!Serial);
DDRB &= ~(1<<PB7);
}
void loop()
{
if(bitRead(PINB,PB7)==1)
{
starttime=micros();
while(bitRead(PINB,PB7)==1);
stoptime=micros();
Serial.print("PULSE WIDTH IS: ");
Serial.println(stoptime-starttime);
}
}
|
|