资源简介
STM8S模拟串口,双串口,虚拟串口
代码片段和文件信息
/* Includes ------------------------------------------------------------------*/
#include “stm8s.h“
#include “stm8s_it.h“
//#include “iostm8s103k3.h“
#include “main.h“
///////////////////////////////////////////////////
#define TIM1_timer 1667 //接收定时器
#define TIM2_timer 1667 //发送定时器
u8 vm_UART_RX_P;//接收缓存指针
#define vm_UART_RX_BUF_L 32//接收缓存长度
u8 vm_UART_RX_BUF[vm_UART_RX_BUF_L];//接收缓存
u8 vm_UART_RX_byte;//扩展串口 字节缓冲区
u8 vm_UART_RX_bit;//扩展串口 计算位数
u8 vm_UART_TX_byte;//扩展串口 字节缓冲区
u8 vm_UART_TX_bit;//扩展串口 计算位数
u8 vm_uart_tx_flag;//正在发送标志
u8 vm_uart_rx_flag;//正在接收标志
#define TIM2_START TIM2->CNTRL = 0;TIM2->CNTRH = 0;TIM2->CR1 |= TIM2_CR1_CEN; //计数器置零,启动定时器
#define TIM2_STOP (TIM2->CR1 &= (~TIM2_CR1_CEN)) //停止定时器
#define TIM1_START TIM1->CNTRL = 0;TIM1->CNTRH = 0;TIM1->CR1 |= TIM1_CR1_CEN; //计数器置零,启动定时器
#define TIM1_STOP (TIM1->CR1 &= (~TIM1_CR1_CEN)) //停止定时器
#define VM_UART_TXD_PORT_WriteHigh GPIOD->ODR |= GPIO_PIN_4
#define VM_UART_TXD_PORT_WriteLow GPIOD->ODR &= (~GPIO_PIN_4)
#define VM_UART_TXD_PORT_OUT GPIOD->DDR |= GPIO_PIN_4;GPIOD->CR1 |= (GPIO_PIN_4);GPIOD->CR2 &= (~GPIO_PIN_4) //设定为输出
#define VM_UART_TXD_PORT_IN GPIOD->DDR &= ~(GPIO_PIN_4);GPIOD->CR1 |= (GPIO_PIN_4);GPIOD->CR2 &= (~GPIO_PIN_4) //设定为输出
#define VM_UART_RXD_PORT_IN GPIOD->DDR &= ~(GPIO_PIN_3);GPIOD->CR1 |= (GPIO_PIN_3);GPIOD->CR2 &= (~GPIO_PIN_3) //只上拉输入 不中断
//设置为输入
#define VM_UART_RXD_PORT_INT_IN GPIOD->DDR &= ~(GPIO_PIN_3);GPIOD->CR1 |= (GPIO_PIN_3);GPIOD->CR2 |= (GPIO_PIN_3) //只上拉输入 不中断
//设置为可中断输入
////////////////////////////////////////////////////////////////////////////////////////////////
INTERRUPT_HANDLER_TRAP(TRAP_IRQHandler)
{
}
INTERRUPT_HANDLER(TLI_IRQHandler 0)
{
}
INTERRUPT_HANDLER(AWU_IRQHandler 1)
{
}
INTERRUPT_HANDLER(CLK_IRQHandler 2)
{
}
INTERRUPT_HANDLER(EXTI_PORTA_IRQHandler 3)
{
}
INTERRUPT_HANDLER(EXTI_PORTB_IRQHandler 4)
{
}
INTERRUPT_HANDLER(EXTI_PORTC_IRQHandler 5)
{
}
INTERRUPT_HANDLER(EXTI_PORTD_IRQHandler 6)
{
//外中断一次收一个字节,只识别起始位
if((GPIOD->IDR & (uint8_t)GPIO_PIN_3) == 0)
{
TIM1_START;//启动定时器
vm_UART_RX_byte = 0;
vm_UART_RX_bit = 0;
VM_UART_RXD_PORT_IN; //只上拉输入 不中断
vm_uart_rx_flag = 1;
}
}
INTERRUPT_HANDLER(EXTI_PORTE_IRQHandler 7)
{}
#ifdef STM8S903
INTERRUPT_HANDLER(EXTI_PORTF_IRQHandler 8)
{}
#endif /*STM8S903*/
#ifdef STM8S208
INTERRUPT_HANDLER(CAN_RX_IRQHandler 8)
{}
INTERRUPT_HANDLER(CAN_TX_IRQHandler 9)
{}
#endif /*STM8S208 || STM8AF52Ax */
INTERRUPT_HANDLER(SPI_IRQHandler 10)
{}
INTERRUPT_HANDLER(TIM1_UPD_OVF_TRG_BRK_IRQHandler 11)//接收
{
TIM1->SR1 = (uint8_t)(~TIM1_IT_UPDATE);
if((GPIOD->IDR & GPIO_PIN_3) == 0)
{
vm_UART_RX_byte /= 2;
}
else
{
vm_UART_RX_byte /= 2;
vm_UART_RX_byte |= 0X80;
}
vm_UART_RX_bit++;
if(vm_UART
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 9949 2014-09-14 19:52 main.c
----------- --------- ---------- ----- ----
9949 1
相关资源
- STM8S003单片机ADC多通道采样
- STM8S003模拟IIC总线读取PCF8563
- STM8S003模拟串口程序
- STM8S003F使用I/O口模拟串口一发送数据
- AD Altium Designer STM8 STM32 库
- STM32的GPIO口模拟串口通信.rar
- STM8 SPI从机通讯程序
- STVD代码量插件
- IAR for STM8注册机
- IAR for STM8 3.10.4汉化补丁
- STM8和STM32F103原理图库AD
- IAR for STM8 3.10.4汉化
- STM8定时器2输入捕获功能寄存器版
- STM8S单片机输出互补PWM可通过刹车输入
- 使用 STM8S103F3 设计的数字电压表头
- STM8S 模拟I2C程序 源码
- stm8s003与ds1307时钟芯片程序
- STM32的GPIO口模拟串口通信
- STM8L152R6 STM8L152R8 SCH封装
- stvd 4.1.2 汉化版ST Visual Develop Version
- STM8真正UFQFPN20封装Altium格式要是骗人
- STM8 UART串口发送完成中断程序
- stm8封装库 AD软件可打开 包括原理图
- stm8s解码pt2262
- STM32 STM8的protel库文件 内含原理图sc
- STM32F407双串口
- STM8 UART 半双工串口通信
- stm8双机iic通讯程序
- 基于STM8定制轻量操作系统Aatomthreads官
- STM8L101低功耗应用
评论
共有 条评论