最近买了一个单向交流计量模块(https://download.csdn.net/download/weixin_43205178/11472943)![在这里插入图片描述]这个模块实现通过自带的电脑串口通信,显示在限免如下形式 艾锐达公司出品的计量模块!淘宝客服只提供一个资料,之前也没写过接口函数,在几年前接受叶老师的指导接口出来了。感谢老师!
特地把程序贴出来!!!
```c
#include “delay.h”
#include “usart3.h”
#include “stdarg.h”
#include “usart.h”
#include “stdio.h”
#include “string.h”
#include “WIFI8266.h”
#include “led.h”
#include “usart3.h”
u8 USART3_RX_BUF[USART3_MAX_RECV_LEN];
u8 USART3_TX_BUF[USART3_MAX_SEND_LEN];
unsigned char Read_ID = 0x01;
unsigned char Tx_Buffer1[8];
unsigned char Rx_Buffer1[40];
unsigned char Rx_Buffer[40];
int receive_finished;
unsigned long Voltage_data, Current_data, Power_data, Energy_data, Pf_data, CO2_data, HZ;
int i = 8; //此次发送数据的长度
int j = 0;
float Pf_data1, HZ1;
int read_enable = 0;
int reveive_numbe = 0;
vu16 USART3_RX_STA = 0;
//中断服务函数 之前找用串口发送数据的程序自己带的函数
void USART3_IRQHandler(void)
{
char Res;
if (USART_GetITStatus(USART3, USART_IT_RXNE) != RESET)
{
USART_ClearITPendingBit(USART3, USART_IT_RXNE);
Res = USART_ReceiveData(USART3);
if (USART3_RX_STA < USART3_MAX_RECV_LEN) //接收的字符串
{
Rx_Buffer1[USART3_RX_STA] = Res;
USART3_RX_STA++;
}
}
if (USART_GetITStatus(USART3, USART_IT_IDLE) != SET)
{
receive_finished = 1; // 这个自动的发送的重点啊 这个IF利用的是空闲中断,在收完数据后自动发送
USART_ClearITPendingBit(USART3, USART_IT_IDLE);
}
USART3->SR;
USART3->DR;
}
//这个是计算CRC函数 买模块自身资料带的函数
unsigned int calccrc(unsigned char crcbuf, unsigned int crc)
{
unsigned char i;
unsigned char chk;
crc = crc ^ crcbuf; for (i = 0; i < 8; i++)
{
chk = (unsigned