资源简介

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


评论

共有 条评论