1. 程式人生 > >PT2272-M4--4鍵無線遙控器(STM32)

PT2272-M4--4鍵無線遙控器(STM32)

一、前期準備
微控制器:STM32F103ZET6
開發環境:MDK5.14
庫函式:標準庫V3.5
PT2272-M4模組:淘寶有售
在這裡插入圖片描述
二、實驗效果
在這裡插入圖片描述
三、驅動原理
PT2272-M4是5V訊號輸出的,所以必要找到微控制器帶FT腳的作為接收口。按下按鍵,對應的輸出埠輸出高電平,反之輸出低電平。A,B,C,D對應D2,D0,D3和D1。
需要完整工程或者有問題的請加QQ:1002521871,驗證:呵呵。

四、驅動程式碼
wirelesskey.h

#ifndef __WIRELESS_KEY_H__
#define	__WIRELESS_KEY_H__
#include "stm32f10x.h"
#include "gpio.h"

#define		WIRELESS_D0	        PEin(12)
#define		WIRELESS_D1		PEin(13)
#define		WIRELESS_D2		PEin(14)
#define		WIRELESS_D3		PEin(15)

#define		WIRELESS_D0_PIN		GPIO_Pin_12
#define		WIRELESS_D1_PIN		GPIO_Pin_13
#define		WIRELESS_D2_PIN		GPIO_Pin_14
#define		WIRELESS_D3_PIN		GPIO_Pin_15

#define    	WIREELESSPORT           GPIOE
#define    	WIRELESSCLKLINE    	RCC_APB2Periph_GPIOE	

extern void WirelessKeyConfiguration(void);
#endif

wirelesskey.c

#include "wirelesskey.h"

void WirelessKeyConfiguration(void)
{
	GPIO_InitTypeDef    GPIO;
    
    //Enable APB2 Bus
    RCC_APB2PeriphClockCmd(WIRELESSCLKLINE, ENABLE);
    
    //Register IO 
    GPIO.GPIO_Pin   = WIRELESS_D0_PIN | WIRELESS_D1_PIN | 
					  WIRELESS_D2_PIN | WIRELESS_D3_PIN;
    GPIO.GPIO_Mode  = GPIO_Mode_IPD;
    GPIO_Init(WIREELESSPORT, &GPIO);
}

由於作者能力有限,有不妥之處歡迎指正,郵箱[email protected]