Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: ArduinoFB SRF05 mbed
Diff: main.cpp
- Revision:
- 0:fac6c6a73e5f
- Child:
- 1:0f0f31f25bbd
diff -r 000000000000 -r fac6c6a73e5f main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Thu Feb 12 10:26:36 2015 +0000
@@ -0,0 +1,87 @@
+
+#include "SRF05.h"
+#include "Arduino.h"
+
+SRF05 srf(D6, D5);//trig;echo
+
+//*******************************************************************************
+//----------------本例程仅供学习使用,未经作者允许,不得用于其他用途。-----------
+//------------------------版权所有,仿冒必究!-----------------------------------
+//----------------1.开发环境:Arduino IDE-----------------------------------------
+//----------------2.测试使用开发板型号:Arduino Leonardo or Arduino UNO R3-------
+//----------------3.单片机使用晶振:16M------------------------------------------
+//----------------4.淘宝网址:http://xmdzpj.taobao.com---------------------------
+//----------------5.作者:真红炎神---------------------------------------------
+//*******************************************************************************/
+
+int latchPin = 4;
+int clockPin =7;
+int dataPin = 8; //这里定义了那三个脚
+
+unsigned char Dis_table[] = {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0X80,0X90}; //LED状态显示的变量
+unsigned char Dis_buf[] = {0xF1,0xF2,0xF4,0xF8};
+unsigned char disbuff[] = {0, 0, 0, 0};
+
+
+void setup ()
+{
+ pinMode(latchPin,OUTPUT);
+ pinMode(clockPin,OUTPUT);
+ pinMode(dataPin,OUTPUT); //让三个脚都是输出状态
+
+}
+
+void display()
+{
+ for(char i=0; i<=3; i++)//扫描四个数码管
+ {
+ digitalWrite(latchPin,LOW); //将ST_CP口上面加低电平让芯片准备好接收数据
+ if(i==1)
+ {
+ shiftOut(dataPin,clockPin,MSBFIRST,Dis_table[disbuff[i]]&0x7F); //发送显示码
+ }
+ else
+ shiftOut(dataPin,clockPin,MSBFIRST,Dis_table[disbuff[i]]);
+ shiftOut(dataPin,clockPin,MSBFIRST,Dis_buf[i] ); //发送通值
+ //串行数据输入引脚为dataPin,时钟引脚为clockPin,执行MSB有限发送,发送数据table[i]
+ digitalWrite(latchPin,HIGH); //将ST_CP这个针脚恢复到高电平
+ delay(2); //延时2ms
+ }
+
+}
+
+void loop()
+{
+
+ float val;
+ val=srf*100;
+ /*
+ unsigned char t=((val%1000)/100);
+
+ disbuff[0]= (unsigned char)(val/1000);
+ disbuff[1]= (unsigned char)((val%1000)/100);
+ disbuff[2]= (unsigned char)((val%100)/10);
+ */
+ disbuff[0]= (unsigned char)(val/1000);
+ disbuff[1]= (val/100)-disbuff[0]*10;
+ disbuff[2]= (val/10)-(disbuff[0]*100+disbuff[1]*10);
+ disbuff[3]= 0;
+
+ for(char time=0;time<30;time++) //显示30次,当作延时,以免读取过快
+ {
+ display();
+ }
+}
+
+
+
+
+main()
+{
+ setup();
+ while(1)
+ {
+ loop();
+ }
+}
+