芯片解密|单片机解密|IC解密|芯片破解|芯片复制| PCB抄板|软件开发

飞芯科技-芯片解密|单片机解密|IC解密|芯片破解|芯片复制| PCB抄板|软件开发

芯片破解stm32 modbus通信程序 485触摸屏

  1. 芯片破解#include "rs485.h"
  2. 芯片破解#include "SysTick.h"
  3. 芯片破解#include "crc16.h"
  4. 芯片破解#include "led.h"

  5. /*******************************************************************************
  6. * 函 数 名         : RS485_Init
  7. * 函数功能                   : USART2初始化函数
  8. * 输    入         : bound:波特率
  9. * 输    出         : 无
  10. *******************************************************************************/  
  11. u8 USART2_RX_BUF[64];                   //接收缓冲,最大64字节
  12. u8 USART2_RX_CNT=0;                       //接收字节计数器
  13. u8 flagFrame=0;                         //帧接收完成标志,即接收到一帧新数据
  14. unsigned char regGroup[5];  //Modbus寄存器组,地址为0x00~0x04

  15. void RS485_Init(u32 bound)
  16. {
  17.         GPIO_InitTypeDef GPIO_InitStructure;
  18.         USART_InitTypeDef USART_InitStructure;
  19.         NVIC_InitTypeDef NVIC_InitStructure;
  20.        
  21.         RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOG|RCC_APB2Periph_GPIOA,ENABLE); //使能GPIOA\G时钟
  22.         RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);//使能USART2时钟
  23.        
  24.         /*  配置GPIO的模式和IO口 */
  25.         GPIO_InitStructure.GPIO_Pin=GPIO_Pin_2;        //TX-485        //串口输出PA2
  26.         GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;                  //复用推挽输出
  27.         GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;       
  28.         GPIO_Init(GPIOA,&GPIO_InitStructure);                /* 初始化串口输入IO */
  29.        
  30.         GPIO_InitStructure.GPIO_Pin=GPIO_Pin_3;        //RX-485           //串口输入PA3
  31.         GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;            //模拟输入
  32.         GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
  33.         GPIO_Init(GPIOA,&GPIO_InitStructure);
  34.        
  35.         GPIO_InitStructure.GPIO_Pin=GPIO_Pin_3;        //CS-485
  36.         GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;           //推挽输出
  37.         GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
  38.         GPIO_Init(GPIOG,&GPIO_InitStructure);
  39.        
  40.         //USART2 初始化设置
  41.         USART_InitStructure.USART_BaudRate = bound;//波特率设置
  42.         USART_InitStructure.USART_WordLength = USART_WordLength_8b;//字长为8位数据格式
  43.         USART_InitStructure.USART_StopBits = USART_StopBits_1;//一个停止位
  44.         USART_InitStructure.USART_Parity = USART_Parity_No;//无奇偶校验位
  45.         USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//无硬件数据流控制
  46.         USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;        //收发模式
  47.         USART_Init(USART2, &USART_InitStructure); //初始化串口2
  48.        
  49.         USART_Cmd(USART2, ENABLE);  //使能串口 2
  50.        
  51.         USART_ClearFlag(USART2, USART_FLAG_TC);
  52.                
  53.         USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);//开启接受中断

  54.         //Usart2 NVIC 配置
  55.         NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
  56.         NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=2;//抢占优先级3
  57.         NVIC_InitStructure.NVIC_IRQChannelSubPriority =2;                //子优先级2
  58.         NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;                        //IRQ通道使能
  59.         NVIC_Init(&NVIC_InitStructure);        //根据指定的参数初始化VIC寄存器、
  60.        
  61.         RS485_TX_EN=0;                                //默认为接收模式      



联系方式

地址:石家庄市新华区民族路77号华强广场D座2009
电话:0311-88816616/87087811
手机:13315190088
传真:0311-67901001
联系人:张工
网址:www.feixindz.com
邮箱:feixindz@163.com
微信:xinpianjiemi
QQ:527263666/568069805

在线客服
热线电话

企业微信