資源簡介
曼徹斯特編碼的驅動代碼,基于stm32F4xx上的代碼。將字節轉換為曼徹斯特編碼,并通過gpio輸出。編碼具有前導碼(高電平),和stop結束標志碼(低電平)

代碼片段和文件信息
#include?“string.h“
#include?“rtthread.h“
#include?“stm32f4xx.h“
#include?“common.h“
#include?“manchester.h“
uint32_t?counter_us?=?0;
static?bool?even_parity_select(uint8_t?ch)//fase?eventrue?uneven
{
bool?parity?=?false;
while?(ch)
{
parity?=?!parity;
ch?=?ch?&?(ch?-?1);
}
return?parity;
}
static?void?udelay(uint32_t?us)
{
counter_us?=?0;
while(us?!=?counter_us);
}
void?TIM3_IRQHandler(void)
{
if?(?TIM_GetITStatus(TIM3?TIM_IT_Update)?!=?RESET?)?
{
TIM_ClearITPendingBit(TIM3??TIM_IT_Update);??
rt_interrupt_enter();
counter_us?++;
rt_interrupt_leave();
}
}
static?void?NVIC_Configuration(void)
{
NVIC_InitTypeDef?NVIC_InitStructure;?
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
NVIC_InitStructure.NVIC_IRQChannel?=?TIM3_IRQn;?
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority?=?0; ?
NVIC_InitStructure.NVIC_IRQChannelSubPriority?=?3;
NVIC_InitStructure.NVIC_IRQChannelCmd?=?ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
static?void?TIM_Configuration(void)
{
TIM_TimebaseInitTypeDef??TIM_TimebaseStructure;
??RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3?ENABLE);?
NVIC_Configuration();
??TIM_TimebaseStructure.TIM_Period?=?10?-?1;???????
??TIM_TimebaseStructure.TIM_Prescaler?=?90?-?1;//10us
??TIM_TimebaseStructure.TIM_ClockDivision?=?TIM_CKD_DIV1;
??TIM_TimebaseStructure.TIM_CounterMode?=?TIM_CounterMode_Up;
??TIM_TimebaseStructure.TIM_RepetitionCounter?=?0;
TIM_TimebaseInit(TIM3?&TIM_TimebaseStructure);
TIM_ClearFlag(TIM3?TIM_FLAG_Update);
TIM_ITConfig(TIM3?TIM_IT_Update?ENABLE);
TIM_Cmd(TIM3?DISABLE);
}
static?void?RCC_Configuration(void)
{
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA?ENABLE);
}
static?void?GPIO_Configuration(void)
{
GPIO_InitTypeDef?GPIO_InitStructure;
/*?TIM3?channel?1?pin?(PA6)?configuration?*/
GPIO_InitStructure.GPIO_Mode?=?GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_Speed?=?GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType?=?GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd?=?GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Pin?=?GPIO_Pin_6;
GPIO_ResetBits(GPIOA?GPIO_Pin_6);
GPIO_Init(GPIOA?&GPIO_InitStructure);
}
void?manchester_init(void)
{
RCC_Configuration();
GPIO_Configuration();
TIM_Configuration();
}
static?void?Manchester_Enable(void)
{
TIM_Cmd(TIM3?ENABLE);
}
static?void?Manchester_Disable(void)
{
TIM_Cmd(TIM3?DISABLE);
}
static?void?manchester_high(void)
{
GPIO_SetBits(GPIOA?GPIO_Pin_6);
}
static?void?manchester_low(void)
{
GPIO_ResetBits(GPIOA?GPIO_Pin_6);
}
/**
*?1.?I/O?output?low?level.
*?2.?Wait?for?half?frame?time?T.
*?3.?I/O?output?high?level.
*?4.?Wait?for?half?frame?time?T.
*?5.?return
*/
static?void?ManchesterOne(void)
{
manchester_low();
udelay(HALF_BIT_TIME);
manchester_high();
udelay(HALF_BIT_TIME);
}
/*
*?1.?I/O?output?high?level.
*?2.?Wait?for?half?frame?time?T.
*?3.?I/O?output?low?l
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????339??2019-06-06?16:06??manchester.h
?????文件???????3769??2019-06-06?16:06??manchester.c
-----------?---------??----------?-----??----
?????????????????4108????????????????????2
- 上一篇:西門子PLC數據讀寫測試工具
- 下一篇:TI官網CC2530例程
評論
共有 條評論