知道你们很懒
我就做个好人
PWM 的发送 给你写好了
这个是我写的汽车遥控钥匙 发射编码测试用的
记得给分啊
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "gpio.h"
#include "stdio.h"
/**/
#define _RF_PWM_LL HAL_GPIO_WritePin(mLED10_GPIO_Port,mLED10_Pin,GPIO_PIN_SET)
#define _RF_PWM_HH HAL_GPIO_WritePin(mLED10_GPIO_Port,mLED10_Pin,GPIO_PIN_RESET)
#define _RF_PWM_Head_Time 60 //60*50us
#define _RF_PWM_Hi_Time 6 //10*50us
#define _RF_PWM_Low_Time 14 //20*50us
volatile uint16_t cgTIMx_50US_RKE;
void cBCMx_RF_PWM_Head()
{
_RF_PWM_LL;
cgTIMx_50US_RKE=_RF_PWM_Head_Time;
while(cgTIMx_50US_RKE){}
}
void cBCMx_RF_PWM_SendByte(uint8_t Data)
{
uint8_t i;
uint8_t tmp;
for(i=0;i<8;i++)
{
tmp=Data;
tmp = (tmp<<i)&0x80;
if(tmp>0)
{
//output 1
_RF_PWM_HH;
cgTIMx_50US_RKE=_RF_PWM_Hi_Time;
while(cgTIMx_50US_RKE){};
_RF_PWM_LL;
cgTIMx_50US_RKE=_RF_PWM_Low_Time;
while(cgTIMx_50US_RKE){};
}
else
{
_RF_PWM_HH;
cgTIMx_50US_RKE=_RF_PWM_Low_Time;
while(cgTIMx_50US_RKE){};
_RF_PWM_LL;
cgTIMx_50US_RKE=_RF_PWM_Hi_Time;
while(cgTIMx_50US_RKE){};
}
}
}
void cBCMx_RF_PWM_Send(uint8_t *buf ,uint8_t len)
{
uint8_t i;
cBCMx_RF_PWM_Head();
for(i=0;i<len;i++) cBCMx_RF_PWM_SendByte(buf[i]);
}
void cBCMx_RF_PWM_Test(void)
{
uint8_t sc[]={0x01,0x02,0xf0,0xf7,0x55,0x88,0x99,0xaa,0xbb,0xcc};
cBCMx_RF_PWM_Send(sc,10);
}
|