资源简介
曼彻斯特编码的驱动代码,基于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例程
相关资源
- stm32-esp8266客户端驱动
- usb2.0-serial驱动
- spiflash 驱动代码
- linux下使用IIC总线读写EEPROM
- FPGA 12864驱动
- proteus仿真 电机驱动电路
- IR2104_+_IRF540_MOS电机驱动全桥
- OLED屏SH1106G驱动
- 51单片机驱动DS1302时间模块+DS18B20温度
- citizen gsx540k驱动
- 基于STM8的温湿度传感器DHT11驱动代码
- 史上最简单的VS2008+WINDDK驱动开发环境
- 用stm32以软件IIC方式驱动1602 解压密码
- AD5820 VCM驱动芯片手册
- VCM驱动DW9710 DS
- s3c6410简单驱动
- ADC0832 Proteus仿真及C51驱动源码
- 修复单击变双击的鼠标过滤驱动源码
- DS18B20 Verilog驱动程序
- usart hmi的串口驱动,测试单片机为S
- 通过驱动开钱箱
- 三鼎全站仪usb驱动
- 基于LPC2366的LCD12864-5液晶驱动程序
- 最完美的STM32读写I2C EEPROM驱动
- STM32掌机驱动OLED屏幕
- 0.96OLED,z-stack驱动
- MOS管驱动电机正反转电路图
- DevView查看内核设备对象的工具
- linux PCIE架构详解
- AT89S52驱动PS2鼠标的程序
评论
共有 条评论