资源简介
曼彻斯特编码的驱动代码,基于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例程
相关资源
- 基于STM32RCT6的步进电机驱动程序
- 直流无刷电机方波驱动 stm32 例程代码
- elantech触控板驱动程序 v13.6.11 官方最
- 联想y470无线网卡驱动 for 32位64位
- 松下plc FP-XH的驱动
- IMX385驱动代码.zip
- 组态王驱动开发包3.0.0.7(中文)
- 飞思卡尔单片机MC9S12XS12G128驱动(硬件
- CASS9.1最新S4数据及驱动+ET199数据及驱
- 带有死区延时的H桥直流电机驱动电路
- USB转串口驱动,FT232R驱动程序,最新
- 德卡D3读卡器测试程序驱动文件
- WinCE下CP210x的驱动程序
- ubuntu9.10 可加载内核模块和字符设备驱
- MCGS触摸屏西门子s7_1200驱动
- FPGA在步进电机驱动上的应用实例及代
- [免费]基于stm32f103ze 的OLED驱动代码
- STM32F103RBT6驱动UC1698控制芯片的160160黑
- RA8806液晶驱动程序
- 内核驱动进程保护演示程序
- STM32F103 DS18B20 V3.5.0固件库驱动程序工
- 组态王中S7-300TCP驱动
- STC12C5A60S2 CH4521 驱动数码管 显示
- STM32F103 CC2500完整驱动(模拟SPI)
- 430系列单片机USBFET下载驱动
- dell阵列卡驱动s100 s300 2008 R2.rar
- keil vcom windows 7 64bit 驱动
- windows ce 系统的GPIO驱动程序
- 1553曼彻斯特编码程序
- 2440 cs8900a 网卡驱动程序
评论
共有 条评论