GY-25Z怎么用啊
全部資料51hei下載地址:
GY25Z_V1資料.rar
(2.1 MB, 下載次數: 39)
2019-5-28 20:55 上傳
點擊文件名下載附件
單片機源程序如下:
- #include <reg52.h>
- #include "string.h"
- #include "usart.h"
- #include "stdio.h"
- /*
- 硬件接法:
- GY-25Z---c51
- 1、GY-25Z_RX---c51_TX,c51復位將發送 輸出數據設置指令和自動輸出設置指令給模塊
- 2、c51_TX---FT232_RX,STM32將數據上傳給上位機
- 3、GY-25Z_TX---c51_RX,接收模塊數據
- 軟件說明:
- 該程序采用串口方式獲取模塊數據,波特率9600
- 所以得用上位機先將模塊串口設置成9600,然后再進行以上操作;
- 注:中斷函數位于stc_it.c
- 聯系方式:
- http://shop62474960.taobao.com/?spm=a230r.7195193.1997079397.2.9qa3Ky&v=1
- */
- void delay(uint16_t x)
- {
- while(x--);
- }
- int main(void)
- {
- uint8_t sum=0,i=0,count=0;
- int16_t rpy[3];
- uint32_t pressure=0;
- double out_P=0;
- Usart_Int(9600);//串口初始化,波特率9600
- LED_0=1;
- ///////////輸出數據設置///////////////////
- USART_send_byte(0xa5);
- USART_send_byte(0x55);
- USART_send_byte(0x10);
- USART_send_byte(0x0a);
- delay(60000);
- delay(60000);
- //////////自動輸出設置//////////////////
- USART_send_byte(0xa5);
- USART_send_byte(0x56);
- USART_send_byte(0x02);
- USART_send_byte(0xfd);
- delay(10000);
- while(1)
- {
- if(Receive_ok)//串口接收完畢
- {
- for(sum=0,i=0;i<(RX_BUF[3]+4);i++)
- sum+=RX_BUF[i];
- count=0;
- if(sum==RX_BUF[i])//校驗和判斷
- {
- if(RX_BUF[2]&0x01) //加速度數據
- count=6;
- if(RX_BUF[2]&0x02) //陀螺數據
- count+=6;
- if(RX_BUF[2]&0x04) //磁場數據
- count+=6;
- if(RX_BUF[2]&0x08) //四元數數據
- count+=8;
- if(RX_BUF[2]&0x10) //歐拉角數據
- {
- LED_0=0;
- rpy[0]=(RX_BUF[4+count]<<8)|RX_BUF[5+count];
- rpy[1]=(RX_BUF[6+count]<<8)|RX_BUF[7+count];
- rpy[2]=(RX_BUF[8+count]<<8)|RX_BUF[9+count];
-
- TI=1;
- printf("RPY: %d , %d , %d ,\r\n",rpy[0]/100,rpy[1]/100,rpy[2]/100);
- count+=6;
- }
- }
- Receive_ok=0;//處理數據完畢標志
-
- }
- }
- }
復制代碼
|