|
|
用模拟口2读取霍尔元件输出的电压,使用中断方式
如果用磁铁快速移动,电压也快速变化输出,但磁铁晃动不记下,
单片机就死机了,必须按reset才能运行。。。
什么原因,哪位大侠解释下
[pre lang="arduino" line="1" file="interrupt.ino"]/*
作者:极客工坊-迷你强
时间:2012年9月11日
IDE版本号:1.0.1
发布地址:www.geek-workshop.com
作用:使用arduino模拟口测量室内温度
*/
int giInterrupt0 = 0;
void setup() {
Serial.begin(9600); //使用9600速率进行串口通讯
//voltage define
analogReference(INTERNAL); //调用板载基准源 1.1V for 168 328P
//interrupt
attachInterrupt(giInterrupt0, getHall, CHANGE);
}
void getTotalVol(float &afVol)
{
int liA1 = analogRead(A1);
afVol = liA1 * (gfRef / 1024.00);
afVol *= 2545.80/510.8 ;
Serial.println("Total Vlotage....");
Serial.println(afVol);
}
void getHall()
{
int liA2 = analogRead(A2);
Serial.println("Hall....\n");
Serial.println(liA2);
Serial.println(liA2* (gfRef / 1024.00) );
Serial.println("Hall End....\n");
}
void loop()
{
Serial.println("wait....\n");
delay(3000); //等待2秒,控制刷新速度
}[/code]
|
|