|
基于STM32F103C8T6下的無(wú)線鼠標(biāo),請(qǐng)參考使用
發(fā)射電路:
0.png (152.63 KB, 下載次數(shù): 57)
下載附件
2018-8-16 17:47 上傳
接受電路:
0.png (135.26 KB, 下載次數(shù): 46)
下載附件
2018-8-16 17:47 上傳
單片機(jī)源程序如下:
- #include "led.h"
- #include "delay.h"
- #include "key.h"
- #include "sys.h"
- #include "usart.h"
- #include "string.h"
- #include "usb_lib.h"
- #include "hw_config.h"
- #include "usb_pwr.h"
- #include "I2C.h"
- #include "mpu6050.h"
- #include "24l01.h"
-
-
- //計(jì)算x1,x2的絕對(duì)值
- u32 usb_abs(u32 x1,u32 x2)
- {
- if(x1>x2)return x1-x2;
- else return x2-x1;
- }
- //設(shè)置USB 連接/斷線
- //enable:0,斷開(kāi)
- // 1,允許連接
- void usb_port_set(u8 enable)
- {
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
- if(enable)_SetCNTR(_GetCNTR()&(~(1<<1)));//退出斷電模式
- else
- {
- _SetCNTR(_GetCNTR()|(1<<1)); // 斷電模式
- GPIOA->CRH&=0XFFF00FFF;
- GPIOA->CRH|=0X00033000;
- PAout(12)=0;
- }
- }
- int main(void)
- {
- // short temp1[3];//加速度計(jì)
- // short temp2[3];
- // short temp3; //溫度
- u8 tmp_buf[5]; //發(fā)射寄存器
- u8 key;
- short X,Y,X1,Y1; //發(fā)送到電腦端的坐標(biāo)值
-
- u8 keysta; //[0]:0,左鍵松開(kāi);1,左鍵按下;
- //[1]:0,右鍵松開(kāi);1,右鍵按下
- //[2]:0,中鍵松開(kāi);1,中鍵按下
- delay_init(); //延時(shí)函數(shù)初始化
- NVIC_Configuration(); //設(shè)置NVIC中斷分組2:2位搶占優(yōu)先級(jí),2位響應(yīng)優(yōu)先級(jí)
- uart_init(9600); //串口初始化為9600
- printf("串口初始化完畢\r\n");
- // LED_Init(); //LED端口初始化
- // KEY_Init(); //按鍵初始化
- // printf("按鍵初始化完畢\r\n");
- I2C_Init();
- printf("IIC初始化完畢\r\n");
- delay_ms(100);
- MPU6050_Init();
- printf("MPU6050初始化完畢\r\n");
- delay_ms(100);
- NRF24L01_Init();
- printf("24l01初始化完畢\r\n");
- while(NRF24L01_Check()) //檢查NRF24L01是否在位.
- {
- printf("未檢測(cè)到24l01\r\n");
- delay_ms(200);
- }
- printf("檢測(cè)到24l01---OK\r\n");
- NRF24L01_RX_Mode();
- printf("設(shè)置24l01為接收模式成功!\r\n");
-
- usb_port_set(0); //USB先斷開(kāi)
- delay_ms(300);
- usb_port_set(1); //USB再次連接
- //USB配置
- USB_Interrupts_Config();
- Set_USBClock();
- USB_Init();
- printf("USB都初始化完畢了,騷年,開(kāi)始接收吧。!\r\n");
- while(1)
- {
- if(NRF24L01_RxPacket(tmp_buf)==0)
- {
- X=(s16)((tmp_buf[1]<<8)|tmp_buf[2]);
- Y=(s16)((tmp_buf[3]<<8)|tmp_buf[4]);
- printf(" %8d%8d\r\n",X,Y);
- Joystick_Send(tmp_buf[0],X,Y,0);
- }
- // X1=(s16)((tmp_buf[1]<<8)|tmp_buf[2]);
- // Y1=(s16)((tmp_buf[3]<<8)|tmp_buf[4]);
- //printf("%8d%8d%4X\r\n",tmp_buf[1],tmp_buf[2],NRF24L01_TxPacket(tmp_buf)); //NRF24l01發(fā)射函數(shù)
- // Joystick_Send(keysta,X/15,Y/15,0);//鼠標(biāo)函數(shù),按鍵,X軸坐標(biāo),Y軸坐標(biāo)
- }
- }
-
復(fù)制代碼
所有資料51hei提供下載:
空中鼠標(biāo)源程序.rar
(378.79 KB, 下載次數(shù): 127)
2018-8-16 17:48 上傳
點(diǎn)擊文件名下載附件
無(wú)線鼠標(biāo)源代碼 下載積分: 黑幣 -5
空中鼠標(biāo)原理圖.rar
(230.52 KB, 下載次數(shù): 91)
2018-8-16 12:40 上傳
點(diǎn)擊文件名下載附件
BOM 下載積分: 黑幣 -5
|
評(píng)分
-
查看全部評(píng)分
|