feat: add STM32 four-channel weighing firmware
This commit is contained in:
+79
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
*
|
||||
* 模块名称 : WM8978音频芯片驱动模块
|
||||
* 文件名称 : bsp_WM8978.h
|
||||
* 版 本 : V1.0
|
||||
* 说 明 : 头文件
|
||||
* 修改记录 :
|
||||
* 版本号 日期 作者 说明
|
||||
* v0.1 2009-12-27 armfly 创建该文件,ST固件库版本为V3.1.2
|
||||
* v1.0 2011-09-04 armfly ST固件库升级到V3.5.0版本。
|
||||
*
|
||||
* Copyright (C), 2010-2011, 安富莱电子 www.armfly.com
|
||||
*
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef _BSP_WM8978_H
|
||||
#define _BSP_WM8978_H
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#define WM8978_SLAVE_ADDRESS 0x34 /* WM8978 I2C从机地址 */
|
||||
|
||||
/* WM8978 音频输入通道控制选项, 可以选择多路,比如 MIC_LEFT_ON | LINE_ON */
|
||||
typedef enum
|
||||
{
|
||||
IN_PATH_OFF = 0x00, /* 无输入 */
|
||||
MIC_LEFT_ON = 0x01, /* LIN,LIP脚,MIC左声道(接板载咪头) */
|
||||
MIC_RIGHT_ON = 0x02, /* RIN,RIP脚,MIC右声道(接GPRS模块音频输出) */
|
||||
LINE_ON = 0x04, /* L2,R2 立体声输入 */
|
||||
AUX_ON = 0x08, /* AUXL,AUXR 立体声输入 */
|
||||
DAC_ON = 0x10, /* I2S数据DAC (CPU产生音频信号) */
|
||||
ADC_ON = 0x20 /* 输入的音频馈入WM8978内部ADC (I2S录音) */
|
||||
}IN_PATH_E;
|
||||
|
||||
/* WM8978 音频输出通道控制选项, 可以选择多路 */
|
||||
typedef enum
|
||||
{
|
||||
OUT_PATH_OFF = 0x00, /* 无输出 */
|
||||
EAR_LEFT_ON = 0x01, /* LOUT1 耳机左声道 */
|
||||
EAR_RIGHT_ON = 0x02, /* ROUT1 耳机右声道 */
|
||||
SPK_ON = 0x04, /* LOUT2和ROUT2反相输出单声道,接扬声器 */
|
||||
OUT3_4_ON = 0x08, /* OUT3 和 OUT4 输出单声道音频, 接GSM模块的音频输入 */
|
||||
}OUT_PATH_E;
|
||||
|
||||
/* 定义最大音量 */
|
||||
#define VOLUME_MAX 63 /* 最大音量 */
|
||||
#define VOLUME_STEP 1 /* 音量调节步长 */
|
||||
|
||||
/* 定义最大MIC增益 */
|
||||
#define GAIN_MAX 63 /* 最大增益 */
|
||||
#define GAIN_STEP 1 /* 增益步长 */
|
||||
|
||||
|
||||
/* 供外部引用的函数声明 */
|
||||
uint8_t wm8978_Init(void);
|
||||
void wm8978_CfgAudioIF(uint16_t _usStandard, uint8_t _ucWordLen);
|
||||
void wm8978_OutMute(uint8_t _ucMute);
|
||||
void wm8978_PowerDown(void);
|
||||
|
||||
void wm8978_CfgAudioPath(uint16_t _InPath, uint16_t _OutPath);
|
||||
|
||||
void wm8978_SetMicGain(uint8_t _ucGain);
|
||||
void wm8978_SetLineGain(uint8_t _ucGain);
|
||||
void wm8978_SetSpkVolume(uint8_t _ucVolume);
|
||||
void wm8978_SetEarVolume(uint8_t _ucVolume);
|
||||
uint8_t wm8978_ReadEarVolume(void);
|
||||
uint8_t wm8978_ReadSpkVolume(void);
|
||||
|
||||
void wm8978_NotchFilter(uint16_t _NFA0, uint16_t _NFA1);
|
||||
|
||||
void I2S_CODEC_Init(void);
|
||||
void I2S_StartPlay(uint16_t _usStandard, uint16_t _usWordLen, uint16_t _usAudioFreq);
|
||||
void I2S_StartRecord(uint16_t _usStandard, uint16_t _usWordLen, uint16_t _usAudioFreq);
|
||||
void I2S_Stop(void);
|
||||
|
||||
void wm8978_RegCash_Output(void);
|
||||
#endif
|
||||
+232
@@ -0,0 +1,232 @@
|
||||
/*************************** (C) COPYRIGHT 2018 PING ****************************
|
||||
* 文件名 :bsp_i2c_gpio.h
|
||||
* 描 述 :IO口模拟I2C程序
|
||||
* 版 本 :V1.0
|
||||
* 日 期 :2018-01-11
|
||||
* 作 者 :XuZhongPing
|
||||
* 更新记录 :
|
||||
*********************************************************************************/
|
||||
|
||||
#include "stm32f10x.h"
|
||||
#include "bsp_i2c_gpio.h"
|
||||
#include "delay.h"
|
||||
|
||||
/* 定义I2C总线连接的GPIO端口, 用户只需要修改下面4行代码即可任意改变SCL和SDA的引脚 */
|
||||
#define GPIO_PORT_I2C GPIOD /* GPIO端口 */
|
||||
#define RCC_I2C_PORT RCC_APB2Periph_GPIOD /* GPIO端口时钟 */
|
||||
#define I2C_SCL_PIN GPIO_Pin_10 /* 连接到SCL时钟线的GPIO */
|
||||
#define I2C_SDA_PIN GPIO_Pin_9 /* 连接到SDA数据线的GPIO */
|
||||
|
||||
|
||||
static void i2c_CfgGpio(void);
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* 函 数 名: i2c_Start
|
||||
* 功能说明: CPU发起I2C总线启动信号
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
void i2c_Start(void)
|
||||
{
|
||||
SDA_OUT(); //sda线输出
|
||||
IIC_SDA=1;
|
||||
IIC_SCL=1;
|
||||
delay_us(4);
|
||||
IIC_SDA=0; //START:when CLK is high,DATA change form high to low
|
||||
delay_us(4);
|
||||
IIC_SCL=0; //钳住I2C总线,准备发送或接收数据
|
||||
}
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* 函 数 名: i2c_Start
|
||||
* 功能说明: CPU发起I2C总线停止信号
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
void i2c_Stop(void)
|
||||
{
|
||||
SDA_OUT();//sda线输出
|
||||
IIC_SCL=0;
|
||||
IIC_SDA=0;//STOP:when CLK is high DATA change form low to high
|
||||
delay_us(4);
|
||||
IIC_SCL=1;
|
||||
IIC_SDA=1;//发送I2C总线结束信号
|
||||
delay_us(4);
|
||||
}
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* 函 数 名: i2c_SendByte
|
||||
* 功能说明: CPU向I2C总线设备发送8bit数据
|
||||
* 形 参:_ucByte : 等待发送的字节
|
||||
* 返 回 值: 无
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
void i2c_SendByte(uint8_t _ucByte)
|
||||
{
|
||||
uint8_t t;
|
||||
|
||||
SDA_OUT();
|
||||
IIC_SCL = 0; //拉低时钟开始数据传输
|
||||
for(t=0; t<8; t++)
|
||||
{
|
||||
//IIC_SDA=(txd&0x80)>>7;
|
||||
if((_ucByte&0x80)>>7)
|
||||
IIC_SDA=1;
|
||||
else
|
||||
IIC_SDA=0;
|
||||
_ucByte<<=1;
|
||||
delay_us(2); //对TEA5767这三个延时都是必须的
|
||||
IIC_SCL=1;
|
||||
delay_us(2);
|
||||
IIC_SCL=0;
|
||||
delay_us(2);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* 函 数 名: i2c_ReadByte
|
||||
* 功能说明: CPU从I2C总线设备读取8bit数据
|
||||
* 形 参:无
|
||||
* 返 回 值: 读到的数据
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
uint8_t i2c_ReadByte(void)
|
||||
{
|
||||
// unsigned char i,receive=0;
|
||||
// SDA_IN();//SDA设置为输入
|
||||
// for(i=0;i<8;i++ )
|
||||
// {
|
||||
// IIC_SCL=0;
|
||||
// delay_us(2);
|
||||
// IIC_SCL=1;
|
||||
// receive<<=1;
|
||||
// if(READ_SDA)receive++;
|
||||
// delay_us(1);
|
||||
// }
|
||||
// if (!ack)
|
||||
// IIC_NAck();//发送nACK
|
||||
// else
|
||||
// IIC_Ack(); //发送ACK
|
||||
// return receive;
|
||||
}
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* 函 数 名: i2c_WaitAck
|
||||
* 功能说明: CPU产生一个时钟,并读取器件的ACK应答信号
|
||||
* 形 参:无
|
||||
* 返 回 值: 返回0表示正确应答,1表示无器件响应
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
uint8_t i2c_WaitAck(void)
|
||||
{
|
||||
uint8_t ucErrTime=0;
|
||||
SDA_IN(); //SDA设置为输入
|
||||
IIC_SDA=1;delay_us(1);
|
||||
IIC_SCL=1;delay_us(1);
|
||||
while(READ_SDA)
|
||||
{
|
||||
ucErrTime++;
|
||||
if(ucErrTime>250)
|
||||
{
|
||||
i2c_Stop();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
IIC_SCL=0;//时钟输出0
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* 函 数 名: i2c_Ack
|
||||
* 功能说明: CPU产生一个ACK信号
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
void i2c_Ack(void)
|
||||
{
|
||||
IIC_SCL=0;
|
||||
SDA_OUT();
|
||||
IIC_SDA=0;
|
||||
delay_us(2);
|
||||
IIC_SCL=1;
|
||||
delay_us(2);
|
||||
IIC_SCL=0;
|
||||
}
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* 函 数 名: i2c_NAck
|
||||
* 功能说明: CPU产生1个NACK信号
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
void i2c_NAck(void)
|
||||
{
|
||||
IIC_SCL=0;
|
||||
SDA_OUT();
|
||||
IIC_SDA=1;
|
||||
delay_us(2);
|
||||
IIC_SCL=1;
|
||||
delay_us(2);
|
||||
IIC_SCL=0;
|
||||
}
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* 函 数 名: i2c_CfgGpio
|
||||
* 功能说明: 配置I2C总线的GPIO,采用模拟IO的方式实现
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
static void i2c_CfgGpio(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
|
||||
RCC_APB2PeriphClockCmd(RCC_I2C_PORT, ENABLE); /* 打开GPIO时钟 */
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = I2C_SCL_PIN | I2C_SDA_PIN;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; /* 开漏输出 GPIO_Mode_Out_PP GPIO_Mode_Out_OD*/
|
||||
GPIO_Init(GPIO_PORT_I2C, &GPIO_InitStructure);
|
||||
|
||||
GPIO_SetBits(GPIO_PORT_I2C, I2C_SCL_PIN | I2C_SDA_PIN);
|
||||
|
||||
/* 给一个停止信号, 复位I2C总线上的所有设备到待机模式 */
|
||||
i2c_Stop();
|
||||
}
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* 函 数 名: i2c_CheckDevice
|
||||
* 功能说明: 检测I2C总线设备,CPU向发送设备地址,然后读取设备应答来判断该设备是否存在
|
||||
* 形 参:_Address:设备的I2C总线地址
|
||||
* 返 回 值: 返回值 0 表示正确, 返回1表示未探测到
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
uint8_t i2c_CheckDevice(uint8_t _Address)
|
||||
{
|
||||
uint8_t ucAck;
|
||||
|
||||
i2c_CfgGpio(); /* 配置GPIO */
|
||||
|
||||
i2c_Start(); /* 发送启动信号 */
|
||||
|
||||
/* 发送设备地址+读写控制bit(0 = w, 1 = r) bit7 先传 */
|
||||
i2c_SendByte(_Address | I2C_WR);
|
||||
ucAck = i2c_WaitAck(); /* 检测设备的ACK应答 */
|
||||
|
||||
i2c_Stop(); /* 发送停止信号 */
|
||||
|
||||
return ucAck;
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
*
|
||||
* 模块名称 : I2C总线驱动模块
|
||||
* 文件名称 : bsp_i2c_gpio.h
|
||||
* 版 本 : V1.0
|
||||
* 说 明 : 头文件。
|
||||
* 修改记录 :
|
||||
* 版本号 日期 作者 说明
|
||||
* v1.0 2011-08-21 armfly ST固件库升级到V3.5.0版本。
|
||||
*
|
||||
* Copyright (C), 2010-2011, 安富莱电子 www.armfly.com
|
||||
*
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef _BSP_I2C_GPIO_H
|
||||
#define _BSP_I2C_GPIO_H
|
||||
|
||||
#include <inttypes.h>
|
||||
#include "stm32f10x.h"
|
||||
|
||||
#define I2C_WR 0 /* 写控制bit */
|
||||
#define I2C_RD 1 /* 读控制bit */
|
||||
|
||||
//IO方向设置
|
||||
#define SDA_IN() {GPIOD->CRH&=0XFFFFFF0F;GPIOD->CRH|=8<<4;}
|
||||
#define SDA_OUT() {GPIOD->CRH&=0XFFFFFF0F;GPIOD->CRH|=3<<4;}
|
||||
|
||||
//IO操作函数
|
||||
#define IIC_SCL PDout(10) //SCL
|
||||
#define IIC_SDA PDout(9) //SDA
|
||||
#define READ_SDA PDin(9) //输入SDA
|
||||
|
||||
void i2c_Start(void);
|
||||
void i2c_Stop(void);
|
||||
void i2c_SendByte(uint8_t _ucByte);
|
||||
uint8_t i2c_ReadByte(void);
|
||||
uint8_t i2c_WaitAck(void);
|
||||
void i2c_Ack(void);
|
||||
void i2c_NAck(void);
|
||||
uint8_t i2c_CheckDevice(uint8_t _Address);
|
||||
|
||||
#endif
|
||||
+1103
File diff suppressed because it is too large
Load Diff
+198
@@ -0,0 +1,198 @@
|
||||
/*************************** (C) COPYRIGHT 2018 PING ****************************
|
||||
* 文件名 :sound.h
|
||||
* 描 述 :语音播报控制程序
|
||||
* 版 本 :V1.0
|
||||
* 日 期 :2016-01-11
|
||||
* 作 者 :XuZhongPing
|
||||
* 更新记录 :
|
||||
*********************************************************************************/
|
||||
#include "sound.h"
|
||||
#include "delay.h"
|
||||
#include "timer.h"
|
||||
#include "usart1.h"
|
||||
#include "stdio.h"
|
||||
#include "string.h"
|
||||
|
||||
#define SPEAKER_PORT_PeriphClock RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO
|
||||
#define SPEAKER_PORT GPIOB
|
||||
#define SPEAKER_CTRL_PIN GPIO_Pin_3
|
||||
|
||||
uint8_t audioOutputMark = 0; //标志是否输出语音
|
||||
uint8_t audioNum = 0; //语音编号
|
||||
uint8_t audioOutputStatus = 0; //音频输出状态
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: SpeakerInit
|
||||
* 功能说明: 扬声器控制接口初始化
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void SpeakerInit(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
RCC_APB2PeriphClockCmd(SPEAKER_PORT_PeriphClock, ENABLE); //使能时钟
|
||||
|
||||
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable , ENABLE); //关闭JTAG的PB3,PB4复用功能
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = SPEAKER_CTRL_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(SPEAKER_PORT, &GPIO_InitStructure);
|
||||
|
||||
GPIO_ResetBits(SPEAKER_PORT, SPEAKER_CTRL_PIN);
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: AudioInit
|
||||
* 功能说明: 音频相关初始化
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void Audio_Init(void)
|
||||
{
|
||||
SpeakerInit();
|
||||
Audio_SetVolume(20);
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: Audio_OutputEnable
|
||||
* 功能说明: 音频输出使能
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
static void Audio_OutputEnable(void)
|
||||
{
|
||||
GPIO_SetBits(SPEAKER_PORT, SPEAKER_CTRL_PIN);
|
||||
audioOutputStatus = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: Audio_OutputDisable
|
||||
* 功能说明: 音频输出失能
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
static void Audio_OutputDisable(void)
|
||||
{
|
||||
GPIO_ResetBits(SPEAKER_PORT, SPEAKER_CTRL_PIN);
|
||||
audioOutputStatus = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: Audio_SetVolume
|
||||
* 功能说明: 设置音频音量
|
||||
* 形 参:val -> 音量值
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void Audio_SetVolume(uint8_t volume)
|
||||
{
|
||||
char str[32];
|
||||
|
||||
if (volume<=30 && volume>=1)
|
||||
{
|
||||
sprintf(str, "AF:%d", volume);
|
||||
USART1_SendFrameData((uint8_t*)str, strlen(str));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: Audio_Play
|
||||
* 功能说明: 播放指定音频
|
||||
* 形 参:num -> 语音编号
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void Audio_PlayOutput(uint8_t num)
|
||||
{
|
||||
char str[32];
|
||||
|
||||
sprintf(str, "A7:%05d", num);
|
||||
Audio_OutputEnable(); //使能语音输出
|
||||
USART1_SendFrameData((uint8_t*)str, strlen(str));
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: Audio_Play
|
||||
* 功能说明: 播放指定音频
|
||||
* 形 参:num -> 语音编号
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void Audio_Play(uint8_t num)
|
||||
{
|
||||
audioOutputMark = 1;
|
||||
audioNum = num;
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: Audio_Play
|
||||
* 功能说明: 播放指定音频
|
||||
* 形 参:num -> 语音编号
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void Audio_PlayTask(void)
|
||||
{
|
||||
static uint8_t RunningStatus = 0x00;
|
||||
|
||||
static timer waitingTimer;
|
||||
static uint8_t timer_ok = 0;
|
||||
|
||||
if(timer_ok == 0)
|
||||
{
|
||||
timer_ok = 1;
|
||||
timer_set(&waitingTimer, CLOCK_SECOND*5);
|
||||
}
|
||||
|
||||
switch(RunningStatus)
|
||||
{
|
||||
case 0x00:
|
||||
if(audioOutputMark == 1)
|
||||
{
|
||||
audioOutputMark = 0;
|
||||
Audio_PlayOutput(audioNum);
|
||||
timer_restart(&waitingTimer);
|
||||
RunningStatus = 0x01;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x01:
|
||||
if(audioOutputMark == 1)
|
||||
{
|
||||
RunningStatus = 0x00;
|
||||
break;
|
||||
}
|
||||
|
||||
if(timer_expired(&waitingTimer))
|
||||
{
|
||||
printf("\r\n停止播放!\r\n");
|
||||
Audio_OutputDisable(); //关闭语音输出
|
||||
RunningStatus = 0x00;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x02:
|
||||
break;
|
||||
|
||||
default:
|
||||
RunningStatus = 0x00;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/******************** (C) COPYRIGHT 2014 GLHF *****END OF FILE*******************/
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
/*************************** (C) COPYRIGHT 2014 GLHF ****************************
|
||||
* 文件名 :sound.h
|
||||
* 描 述 :语音播报控制头文件
|
||||
* 版 本 :V1.0
|
||||
* 日 期 :2016-01-11
|
||||
* 作 者 :XuZhongPing
|
||||
* 更新记录 :
|
||||
*********************************************************************************/
|
||||
#ifndef __SOUND_H
|
||||
#define __SOUND_H
|
||||
#include "stm32f10x.h"
|
||||
#include "stdio.h"
|
||||
|
||||
extern uint8_t audioOutputMark; //标志是否输出语音
|
||||
extern uint8_t audioNum; //语音编号
|
||||
extern uint8_t audioOutputStatus; //音频输出状态
|
||||
|
||||
void AudioInit(void);
|
||||
void VoiceBroadcast (uint8_t number);
|
||||
|
||||
void Audio_Init(void);
|
||||
void Audio_SetVolume(uint8_t volume);
|
||||
void Audio_Play(uint8_t num);
|
||||
void Audio_PlayTask(void);
|
||||
|
||||
#endif
|
||||
|
||||
/******************** (C) COPYRIGHT 2014 GLHF *****END OF FILE*******************/
|
||||
@@ -0,0 +1,15 @@
|
||||
#ifndef __SOUNDFILELIST_H
|
||||
#define __SOUNDFILELIST_H
|
||||
#include "stm32f10x.h"
|
||||
|
||||
const uint32_t SOUND_FILE_LIST[5][2] = {
|
||||
/*起启地址 长度*/
|
||||
{0x00002C, 0x0088BC}, //00语音信息
|
||||
{0x0088E8, 0x00F898}, //01语音信息
|
||||
{0x018180, 0x0151F8}, //02语音信息
|
||||
{0x02D378, 0x01701A}, //03语音信息
|
||||
{0x044392, 0x032E5C} //04语音信息
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
+669
@@ -0,0 +1,669 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :buzzer.c
|
||||
* 描 述 :蜂鸣器驱动程序
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/03/06
|
||||
*********************************************************************************/
|
||||
#include "buzzer.h"
|
||||
#include "timer.h"
|
||||
|
||||
#define BEEP_PeriphClock RCC_APB2Periph_GPIOB
|
||||
#define BEEP_PORT GPIOB
|
||||
#define BEEP_PIN GPIO_Pin_2
|
||||
|
||||
uint8_t beep_startUpMark = 0; //开机提示标志
|
||||
uint8_t beep_shortBeepMark = 0; //蜂鸣器短响标志
|
||||
uint8_t beep_longBeepMark = 0; //蜂鸣器长响标志
|
||||
uint8_t beep_closeDoorBeepMark = 0; //蜂鸣器关门响标志
|
||||
uint8_t beep_warningBeepMark = 0; //蜂鸣器错误警告提示响标志
|
||||
uint8_t beep_contSlowBeepMark = 0; //蜂鸣器连续慢响标志
|
||||
uint8_t beep_contFastBeepMark = 0; //蜂鸣器连续快响标志
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: KeyInit
|
||||
* 功能说明: 开关IO口初始化
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void BeepInit(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
RCC_APB2PeriphClockCmd(BEEP_PeriphClock, ENABLE);
|
||||
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = BEEP_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(BEEP_PORT, &GPIO_InitStructure);
|
||||
|
||||
GPIO_ResetBits(BEEP_PORT, BEEP_PIN);
|
||||
|
||||
beep_startUpMark = 1; //标志正在开机启动提示
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: SetBuzzerStatus
|
||||
* 功能说明: 设置蜂鸣器工作状态
|
||||
* 形 参:param -> 设置的状态,0关,1:开
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void SetBuzzerStatus(uint8_t param)
|
||||
{
|
||||
if(param)
|
||||
{
|
||||
GPIO_SetBits(BEEP_PORT, BEEP_PIN);
|
||||
// printf("\r\n开蜂鸣器\r\n");
|
||||
}else{
|
||||
GPIO_ResetBits(BEEP_PORT, BEEP_PIN);
|
||||
// printf("\r\n关蜂鸣器\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: BEEP_ShortBeep
|
||||
* 功能说明: 蜂鸣器短响
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
static void BEEP_ShortBeep(void)
|
||||
{
|
||||
static uint8_t beepStatus = 0x00;
|
||||
|
||||
static timer beepOnTimer;
|
||||
static uint8_t timer_ok = 0;
|
||||
|
||||
if(timer_ok == 0)
|
||||
{
|
||||
timer_ok = 1;
|
||||
|
||||
timer_set(&beepOnTimer, 2);
|
||||
}
|
||||
|
||||
switch(beepStatus)
|
||||
{
|
||||
case 0x00:
|
||||
if(beep_shortBeepMark == 1)
|
||||
{
|
||||
beep_shortBeepMark = 0;
|
||||
SetBuzzerStatus(1); //打开蜂鸣器
|
||||
|
||||
timer_restart(&beepOnTimer);
|
||||
beepStatus = 0x01;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x01:
|
||||
if(timer_expired(&beepOnTimer))
|
||||
{
|
||||
SetBuzzerStatus(0); //关闭蜂鸣器
|
||||
beepStatus = 0x00;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
SetBuzzerStatus(0); //关闭蜂鸣器
|
||||
beepStatus = 0x00;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: BEEP_LongBeep
|
||||
* 功能说明: 蜂鸣器长响
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
static void BEEP_LongBeep(void)
|
||||
{
|
||||
static uint8_t beepStatus = 0x00;
|
||||
|
||||
static timer beepOnTimer;
|
||||
static uint8_t timer_ok = 0;
|
||||
|
||||
if(timer_ok == 0)
|
||||
{
|
||||
timer_ok = 1;
|
||||
|
||||
timer_set(&beepOnTimer, 20);
|
||||
}
|
||||
|
||||
switch(beepStatus)
|
||||
{
|
||||
case 0x00:
|
||||
if(beep_longBeepMark == 1)
|
||||
{
|
||||
beep_longBeepMark = 0;
|
||||
SetBuzzerStatus(1); //打开蜂鸣器
|
||||
|
||||
timer_restart(&beepOnTimer);
|
||||
beepStatus = 0x01;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x01:
|
||||
if(timer_expired(&beepOnTimer))
|
||||
{
|
||||
SetBuzzerStatus(0); //关闭蜂鸣器
|
||||
beepStatus = 0x00;
|
||||
break;
|
||||
}
|
||||
SetBuzzerStatus(1); //打开蜂鸣器
|
||||
break;
|
||||
|
||||
default:
|
||||
SetBuzzerStatus(0); //关闭蜂鸣器
|
||||
beepStatus = 0x00;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: BEEP_StartUpBeep
|
||||
* 功能说明: 蜂鸣器开机提示声
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
static void BEEP_StartUpBeep(void)
|
||||
{
|
||||
static uint8_t beepStatus = 0x00;
|
||||
|
||||
static timer beepOnTimer1;
|
||||
static timer beepOnTimer2;
|
||||
static timer beepOffTimer1;
|
||||
static timer beepOffTimer2;
|
||||
|
||||
static uint8_t timer_ok = 0;
|
||||
|
||||
if(timer_ok == 0)
|
||||
{
|
||||
timer_ok = 1;
|
||||
|
||||
timer_set(&beepOnTimer1, 1);
|
||||
timer_set(&beepOnTimer2, 2);
|
||||
timer_set(&beepOffTimer1, 1);
|
||||
timer_set(&beepOffTimer2, 2);
|
||||
}
|
||||
|
||||
switch(beepStatus)
|
||||
{
|
||||
case 0x00:
|
||||
if(beep_startUpMark == 1)
|
||||
{
|
||||
beep_startUpMark = 0;
|
||||
SetBuzzerStatus(1); //打开蜂鸣器
|
||||
timer_restart(&beepOnTimer1);
|
||||
beepStatus = 0x01;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x01:
|
||||
if(timer_expired(&beepOnTimer1))
|
||||
{
|
||||
SetBuzzerStatus(0); //关闭蜂鸣器
|
||||
timer_restart(&beepOffTimer1);
|
||||
beepStatus = 0x02;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x02:
|
||||
if(timer_expired(&beepOffTimer1))
|
||||
{
|
||||
SetBuzzerStatus(1); //打开蜂鸣器
|
||||
timer_restart(&beepOnTimer2);
|
||||
beepStatus = 0x03;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x03:
|
||||
if(timer_expired(&beepOnTimer2))
|
||||
{
|
||||
SetBuzzerStatus(0); //关闭蜂鸣器
|
||||
timer_restart(&beepOffTimer2);
|
||||
beepStatus = 0x04;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x04:
|
||||
if(timer_expired(&beepOffTimer2))
|
||||
{
|
||||
SetBuzzerStatus(1);
|
||||
timer_restart(&beepOnTimer2);
|
||||
beepStatus = 0x05;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x05:
|
||||
if(timer_expired(&beepOnTimer2))
|
||||
{
|
||||
SetBuzzerStatus(0); //关闭蜂鸣器
|
||||
beep_startUpMark = 0;
|
||||
beepStatus = 0x00;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
SetBuzzerStatus(0); //关闭蜂鸣器
|
||||
beepStatus = 0x00;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: BEEP_CloseDoorBeep
|
||||
* 功能说明: 蜂鸣器关门提示声
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
static void BEEP_CloseDoorBeep(void)
|
||||
{
|
||||
static uint8_t beepStatus = 0x00;
|
||||
|
||||
static timer closeDoorBeepOnTimer;
|
||||
static uint8_t timer_ok = 0;
|
||||
|
||||
if(timer_ok == 0)
|
||||
{
|
||||
timer_ok = 1;
|
||||
|
||||
timer_set(&closeDoorBeepOnTimer, 5);
|
||||
}
|
||||
|
||||
switch(beepStatus)
|
||||
{
|
||||
case 0x00:
|
||||
if(beep_closeDoorBeepMark == 1)
|
||||
{
|
||||
beep_closeDoorBeepMark = 0;
|
||||
SetBuzzerStatus(1); //打开蜂鸣器
|
||||
timer_restart(&closeDoorBeepOnTimer);
|
||||
beepStatus = 0x01;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x01:
|
||||
if(timer_expired(&closeDoorBeepOnTimer))
|
||||
{
|
||||
SetBuzzerStatus(0); //关闭蜂鸣器
|
||||
timer_restart(&closeDoorBeepOnTimer);
|
||||
beepStatus = 0x02;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x02:
|
||||
if(timer_expired(&closeDoorBeepOnTimer))
|
||||
{
|
||||
SetBuzzerStatus(1); //打开蜂鸣器
|
||||
timer_restart(&closeDoorBeepOnTimer);
|
||||
beepStatus = 0x03;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x03:
|
||||
if(timer_expired(&closeDoorBeepOnTimer))
|
||||
{
|
||||
SetBuzzerStatus(0); //关闭蜂鸣器
|
||||
timer_restart(&closeDoorBeepOnTimer);
|
||||
beepStatus = 0x04;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x04:
|
||||
if(timer_expired(&closeDoorBeepOnTimer))
|
||||
{
|
||||
SetBuzzerStatus(1); //打开蜂鸣器
|
||||
timer_restart(&closeDoorBeepOnTimer);
|
||||
beepStatus = 0x05;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x05:
|
||||
if(timer_expired(&closeDoorBeepOnTimer))
|
||||
{
|
||||
SetBuzzerStatus(0); //关闭蜂鸣器
|
||||
beep_closeDoorBeepMark = 0;
|
||||
beepStatus = 0x00;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
SetBuzzerStatus(0); //关闭蜂鸣器
|
||||
beepStatus = 0x00;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: BEEP_WarningBeep
|
||||
* 功能说明: 蜂鸣器警告提示声
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
static void BEEP_WarningBeep(void)
|
||||
{
|
||||
static uint8_t beepStatus = 0x00;
|
||||
|
||||
static timer warningBeepOnTimer;
|
||||
static timer warningBeepOffTimer;
|
||||
static uint8_t timer_ok = 0;
|
||||
|
||||
if(timer_ok == 0)
|
||||
{
|
||||
timer_ok = 1;
|
||||
|
||||
timer_set(&warningBeepOnTimer, 2);
|
||||
timer_set(&warningBeepOffTimer, 2);
|
||||
}
|
||||
|
||||
switch(beepStatus)
|
||||
{
|
||||
case 0x00:
|
||||
if(beep_warningBeepMark == 1)
|
||||
{
|
||||
beep_warningBeepMark = 0;
|
||||
SetBuzzerStatus(1); //打开蜂鸣器
|
||||
timer_restart(&warningBeepOnTimer);
|
||||
beepStatus = 0x01;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x01:
|
||||
if(timer_expired(&warningBeepOnTimer))
|
||||
{
|
||||
SetBuzzerStatus(0); //关闭蜂鸣器
|
||||
timer_restart(&warningBeepOnTimer);
|
||||
beepStatus = 0x02;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x02:
|
||||
if(timer_expired(&warningBeepOnTimer))
|
||||
{
|
||||
SetBuzzerStatus(1); //打开蜂鸣器
|
||||
timer_restart(&warningBeepOnTimer);
|
||||
beepStatus = 0x03;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x03:
|
||||
if(timer_expired(&warningBeepOnTimer))
|
||||
{
|
||||
SetBuzzerStatus(0); //关闭蜂鸣器
|
||||
timer_restart(&warningBeepOnTimer);
|
||||
beepStatus = 0x04;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x04:
|
||||
if(timer_expired(&warningBeepOnTimer))
|
||||
{
|
||||
SetBuzzerStatus(1); //打开蜂鸣器
|
||||
timer_restart(&warningBeepOnTimer);
|
||||
beepStatus = 0x05;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x05:
|
||||
if(timer_expired(&warningBeepOnTimer))
|
||||
{
|
||||
SetBuzzerStatus(0); //关闭蜂鸣器
|
||||
timer_restart(&warningBeepOnTimer);
|
||||
beepStatus = 0x06;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x06:
|
||||
if(timer_expired(&warningBeepOnTimer))
|
||||
{
|
||||
SetBuzzerStatus(1); //打开蜂鸣器
|
||||
timer_restart(&warningBeepOnTimer);
|
||||
beepStatus = 0x07;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x07:
|
||||
if(timer_expired(&warningBeepOnTimer))
|
||||
{
|
||||
SetBuzzerStatus(0); //关闭蜂鸣器
|
||||
timer_restart(&warningBeepOnTimer);
|
||||
beepStatus = 0x08;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x08:
|
||||
if(timer_expired(&warningBeepOnTimer))
|
||||
{
|
||||
SetBuzzerStatus(1); //打开蜂鸣器
|
||||
timer_restart(&warningBeepOnTimer);
|
||||
beepStatus = 0x09;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x09:
|
||||
if(timer_expired(&warningBeepOnTimer))
|
||||
{
|
||||
SetBuzzerStatus(0); //关闭蜂鸣器
|
||||
beep_warningBeepMark = 0;
|
||||
beepStatus = 0x00;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
SetBuzzerStatus(0); //关闭蜂鸣器
|
||||
beep_warningBeepMark = 0;
|
||||
beepStatus = 0x00;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: BEEP_ContSlowBeep
|
||||
* 功能说明: 蜂鸣器连续慢响
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
static void BEEP_ContSlowBeep(void)
|
||||
{
|
||||
static uint8_t beepStatus = 0x00;
|
||||
|
||||
static timer beepOnTimer;
|
||||
static timer beepOffTimer;
|
||||
static uint8_t timer_ok = 0;
|
||||
|
||||
if(timer_ok == 0)
|
||||
{
|
||||
timer_ok = 1;
|
||||
|
||||
timer_set(&beepOnTimer, 2);
|
||||
timer_set(&beepOffTimer, 8);
|
||||
}
|
||||
|
||||
switch(beepStatus)
|
||||
{
|
||||
case 0x00:
|
||||
if(beep_contSlowBeepMark == 1)
|
||||
{
|
||||
SetBuzzerStatus(1); //打开蜂鸣器
|
||||
|
||||
timer_restart(&beepOnTimer);
|
||||
beepStatus = 0x01;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x01:
|
||||
if(timer_expired(&beepOnTimer))
|
||||
{
|
||||
SetBuzzerStatus(0); //关闭蜂鸣器
|
||||
timer_restart(&beepOffTimer);
|
||||
beepStatus = 0x02;
|
||||
break;
|
||||
}
|
||||
|
||||
if(beep_contSlowBeepMark == 0)
|
||||
{
|
||||
SetBuzzerStatus(0);
|
||||
beepStatus = 0x00;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x02:
|
||||
if(timer_expired(&beepOffTimer))
|
||||
{
|
||||
beepStatus = 0x00;
|
||||
break;
|
||||
}
|
||||
|
||||
if(beep_contSlowBeepMark == 0)
|
||||
{
|
||||
SetBuzzerStatus(0);
|
||||
beepStatus = 0x00;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
SetBuzzerStatus(0); //关闭蜂鸣器
|
||||
beepStatus = 0x00;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: BEEP_ContFastBeep
|
||||
* 功能说明: 蜂鸣器连续快响
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
static void BEEP_ContFastBeep(void)
|
||||
{
|
||||
static uint8_t beepStatus = 0x00;
|
||||
|
||||
static timer beepOnTimer;
|
||||
static timer beepOffTimer;
|
||||
static uint8_t timer_ok = 0;
|
||||
|
||||
if(timer_ok == 0)
|
||||
{
|
||||
timer_ok = 1;
|
||||
|
||||
timer_set(&beepOnTimer, 1);
|
||||
timer_set(&beepOffTimer, 2);
|
||||
}
|
||||
|
||||
switch(beepStatus)
|
||||
{
|
||||
case 0x00:
|
||||
if(beep_contFastBeepMark == 1)
|
||||
{
|
||||
SetBuzzerStatus(1); //打开蜂鸣器
|
||||
|
||||
timer_restart(&beepOnTimer);
|
||||
beepStatus = 0x01;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x01:
|
||||
if(timer_expired(&beepOnTimer))
|
||||
{
|
||||
SetBuzzerStatus(0); //关闭蜂鸣器
|
||||
timer_restart(&beepOffTimer);
|
||||
beepStatus = 0x02;
|
||||
break;
|
||||
}
|
||||
|
||||
if(beep_contFastBeepMark == 0)
|
||||
{
|
||||
SetBuzzerStatus(0);
|
||||
beepStatus = 0x00;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x02:
|
||||
if(timer_expired(&beepOffTimer))
|
||||
{
|
||||
beepStatus = 0x00;
|
||||
break;
|
||||
}
|
||||
|
||||
if(beep_contFastBeepMark == 0)
|
||||
{
|
||||
SetBuzzerStatus(0);
|
||||
beepStatus = 0x00;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
SetBuzzerStatus(0); //关闭蜂鸣器
|
||||
beepStatus = 0x00;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: BeepTask
|
||||
* 功能说明:
|
||||
* 形 参:无
|
||||
* 返 回 值: 返回对应开关的键值
|
||||
***********************************************************************
|
||||
*/
|
||||
void BeepTask(void)
|
||||
{
|
||||
BEEP_ContSlowBeep();
|
||||
BEEP_ContFastBeep();
|
||||
BEEP_ShortBeep();
|
||||
BEEP_LongBeep();
|
||||
BEEP_StartUpBeep();
|
||||
BEEP_CloseDoorBeep();
|
||||
BEEP_WarningBeep();
|
||||
}
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 CXHY *****END OF FILE*******************/
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :buzzer.h
|
||||
* 描 述 : 蜂鸣器驱动程序
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/03/06
|
||||
*********************************************************************************/
|
||||
#ifndef __BUZZER_H
|
||||
#define __BUZZER_H
|
||||
|
||||
#include "stm32f10x.h"
|
||||
|
||||
extern uint8_t beep_startUpMark; //开机提示标志
|
||||
extern uint8_t beep_shortBeepMark; //蜂鸣器短响标志
|
||||
extern uint8_t beep_longBeepMark; //蜂鸣器长响标志
|
||||
extern uint8_t beep_closeDoorBeepMark; //蜂鸣器关门响标志
|
||||
extern uint8_t beep_warningBeepMark; //蜂鸣器错误警告提示响标志
|
||||
extern uint8_t beep_contSlowBeepMark; //蜂鸣器连续慢响标志
|
||||
extern uint8_t beep_contFastBeepMark; //蜂鸣器连续快响标志
|
||||
|
||||
void BeepInit(void);
|
||||
void BeepTask(void);
|
||||
|
||||
#endif
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 CXHY *****END OF FILE*******************/
|
||||
+1387
File diff suppressed because it is too large
Load Diff
+72
@@ -0,0 +1,72 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :device.h
|
||||
* 描 述 :设备控制程序
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/03/06
|
||||
*********************************************************************************/
|
||||
#ifndef __DEVICE_H
|
||||
#define __DEVICE_H
|
||||
|
||||
//四分类+有害箱体类型定义(四分类一体的箱体要将此定义注释掉)
|
||||
#define FOUR_CHANNEL_AND_HARMFUL
|
||||
#define FOUR_DROP_PORTS
|
||||
|
||||
#include "stm32f10x.h"
|
||||
#include "usart1.h"
|
||||
#include "usart2.h"
|
||||
#include "usart3.h"
|
||||
#include "usart4.h"
|
||||
#include "usart5.h"
|
||||
|
||||
#include "string.h"
|
||||
#include "stdlib.h"
|
||||
|
||||
#include "led.h"
|
||||
#include "key.h"
|
||||
#include "opto_sw_key.h"
|
||||
#include "sw_key.h"
|
||||
#include "buzzer.h"
|
||||
#include "scale.h"
|
||||
#include "ElectronicLock.h"
|
||||
#include "motor.h"
|
||||
#include "RFID_IC.h"
|
||||
#include "qr_code.h"
|
||||
#include "ntc.h"
|
||||
#include "sound.h"
|
||||
#include "spi.h"
|
||||
#include "flash.h"
|
||||
#include "stmflash.h"
|
||||
#include "distancer.h"
|
||||
|
||||
#include "ec200x.h"
|
||||
#include "disinfection.h"
|
||||
#include "door_ctrl.h"
|
||||
#include "m_s_comm.h"
|
||||
|
||||
#define VersionNumber "V2.1_260709_4CH"
|
||||
|
||||
void show(uint8_t num[], uint8_t n);
|
||||
void CalcOverflowStartPointParam(void);
|
||||
void DeviceInit(void); //设备初始化
|
||||
void DeviceTest(void); //硬件测试
|
||||
void UserIdentificationTask(void);
|
||||
uint8_t GetPutInType(void); //取得开门投放类型
|
||||
void ShowPutInTyep(uint8_t uType);
|
||||
void GetUserInfo(uint8_t inputType); //根据开门请求方式来取得用户的相关信息
|
||||
void ClearPutInInfo(void); //清除开门请求
|
||||
|
||||
|
||||
void DeviceScanning(void);
|
||||
void PutInOpenDoorTask(void);
|
||||
void OpenDoorRequestTask(void);
|
||||
void DeviceControlTask(void);
|
||||
void CollectorLockCtrlTask(void);
|
||||
void FillLightTask(void);
|
||||
void CoolingFanCtrlTask(void);
|
||||
void SprayCtrlTask(void);
|
||||
void SystemExceptionTask(void);
|
||||
|
||||
#endif
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 CXHY *****END OF FILE*******************/
|
||||
+1694
File diff suppressed because it is too large
Load Diff
+36
@@ -0,0 +1,36 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :deviceSet.h
|
||||
* 描 述 :设备设置程序
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2019/03/06
|
||||
*********************************************************************************/
|
||||
#ifndef __DEVICE_SET_H
|
||||
#define __DEVICE_SET_H
|
||||
|
||||
#include "stm32f10x.h"
|
||||
#include "string.h"
|
||||
#include "stdlib.h"
|
||||
|
||||
#include "led.h"
|
||||
#include "key.h"
|
||||
#include "opto_sw_key.h"
|
||||
#include "sw_key.h"
|
||||
#include "usart5.h"
|
||||
|
||||
#include "sound.h"
|
||||
#include "spi.h"
|
||||
#include "flash.h"
|
||||
|
||||
void DeviceInfoShow(void);
|
||||
void ShowRecyclingBinsType(uint8_t type);
|
||||
void DeviceTypeSet(uint8_t setkeyVal);
|
||||
void DeviceSetParamInit(void);
|
||||
void DeviceParamInit(void);
|
||||
void SetDefaultOverflowAlarmParam(void);
|
||||
|
||||
void ParamSetTask(void);
|
||||
|
||||
#endif
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 CXHY *****END OF FILE*******************/
|
||||
+387
@@ -0,0 +1,387 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :distancer.c
|
||||
* 描 述 :测距程序
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/08/04
|
||||
*********************************************************************************/
|
||||
#include "distancer.h"
|
||||
#include "timer.h"
|
||||
#include "delay.h"
|
||||
#include "my_math.h"
|
||||
#include "data_typedef.h"
|
||||
#include "key.h"
|
||||
#include "pc_protocol.h"
|
||||
|
||||
uint16_t distanceCnt1 = 0;
|
||||
uint16_t distanceCnt2 = 0;
|
||||
|
||||
uint8_t distanceBuf1[DISTANCE_CNT_MAX] = {0}; //采样数据缓存
|
||||
uint8_t distanceBuf2[DISTANCE_CNT_MAX] = {0};
|
||||
|
||||
uint8_t outputDistance1 = 255; //多次采样处理过后的测距数据
|
||||
uint8_t outputDistance2 = 255;
|
||||
uint8_t outputDistance3 = 255;
|
||||
uint8_t outputDistance4 = 255;
|
||||
|
||||
uint8_t restartGetDisDataMark = 0; //重新开始采样标志
|
||||
|
||||
|
||||
|
||||
void showData(uint8_t num[], uint8_t n)
|
||||
{
|
||||
uint8_t i;
|
||||
printf("\r\n");
|
||||
for(i=0; i<n; i++)
|
||||
{
|
||||
printf("%03d ",num[i]);
|
||||
}
|
||||
printf("\r\n");
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: DataSort
|
||||
* 功能说明: 对输入的数组进行排序(从大到小排列)
|
||||
* 形 参:
|
||||
* x[]:需要处理的数组
|
||||
* n:数组的长度
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void DataSort(uint8_t x[], uint8_t n)
|
||||
{
|
||||
uint8_t i,j,k,t;
|
||||
|
||||
for (i=0; i<n-1; i++)
|
||||
{
|
||||
k = i;
|
||||
for(j=i+1; j<n; j++)
|
||||
{
|
||||
if(x[j] > x[k]) k = j;
|
||||
}
|
||||
if(k != i)
|
||||
{
|
||||
t = x[i];
|
||||
x[i] = x[k];
|
||||
x[k] = t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: uint average(uint *p,uchar n)
|
||||
* 功能说明: 去掉最大和最小值后求平均数
|
||||
* 形 参:
|
||||
* x[]:需要处理的数组
|
||||
* n:数组的长度
|
||||
* discardVal:丢弃值(两头各丢掉的数据数量)
|
||||
* 返 回 值: 处理后的结果
|
||||
***********************************************************************
|
||||
*/
|
||||
uint8_t Average(uint8_t x[], uint8_t n, uint8_t discardVal)
|
||||
{
|
||||
uint8_t i = 0;
|
||||
uint8_t aver = 0;
|
||||
uint32_t sum = 0;
|
||||
|
||||
for(i = discardVal; i < n-discardVal; i++)
|
||||
{
|
||||
sum = sum+x[i];
|
||||
}
|
||||
aver = sum/(n - discardVal*2);
|
||||
return aver;
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: DistanceDataUpdata
|
||||
* 功能说明: 多次采样满溢测距数据处理程序
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void DistanceDataUpdata(void)
|
||||
{
|
||||
static uint8_t currentStatus = 0x00;
|
||||
static uint8_t nextStatus = 0x00;
|
||||
|
||||
static timer waitingTimer;
|
||||
|
||||
static uint8_t timer_ok = 0;
|
||||
|
||||
if(timer_ok == 0)
|
||||
{
|
||||
timer_ok = 1;
|
||||
|
||||
timer_set(&waitingTimer, CLOCK_SECOND*15);
|
||||
}
|
||||
|
||||
if(restartGetDisDataMark == 1)
|
||||
{
|
||||
restartGetDisDataMark = 0;
|
||||
|
||||
distanceCnt1 = 0;
|
||||
distanceCnt2 = 0;
|
||||
|
||||
printf("\r\n重新采集满溢数据!\r\n");
|
||||
timer_restart(&waitingTimer);
|
||||
}
|
||||
|
||||
if(putInProgress == 0)
|
||||
{
|
||||
if(timer_expired(&waitingTimer))
|
||||
{
|
||||
timer_restart(&waitingTimer);
|
||||
|
||||
printf("\r\n测距数据处理!\r\n");
|
||||
|
||||
printf("\r\ndistanceCnt1 = %d\r\n", distanceCnt1);
|
||||
showData(distanceBuf1, distanceCnt1);
|
||||
DataSort(distanceBuf1, distanceCnt1);
|
||||
showData(distanceBuf1, distanceCnt1);
|
||||
outputDistance1 = Average(distanceBuf1, distanceCnt1, 10);
|
||||
if((outputDistance1 > distanceParamAtStart) && (outputDistance1 != 255))
|
||||
{
|
||||
outputDistance1 = devChannel1DisMaxVal;
|
||||
}
|
||||
printf("\r\noutputDistance1 = %d\r\n", outputDistance1);
|
||||
|
||||
printf("\r\ndistanceCnt2 = %d\r\n", distanceCnt2);
|
||||
showData(distanceBuf2, distanceCnt2);
|
||||
DataSort(distanceBuf2, distanceCnt2);
|
||||
showData(distanceBuf2, distanceCnt2);
|
||||
outputDistance2 = Average(distanceBuf2, distanceCnt2, 10);
|
||||
if((outputDistance2 > distanceParamAtStart) && (outputDistance2 != 255))
|
||||
{
|
||||
outputDistance2 = devChannel2DisMaxVal;
|
||||
}
|
||||
printf("\r\noutputDistance2 = %d\r\n", outputDistance2);
|
||||
|
||||
//计算变量归零重新开始
|
||||
distanceCnt1 = 0;
|
||||
distanceCnt2 = 0;
|
||||
|
||||
PC_ProCommandSend(0x62);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: OverflowDetectionTask
|
||||
* 功能说明: 桶装满检测任务
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void OverflowDetectionTask(void)
|
||||
{
|
||||
uint8_t a1 = 0, a2 = 0, a3 = 0, a4 = 0;
|
||||
uint8_t A1 = 0, A2 = 0, A3 = 0, A4 = 0;
|
||||
|
||||
static uint8_t fullMarkPre1 = 0;
|
||||
static uint8_t fullMarkPre2 = 0;
|
||||
static uint8_t fullMarkPre3 = 0;
|
||||
static uint8_t fullMarkPre4 = 0;
|
||||
|
||||
static timer timer_60s;
|
||||
static uint8_t timer_ok = 0;
|
||||
|
||||
if(timer_ok == 0)
|
||||
{
|
||||
timer_ok = 1;
|
||||
timer_set(&timer_60s, CLOCK_SECOND*10);
|
||||
}
|
||||
|
||||
//根据设定的参数判断是否装满
|
||||
//第1通道满溢判断
|
||||
if((devChannel1DisDepthVal > 0) && (outputDistance1 <= devChannel1DisMaxVal))
|
||||
{
|
||||
a1 = devChannel1DisMaxVal - outputDistance1;
|
||||
A1 = ((uint16_t)a1*100)/devChannel1DisDepthVal;
|
||||
|
||||
// printf("\r\nd1 = %d, a1 = %d, A1 = %d\r\n", getDistance1, a1, A1);
|
||||
|
||||
if(A1 >= devChannel1DisAlarmPercent)
|
||||
{
|
||||
fullMark1 = 1;
|
||||
}else{
|
||||
fullMark1 = 0;
|
||||
}
|
||||
}else{ //当前所测得的距大于设定的安装高度说明为空箱
|
||||
fullMark1 = 0;
|
||||
}
|
||||
|
||||
//第2通道满溢判断
|
||||
if((devChannel2DisDepthVal > 0) && (outputDistance2 <= devChannel2DisMaxVal))
|
||||
{
|
||||
a2 = devChannel2DisMaxVal - outputDistance2;
|
||||
A2 = ((uint16_t)a2*100)/devChannel2DisDepthVal;
|
||||
|
||||
// printf("\r\nd2 = %d, a2 = %d, A2 = %d\r\n", getDistance2, a2, A2);
|
||||
|
||||
if(A2 >= devChannel2DisAlarmPercent)
|
||||
{
|
||||
fullMark2 = 1;
|
||||
}else{
|
||||
fullMark2 = 0;
|
||||
}
|
||||
}else{ //当前所测得的距大于设定的安装高度说明为空箱
|
||||
fullMark2 = 0;
|
||||
}
|
||||
|
||||
//第3通道满溢判断
|
||||
if((devChannel3DisDepthVal > 0) && (outputDistance3 <= devChannel3DisMaxVal))
|
||||
{
|
||||
a3 = devChannel3DisMaxVal - outputDistance3;
|
||||
A3 = ((uint16_t)a3*100)/devChannel3DisDepthVal;
|
||||
fullMark3 = (A3 >= devChannel3DisAlarmPercent) ? 1 : 0;
|
||||
}else{
|
||||
fullMark3 = 0;
|
||||
}
|
||||
|
||||
//第4通道满溢判断
|
||||
if((devChannel4DisDepthVal > 0) && (outputDistance4 <= devChannel4DisMaxVal))
|
||||
{
|
||||
a4 = devChannel4DisMaxVal - outputDistance4;
|
||||
A4 = ((uint16_t)a4*100)/devChannel4DisDepthVal;
|
||||
fullMark4 = (A4 >= devChannel4DisAlarmPercent) ? 1 : 0;
|
||||
}else{
|
||||
fullMark4 = 0;
|
||||
}
|
||||
|
||||
//根据满溢及故障情况设置指示灯
|
||||
if((netStatus == 2) || (devRunnigStatus == 2))
|
||||
{
|
||||
//设置有故障时的灯光颜色
|
||||
SetKeyLedOFF(1);
|
||||
SetKeyLedON(2);
|
||||
SetKeyLedOFF(3);
|
||||
SetKeyLedON(4);
|
||||
}else{
|
||||
#ifdef FOUR_DROP_PORTS
|
||||
//四投放口面板每个投放口使用一个满溢指示灯。
|
||||
if(fullMark1) SetKeyLedON(1); else SetKeyLedOFF(1);
|
||||
if(fullMark2) SetKeyLedON(2); else SetKeyLedOFF(2);
|
||||
if(fullMark3) SetKeyLedON(3); else SetKeyLedOFF(3);
|
||||
if(fullMark4) SetKeyLedON(4); else SetKeyLedOFF(4);
|
||||
#else
|
||||
//通道1
|
||||
if(fullMark1 == 1)
|
||||
{
|
||||
SetKeyLedOFF(1);
|
||||
SetKeyLedON(2);
|
||||
}else{
|
||||
SetKeyLedON(1);
|
||||
SetKeyLedOFF(2);
|
||||
}
|
||||
|
||||
//通道2
|
||||
if(fullMark2 == 1)
|
||||
{
|
||||
SetKeyLedOFF(3);
|
||||
SetKeyLedON(4);
|
||||
}else{
|
||||
SetKeyLedON(3);
|
||||
SetKeyLedOFF(4);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
//打印调试信息
|
||||
if((fullMarkPre1 != fullMark1) || (fullMarkPre2 != fullMark2) ||
|
||||
(fullMarkPre3 != fullMark3) || (fullMarkPre4 != fullMark4))
|
||||
{
|
||||
if(fullMark1 == 1)
|
||||
{
|
||||
printf("\r\nCH1装满\r\n");
|
||||
}else{
|
||||
printf("\r\nCH1已清空\r\n");
|
||||
}
|
||||
fullMarkPre1 = fullMark1;
|
||||
printf("\r\nd1 = %d, a1 = %d, A1 = %d%%\r\n", outputDistance1, a1, A1);
|
||||
|
||||
if(fullMark2 == 1)
|
||||
{
|
||||
printf("\r\nCH2装满\r\n");
|
||||
}else{
|
||||
printf("\r\nCH2已清空\r\n");
|
||||
}
|
||||
fullMarkPre2 = fullMark2;
|
||||
|
||||
printf("\r\nd2 = %d, a2 = %d, A2 = %d%%\r\n", outputDistance2, a2, A2);
|
||||
|
||||
fullMarkPre3 = fullMark3;
|
||||
fullMarkPre4 = fullMark4;
|
||||
printf("\r\nd3 = %d, a3 = %d, A3 = %d%%\r\n", outputDistance3, a3, A3);
|
||||
printf("\r\nd4 = %d, a4 = %d, A4 = %d%%\r\n", outputDistance4, a4, A4);
|
||||
|
||||
PC_ProCommandSend(0x62);
|
||||
}
|
||||
|
||||
// //打印调试信息
|
||||
// if(fullMarkPre1 != fullMark1)
|
||||
// {
|
||||
// if(fullMark1 == 1)
|
||||
// {
|
||||
// printf("\r\nCH1装满\r\n");
|
||||
// }else{
|
||||
// printf("\r\nCH1已清空\r\n");
|
||||
// }
|
||||
// fullMarkPre1 = fullMark1;
|
||||
// printf("\r\nd1 = %d, a1 = %d, A1 = %d%%\r\n", getDistance1, a1, A1);
|
||||
// }
|
||||
//
|
||||
// if(fullMarkPre2 != fullMark2)
|
||||
// {
|
||||
// if(fullMark2 == 1)
|
||||
// {
|
||||
// printf("\r\nCH2装满\r\n");
|
||||
// }else{
|
||||
// printf("\r\nCH2已清空\r\n");
|
||||
// }
|
||||
// fullMarkPre2 = fullMark2;
|
||||
//
|
||||
// printf("\r\nd2 = %d, a2 = %d, A2 = %d%%\r\n", getDistance2, a2, A2);
|
||||
// }
|
||||
//
|
||||
// if(fullMarkPre3 != fullMark3)
|
||||
// {
|
||||
// if(fullMark3 == 1)
|
||||
// {
|
||||
// printf("\r\nCH3装满\r\n");
|
||||
// }else{
|
||||
// printf("\r\nCH3已清空\r\n");
|
||||
// }
|
||||
// fullMarkPre3 = fullMark3;
|
||||
// printf("\r\nd3 = %d, a3 = %d, A3 = %d%%\r\n", getDistance3, a3, A3);
|
||||
// }
|
||||
//
|
||||
// if(fullMarkPre4 != fullMark4)
|
||||
// {
|
||||
// if(fullMark4 == 1)
|
||||
// {
|
||||
// printf("\r\nCH4装满\r\n");
|
||||
// }else{
|
||||
// printf("\r\nCH4已清空\r\n");
|
||||
// }
|
||||
// fullMarkPre4 = fullMark4;
|
||||
// printf("\r\nd4 = %d, a4 = %d, A4 = %d%%\r\n", getDistance4, a4, A4);
|
||||
// }
|
||||
|
||||
//装满后1分钟打印一次装满提示
|
||||
if(timer_expired(&timer_60s))
|
||||
{
|
||||
timer_restart(&timer_60s);
|
||||
|
||||
printf("\r\n通道1:d1 = %d, a1 = %d, A1 = %d%%\r\n", outputDistance1, a1, A1);
|
||||
printf("\r\n通道2:d2 = %d, a2 = %d, A2 = %d%%\r\n", outputDistance2, a2, A2);
|
||||
printf("\r\n通道3:d3 = %d, a3 = %d, A3 = %d%%\r\n", outputDistance3, a3, A3);
|
||||
printf("\r\n通道4:d4 = %d, a4 = %d, A4 = %d%%\r\n", outputDistance4, a4, A4);
|
||||
}
|
||||
}
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 CXHY *****END OF FILE*******************/
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :distancer.h
|
||||
* 描 述 :测距程序
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/08/04
|
||||
*********************************************************************************/
|
||||
#ifndef __DISTANCER_H
|
||||
#define __DISTANCER_H
|
||||
#include "stm32f10x.h"
|
||||
#include "IR_Distancer.h"
|
||||
#include "UltrasonicWave.h"
|
||||
|
||||
|
||||
// 设备类型
|
||||
typedef enum
|
||||
{
|
||||
ULTRASONIC_DISTANCER = 1, //超声波测距
|
||||
IR_DISTANCER //红外测距
|
||||
}DistanceSensorDefine;
|
||||
|
||||
extern uint8_t distancerTpye; //测距传感器的类型
|
||||
|
||||
#define DISTANCE_CNT_MAX 120
|
||||
|
||||
extern uint16_t distanceCnt1;
|
||||
extern uint16_t distanceCnt2;
|
||||
|
||||
extern uint8_t distanceBuf1[DISTANCE_CNT_MAX];
|
||||
extern uint8_t distanceBuf2[DISTANCE_CNT_MAX];
|
||||
|
||||
extern uint8_t restartGetDisDataMark;
|
||||
|
||||
extern uint8_t outputDistance1;
|
||||
extern uint8_t outputDistance2;
|
||||
extern uint8_t outputDistance3;
|
||||
extern uint8_t outputDistance4;
|
||||
|
||||
|
||||
void GetDistanceTask(void);
|
||||
void OverflowDetectionTask(void);
|
||||
|
||||
void DistanceDataUpdata(void);
|
||||
|
||||
#endif
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 CXHY *****END OF FILE*******************/
|
||||
+492
@@ -0,0 +1,492 @@
|
||||
/*************************** (C) COPYRIGHT 2020 Ping ****************************
|
||||
* 文件名 :m_s_comm.c
|
||||
* 描 述 :主从MCU通讯处理程序
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2020/03/31
|
||||
*********************************************************************************/
|
||||
#include "m_s_comm.h"
|
||||
#include "device.h"
|
||||
#include "data_typedef.h"
|
||||
//#include "distancer.h"
|
||||
|
||||
uint8_t M_S_RX_BUF[M_S_RECV_LEN]; //接收缓冲
|
||||
uint8_t M_S_TX_BUF[M_S_SEND_LEN]; //发送缓冲
|
||||
|
||||
static void M_S_DataDecode(uint8_t *pRxBuf, uint8_t *pTxBuf);
|
||||
|
||||
static uint8_t CorrectOverflowDistance(uint8_t rawDistance, uint16_t channelWeight,
|
||||
uint8_t maxVal, uint8_t depthVal)
|
||||
{
|
||||
uint16_t correctedDistance;
|
||||
uint16_t measureStart;
|
||||
|
||||
if(rawDistance == 255)
|
||||
{
|
||||
return 255;
|
||||
}
|
||||
|
||||
correctedDistance = (uint16_t)rawDistance + 15;
|
||||
measureStart = maxVal - (((uint16_t)depthVal * PerCentSetVal) / 100);
|
||||
|
||||
if(correctedDistance > measureStart)
|
||||
{
|
||||
correctedDistance = maxVal;
|
||||
}
|
||||
|
||||
if((channelWeight < 1700) && (correctedDistance < 75))
|
||||
{
|
||||
correctedDistance = maxVal;
|
||||
}
|
||||
|
||||
return (uint8_t)correctedDistance;
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: M_S_DataPackingAndSend
|
||||
* 功能说明: 主从机通讯数据打包及发送
|
||||
* 形 参: *pdata -> 需要打包的数据地址,dataLen -> 数据长度
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void M_S_DataPackingAndSend(uint8_t *pdata, uint16_t dataLen)
|
||||
{
|
||||
uint8_t i;
|
||||
uint8_t CS = 0x68;
|
||||
uint8_t TX_Size = 0;
|
||||
|
||||
uint8_t sendDataBuf[128];
|
||||
uint8_t dataAddrIndex = 0;
|
||||
uint8_t sendDataLen = 0;
|
||||
|
||||
sendDataBuf[dataAddrIndex++] = 0xfe; //发送前导字节
|
||||
sendDataBuf[dataAddrIndex++] = 0xfe;
|
||||
sendDataBuf[dataAddrIndex++] = 0xfe;
|
||||
sendDataBuf[dataAddrIndex++] = 0x68; //发送帧头
|
||||
|
||||
sendDataBuf[dataAddrIndex++] = *pdata; //发送地址
|
||||
CS += *pdata;
|
||||
sendDataBuf[dataAddrIndex++] = 0x68; //发送帧头
|
||||
CS += 0x68;
|
||||
sendDataBuf[dataAddrIndex++] = *(pdata+1); //发送帧命令
|
||||
CS += *(pdata+1);
|
||||
TX_Size = *(pdata+2); //取出通讯数据长度
|
||||
sendDataBuf[dataAddrIndex++] = TX_Size; //发送数据长度
|
||||
CS += *(pdata+2);
|
||||
for(i=0; i<TX_Size; i++) //加载发送数据
|
||||
{
|
||||
sendDataBuf[dataAddrIndex++] = *(pdata+i+3);
|
||||
CS += (*(pdata+i+3));
|
||||
}
|
||||
sendDataBuf[dataAddrIndex++] = CS; //发送校验字节
|
||||
sendDataBuf[dataAddrIndex++] = 0x16; //发送帧尾
|
||||
|
||||
sendDataLen = dataAddrIndex;
|
||||
|
||||
// showHex(sendDataBuf, sendDataLen);
|
||||
|
||||
USART2_SendFrameData(sendDataBuf, sendDataLen);
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: M_S_CommandSend
|
||||
* 功能说明: 从机向主机发送数据通讯命令
|
||||
* 形 参: comNum -> 指令号
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void M_S_CommandSend(uint8_t comNum)
|
||||
{
|
||||
uint8_t dataLen = 0; //打包后的协议总长度
|
||||
uint8_t dataIndex = 0; //发送的数据下标索引
|
||||
|
||||
M_S_TX_BUF[0] = 0x00; //设置通讯地址
|
||||
M_S_TX_BUF[1] = comNum; //存入命令码
|
||||
|
||||
dataIndex += 3; //从地址、命令、长度后开始算起
|
||||
|
||||
printf("\r\nM->S --> 0x%02X\r\n", comNum);
|
||||
|
||||
switch(comNum)
|
||||
{
|
||||
case 0x01:
|
||||
|
||||
break;
|
||||
|
||||
case 0xA1: //启动称盘校准
|
||||
M_S_TX_BUF[dataIndex++] = scaleNum;
|
||||
break;
|
||||
|
||||
case 0xA5: //发送称盘校准失败
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
//存入通信数据长度
|
||||
M_S_TX_BUF[2] = dataIndex - 3; //存入通讯数据长度字节
|
||||
dataLen = dataIndex;
|
||||
|
||||
// printf("\r\nlen = %d\r\n", dataLen);
|
||||
M_S_DataPackingAndSend(M_S_TX_BUF, dataLen); //按指定规则打包数据然后发送
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: OverflowDataCorrection1
|
||||
* 功能说明: 满溢数据修正
|
||||
* 形 参: 无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
static void OverflowDataCorrection1(void)
|
||||
{
|
||||
static uint8_t currentStatus = 0x00;
|
||||
static uint8_t nextStatus = 0x00;
|
||||
|
||||
static uint16_t preweight = 0;
|
||||
uint16_t tempDate = 0;
|
||||
|
||||
currentStatus = nextStatus;
|
||||
switch(currentStatus)
|
||||
{
|
||||
case 0x00:
|
||||
if((weight1 > 2000) && (getDistance1) < 65) //满溢超过90%,且重量达到10kg,则强行就数据进行修正,直到重量变轻为5kg以下
|
||||
{
|
||||
printf("\r\nNo.1开始数据修正!\r\n");
|
||||
|
||||
preweight = weight1;
|
||||
getDistance1 = 55;
|
||||
nextStatus = 0x01;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x01:
|
||||
if(weight1 < preweight)
|
||||
{
|
||||
tempDate = preweight - weight1;
|
||||
}else{
|
||||
tempDate = 0;
|
||||
}
|
||||
|
||||
if(tempDate > 500) //重量变轻(即收运拉出内桶)
|
||||
{
|
||||
|
||||
printf("\r\nNo.1数据取消修正!\r\n");
|
||||
nextStatus = 0x00;
|
||||
break;
|
||||
}else{
|
||||
getDistance1 = 55;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
nextStatus = 0x00;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: OverflowDataCorrection1
|
||||
* 功能说明: 满溢数据修正
|
||||
* 形 参: 无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
static void OverflowDataCorrection2(void)
|
||||
{
|
||||
static uint8_t currentStatus = 0x00;
|
||||
static uint8_t nextStatus = 0x00;
|
||||
|
||||
static uint16_t preweight = 0;
|
||||
uint16_t tempDate = 0;
|
||||
|
||||
currentStatus = nextStatus;
|
||||
switch(currentStatus)
|
||||
{
|
||||
case 0x00:
|
||||
if((weight2 > 2000) && (getDistance2) < 65) //满溢超过90%,且重量达到10kg,则强行就数据进行修正,直到重量变轻为5kg以下
|
||||
{
|
||||
printf("\r\nNo.2开始数据修正!\r\n");
|
||||
|
||||
preweight = weight2;
|
||||
getDistance2 = 55;
|
||||
nextStatus = 0x01;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x01:
|
||||
if(weight2 < preweight)
|
||||
{
|
||||
tempDate = preweight - weight2;
|
||||
}else{
|
||||
tempDate = 0;
|
||||
}
|
||||
|
||||
if(tempDate > 500) //重量变轻(即收运拉出内桶)
|
||||
{
|
||||
printf("\r\nNo.2数据取消修正!\r\n");
|
||||
nextStatus = 0x00;
|
||||
break;
|
||||
}else{
|
||||
getDistance2 = 55;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
nextStatus = 0x00;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: M_S_DataDecode
|
||||
* 功能说明: 主从机通讯数据解析
|
||||
* 形 参: *pRxBuf -> 接收缓存的地址,*pTxBuf -> 发送数据缓存地址
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
static void M_S_DataDecode(uint8_t *pRxBuf, uint8_t *pTxBuf)
|
||||
{
|
||||
uint8_t comNum = 0; //主从机指令码
|
||||
|
||||
comNum = *(pRxBuf+1);
|
||||
|
||||
// printf("\r\nS->M <-- 0x%02X\r\n", comNum);
|
||||
switch(comNum) //通讯命令译码
|
||||
{
|
||||
case 0x01: //收到从机MCU2发送过来的称重、测距、光电开关状态数据
|
||||
weight1 = *(pRxBuf+3) << 8;
|
||||
weight1 |= *(pRxBuf+4);
|
||||
|
||||
weight2 = *(pRxBuf+5) << 8;
|
||||
weight2 |= *(pRxBuf+6);
|
||||
|
||||
weight3 = *(pRxBuf+7) << 8;
|
||||
weight3 |= *(pRxBuf+8);
|
||||
|
||||
weight4 = *(pRxBuf+9) << 8;
|
||||
weight4 |= *(pRxBuf+10);
|
||||
|
||||
//测距数据
|
||||
//根据硬件接口连接线顺序进行转换
|
||||
#ifdef FOUR_CHANNEL_AND_HARMFUL
|
||||
//------------------------------------------------------------------->
|
||||
|
||||
if(updateDistanceMark == 0) //投放过程不更新测距值
|
||||
{
|
||||
getDistance1 = CorrectOverflowDistance(*(pRxBuf+11), weight1,
|
||||
devChannel1DisMaxVal, devChannel1DisDepthVal);
|
||||
getDistance2 = CorrectOverflowDistance(*(pRxBuf+12), weight2,
|
||||
devChannel2DisMaxVal, devChannel2DisDepthVal);
|
||||
getDistance3 = CorrectOverflowDistance(*(pRxBuf+13), weight3,
|
||||
devChannel3DisMaxVal, devChannel3DisDepthVal);
|
||||
getDistance4 = CorrectOverflowDistance(*(pRxBuf+14), weight4,
|
||||
devChannel4DisMaxVal, devChannel4DisDepthVal);
|
||||
|
||||
outputDistance1 = getDistance1;
|
||||
outputDistance2 = getDistance2;
|
||||
outputDistance3 = getDistance3;
|
||||
outputDistance4 = getDistance4;
|
||||
|
||||
printf("\r\nGet D1=%d, D2=%d, D3=%d, D4=%d\r\n",
|
||||
getDistance1, getDistance2, getDistance3, getDistance4);
|
||||
}
|
||||
//<-------------------------------------------------------------------
|
||||
|
||||
//测距数据经过补尝
|
||||
// if(updateDistanceMark == 0) //投放过程不更新测距值
|
||||
// {
|
||||
// tempData1 = *(pRxBuf+11);
|
||||
// tempData2 = *(pRxBuf+12);
|
||||
//
|
||||
// //取出第1路测距数据
|
||||
// if(tempData1 == 255)
|
||||
// {
|
||||
// getDistance1 = 255;
|
||||
// }else{
|
||||
// tempData1 += 35; //根据安装高度补偿距离值
|
||||
//
|
||||
// if(tempData1 > distanceParamAtStart)
|
||||
// {
|
||||
// getDistance1 = devChannel1DisMaxVal;
|
||||
// }else{
|
||||
// getDistance1 = tempData1;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// //20230727修改,满溢数据修正
|
||||
// OverflowDataCorrection1();
|
||||
//
|
||||
// if((weight1 < 1500) && (getDistance1) > 80)
|
||||
// {
|
||||
// getDistance1 = devChannel1DisMaxVal;
|
||||
// }
|
||||
//
|
||||
// //20230524修改,换红外传感器及调整安装高度不做多次采集处理
|
||||
// outputDistance1 = getDistance1;
|
||||
//
|
||||
//// distanceBuf1[distanceCnt1++] = getDistance1;
|
||||
//// if(distanceCnt1 >= DISTANCE_CNT_MAX)
|
||||
//// {
|
||||
//// distanceCnt1 = DISTANCE_CNT_MAX - 1;
|
||||
//// printf("\r\nCnt1 >= MAX\r\n");
|
||||
//// }
|
||||
//
|
||||
// //取出第2路测距数据
|
||||
// if(tempData2 == 255)
|
||||
// {
|
||||
// getDistance2 = 255;
|
||||
// }else{
|
||||
// tempData2 += 35; //根据安装高度补偿距离值
|
||||
//
|
||||
// if(tempData2 > distanceParamAtStart)
|
||||
// {
|
||||
// getDistance2 = devChannel1DisMaxVal;
|
||||
// }else{
|
||||
// getDistance2 = tempData2;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// //20230727修改,满溢数据修正
|
||||
// OverflowDataCorrection2();
|
||||
//
|
||||
// if((weight2 < 1500) && (getDistance2) > 80)
|
||||
// {
|
||||
// getDistance2 = devChannel2DisMaxVal;
|
||||
// }
|
||||
//
|
||||
// //20230524修改,换红外传感器及调整安装高度不做多次采集处理
|
||||
// outputDistance2 = getDistance2;
|
||||
//
|
||||
//// distanceBuf2[distanceCnt2++] = getDistance2;
|
||||
//// if(distanceCnt2 >= DISTANCE_CNT_MAX)
|
||||
//// {
|
||||
//// distanceCnt2 = DISTANCE_CNT_MAX - 1;
|
||||
//// printf("\r\nCnt2 >= MAX\r\n");
|
||||
//// }
|
||||
//
|
||||
//
|
||||
// getDistance3 = *(pRxBuf+13);
|
||||
// getDistance4 = *(pRxBuf+14);
|
||||
//
|
||||
// printf("\r\nGet D1=%d, D2=%d\r\n", getDistance1, getDistance2);
|
||||
// }
|
||||
|
||||
// getDistance1 = *(pRxBuf+11);
|
||||
// getDistance2 = *(pRxBuf+12);
|
||||
// getDistance3 = *(pRxBuf+13);
|
||||
// getDistance4 = *(pRxBuf+14);
|
||||
#else
|
||||
getDistance1 = *(pRxBuf+11);
|
||||
getDistance4 = *(pRxBuf+12);
|
||||
getDistance2 = *(pRxBuf+13);
|
||||
getDistance3 = *(pRxBuf+14);
|
||||
#endif
|
||||
|
||||
//主板温度
|
||||
temperature_C = *(pRxBuf+15);
|
||||
|
||||
//收运门状态
|
||||
getRecycleClearDoorMark = *(pRxBuf+16);
|
||||
|
||||
//外部温度
|
||||
temperature_A = *(pRxBuf+17);
|
||||
|
||||
//接近开关状态
|
||||
switchKey1Status = *(pRxBuf+18);
|
||||
switchKey2Status = *(pRxBuf+19);
|
||||
|
||||
getMcu2SensorDataMark = 1; //标志接收到数据,由外部读取后清除
|
||||
break;
|
||||
|
||||
case 0x02: //MCU2检测到的光电开关状态数据(用于当按键使用)
|
||||
optoKeyStatus = *(pRxBuf+3);
|
||||
break;
|
||||
|
||||
case 0x03: //GPS定位信息
|
||||
gpsConnectSta = *(pRxBuf+3); //GPS模块硬件连接状态
|
||||
gpsStatus = *(pRxBuf+4); //GPS定位状态
|
||||
gpsEW = *(pRxBuf+5); //经度方向(0->E-东,W-西)
|
||||
gpsLon = *(pRxBuf+6) << 24; //经度(已放大1000000倍)
|
||||
gpsLon |= *(pRxBuf+7) << 16;
|
||||
gpsLon |= *(pRxBuf+8) << 8;
|
||||
gpsLon |= *(pRxBuf+9);
|
||||
gpsNS = *(pRxBuf+10); //纬度方向(0->N-北,1->S-南)
|
||||
gpsLat = *(pRxBuf+11) << 24; //纬度(已放大1000000倍)
|
||||
gpsLat |= *(pRxBuf+12) << 16;
|
||||
gpsLat |= *(pRxBuf+13) << 8;
|
||||
gpsLat |= *(pRxBuf+14);
|
||||
|
||||
getGpsStatus = 1;
|
||||
break;
|
||||
|
||||
case 0xA2: //取得校准零点
|
||||
receiveScaleNum = *(pRxBuf+3);
|
||||
switch(receiveScaleNum)
|
||||
{
|
||||
case 1:
|
||||
getCalibraZeroMark1 = 1;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
getCalibraZeroMark2 = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 0xA3: //校准完成
|
||||
receiveScaleNum = *(pRxBuf+3);
|
||||
switch(receiveScaleNum)
|
||||
{
|
||||
case 1:
|
||||
getCalibraParamOkMark1 = 1;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
getCalibraParamOkMark2 = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default: //其他命令
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: M_S_DataDecodeTask
|
||||
* 功能说明: 主从机数据通讯解析处理任务
|
||||
* 形 参: 无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void M_S_DataDecodeTask(void)
|
||||
{
|
||||
if(USART2_RX_STA == 0xfd) //有接收到主机发送的数据
|
||||
{
|
||||
M_S_DataDecode(USART2_RX_BUF, USART2_TX_BUF); //解释返回的数据
|
||||
|
||||
memset(USART2_RX_BUF, 0x00, USART2_RECV_LEN); //清除缓存内容
|
||||
USART2_RX_STA = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 CXHY *****END OF FILE*******************/
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
#ifndef __M_S_COMM_H
|
||||
#define __M_S_COMM_H
|
||||
#include "stm32f10x.h"
|
||||
|
||||
#define M_S_RECV_LEN 128 //最大接收缓存字节数
|
||||
#define M_S_SEND_LEN 128 //最大发送缓存字节数
|
||||
|
||||
extern uint8_t M_S_RX_BUF[M_S_RECV_LEN]; //接收缓冲
|
||||
extern uint8_t M_S_TX_BUF[M_S_SEND_LEN]; //发送缓冲
|
||||
|
||||
void M_S_CommandSend(uint8_t comNum); //主从机数据发送
|
||||
void M_S_DataDecodeTask(void); //主从机数据解析
|
||||
|
||||
#endif
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 CXHY *****END OF FILE*******************/
|
||||
@@ -0,0 +1,308 @@
|
||||
/*************************** (C) COPYRIGHT 2017 YNHB ****************************
|
||||
* 文件名 :disinfection.c
|
||||
* 描 述 :消毒控制程序
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2020/04/17
|
||||
*********************************************************************************/
|
||||
#include "disinfection.h"
|
||||
#include "timer.h"
|
||||
#include "ElectronicLock.h"
|
||||
#include "motor.h"
|
||||
|
||||
uint8_t disinfectionStatus = 0;
|
||||
uint8_t disinfectingMark = 0; //消毒状态
|
||||
uint8_t sprayDisinfectionStatus = 0;
|
||||
uint8_t sprayDisinfectingMark = 0; //喷淋消毒状态标志
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: StartUpDisinfection
|
||||
* 功能说明: 启动消毒
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void StartUpDisinfection(void)
|
||||
{
|
||||
Unlock(5);
|
||||
|
||||
printf("\r\n启动消毒除臭!\r\n");
|
||||
disinfectionStatus = 1; //标志当前正在消毒状态
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: StopDisinfection
|
||||
* 功能说明: 停止消毒
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void StopDisinfection(void)
|
||||
{
|
||||
Locked(5);
|
||||
|
||||
printf("\r\n停止消毒除臭!\r\n");
|
||||
disinfectionStatus = 0; //标志当前消毒处于停止状态
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: DisinfectingTask
|
||||
* 功能说明: 消毒处理任务
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void DisinfectingTask(void)
|
||||
{
|
||||
static uint8_t executeSteps = 0;
|
||||
|
||||
static timer disinfectingTimer; //消毒开启时间
|
||||
static timer sleepTimer; //消毒装置休眠时间
|
||||
static timer waitingTimer;
|
||||
|
||||
static uint8_t timer_ok = 0;
|
||||
|
||||
if(timer_ok == 0)
|
||||
{
|
||||
timer_ok = 1;
|
||||
timer_set(&disinfectingTimer, CLOCK_SECOND*60*30); //消毒工作时间定时器
|
||||
timer_set(&sleepTimer, CLOCK_SECOND*60*30); //消毒装置休眠时间
|
||||
timer_set(&waitingTimer, CLOCK_SECOND*2); //创建1个定时器
|
||||
}
|
||||
|
||||
|
||||
switch(executeSteps)
|
||||
{
|
||||
case 0x00:
|
||||
if(disinfectingMark == 1)
|
||||
{
|
||||
StartUpDisinfection();
|
||||
printf("\r\n启动消毒!\r\n");
|
||||
timer_restart(&disinfectingTimer);
|
||||
executeSteps = 0x01;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x01: //消毒进行中
|
||||
if(timer_expired(&disinfectingTimer))
|
||||
{
|
||||
StopDisinfection(); //消毒时间到停止消毒
|
||||
|
||||
printf("\r\n消毒完成!\r\n");
|
||||
disinfectingMark = 0;
|
||||
executeSteps = 0x03;
|
||||
break;
|
||||
}
|
||||
|
||||
//消毒过程中如果有投放,则暂停消毒
|
||||
if(disinfectingMark == 2)
|
||||
{
|
||||
StopDisinfection();
|
||||
printf("\r\n暂停消毒!\r\n");
|
||||
executeSteps = 0x02;
|
||||
break;
|
||||
}
|
||||
|
||||
// //消毒过程中如果有投放或者打开收运门,则中断消毒
|
||||
// if(disinfectingMark == 0)
|
||||
// {
|
||||
// StopDisinfection();
|
||||
// printf("\r\n中断消毒!\r\n");
|
||||
// executeSteps = 0x03;
|
||||
// break;
|
||||
// }
|
||||
break;
|
||||
|
||||
case 0x02: //暂停消毒
|
||||
if(timer_expired(&disinfectingTimer))
|
||||
{
|
||||
StopDisinfection(); //消毒时间到停止消毒
|
||||
|
||||
printf("\r\n消毒时间到!\r\n");
|
||||
disinfectingMark = 0;
|
||||
executeSteps = 0x03;
|
||||
break;
|
||||
}
|
||||
|
||||
if(disinfectingMark == 1)
|
||||
{
|
||||
StartUpDisinfection();
|
||||
printf("\r\n重新启动消毒!\r\n");
|
||||
executeSteps = 0x01;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x03: //消毒装置启动休眠定时
|
||||
printf("\r\n消毒装置进入休眠!\r\n");
|
||||
timer_restart(&sleepTimer);
|
||||
executeSteps = 0x04;
|
||||
break;
|
||||
|
||||
case 0x04: //消毒装置进入休眠
|
||||
if(timer_expired(&sleepTimer))
|
||||
{
|
||||
printf("\r\n消毒装置休眠时间到!\r\n");
|
||||
executeSteps = 0x00;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
StopDisinfection();
|
||||
disinfectingMark = 0;
|
||||
executeSteps = 0x00;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: StartUpDisinfection
|
||||
* 功能说明: 启动消毒
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void StartUpSprayDisinfection(void)
|
||||
{
|
||||
DoorClose(3);
|
||||
|
||||
printf("\r\n启动喷淋消毒除臭!\r\n");
|
||||
sprayDisinfectionStatus = 1; //标志当前正在消毒状态
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: StopDisinfection
|
||||
* 功能说明: 停止消毒
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void StopSprayDisinfection(void)
|
||||
{
|
||||
DoorStop(3);
|
||||
|
||||
printf("\r\n停止喷淋消毒除臭!\r\n");
|
||||
sprayDisinfectionStatus = 0; //标志当前消毒处于停止状态
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: SprayDisinfectingTask
|
||||
* 功能说明: 喷淋消毒处理任务
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void SprayDisinfectingTask(void)
|
||||
{
|
||||
static uint8_t executeSteps = 0;
|
||||
|
||||
static timer disinfectingTimer; //消毒开启时间
|
||||
static timer sleepTimer; //消毒装置休眠时间
|
||||
static timer waitingTimer;
|
||||
|
||||
static uint8_t timer_ok = 0;
|
||||
|
||||
if(timer_ok == 0)
|
||||
{
|
||||
timer_ok = 1;
|
||||
timer_set(&disinfectingTimer, CLOCK_SECOND*3); //消毒工作时间定时器
|
||||
// timer_set(&sleepTimer, CLOCK_SECOND*60*30); //消毒装置休眠时间
|
||||
timer_set(&sleepTimer, CLOCK_SECOND*1); //消毒装置休眠时间
|
||||
timer_set(&waitingTimer, CLOCK_SECOND*2); //创建1个定时器
|
||||
}
|
||||
|
||||
|
||||
switch(executeSteps)
|
||||
{
|
||||
case 0x00:
|
||||
if(sprayDisinfectingMark == 1)
|
||||
{
|
||||
StartUpSprayDisinfection();
|
||||
printf("\r\n启动消毒!\r\n");
|
||||
timer_restart(&disinfectingTimer);
|
||||
executeSteps = 0x01;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x01: //消毒进行中
|
||||
if(timer_expired(&disinfectingTimer))
|
||||
{
|
||||
StopSprayDisinfection(); //消毒时间到停止消毒
|
||||
|
||||
printf("\r\n消毒完成!\r\n");
|
||||
sprayDisinfectingMark = 0;
|
||||
executeSteps = 0x03;
|
||||
break;
|
||||
}
|
||||
|
||||
//消毒过程中如果有投放,则暂停消毒
|
||||
if(sprayDisinfectingMark == 2)
|
||||
{
|
||||
StopSprayDisinfection();
|
||||
printf("\r\n暂停消毒!\r\n");
|
||||
executeSteps = 0x02;
|
||||
break;
|
||||
}
|
||||
|
||||
// //消毒过程中如果有投放或者打开收运门,则中断消毒
|
||||
// if(disinfectingMark == 0)
|
||||
// {
|
||||
// StopDisinfection();
|
||||
// printf("\r\n中断消毒!\r\n");
|
||||
// executeSteps = 0x03;
|
||||
// break;
|
||||
// }
|
||||
break;
|
||||
|
||||
case 0x02: //暂停消毒
|
||||
if(timer_expired(&disinfectingTimer))
|
||||
{
|
||||
StopSprayDisinfection(); //消毒时间到停止消毒
|
||||
|
||||
printf("\r\n消毒时间到!\r\n");
|
||||
sprayDisinfectingMark = 0;
|
||||
executeSteps = 0x03;
|
||||
break;
|
||||
}
|
||||
|
||||
if(sprayDisinfectingMark == 1)
|
||||
{
|
||||
StartUpSprayDisinfection();
|
||||
printf("\r\n重新启动消毒!\r\n");
|
||||
executeSteps = 0x01;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x03: //消毒装置启动休眠定时
|
||||
printf("\r\n消毒装置进入休眠!\r\n");
|
||||
timer_restart(&sleepTimer);
|
||||
executeSteps = 0x04;
|
||||
break;
|
||||
|
||||
case 0x04: //消毒装置进入休眠
|
||||
if(timer_expired(&sleepTimer))
|
||||
{
|
||||
printf("\r\n消毒装置休眠时间到!\r\n");
|
||||
executeSteps = 0x00;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
StopSprayDisinfection();
|
||||
sprayDisinfectingMark = 0;
|
||||
executeSteps = 0x00;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 YNHB *****END OF FILE*******************/
|
||||
@@ -0,0 +1,28 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :disinfection.h
|
||||
* 描 述 :消毒控制程序头文件
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2020/04/17
|
||||
*********************************************************************************/
|
||||
#ifndef __DISINFECTION_H
|
||||
#define __DISINFECTION_H
|
||||
|
||||
#include "stm32f10x.h"
|
||||
#include "stdio.h"
|
||||
|
||||
extern uint8_t disinfectionStatus;
|
||||
extern uint8_t disinfectingMark; //消毒状态
|
||||
extern uint8_t sprayDisinfectingMark; //喷淋消毒状态标志
|
||||
|
||||
void StartUpDisinfection(void); //启动消毒除臭
|
||||
void StopDisinfection(void); //停止消毒除臭
|
||||
void DisinfectingTask(void); //消毒除臭处理任务
|
||||
|
||||
void StartUpSprayDisinfection(void); //启动喷淋消毒
|
||||
void StopSprayDisinfection(void); //停止喷淋消毒
|
||||
void SprayDisinfectingTask(void);
|
||||
|
||||
#endif
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 CXHY *****END OF FILE*******************/
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
#include "exti.h"
|
||||
#include "led.h"
|
||||
#include "key.h"
|
||||
#include "delay.h"
|
||||
#include "usart.h"
|
||||
|
||||
|
||||
//外部中断初始化程序
|
||||
//初始化PA0,PA13,PA15为中断输入.
|
||||
void EXTIX_Init(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
EXTI_InitTypeDef EXTI_InitStructure;
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
|
||||
|
||||
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable , ENABLE); //关闭jtag
|
||||
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_AFIO,ENABLE);
|
||||
|
||||
//init GPIOC.7 下拉输入
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;
|
||||
GPIO_Init(GPIOC, &GPIO_InitStructure);
|
||||
|
||||
|
||||
//GPIOC.7
|
||||
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC,GPIO_PinSource7);
|
||||
|
||||
EXTI_InitStructure.EXTI_Line=EXTI_Line7;
|
||||
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
|
||||
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
|
||||
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
|
||||
EXTI_Init(&EXTI_InitStructure);
|
||||
|
||||
|
||||
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn; //使能按键所在的外部中断通道
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02; //先占优先级4位,共16级
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x02; //先占优先级0位,从优先级4位
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能外部中断通道
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
}
|
||||
|
||||
|
||||
void EXTI9_5_IRQHandler(void)
|
||||
{
|
||||
delay_ms(10); //消抖
|
||||
if(EXTI_GetITStatus(EXTI_Line7) != RESET) //检查指定的EXTI7线路触发请求发生与否
|
||||
{
|
||||
LED0=!LED0;
|
||||
LED1=!LED1;
|
||||
}
|
||||
EXTI_ClearITPendingBit(EXTI_Line7); //清除EXTI7线路挂起位
|
||||
}
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
#ifndef __EXTI_H
|
||||
#define __EXIT_H
|
||||
#include "sys.h"
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
//本程序只供学习使用,未经作者许可,不得用于其它任何用途
|
||||
//Mini STM32开发板
|
||||
//外部中断 驱动代码
|
||||
//正点原子@ALIENTEK
|
||||
//技术论坛:www.openedv.com
|
||||
//修改日期:2010/12/01
|
||||
//版本:V1.0
|
||||
//版权所有,盗版必究。
|
||||
//Copyright(C) 正点原子 2009-2019
|
||||
//All rights reserved
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
void EXTIX_Init(void);//IO初始化
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,270 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :ElectronicLock.c
|
||||
* 描 述 :电子锁控制驱动程序
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/05/06
|
||||
*********************************************************************************/
|
||||
#include "ElectronicLock.h"
|
||||
#include "RFID_IC.h"
|
||||
#include "timer.h"
|
||||
|
||||
#define ELE_LOCK1_PeriphClock RCC_APB2Periph_GPIOC
|
||||
#define ELE_LOCK1_PORT GPIOC
|
||||
#define ELE_LOCK1_PIN GPIO_Pin_2
|
||||
|
||||
#define ELE_LOCK2_PeriphClock RCC_APB2Periph_GPIOC
|
||||
#define ELE_LOCK2_PORT GPIOC
|
||||
#define ELE_LOCK2_PIN GPIO_Pin_3
|
||||
|
||||
#define ELE_LOCK3_PeriphClock RCC_APB2Periph_GPIOA
|
||||
#define ELE_LOCK3_PORT GPIOA
|
||||
#define ELE_LOCK3_PIN GPIO_Pin_0
|
||||
|
||||
#define ELE_LOCK4_PeriphClock RCC_APB2Periph_GPIOA
|
||||
#define ELE_LOCK4_PORT GPIOA
|
||||
#define ELE_LOCK4_PIN GPIO_Pin_1
|
||||
|
||||
#define ELE_LOCK5_PeriphClock RCC_APB2Periph_GPIOB
|
||||
#define ELE_LOCK5_PORT GPIOB
|
||||
#define ELE_LOCK5_PIN GPIO_Pin_13
|
||||
|
||||
#define ELE_LOCK6_PeriphClock RCC_APB2Periph_GPIOB
|
||||
#define ELE_LOCK6_PORT GPIOB
|
||||
#define ELE_LOCK6_PIN GPIO_Pin_14
|
||||
|
||||
|
||||
uint8_t lockStatus_1 = 0;
|
||||
uint8_t lockStatus_2 = 0;
|
||||
uint8_t lockStatus_3 = 0;
|
||||
uint8_t lockStatus_4 = 0;
|
||||
uint8_t lockStatus_5 = 0;
|
||||
uint8_t lockStatus_6 = 0;
|
||||
|
||||
uint8_t isUnlockingMark = 0;
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: ElectronicLock_Init
|
||||
* 功能说明: 电子锁控制IO口初始化
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void ElectronicLock_Init(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
|
||||
RCC_APB2PeriphClockCmd(ELE_LOCK1_PeriphClock, ENABLE); //使能端口时钟
|
||||
RCC_APB2PeriphClockCmd(ELE_LOCK2_PeriphClock, ENABLE);
|
||||
RCC_APB2PeriphClockCmd(ELE_LOCK3_PeriphClock, ENABLE);
|
||||
RCC_APB2PeriphClockCmd(ELE_LOCK4_PeriphClock, ENABLE);
|
||||
RCC_APB2PeriphClockCmd(ELE_LOCK5_PeriphClock, ENABLE);
|
||||
RCC_APB2PeriphClockCmd(ELE_LOCK6_PeriphClock, ENABLE);
|
||||
|
||||
//第一路电磁锁IO口配置
|
||||
GPIO_InitStructure.GPIO_Pin = ELE_LOCK1_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(ELE_LOCK1_PORT, &GPIO_InitStructure);
|
||||
|
||||
GPIO_ResetBits(ELE_LOCK1_PORT, ELE_LOCK1_PIN);
|
||||
|
||||
//第二路电磁锁IO口配置
|
||||
GPIO_InitStructure.GPIO_Pin = ELE_LOCK2_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(ELE_LOCK2_PORT, &GPIO_InitStructure);
|
||||
|
||||
GPIO_ResetBits(ELE_LOCK2_PORT, ELE_LOCK2_PIN);
|
||||
|
||||
//第三路电磁锁IO口配置
|
||||
GPIO_InitStructure.GPIO_Pin = ELE_LOCK3_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(ELE_LOCK3_PORT, &GPIO_InitStructure);
|
||||
|
||||
GPIO_ResetBits(ELE_LOCK3_PORT, ELE_LOCK3_PIN);
|
||||
|
||||
//第四路电磁锁IO口配置
|
||||
GPIO_InitStructure.GPIO_Pin = ELE_LOCK4_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(ELE_LOCK4_PORT, &GPIO_InitStructure);
|
||||
|
||||
GPIO_ResetBits(ELE_LOCK4_PORT, ELE_LOCK4_PIN);
|
||||
|
||||
//第五路电磁锁IO口配置
|
||||
GPIO_InitStructure.GPIO_Pin = ELE_LOCK5_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(ELE_LOCK5_PORT, &GPIO_InitStructure);
|
||||
|
||||
GPIO_ResetBits(ELE_LOCK5_PORT, ELE_LOCK5_PIN);
|
||||
|
||||
//第六路电磁锁IO口配置
|
||||
GPIO_InitStructure.GPIO_Pin = ELE_LOCK6_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(ELE_LOCK6_PORT, &GPIO_InitStructure);
|
||||
|
||||
GPIO_ResetBits(ELE_LOCK6_PORT, ELE_LOCK6_PIN);
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: Unlock
|
||||
* 功能说明: 开锁
|
||||
* 形 参:num -> 哪一路电子锁
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void Unlock(uint8_t num)
|
||||
{
|
||||
switch(num)
|
||||
{
|
||||
case 1:
|
||||
GPIO_SetBits(ELE_LOCK1_PORT, ELE_LOCK1_PIN);
|
||||
lockStatus_1 = 1;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
GPIO_SetBits(ELE_LOCK2_PORT, ELE_LOCK2_PIN);
|
||||
lockStatus_2 = 1;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
GPIO_SetBits(ELE_LOCK3_PORT, ELE_LOCK3_PIN);
|
||||
lockStatus_3 = 1;
|
||||
break;
|
||||
|
||||
case 4:
|
||||
GPIO_SetBits(ELE_LOCK4_PORT, ELE_LOCK4_PIN);
|
||||
lockStatus_4 = 1;
|
||||
break;
|
||||
|
||||
case 5:
|
||||
GPIO_SetBits(ELE_LOCK5_PORT, ELE_LOCK5_PIN);
|
||||
lockStatus_5 = 1;
|
||||
break;
|
||||
|
||||
case 6:
|
||||
GPIO_SetBits(ELE_LOCK6_PORT, ELE_LOCK6_PIN);
|
||||
lockStatus_6 = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("\r\n没有此通道电磁锁!-> %d\r\n", num);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: Locked
|
||||
* 功能说明: 上锁
|
||||
* 形 参:num -> 哪一路电子锁
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void Locked(uint8_t num)
|
||||
{
|
||||
switch(num)
|
||||
{
|
||||
case 1:
|
||||
GPIO_ResetBits(ELE_LOCK1_PORT, ELE_LOCK1_PIN);
|
||||
lockStatus_1 = 0;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
GPIO_ResetBits(ELE_LOCK2_PORT, ELE_LOCK2_PIN);
|
||||
lockStatus_2 = 0;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
GPIO_ResetBits(ELE_LOCK3_PORT, ELE_LOCK3_PIN);
|
||||
lockStatus_3 = 0;
|
||||
break;
|
||||
|
||||
case 4:
|
||||
GPIO_ResetBits(ELE_LOCK4_PORT, ELE_LOCK4_PIN);
|
||||
lockStatus_4 = 0;
|
||||
break;
|
||||
|
||||
case 5:
|
||||
GPIO_ResetBits(ELE_LOCK5_PORT, ELE_LOCK5_PIN);
|
||||
lockStatus_5 = 0;
|
||||
break;
|
||||
|
||||
case 6:
|
||||
GPIO_ResetBits(ELE_LOCK6_PORT, ELE_LOCK6_PIN);
|
||||
lockStatus_6 = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("\r\n没有此通道电磁锁!-> %d\r\n", num);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: ElectronicLockCtrlTask
|
||||
* 功能说明: 电子锁控制任务
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void ElectronicLockCtrlTask(void)
|
||||
{
|
||||
static uint8_t eleLockNum = 1;
|
||||
static uint8_t EleLockStatus = 0x00;
|
||||
|
||||
static timer waitingTimer;
|
||||
static uint8_t timer_ok = 0;
|
||||
|
||||
if(timer_ok == 0)
|
||||
{
|
||||
timer_ok = 1;
|
||||
timer_set(&waitingTimer, 2);
|
||||
}
|
||||
|
||||
switch(EleLockStatus)
|
||||
{
|
||||
case 0x00:
|
||||
if(timer_expired(&waitingTimer))
|
||||
{
|
||||
Unlock(eleLockNum);
|
||||
|
||||
printf("\r\n开锁 -> %d\r\n", eleLockNum);
|
||||
timer_restart(&waitingTimer);
|
||||
EleLockStatus = 0x01;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x01:
|
||||
if(timer_expired(&waitingTimer))
|
||||
{
|
||||
Locked(eleLockNum);
|
||||
printf("\r\n上锁 -> %d\r\n", eleLockNum);
|
||||
|
||||
eleLockNum++;
|
||||
if(eleLockNum >= 7)
|
||||
{
|
||||
eleLockNum = 1;
|
||||
}
|
||||
timer_restart(&waitingTimer);
|
||||
EleLockStatus = 0x00;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 CXHY *****END OF FILE*******************/
|
||||
@@ -0,0 +1,29 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :ElectronicLock.c
|
||||
* 描 述 :电子锁控制驱动程序
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/05/06
|
||||
*********************************************************************************/
|
||||
#ifndef __ELE_LOCK_H
|
||||
#define __ELE_LOCK_H
|
||||
#include "stm32f10x.h"
|
||||
#include "stdio.h"
|
||||
|
||||
extern uint8_t lockStatus_1;
|
||||
extern uint8_t lockStatus_2;
|
||||
extern uint8_t lockStatus_3;
|
||||
extern uint8_t lockStatus_4;
|
||||
extern uint8_t lockStatus_5;
|
||||
extern uint8_t lockStatus_6;
|
||||
|
||||
extern uint8_t isUnlockingMark;
|
||||
|
||||
void ElectronicLock_Init(void); //初始化
|
||||
void Unlock(uint8_t num);
|
||||
void Locked(uint8_t num);
|
||||
void ElectronicLockCtrlTask(void);
|
||||
|
||||
#endif
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 CXHY *****END OF FILE*******************/
|
||||
+257
@@ -0,0 +1,257 @@
|
||||
#include "flash.h"
|
||||
#include "spi.h"
|
||||
#include "delay.h"
|
||||
|
||||
uint16_t SPI_FLASH_TYPE = W25Q64; //默认就是25Q64
|
||||
|
||||
//4Kbytes为一个Sector
|
||||
//16个扇区为1个Block
|
||||
//W25X16
|
||||
//容量为2M字节,共有32个Block,512个Sector
|
||||
|
||||
//初始化SPI FLASH的IO口
|
||||
void SPI_Flash_Init(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE);//PORTB时钟使能
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; // PA4 推挽
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(GPIOE, &GPIO_InitStructure);
|
||||
GPIO_SetBits(GPIOE, GPIO_Pin_7);
|
||||
|
||||
// SPI1_Init(); //初始化SPI
|
||||
// SPI_SetSpeed(SPI_BaudRatePrescaler_2);//设置为18M时钟,高速模式
|
||||
SPI_FLASH_TYPE = SPI_Flash_ReadID();//读取FLASH ID.
|
||||
|
||||
}
|
||||
|
||||
//读取SPI_FLASH的状态寄存器
|
||||
//BIT7 6 5 4 3 2 1 0
|
||||
//SPR RV TB BP2 BP1 BP0 WEL BUSY
|
||||
//SPR:默认0,状态寄存器保护位,配合WP使用
|
||||
//TB,BP2,BP1,BP0:FLASH区域写保护设置
|
||||
//WEL:写使能锁定
|
||||
//BUSY:忙标记位(1,忙;0,空闲)
|
||||
//默认:0x00
|
||||
uint8_t SPI_Flash_ReadSR(void)
|
||||
{
|
||||
uint8_t byte=0;
|
||||
SPI_FLASH_CS=0; //使能器件
|
||||
SPI1_ReadWriteByte(W25X_ReadStatusReg); //发送读取状态寄存器命令
|
||||
byte=SPI1_ReadWriteByte(0Xff); //读取一个字节
|
||||
SPI_FLASH_CS=1; //取消片选
|
||||
return byte;
|
||||
}
|
||||
//写SPI_FLASH状态寄存器
|
||||
//只有SPR,TB,BP2,BP1,BP0(bit 7,5,4,3,2)可以写!!!
|
||||
void SPI_FLASH_Write_SR(uint8_t sr)
|
||||
{
|
||||
SPI_FLASH_CS=0; //使能器件
|
||||
SPI1_ReadWriteByte(W25X_WriteStatusReg); //发送写取状态寄存器命令
|
||||
SPI1_ReadWriteByte(sr); //写入一个字节
|
||||
SPI_FLASH_CS=1; //取消片选
|
||||
}
|
||||
|
||||
//SPI_FLASH写使能
|
||||
//将WEL置位
|
||||
void SPI_FLASH_Write_Enable(void)
|
||||
{
|
||||
SPI_FLASH_CS=0; //使能器件
|
||||
SPI1_ReadWriteByte(W25X_WriteEnable); //发送写使能
|
||||
SPI_FLASH_CS=1; //取消片选
|
||||
}
|
||||
|
||||
//SPI_FLASH写禁止
|
||||
//将WEL清零
|
||||
void SPI_FLASH_Write_Disable(void)
|
||||
{
|
||||
SPI_FLASH_CS=0; //使能器件
|
||||
SPI1_ReadWriteByte(W25X_WriteDisable); //发送写禁止指令
|
||||
SPI_FLASH_CS=1; //取消片选
|
||||
}
|
||||
//读取芯片ID W25X16的ID:0XEF14
|
||||
uint16_t SPI_Flash_ReadID(void)
|
||||
{
|
||||
uint16_t Temp = 0;
|
||||
SPI_FLASH_CS=0;
|
||||
SPI1_ReadWriteByte(0x90);//发送读取ID命令
|
||||
SPI1_ReadWriteByte(0x00);
|
||||
SPI1_ReadWriteByte(0x00);
|
||||
SPI1_ReadWriteByte(0x00);
|
||||
Temp|=SPI1_ReadWriteByte(0xFF)<<8;
|
||||
Temp|=SPI1_ReadWriteByte(0xFF);
|
||||
SPI_FLASH_CS=1;
|
||||
return Temp;
|
||||
}
|
||||
//读取SPI FLASH
|
||||
//在指定地址开始读取指定长度的数据
|
||||
//pBuffer:数据存储区
|
||||
//ReadAddr:开始读取的地址(24bit)
|
||||
//NumByteToRead:要读取的字节数(最大65535)
|
||||
void SPI_Flash_Read(uint8_t* pBuffer, uint32_t ReadAddr, uint16_t NumByteToRead)
|
||||
{
|
||||
uint16_t i;
|
||||
SPI_FLASH_CS=0; //使能器件
|
||||
SPI1_ReadWriteByte(W25X_ReadData); //发送读取命令
|
||||
SPI1_ReadWriteByte((uint8_t)((ReadAddr)>>16)); //发送24bit地址
|
||||
SPI1_ReadWriteByte((uint8_t)((ReadAddr)>>8));
|
||||
SPI1_ReadWriteByte((uint8_t)ReadAddr);
|
||||
for(i=0;i<NumByteToRead;i++)
|
||||
{
|
||||
pBuffer[i]=SPI1_ReadWriteByte(0XFF); //循环读数
|
||||
}
|
||||
SPI_FLASH_CS=1; //取消片选
|
||||
}
|
||||
|
||||
//SPI在一页(0~65535)内写入少于256个字节的数据
|
||||
//在指定地址开始写入最大256字节的数据
|
||||
//pBuffer:数据存储区
|
||||
//WriteAddr:开始写入的地址(24bit)
|
||||
//NumByteToWrite:要写入的字节数(最大256),该数不应该超过该页的剩余字节数!!!
|
||||
void SPI_Flash_Write_Page(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite)
|
||||
{
|
||||
uint16_t i;
|
||||
SPI_FLASH_Write_Enable(); //SET WEL
|
||||
SPI_FLASH_CS=0; //使能器件
|
||||
SPI1_ReadWriteByte(W25X_PageProgram); //发送写页命令
|
||||
SPI1_ReadWriteByte((uint8_t)((WriteAddr)>>16)); //发送24bit地址
|
||||
SPI1_ReadWriteByte((uint8_t)((WriteAddr)>>8));
|
||||
SPI1_ReadWriteByte((uint8_t)WriteAddr);
|
||||
for(i=0;i<NumByteToWrite;i++)SPI1_ReadWriteByte(pBuffer[i]);//循环写数
|
||||
SPI_FLASH_CS=1; //取消片选
|
||||
SPI_Flash_Wait_Busy(); //等待写入结束
|
||||
}
|
||||
//无检验写SPI FLASH
|
||||
//必须确保所写的地址范围内的数据全部为0XFF,否则在非0XFF处写入的数据将失败!
|
||||
//具有自动换页功能
|
||||
//在指定地址开始写入指定长度的数据,但是要确保地址不越界!
|
||||
//pBuffer:数据存储区
|
||||
//WriteAddr:开始写入的地址(24bit)
|
||||
//NumByteToWrite:要写入的字节数(最大65535)
|
||||
//CHECK OK
|
||||
void SPI_Flash_Write_NoCheck(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite)
|
||||
{
|
||||
uint16_t pageremain;
|
||||
pageremain=256-WriteAddr%256; //单页剩余的字节数
|
||||
if(NumByteToWrite<=pageremain)pageremain=NumByteToWrite;//不大于256个字节
|
||||
while(1)
|
||||
{
|
||||
SPI_Flash_Write_Page(pBuffer,WriteAddr,pageremain);
|
||||
if(NumByteToWrite==pageremain)break;//写入结束了
|
||||
else //NumByteToWrite>pageremain
|
||||
{
|
||||
pBuffer+=pageremain;
|
||||
WriteAddr+=pageremain;
|
||||
|
||||
NumByteToWrite-=pageremain; //减去已经写入了的字节数
|
||||
if(NumByteToWrite>256)pageremain=256; //一次可以写入256个字节
|
||||
else pageremain=NumByteToWrite; //不够256个字节了
|
||||
}
|
||||
};
|
||||
}
|
||||
//写SPI FLASH
|
||||
//在指定地址开始写入指定长度的数据
|
||||
//该函数带擦除操作!
|
||||
//pBuffer:数据存储区
|
||||
//WriteAddr:开始写入的地址(24bit)
|
||||
//NumByteToWrite:要写入的字节数(最大65535)
|
||||
uint8_t SPI_FLASH_BUF[4096];
|
||||
void SPI_Flash_Write(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite)
|
||||
{
|
||||
uint32_t secpos;
|
||||
uint16_t secoff;
|
||||
uint16_t secremain;
|
||||
uint16_t i;
|
||||
|
||||
secpos=WriteAddr/4096;//扇区地址 0~511 for w25x16
|
||||
secoff=WriteAddr%4096;//在扇区内的偏移
|
||||
secremain=4096-secoff;//扇区剩余空间大小
|
||||
|
||||
if(NumByteToWrite<=secremain)secremain=NumByteToWrite;//不大于4096个字节
|
||||
while(1)
|
||||
{
|
||||
SPI_Flash_Read(SPI_FLASH_BUF,secpos*4096,4096);//读出整个扇区的内容
|
||||
for(i=0;i<secremain;i++)//校验数据
|
||||
{
|
||||
if(SPI_FLASH_BUF[secoff+i]!=0XFF)break;//需要擦除
|
||||
}
|
||||
if(i<secremain)//需要擦除
|
||||
{
|
||||
SPI_Flash_Erase_Sector(secpos);//擦除这个扇区
|
||||
for(i=0;i<secremain;i++) //复制
|
||||
{
|
||||
SPI_FLASH_BUF[i+secoff]=pBuffer[i];
|
||||
}
|
||||
SPI_Flash_Write_NoCheck(SPI_FLASH_BUF,secpos*4096,4096);//写入整个扇区
|
||||
|
||||
}else SPI_Flash_Write_NoCheck(pBuffer,WriteAddr,secremain);//写已经擦除了的,直接写入扇区剩余区间.
|
||||
if(NumByteToWrite==secremain)break;//写入结束了
|
||||
else//写入未结束
|
||||
{
|
||||
secpos++;//扇区地址增1
|
||||
secoff=0;//偏移位置为0
|
||||
|
||||
pBuffer+=secremain; //指针偏移
|
||||
WriteAddr+=secremain;//写地址偏移
|
||||
NumByteToWrite-=secremain; //字节数递减
|
||||
if(NumByteToWrite>4096)secremain=4096; //下一个扇区还是写不完
|
||||
else secremain=NumByteToWrite; //下一个扇区可以写完了
|
||||
}
|
||||
};
|
||||
}
|
||||
//擦除整个芯片
|
||||
//整片擦除时间:
|
||||
//W25X16:25s
|
||||
//W25X32:40s
|
||||
//W25X64:40s
|
||||
//等待时间超长...
|
||||
void SPI_Flash_Erase_Chip(void)
|
||||
{
|
||||
SPI_FLASH_Write_Enable(); //SET WEL
|
||||
SPI_Flash_Wait_Busy();
|
||||
SPI_FLASH_CS=0; //使能器件
|
||||
SPI1_ReadWriteByte(W25X_ChipErase); //发送片擦除命令
|
||||
SPI_FLASH_CS=1; //取消片选
|
||||
SPI_Flash_Wait_Busy(); //等待芯片擦除结束
|
||||
}
|
||||
//擦除一个扇区
|
||||
//Dst_Addr:扇区地址 0~511 for w25x16
|
||||
//擦除一个山区的最少时间:150ms
|
||||
void SPI_Flash_Erase_Sector(uint32_t Dst_Addr)
|
||||
{
|
||||
Dst_Addr*=4096;
|
||||
SPI_FLASH_Write_Enable(); //SET WEL
|
||||
SPI_Flash_Wait_Busy();
|
||||
SPI_FLASH_CS=0; //使能器件
|
||||
SPI1_ReadWriteByte(W25X_SectorErase); //发送扇区擦除指令
|
||||
SPI1_ReadWriteByte((uint8_t)((Dst_Addr)>>16)); //发送24bit地址
|
||||
SPI1_ReadWriteByte((uint8_t)((Dst_Addr)>>8));
|
||||
SPI1_ReadWriteByte((uint8_t)Dst_Addr);
|
||||
SPI_FLASH_CS=1; //取消片选
|
||||
SPI_Flash_Wait_Busy(); //等待擦除完成
|
||||
}
|
||||
//等待空闲
|
||||
void SPI_Flash_Wait_Busy(void)
|
||||
{
|
||||
while ((SPI_Flash_ReadSR()&0x01)==0x01); // 等待BUSY位清空
|
||||
}
|
||||
//进入掉电模式
|
||||
void SPI_Flash_PowerDown(void)
|
||||
{
|
||||
SPI_FLASH_CS=0; //使能器件
|
||||
SPI1_ReadWriteByte(W25X_PowerDown); //发送掉电命令
|
||||
SPI_FLASH_CS=1; //取消片选
|
||||
delay_us(3); //等待TPD
|
||||
}
|
||||
//唤醒
|
||||
void SPI_Flash_WAKEUP(void)
|
||||
{
|
||||
SPI_FLASH_CS=0; //使能器件
|
||||
SPI1_ReadWriteByte(W25X_ReleasePowerDown); // send W25X_PowerDown command 0xAB
|
||||
SPI_FLASH_CS=1; //取消片选
|
||||
delay_us(3); //等待TRES1
|
||||
}
|
||||
|
||||
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
#ifndef __FLASH_H
|
||||
#define __FLASH_H
|
||||
#include "stm32f10x.h"
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
//本程序只供学习使用,未经作者许可,不得用于其它任何用途
|
||||
//ALIENTEK战舰STM32开发板
|
||||
//W25Q64 代码
|
||||
//正点原子@ALIENTEK
|
||||
//技术论坛:www.openedv.com
|
||||
//修改日期:2012/9/9
|
||||
//版本:V1.0
|
||||
//版权所有,盗版必究。
|
||||
//Copyright(C) 广州市星翼电子科技有限公司 2009-2019
|
||||
//All rights reserved
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//W25X系列/Q系列芯片列表
|
||||
//W25Q80 ID 0XEF13
|
||||
//W25Q16 ID 0XEF14
|
||||
//W25Q32 ID 0XEF15
|
||||
//W25Q32 ID 0XEF16
|
||||
#define W25Q80 0XEF13
|
||||
#define W25Q16 0XEF14
|
||||
#define W25Q32 0XEF15
|
||||
#define W25Q64 0XEF16
|
||||
|
||||
extern u16 SPI_FLASH_TYPE;//定义我们使用的flash芯片型号
|
||||
|
||||
#define SPI_FLASH_CS PEout(7) //选中FLASH
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//指令表
|
||||
#define W25X_WriteEnable 0x06
|
||||
#define W25X_WriteDisable 0x04
|
||||
#define W25X_ReadStatusReg 0x05
|
||||
#define W25X_WriteStatusReg 0x01
|
||||
#define W25X_ReadData 0x03
|
||||
#define W25X_FastReadData 0x0B
|
||||
#define W25X_FastReadDual 0x3B
|
||||
#define W25X_PageProgram 0x02
|
||||
#define W25X_BlockErase 0xD8
|
||||
#define W25X_SectorErase 0x20
|
||||
#define W25X_ChipErase 0xC7
|
||||
#define W25X_PowerDown 0xB9
|
||||
#define W25X_ReleasePowerDown 0xAB
|
||||
#define W25X_DeviceID 0xAB
|
||||
#define W25X_ManufactDeviceID 0x90
|
||||
#define W25X_JedecDeviceID 0x9F
|
||||
|
||||
void SPI_Flash_Init(void);
|
||||
u16 SPI_Flash_ReadID(void); //读取FLASH ID
|
||||
u8 SPI_Flash_ReadSR(void); //读取状态寄存器
|
||||
void SPI_FLASH_Write_SR(u8 sr); //写状态寄存器
|
||||
void SPI_FLASH_Write_Enable(void); //写使能
|
||||
void SPI_FLASH_Write_Disable(void); //写保护
|
||||
void SPI_Flash_Write_NoCheck(u8* pBuffer,u32 WriteAddr,u16 NumByteToWrite);
|
||||
void SPI_Flash_Read(u8* pBuffer,u32 ReadAddr,u16 NumByteToRead); //读取flash
|
||||
void SPI_Flash_Write(u8* pBuffer,u32 WriteAddr,u16 NumByteToWrite);//写入flash
|
||||
void SPI_Flash_Erase_Chip(void); //整片擦除
|
||||
void SPI_Flash_Erase_Sector(u32 Dst_Addr);//扇区擦除
|
||||
void SPI_Flash_Wait_Busy(void); //等待空闲
|
||||
void SPI_Flash_PowerDown(void); //进入掉电模式
|
||||
void SPI_Flash_WAKEUP(void); //唤醒
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Executable
+265
@@ -0,0 +1,265 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :gps.c
|
||||
* 描 述 :GPS驱动代码
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/03/05
|
||||
*********************************************************************************/
|
||||
#include "gps.h"
|
||||
#include "delay.h"
|
||||
#include "usart4.h"
|
||||
#include "stdio.h"
|
||||
#include "stdarg.h"
|
||||
#include "string.h"
|
||||
#include "math.h"
|
||||
|
||||
nmea_msg gpsx; //GPS信息
|
||||
__align(4) u8 dtbuf[50]; //打印缓存器
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: NMEA_Comma_Pos
|
||||
* 功能说明: 从buf里面得到第cx个逗号所在的位置
|
||||
* 形 参: buf,数据缓存
|
||||
* cx,第几个逗号所在的位置
|
||||
* 返 回 值: 0~0XFE,代表逗号所在位置的偏移
|
||||
* 0XFF,代表不存在第cx个逗号
|
||||
***********************************************************************
|
||||
*/
|
||||
u8 NMEA_Comma_Pos(u8 *buf, u8 cx)
|
||||
{
|
||||
u8 *p = buf;
|
||||
while(cx)
|
||||
{
|
||||
if((*buf == '*') || (*buf < ' ') || (*buf > 'z')) return 0XFF; //遇到'*'或者非法字符,则不存在第cx个逗号
|
||||
if(*buf == ',') cx--;
|
||||
buf++;
|
||||
}
|
||||
return buf - p;
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: NMEA_Pow
|
||||
* 功能说明: m^n函数
|
||||
* 形 参: m,底数
|
||||
* n,指数
|
||||
* 返 回 值: 运算后的结果
|
||||
***********************************************************************
|
||||
*/
|
||||
u32 NMEA_Pow(u8 m, u8 n)
|
||||
{
|
||||
u32 result = 1;
|
||||
while(n--)result *= m;
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: NMEA_Str2num
|
||||
* 功能说明: str转换为数字,以','或者'*'结束
|
||||
* 形 参: buf:数字存储区
|
||||
* dx:小数点位数,返回给调用函数
|
||||
* 返 回 值: 转换后的结果
|
||||
***********************************************************************
|
||||
*/
|
||||
int NMEA_Str2num(u8 *buf, u8 *dx)
|
||||
{
|
||||
u8 *p = buf;
|
||||
u32 ires = 0, fres = 0;
|
||||
u8 ilen = 0, flen = 0, i;
|
||||
u8 mask = 0;
|
||||
int res;
|
||||
while(1) //得到整数和小数的长度
|
||||
{
|
||||
if(*p == '-'){mask |= 0X02; p++;}//是负数
|
||||
if(*p == ',' || (*p == '*'))break;//遇到结束了
|
||||
if(*p == '.'){mask |= 0X01; p++;}//遇到小数点了
|
||||
else if((*p > '9') || (*p < '0')) //有非法字符
|
||||
{
|
||||
ilen = 0;
|
||||
flen = 0;
|
||||
break;
|
||||
}
|
||||
if(mask & 0X01)flen++;
|
||||
else ilen++;
|
||||
p++;
|
||||
}
|
||||
if(mask & 0X02)buf++; //去掉负号
|
||||
for(i = 0; i<ilen; i++) //得到整数部分数据
|
||||
{
|
||||
ires += NMEA_Pow(10, ilen-1-i) * (buf[i]-'0');
|
||||
}
|
||||
if(flen > 5)flen = 5; //最多取5位小数
|
||||
*dx = flen; //小数点位数
|
||||
for(i = 0; i<flen; i++) //得到小数部分数据
|
||||
{
|
||||
fres += NMEA_Pow(10, flen-1-i) * (buf[ilen+1+i] - '0');
|
||||
}
|
||||
res = ires * NMEA_Pow(10, flen) + fres;
|
||||
if(mask & 0X02)res=-res;
|
||||
return res;
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: gps_control
|
||||
* 功能说明: 分析GPGGA信息(GPS定位信息)
|
||||
* 形 参: *gpsx:nmea信息结构体(输出的全局变量)
|
||||
* *buf:接收到的GPS数据缓冲区首地址
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void gps_control(void)
|
||||
{
|
||||
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA , ENABLE); //使能PB端口时钟
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO口速度为50MHz
|
||||
GPIO_Init(GPIOA, &GPIO_InitStructure); //根据设定参数初始化
|
||||
|
||||
GPIO_SetBits(GPIOA, GPIO_Pin_4);
|
||||
}
|
||||
|
||||
void open_gps(void)
|
||||
{
|
||||
GPIO_SetBits(GPIOA, GPIO_Pin_4);
|
||||
}
|
||||
|
||||
void close_gps(void)
|
||||
{
|
||||
GPIO_ResetBits(GPIOA, GPIO_Pin_4);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: NMEA_GPGGA_Analysis
|
||||
* 功能说明: 分析GPGGA信息(GPS定位信息)
|
||||
* 形 参: *gpsx:nmea信息结构体(输出的全局变量)
|
||||
* *buf:接收到的GPS数据缓冲区首地址
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void NMEA_GPGGA_Analysis(nmea_msg *gpsx, u8 *buf)
|
||||
{
|
||||
u8 *p1, dx;
|
||||
u8 posx;
|
||||
p1 = (u8*)strstr((const char *)buf, "$GPGGA");
|
||||
|
||||
posx = NMEA_Comma_Pos(p1, 6); //得到GPS状态
|
||||
if(posx != 0XFF)gpsx->gpssta = NMEA_Str2num(p1+posx, &dx);
|
||||
|
||||
posx = NMEA_Comma_Pos(p1, 7); //得到用于定位的卫星数
|
||||
if(posx != 0XFF)gpsx->posslnum = NMEA_Str2num(p1+posx, &dx);
|
||||
|
||||
posx = NMEA_Comma_Pos(p1, 9); //得到海拔高度
|
||||
if(posx != 0XFF)gpsx->altitude = NMEA_Str2num(p1+posx, &dx);
|
||||
gpsx->altitude *= 1000;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: NMEA_GPRMC_Analysis
|
||||
* 功能说明: 分析GPRMC信息(GPS推荐定位信息)
|
||||
* 形 参: *gpsx:nmea信息结构体(输出的全局变量)
|
||||
* *buf:接收到的GPS数据缓冲区首地址
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void NMEA_GPRMC_Analysis(nmea_msg *gpsx, u8 *buf)
|
||||
{
|
||||
u8 *p1,dx;
|
||||
u8 posx;
|
||||
u32 temp;
|
||||
float rs;
|
||||
p1 = (u8*)strstr((const char *)buf, "$GPRMC");
|
||||
posx = NMEA_Comma_Pos(p1, 1); //得到UTC时间
|
||||
if(posx != 0XFF)
|
||||
{
|
||||
temp = NMEA_Str2num(p1+posx, &dx)/NMEA_Pow(10,dx); //得到UTC时间,去掉ms
|
||||
gpsx->utc.hour = temp/10000;
|
||||
gpsx->utc.min = (temp/100)%100;
|
||||
gpsx->utc.sec = temp%100;
|
||||
}
|
||||
|
||||
posx = NMEA_Comma_Pos(p1,3); //得到纬度
|
||||
if(posx != 0XFF)
|
||||
{
|
||||
temp = NMEA_Str2num(p1+posx, &dx);
|
||||
gpsx->latitude = temp/NMEA_Pow(10, dx+2); //得到°
|
||||
rs = temp%NMEA_Pow(10, dx+2); //得到'
|
||||
gpsx->latitude = gpsx->latitude*NMEA_Pow(10, 5)+(rs*NMEA_Pow(10, 5-dx))/60;//转换为°
|
||||
gpsx->latitude /= 10; //缩小10倍便于传输,最终放大10000倍
|
||||
}
|
||||
|
||||
posx = NMEA_Comma_Pos(p1, 4); //南纬还是北纬
|
||||
if(posx != 0XFF)gpsx->nshemi = *(p1 + posx);
|
||||
|
||||
posx = NMEA_Comma_Pos(p1, 5); //得到经度
|
||||
if(posx != 0XFF)
|
||||
{
|
||||
temp = NMEA_Str2num(p1+posx, &dx);
|
||||
gpsx->longitude = temp/NMEA_Pow(10, dx+2); //得到°
|
||||
rs = temp%NMEA_Pow(10, dx+2); //得到'
|
||||
gpsx->longitude = gpsx->longitude * NMEA_Pow(10, 5)+(rs * NMEA_Pow(10, 5-dx))/60;//转换为°
|
||||
gpsx->longitude /= 10; //缩小10倍便于传输,最终放大10000倍
|
||||
}
|
||||
|
||||
posx = NMEA_Comma_Pos(p1, 6); //东经还是西经
|
||||
if(posx != 0XFF)gpsx->ewhemi = *(p1 + posx);
|
||||
|
||||
posx = NMEA_Comma_Pos(p1, 9); //得到UTC日期
|
||||
if(posx != 0XFF)
|
||||
{
|
||||
temp = NMEA_Str2num(p1+posx, &dx); //得到UTC日期
|
||||
gpsx->utc.date = temp/10000;
|
||||
gpsx->utc.month = (temp/100)%100;
|
||||
gpsx->utc.year = 2000 + temp%100;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: GPS_Analysis
|
||||
* 功能说明: 提取NMEA-0183信息
|
||||
* 形 参: *gpsx:nmea信息结构体(输出的全局变量)
|
||||
* *buf:接收到的GPS数据缓冲区首地址
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void GPS_Analysis(nmea_msg *gpsx, u8 *buf)
|
||||
{
|
||||
NMEA_GPGGA_Analysis(gpsx, buf); //GPGGA解析
|
||||
NMEA_GPRMC_Analysis(gpsx, buf); //GPRMC解析
|
||||
}
|
||||
|
||||
void PrinterfGpsInfo(void)
|
||||
{
|
||||
float tp;
|
||||
|
||||
printf("\r\n定位状态:%d\r\n", gpsx.gpssta);
|
||||
if(gpsx.gpssta == 1)
|
||||
{
|
||||
printf("\r\n已定位\r\n");
|
||||
|
||||
tp = gpsx.longitude;
|
||||
printf("\r\n经度:%.4f %1c\r\n", tp/=10000, gpsx.ewhemi); //得到经度字符串
|
||||
|
||||
tp = gpsx.latitude;
|
||||
printf("\r\n纬度:%.4f %1c\r\n", tp/=10000, gpsx.nshemi); //得到纬度字符串
|
||||
|
||||
tp = gpsx.altitude;
|
||||
printf("\r\n高度:%.4f\r\n", tp/=10000); //得到纬度字符串
|
||||
}else{
|
||||
printf("\r\n未定位\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
/******************** (C) COPYRIGHT 2014 CHY *****END OF FILE*******************/
|
||||
Executable
+54
@@ -0,0 +1,54 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :gps.h
|
||||
* 描 述 :GPS头文件驱动代码
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2013/11/21
|
||||
*********************************************************************************/
|
||||
#ifndef __GPS_H
|
||||
#define __GPS_H
|
||||
|
||||
#include "stm32f10x.h"
|
||||
|
||||
//GPS NMEA-0183协议重要参数结构体定义
|
||||
|
||||
//UTC时间信息
|
||||
typedef struct
|
||||
{
|
||||
uint16_t year; //年份
|
||||
uint8_t month; //月份
|
||||
uint8_t date; //日期
|
||||
uint8_t hour; //小时
|
||||
uint8_t min; //分钟
|
||||
uint8_t sec; //秒钟
|
||||
}nmea_utc_time;
|
||||
|
||||
//NMEA 0183 协议解析后数据存放结构体
|
||||
typedef struct
|
||||
{
|
||||
nmea_utc_time utc; //UTC时间
|
||||
uint32_t latitude; //纬度 分扩大10000倍,实际要除以10000
|
||||
uint8_t nshemi; //北纬/南纬,N:北纬;S:南纬
|
||||
uint32_t longitude; //经度 分扩大10000倍,实际要除以10000
|
||||
uint8_t ewhemi; //东经/西经,E:东经;W:西经
|
||||
uint8_t gpssta; //GPS状态:0,未定位;1,非差分定位;2,差分定位;6,正在估算
|
||||
uint8_t posslnum; //用于定位的卫星数量,0~12
|
||||
|
||||
uint32_t altitude; //海拔高度,放大了10000倍,实际除以10000.单位:0.1m
|
||||
}nmea_msg;
|
||||
|
||||
extern nmea_msg gpsx;
|
||||
|
||||
void GPS_Analysis(nmea_msg *gpsx,uint8_t *buf);
|
||||
void NMEA_GPGGA_Analysis(nmea_msg *gpsx,uint8_t *buf);
|
||||
void NMEA_GPRMC_Analysis(nmea_msg *gpsx,uint8_t *buf);
|
||||
|
||||
void PrinterfGpsInfo(void); //显示GPS定位信息
|
||||
|
||||
void gps_control(void);
|
||||
void open_gps(void);
|
||||
void close_gps(void);
|
||||
|
||||
#endif
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 CXHY *****END OF FILE*******************/
|
||||
+544
@@ -0,0 +1,544 @@
|
||||
#include "at_proc.h"
|
||||
#include "gsm_uart.h"
|
||||
#include "gsm_uart_conf.h"
|
||||
#include "my_math.h"
|
||||
#include "ec200x.h"
|
||||
#include "data_typedef.h"
|
||||
|
||||
char command_CIPSEND[16];
|
||||
|
||||
AT_CMD_PARAM at_cmd_table[]={
|
||||
{AT_CMD_AT_NO, "AT", "OK", "ERROR", AT_CMD_UNKNOWN},
|
||||
{AT_CMD_ATE0_NO, "ATE0", "OK", "ERROR", AT_CMD_UNKNOWN},
|
||||
{AT_CMD_CGSN_NO, "AT+CGSN", "OK", "ERROR", AT_CMD_UNKNOWN},
|
||||
{AT_CMD_CPIN_NO, "AT+CPIN?", "+CPIN: READY", "ERROR", AT_CMD_UNKNOWN},
|
||||
{AT_CMD_ICCID_NO, "AT+QCCID", "+QCCID:", "ERROR", AT_CMD_UNKNOWN},
|
||||
{AT_CMD_CSQ_NO, "AT+CSQ", "+CSQ:", "ERROR", AT_CMD_UNKNOWN},
|
||||
{AT_CMD_CREG_NO, "AT+CREG?", "+CREG: 0,1", "ERROR", AT_CMD_UNKNOWN},
|
||||
{AT_CMD_CGREG_NO, "AT+CGREG?", "+CGREG: 0,1", "ERROR", AT_CMD_UNKNOWN},
|
||||
{AT_CMD_COPS_NO, "AT+COPS?", "OK", "ERROR", AT_CMD_UNKNOWN},
|
||||
{AT_CMD_QICSGP_NO, "AT+QICSGP=1,1,\"UNINET\","","",1", "OK", "ERROR", AT_CMD_UNKNOWN},
|
||||
{AT_CMD_QIACT_NO, "AT+QIACT=1", "OK", "ERROR", AT_CMD_UNKNOWN},
|
||||
{AT_CMD_QIDEACT_NO, "AT+QIDEACT=1", "OK", "ERROR", AT_CMD_UNKNOWN},
|
||||
{AT_CMD_CHECK_QIACT_NO, "AT+QIACT?", "OK", "ERROR", AT_CMD_UNKNOWN},
|
||||
{AT_CMD_QIOPEN, TCP_IP_COM, "+QIOPEN: 0,0", "CONNECT FAIL", AT_CMD_UNKNOWN},
|
||||
{AT_CMD_QICLOSE_NO, "AT+QICLOSE=0", "OK", "SEND FAIL", AT_CMD_UNKNOWN},
|
||||
{AT_CMD_QISEND, "AT+QISEND=0,4", ">", "SEND OK", AT_CMD_UNKNOWN},
|
||||
{AT_CMD_CHECK_QISEND_NO, "AT+QISEND=0,0", "+QISEND:", "ERROR", AT_CMD_UNKNOWN},
|
||||
{AT_CMD_QIRD_NO, "AT+QIRD=0,1500", "+QIRD:", "ERROR", AT_CMD_UNKNOWN},
|
||||
{AT_CMD_QNTP_NO, "AT+QNTP", "+QNTP:", "ERROR", AT_CMD_UNKNOWN},
|
||||
{AT_CMD_CCLK_NO, "AT+CCLK?", "+CCLK:", "+CME ERROR", AT_CMD_UNKNOWN},
|
||||
};
|
||||
|
||||
#define AT_RX_BUFFER 100
|
||||
|
||||
uint8_t rx_buffer[AT_RX_BUFFER];
|
||||
uint8_t sendAtCmdNo=0;
|
||||
|
||||
uint8_t networkIsReg=0;
|
||||
uint8_t receiveDataReady = 0;
|
||||
uint8_t receiveDataLen = 0;
|
||||
|
||||
#define AT_COMMON_ERROR_STRING "+CME ERROR:"
|
||||
|
||||
|
||||
|
||||
void show_buf(uint8_t num[], uint8_t n)
|
||||
{
|
||||
uint8_t i;
|
||||
printf("\r\n");
|
||||
for(i=0; i<n; i++)
|
||||
{
|
||||
printf("%02X ",num[i]);
|
||||
}
|
||||
printf("\r\n");
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: mem_cmp
|
||||
* 功能说明: 字符串比较
|
||||
* 形 参: src->原字符串
|
||||
* dst->目标字符串
|
||||
* len->字符串的长度
|
||||
* 返 回 值: 0->相同,1不相同
|
||||
***********************************************************************
|
||||
*/
|
||||
static uint8_t mem_cmp(uint8_t *src, uint8_t *dst, uint8_t len)
|
||||
{
|
||||
uint8_t i = 0, ret = 0;
|
||||
|
||||
while(i<len)
|
||||
{
|
||||
if(src[i] == 0 || dst[i] == 0 || src[i] != dst[i])
|
||||
{
|
||||
ret = 1;
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: str_len
|
||||
* 功能说明: 取得字符串长度
|
||||
* 形 参: string->待计算的字符串
|
||||
* 返 回 值: 字符串长度
|
||||
***********************************************************************
|
||||
*/
|
||||
static uint8_t str_len(uint8_t* string)
|
||||
{
|
||||
uint8_t i=0;
|
||||
|
||||
while(string[i] != 0) i++;
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: GSM_SendAtCmd
|
||||
* 功能说明: GSM模块发送AT指令
|
||||
* 形 参: cmd->发送的命令字符串
|
||||
* atCmdNo->AT指令编号
|
||||
* 返 回 值: 0->发送成功(得到了期待的应答结果)
|
||||
* 1->发送失败
|
||||
***********************************************************************
|
||||
*/
|
||||
void GSM_SendAtCmd(char *cmd, uint8_t atCmdNo)
|
||||
{
|
||||
sendAtCmdNo = atCmdNo;
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_UNKNOWN;
|
||||
GSM_GPRS_printf("%s\r\n", cmd); //发送命令
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: getCommand_CIPSEND
|
||||
* 功能说明: 根据发送的数据长度自动生成对应的AT+CIPSEND=<?>命令
|
||||
* 形 参:msg
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void getCommand_CIPSEND(uint16_t len)
|
||||
{
|
||||
char lenNum[4];
|
||||
|
||||
sprintf((char*)command_CIPSEND, "AT+CIPSEND=");
|
||||
sprintf((char*)lenNum, "%d", len);
|
||||
strcat((char*)command_CIPSEND, lenNum);
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: IMEI_TO_HEX
|
||||
* 功能说明: 将IMEI号转换成HEX
|
||||
* 形 参:传入字符串的IMEI号
|
||||
* 返 回 值:
|
||||
***********************************************************************
|
||||
*/
|
||||
void IMEI_TO_HEX(char *pStrData)
|
||||
{
|
||||
uint8_t i;
|
||||
uint64_t imeiNum = 0;
|
||||
uint32_t imeiNumH = 0;
|
||||
uint32_t imeiNumL = 0;
|
||||
|
||||
for(i = 0; i < 15; i++){
|
||||
imeiNum += ((*pStrData++) - 0x30) * Pow(10, 14-i);
|
||||
}
|
||||
imeiNumH = imeiNum/4294967296;
|
||||
imeiNumL = (uint32_t)imeiNum;
|
||||
|
||||
// printf("\r\n%x \r\n", imeiNumH);
|
||||
// printf("\r\n%x \r\n", imeiNumL);
|
||||
|
||||
gsm_msg.IMEI_HEX[0] = imeiNumH >> 24;
|
||||
gsm_msg.IMEI_HEX[1] = imeiNumH >> 16;
|
||||
gsm_msg.IMEI_HEX[2] = imeiNumH >> 8;
|
||||
gsm_msg.IMEI_HEX[3] = imeiNumH;
|
||||
|
||||
gsm_msg.IMEI_HEX[4] = imeiNumL >> 24;
|
||||
gsm_msg.IMEI_HEX[5] = imeiNumL >> 16;
|
||||
gsm_msg.IMEI_HEX[6] = imeiNumL >> 8;
|
||||
gsm_msg.IMEI_HEX[7] = imeiNumL;
|
||||
|
||||
// for(i = 0; i < 8; i++){
|
||||
// printf("%x ", gsm_msg.IMEI_HEX[i]);
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
void AT_Protocol(uint8_t* pCdmStr, uint8_t length)
|
||||
{
|
||||
uint8_t i = 0;
|
||||
char *p;
|
||||
uint8_t *pSuccStr; //AT指令操作成功的应答字符串;
|
||||
uint8_t succStrLen;
|
||||
|
||||
uint8_t *pFailedStr; //AT指令操作失败的应答字符串;
|
||||
uint8_t failedStrLen;
|
||||
|
||||
if(length == 2) return; //空行,不处理
|
||||
|
||||
if(sendAtCmdNo >= CMD_TABLE_LENGTH) return; //判断是否是前面发送过at需要处理的
|
||||
|
||||
if(!((pCdmStr[length-2] == '\r') && (pCdmStr[length-1] == '\n'))) //不是回车换行("\r\n")结尾
|
||||
{
|
||||
if(!((sendAtCmdNo == AT_CMD_QISEND) && (GPRS_RX_BUF[length - 1] == '>'))) return; //不是IPSEND指令的应答“>”
|
||||
}
|
||||
|
||||
i = 0;
|
||||
while(*pCdmStr == '\0') //过滤掉前面的空格
|
||||
{
|
||||
pCdmStr = pCdmStr++;
|
||||
i++;
|
||||
if(i >= length) break;
|
||||
}
|
||||
|
||||
pSuccStr = at_cmd_table[sendAtCmdNo-1].success;
|
||||
succStrLen = str_len(pSuccStr);
|
||||
|
||||
pFailedStr = at_cmd_table[sendAtCmdNo-1].failed;
|
||||
failedStrLen = str_len(pFailedStr);
|
||||
|
||||
if((char*)strstr((const char*)pCdmStr, "+QIURC") != NULL) //URC AT指令
|
||||
{
|
||||
if((char*)strstr((const char*)pCdmStr, "recv") != NULL) //数据接收URC
|
||||
{
|
||||
if(mem_cmp(pCdmStr, (uint8_t*)RECEIVE_SERVER_DATA, strlen(RECEIVE_SERVER_DATA)) == 0)
|
||||
{
|
||||
p = (char*)strstr((const char*)pCdmStr, ",");
|
||||
p = (char*)strstr((const char*)p+1, ",");
|
||||
recDataLen = atoi(p+1);
|
||||
GSM_ReceiveType = 1;
|
||||
// printf("\r\n接收数据URC\r\n");
|
||||
// printf("\r\nlen=%d\r\n", recDataLen);
|
||||
}
|
||||
}else if((char*)strstr((const char*)pCdmStr, "closed") != NULL){ //连接断开URC
|
||||
connectionClosedMark = 1;
|
||||
// printf("\r\n连接断开URC!\r\n");
|
||||
}else if((char*)strstr((const char*)pCdmStr, "incoming full") != NULL){ //客户端连接已满URC
|
||||
printf("\r\n连接已满URC!\r\n");
|
||||
}else if((char*)strstr((const char*)pCdmStr, "ncoming") != NULL){ //客户端连接URC
|
||||
printf("\r\n客户端连接URC!\r\n");
|
||||
}else if((char*)strstr((const char*)pCdmStr, "pdpdeact") != NULL){ //PDP去激活URC
|
||||
printf("\r\nPDP去激活URC!\r\n");
|
||||
}else{}
|
||||
}else{ //常规AT指令
|
||||
switch(sendAtCmdNo)
|
||||
{
|
||||
case AT_CMD_AT_NO: //AT
|
||||
if(mem_cmp(pCdmStr, (uint8_t*)AT_CMD_AT_AT, strlen(AT_CMD_AT_AT)) == 0)
|
||||
{
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_SUCCESS;
|
||||
// printf("\r\nat\r\n");
|
||||
sendAtCmdNo = 0;
|
||||
}else if(mem_cmp(pCdmStr, (uint8_t*)AT_CMD_AT_OK, strlen(AT_CMD_AT_OK)) == 0){
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_SUCCESS;
|
||||
// printf("\r\nok\r\n");
|
||||
sendAtCmdNo = 0;
|
||||
}else if(mem_cmp(pCdmStr, (uint8_t*)AT_COMMON_ERROR_STRING, strlen(AT_CMD_AT_ERROR)) == 0){
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_FAILED;
|
||||
}else{}
|
||||
break;
|
||||
|
||||
case AT_CMD_ATE0_NO: //关闭回显
|
||||
if(mem_cmp(pSuccStr, pCdmStr, succStrLen) == 0)
|
||||
{
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_SUCCESS;
|
||||
sendAtCmdNo = 0;
|
||||
}else if(mem_cmp(pCdmStr, (uint8_t*)AT_COMMON_ERROR_STRING, strlen(AT_CMD_AT_ERROR)) == 0){
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_FAILED;
|
||||
}else{}
|
||||
break;
|
||||
|
||||
case AT_CMD_CGSN_NO: //AT+CGSN 获取IMEI号
|
||||
if(length == 17)
|
||||
{
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_SUCCESS; //设置当前的AT指令操作结果成功
|
||||
sendAtCmdNo = 0; //清除发送AT指令编号
|
||||
memcpy(gsm_msg.IMEI, pCdmStr, 15);
|
||||
gsm_msg.IMEI[15] = '\0';
|
||||
IMEI_TO_HEX(gsm_msg.IMEI); //将字符串的IMEI号转换成HEX格式为后面传输
|
||||
}
|
||||
break;
|
||||
|
||||
case AT_CMD_CPIN_NO: //AT+CPIN? 查询SIM卡状态
|
||||
if(mem_cmp(pSuccStr, pCdmStr, succStrLen) == 0)
|
||||
{
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_SUCCESS;
|
||||
sendAtCmdNo = 0;
|
||||
}else if(mem_cmp(pCdmStr, (uint8_t*)AT_COMMON_ERROR_STRING, strlen(AT_CMD_AT_ERROR)) == 0){
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_FAILED;
|
||||
}else{}
|
||||
break;
|
||||
|
||||
case AT_CMD_ICCID_NO: //AT+QCCID 查询SIM卡的ICCID号
|
||||
if(mem_cmp(pSuccStr, pCdmStr, succStrLen) == 0)
|
||||
{
|
||||
memcpy(gsm_msg.ICCID, pCdmStr+8, 20);
|
||||
gsm_msg.ICCID[20] = '\0';
|
||||
// show_buf((uint8_t*)gsm_msg.ICCID, 20);
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_SUCCESS;
|
||||
sendAtCmdNo = 0;
|
||||
}else if(mem_cmp(pCdmStr, (uint8_t*)AT_COMMON_ERROR_STRING, strlen(AT_CMD_AT_ERROR)) == 0){
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_FAILED;
|
||||
}else{}
|
||||
break;
|
||||
|
||||
case AT_CMD_CSQ_NO: //AT+CSQ 查询网络信号强度
|
||||
// printf("\r\ncsq = %s\r\n", pCdmStr);
|
||||
if(mem_cmp(pSuccStr, pCdmStr, succStrLen) == 0)
|
||||
{
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_SUCCESS;
|
||||
sendAtCmdNo = 0;
|
||||
signal = atoi((const char *)(pCdmStr+6));
|
||||
// printf("\r\nrssi = %d\r\n", signal);
|
||||
}else if(mem_cmp(pCdmStr, (uint8_t*)AT_COMMON_ERROR_STRING, strlen(AT_CMD_AT_ERROR)) == 0){
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_FAILED;
|
||||
}else{}
|
||||
break;
|
||||
|
||||
case AT_CMD_CREG_NO: //AT+CREG? 查询网络注册状态
|
||||
if(mem_cmp(pSuccStr, pCdmStr, succStrLen) == 0) //注册的,归属网络
|
||||
{
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_SUCCESS;
|
||||
sendAtCmdNo = 0;
|
||||
}else if(mem_cmp((uint8_t*)AT_CMD_AT_CREG, pCdmStr, succStrLen) == 0){ //注册的,漫游中
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_SUCCESS;
|
||||
sendAtCmdNo = 0;
|
||||
}else if(mem_cmp(pCdmStr, (uint8_t*)AT_COMMON_ERROR_STRING, strlen(AT_CMD_AT_ERROR)) == 0){
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_FAILED;
|
||||
}else{}
|
||||
break;
|
||||
|
||||
case AT_CMD_CGREG_NO: //AT+CGREG? 检查GPRS附着状态
|
||||
if(mem_cmp(pSuccStr, pCdmStr, succStrLen) == 0) //注册的,归属网络
|
||||
{
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_SUCCESS;
|
||||
sendAtCmdNo = 0;
|
||||
}else if(mem_cmp((uint8_t*)AT_CMD_AT_CGREG, pCdmStr, succStrLen) == 0){ //注册的,漫游中
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_SUCCESS;
|
||||
sendAtCmdNo = 0;
|
||||
}else if(mem_cmp(pCdmStr, (uint8_t*)AT_COMMON_ERROR_STRING, strlen(AT_CMD_AT_ERROR)) == 0){
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_FAILED;
|
||||
}else{}
|
||||
break;
|
||||
|
||||
case AT_CMD_COPS_NO: //查询网络运营商
|
||||
if((char*)strstr((const char*)pCdmStr, "CHINA MOBILE") != NULL){
|
||||
gsm_msg.OperatorType = 1;
|
||||
memcpy(gsm_msg.Operator, "CHINA MOBILE", strlen("CHINA MOBILE"));
|
||||
}else if((char*)strstr((const char*)pCdmStr, "CHN-UNICOM") != NULL){
|
||||
gsm_msg.OperatorType = 2;
|
||||
memcpy(gsm_msg.Operator, "CHN-UNICOM", strlen("CHN-UNICOM"));
|
||||
}else{
|
||||
}
|
||||
|
||||
if(mem_cmp(pSuccStr, pCdmStr, succStrLen) == 0)
|
||||
{
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_SUCCESS;
|
||||
sendAtCmdNo = 0;
|
||||
}else if(mem_cmp(pFailedStr, pCdmStr, failedStrLen) == 0){
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_FAILED;
|
||||
}else if(mem_cmp(pCdmStr, (uint8_t*)AT_COMMON_ERROR_STRING, strlen(AT_CMD_AT_ERROR)) == 0){
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_FAILED;
|
||||
}else{}
|
||||
break;
|
||||
|
||||
case AT_CMD_QICSGP_NO: //开始任务,设置APN
|
||||
if(mem_cmp(pSuccStr, pCdmStr, succStrLen) == 0)
|
||||
{
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_SUCCESS;
|
||||
sendAtCmdNo = 0;
|
||||
}else if(mem_cmp(pFailedStr, pCdmStr, failedStrLen) == 0){
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_FAILED;
|
||||
}else if(mem_cmp(pCdmStr, (uint8_t*)AT_COMMON_ERROR_STRING, strlen(AT_CMD_AT_ERROR)) == 0){
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_FAILED;
|
||||
}else{}
|
||||
break;
|
||||
|
||||
case AT_CMD_QIDEACT_NO: //反激活PDP
|
||||
if(mem_cmp(pSuccStr, pCdmStr, succStrLen) == 0)
|
||||
{
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_SUCCESS;
|
||||
sendAtCmdNo = 0;
|
||||
}else if(mem_cmp(pFailedStr, pCdmStr, failedStrLen) == 0){
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_FAILED;
|
||||
}else if(mem_cmp(pCdmStr, (uint8_t*)AT_COMMON_ERROR_STRING, strlen(AT_CMD_AT_ERROR)) == 0){
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_FAILED;
|
||||
}else{}
|
||||
break;
|
||||
|
||||
case AT_CMD_QIACT_NO: //建立无线链路
|
||||
if(mem_cmp(pSuccStr, pCdmStr, succStrLen) == 0)
|
||||
{
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_SUCCESS;
|
||||
sendAtCmdNo = 0;
|
||||
}else if(mem_cmp(pFailedStr, pCdmStr, failedStrLen) == 0){
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_FAILED;
|
||||
}else if(mem_cmp(pCdmStr, (uint8_t*)AT_COMMON_ERROR_STRING, strlen(AT_CMD_AT_ERROR)) == 0){
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_FAILED;
|
||||
}else{}
|
||||
break;
|
||||
|
||||
case AT_CMD_CHECK_QIACT_NO: //查询当前场景及IP
|
||||
if(mem_cmp(pSuccStr, pCdmStr, succStrLen) == 0)
|
||||
{
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_SUCCESS;
|
||||
sendAtCmdNo = 0;
|
||||
}else if(mem_cmp(pFailedStr, pCdmStr, failedStrLen) == 0){
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_FAILED;
|
||||
}else if(mem_cmp(pCdmStr, (uint8_t*)AT_COMMON_ERROR_STRING, strlen(AT_CMD_AT_ERROR)) == 0){
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_FAILED;
|
||||
}
|
||||
break;
|
||||
|
||||
case AT_CMD_QIOPEN: //开始链接远端服务器
|
||||
if(mem_cmp(pSuccStr, pCdmStr, succStrLen) == 0)
|
||||
{
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_SUCCESS;
|
||||
sendAtCmdNo = 0;
|
||||
}else if(mem_cmp(pFailedStr, pCdmStr, failedStrLen) == 0){
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_FAILED;
|
||||
sendAtCmdNo = 0;
|
||||
}else if(mem_cmp(pCdmStr, (uint8_t*)AT_COMMON_ERROR_STRING, strlen(AT_CMD_AT_ERROR)) == 0){
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_FAILED;
|
||||
}
|
||||
break;
|
||||
|
||||
case AT_CMD_QISEND: //发送数据
|
||||
if(mem_cmp((uint8_t*)SEND_STATUS_READY, pCdmStr, 1) == 0)
|
||||
{
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_CIPSEND_READY;
|
||||
// sendAtCmdNo = 0;
|
||||
}
|
||||
else if(mem_cmp((uint8_t*)SEND_STATUS_SEND_OK, pCdmStr, 7) == 0)
|
||||
{
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_CIPSEND_OK;
|
||||
sendAtCmdNo = 0;
|
||||
}
|
||||
else if(mem_cmp((uint8_t*)SEND_STATUS_SEND_FAIL, pCdmStr, 9) == 0)
|
||||
{
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_SEND_FAIL;
|
||||
sendAtCmdNo = 0;
|
||||
}
|
||||
else if(mem_cmp((uint8_t*)AT_CMD_AT_ERROR, pCdmStr, 5) == 0)
|
||||
{
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_SEND_FAIL;
|
||||
sendAtCmdNo = 0;
|
||||
}
|
||||
else if(mem_cmp((uint8_t*)SEND_STATUS_CLOSED, pCdmStr, 6) == 0)
|
||||
{
|
||||
at_cmd_table[sendAtCmdNo-1].result = TCP_STATUS_CLOSED;
|
||||
sendAtCmdNo = 0;
|
||||
}
|
||||
else if(mem_cmp((uint8_t*)AT_COMMON_ERROR_STRING, pCdmStr, strlen(AT_CMD_AT_ERROR)) == 0){
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_SEND_FAIL;
|
||||
sendAtCmdNo = 0;
|
||||
}else{}
|
||||
|
||||
break;
|
||||
|
||||
case AT_CMD_CHECK_QISEND_NO: //查询发送的数据
|
||||
if(mem_cmp(pSuccStr, pCdmStr, succStrLen) == 0)
|
||||
{
|
||||
// printf("\r\nbyt=%s\r\n", pCdmStr);
|
||||
p = (char*)strstr((const char*)pCdmStr, ":");
|
||||
if(p != NULL)
|
||||
{
|
||||
total_send_length = atoi((const char *)(p+2));
|
||||
// printf("\r\nsendBytes = %d\r\n", total_send_length);
|
||||
}
|
||||
|
||||
p = (char*)strstr((const char*)pCdmStr, ",");
|
||||
if(p != NULL)
|
||||
{
|
||||
ackedBytes = atoi((const char *)(p+1));
|
||||
// printf("\r\nackedBytes = %d\r\n", ackedBytes);
|
||||
}
|
||||
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_SUCCESS;
|
||||
sendAtCmdNo = 0;
|
||||
}else if(mem_cmp(pFailedStr, pCdmStr, failedStrLen) == 0){
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_FAILED;
|
||||
}else if(mem_cmp(pCdmStr, (uint8_t*)AT_COMMON_ERROR_STRING, strlen(AT_CMD_AT_ERROR)) == 0){
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_FAILED;
|
||||
}else{}
|
||||
break;
|
||||
|
||||
case AT_CMD_QIRD_NO: //读取接收到的数据
|
||||
if(mem_cmp(pSuccStr, pCdmStr, succStrLen) == 0)
|
||||
{
|
||||
p = (char*)strstr((const char*)pCdmStr, ": ");
|
||||
receiveDataLen = atoi((p+1));
|
||||
// printf("\r\nlen=%d\r\n", receiveDataLen);
|
||||
receiveDataReady = 1;
|
||||
}else if(mem_cmp((uint8_t *)"OK", pCdmStr, 2) == 0){
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_SUCCESS;
|
||||
|
||||
receiveDataReady = 0;
|
||||
sendAtCmdNo = 0;
|
||||
}else if(mem_cmp(pFailedStr, pCdmStr, failedStrLen) == 0){
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_FAILED;
|
||||
}else if(mem_cmp(pCdmStr, (uint8_t*)AT_COMMON_ERROR_STRING, strlen(AT_CMD_AT_ERROR)) == 0){
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_FAILED;
|
||||
}else{}
|
||||
break;
|
||||
|
||||
case AT_CMD_QICLOSE_NO: //"AT+CIPCLOSE=1" 关闭连接
|
||||
if(mem_cmp(pSuccStr, pCdmStr, succStrLen) == 0)
|
||||
{
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_SUCCESS;
|
||||
sendAtCmdNo = 0;
|
||||
}else if(mem_cmp(pFailedStr, pCdmStr, failedStrLen) == 0){
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_FAILED;
|
||||
}else if(mem_cmp(pCdmStr, (uint8_t*)AT_COMMON_ERROR_STRING, strlen(AT_CMD_AT_ERROR)) == 0){
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_FAILED;
|
||||
}else{}
|
||||
break;
|
||||
|
||||
case AT_CMD_QNTP_NO: //同步NTP服务器时间
|
||||
if(mem_cmp(pSuccStr, pCdmStr, succStrLen) == 0)
|
||||
{
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_SUCCESS;
|
||||
sendAtCmdNo = 0;
|
||||
}else if(mem_cmp(pFailedStr, pCdmStr, failedStrLen) == 0){
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_FAILED;
|
||||
}else if(mem_cmp(pCdmStr, (uint8_t*)AT_COMMON_ERROR_STRING, strlen(AT_CMD_AT_ERROR)) == 0){
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_FAILED;
|
||||
}else{}
|
||||
break;
|
||||
|
||||
case AT_CMD_CCLK_NO: //查询时间
|
||||
// printf("\r\nT=%s\r\n", pCdmStr);
|
||||
if(mem_cmp(pSuccStr, pCdmStr, succStrLen) == 0)
|
||||
{
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_SUCCESS;
|
||||
sendAtCmdNo = 0;
|
||||
|
||||
//返回的格式为:+CCLK: "20/08/26,08:42:39+32"
|
||||
p = (char*)strstr((const char*)pCdmStr, "\"");
|
||||
|
||||
GMT_Time.year = 2000 + (*(p+1)-'0')*10 + (*(p+2)-'0');
|
||||
GMT_Time.month = (*(p+4)-'0')*10 + (*(p+5)-'0');
|
||||
GMT_Time.day = (*(p+7)-'0')*10 + (*(p+8)-'0');
|
||||
|
||||
GMT_Time.hour = (*(p+10)-'0')*10 + (*(p+11)-'0');
|
||||
GMT_Time.minute = (*(p+13)-'0')*10 + (*(p+14)-'0');
|
||||
GMT_Time.second = (*(p+16)-'0')*10 + (*(p+17)-'0');
|
||||
}else if(mem_cmp(pCdmStr, (uint8_t*)AT_COMMON_ERROR_STRING, strlen(AT_CMD_AT_ERROR)) == 0){
|
||||
at_cmd_table[sendAtCmdNo-1].result = AT_CMD_FAILED;
|
||||
}else{}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 CXHY *****END OF FILE*******************/
|
||||
+126
@@ -0,0 +1,126 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :at_proc.h
|
||||
* 描 述 :GSM AT指令解析
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/02/05
|
||||
*********************************************************************************/
|
||||
#ifndef _AT_PROC_H_
|
||||
#define _AT_PROC_H_
|
||||
|
||||
#include "stm32f10x.h"
|
||||
#include "stdio.h"
|
||||
|
||||
#define AT_CMD_COMMON_ERROR "+CME ERROR:"
|
||||
|
||||
#define AT_CMD_SEND_OK "SEND OK"
|
||||
#define AT_CMD_AT_OK "OK"
|
||||
#define AT_CMD_AT_AT "AT"
|
||||
#define AT_CMD_AT_ATE0 "ATE0\r"
|
||||
#define AT_CMD_AT_CREG "+CREG: 0,5"
|
||||
#define AT_CMD_AT_CGREG "+CGREG: 0,5"
|
||||
#define AT_CMD_AT_ERROR "ERROR"
|
||||
|
||||
//GPRS数据发送过程应答字符
|
||||
#define SEND_STATUS_READY ">"
|
||||
#define SEND_STATUS_SEND_OK "SEND OK"
|
||||
#define SEND_STATUS_SEND_FAIL "SEND FAIL"
|
||||
#define SEND_STATUS_CLOSED "CLOSED"
|
||||
|
||||
//GPRS工作状态
|
||||
#define CIPSTATUS_IP_INITIAL "STATE: IP INITIAL"
|
||||
#define CIPSTATUS_IP_START "STATE: IP START"
|
||||
#define CIPSTATUS_IP_CONFIG "STATE: IP CONFIG"
|
||||
#define CIPSTATUS_IP_GPRSACT "STATE: IP GPRSACT"
|
||||
#define CIPSTATUS_IP_STATUS "STATE: IP STATUS"
|
||||
#define CIPSTATUS_TCP_CONNECTING "STATE: TCP CONNECTING"
|
||||
#define CIPSTATUS_CONNECT_OK "STATE: CONNECT OK"
|
||||
#define CIPSTATUS_TCP_CLOSING "STATE: TCP CLOSING"
|
||||
#define CIPSTATUS_TCP_CLOSED "STATE: TCP CLOSED"
|
||||
#define CIPSTATUS_PDP_DEACT "STATE: PDP DEACT"
|
||||
|
||||
//模块上报URC
|
||||
#define RECEIVE_URC "+QIURC: " //模块上报URC
|
||||
#define RECEIVE_SERVER_DATA "+QIURC: \"recv\"" //数据接收URC
|
||||
|
||||
typedef enum
|
||||
{
|
||||
AT_CMD_AT_NO = 1, //AT测试指令
|
||||
AT_CMD_ATE0_NO, //回显设置指令
|
||||
AT_CMD_CGSN_NO, //IMEI号查询指令
|
||||
AT_CMD_CPIN_NO, //查询SIM卡状态
|
||||
AT_CMD_ICCID_NO, //查询SIM卡的ICCID卡号
|
||||
AT_CMD_CSQ_NO, //查询信号强度
|
||||
AT_CMD_CREG_NO, //查询网络注册状态
|
||||
AT_CMD_CGREG_NO, //查询GPRS附着状态
|
||||
AT_CMD_COPS_NO, //查询运营商
|
||||
AT_CMD_QICSGP_NO, //配置TCP/IP场景参数
|
||||
AT_CMD_QIACT_NO, //激活PDP场景
|
||||
AT_CMD_QIDEACT_NO, //反激活PDP场景
|
||||
AT_CMD_CHECK_QIACT_NO, //查询PDP场景状态
|
||||
AT_CMD_QIOPEN, //建立TCP客户端连接
|
||||
AT_CMD_QICLOSE_NO, //关闭连接
|
||||
AT_CMD_QISEND, //发送数据
|
||||
AT_CMD_CHECK_QISEND_NO, //查询数据发送状态
|
||||
AT_CMD_QIRD_NO, //读取接收到的数据
|
||||
AT_CMD_QNTP_NO, //同步NTP服务器时间
|
||||
AT_CMD_CCLK_NO, //查询时间
|
||||
}_AT_CMD_Number;
|
||||
|
||||
|
||||
//GPRS发送命令后模块应答的结果
|
||||
typedef enum
|
||||
{
|
||||
AT_CMD_SUCCESS = 1,
|
||||
AT_CMD_CIPSEND_READY = 10,
|
||||
AT_CMD_CIPSEND_OK = 11,
|
||||
AT_CMD_SEND_FAIL = 12,
|
||||
TCP_STATUS_CLOSED = 13,
|
||||
|
||||
AT_CMD_FAILED = 100,
|
||||
AT_CMD_TIMEOUE = 101,
|
||||
AT_CMD_UNKNOWN = 255
|
||||
|
||||
}AT_CMD_RESULT;
|
||||
|
||||
//GPRS工作状态
|
||||
typedef enum
|
||||
{
|
||||
GPRS_STATUS_IP_INITIAL = 20,
|
||||
GPRS_STATUS_IP_START,
|
||||
GPRS_STATUS_IP_CONFIG,
|
||||
GPRS_STATUS_IP_GPRSACT,
|
||||
GPRS_STATUS_IP_STATUS,
|
||||
GPRS_STATUS_TCP_CONNECTING,
|
||||
GPRS_STATUS_CONNECT_OK,
|
||||
GPRS_STATUS_TCP_CLOSING,
|
||||
GPRS_STATUS_TCP_CLOSED,
|
||||
GPRS_STATUS_PDP_DEACT,
|
||||
}AT_CMD_RESULT_GPRS_STATUS;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t cmdNo;
|
||||
uint8_t cmd[64];
|
||||
uint8_t success[15];
|
||||
uint8_t failed[15];
|
||||
uint8_t result;
|
||||
}AT_CMD_PARAM;
|
||||
|
||||
extern uint8_t sendAtCmdNo;
|
||||
extern uint8_t networkIsReg;
|
||||
|
||||
extern uint8_t receiveDataReady;
|
||||
extern uint8_t receiveDataLen;
|
||||
|
||||
#define CMD_TABLE_LENGTH 30
|
||||
|
||||
extern AT_CMD_PARAM at_cmd_table[CMD_TABLE_LENGTH];
|
||||
|
||||
void GSM_SendAtCmd(char *cmd, uint8_t atCmdNo);
|
||||
void getCommand_CIPSEND(uint16_t len);
|
||||
void AT_Protocol(uint8_t* pCdmStr, uint8_t length); //AT返回值解析函数
|
||||
|
||||
|
||||
#endif
|
||||
/******************** (C) COPYRIGHT 2017 CXHY *****END OF FILE*******************/
|
||||
+1569
File diff suppressed because it is too large
Load Diff
+37
@@ -0,0 +1,37 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :gsm_gprs.h
|
||||
* 描 述 :SIM900A驱动头文件
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2013/11/21
|
||||
*********************************************************************************/
|
||||
#ifndef __EC200X_H__
|
||||
#define __EC200X_H__
|
||||
#include "stm32f10x.h"
|
||||
#include "stdio.h"
|
||||
#include "gsm_uart_conf.h"
|
||||
|
||||
#define GSM_PW_KEY PBout(12)
|
||||
|
||||
//设备连接状态
|
||||
typedef enum
|
||||
{
|
||||
OFFLINE = 0, //离线
|
||||
ONLINE = 1 //在线
|
||||
|
||||
}_ConnectionStatus;
|
||||
|
||||
extern uint8_t GSM_isPowerON; //GSM模块是否处于开机
|
||||
extern uint8_t ConnectionStatus; //连接状态(当有数据包发送成功后置位为在线状态)
|
||||
extern uint8_t connectionClosedMark; //连接断开标志
|
||||
|
||||
extern uint16_t networkConnectionCount; //建立网络连接次数
|
||||
|
||||
void LTE_Init(void);
|
||||
uint8_t GSM_PowerON(void);
|
||||
uint8_t GSM_PowerOFF(void);
|
||||
|
||||
void GSM_GPRS_Task(void);
|
||||
#endif
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 CXHY *****END OF FILE*******************/
|
||||
+1356
File diff suppressed because it is too large
Load Diff
+33
@@ -0,0 +1,33 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :gsm_gprs.h
|
||||
* 描 述 :SIM900A驱动头文件
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2013/11/21
|
||||
*********************************************************************************/
|
||||
#ifndef __GSM_GPRS_H__
|
||||
#define __GSM_GPRS_H__
|
||||
|
||||
// #include "gsm_uart_conf.h"
|
||||
//
|
||||
// #define GSM_PW_KEY PBout(12)
|
||||
|
||||
// //设备连接状态
|
||||
// typedef enum
|
||||
// {
|
||||
// OFFLINE = 0, //离线
|
||||
// ONLINE = 1 //在线
|
||||
|
||||
// }_ConnectionStatus;
|
||||
|
||||
// extern uint8_t GSM_isPowerON; //GSM模块是否处于开机
|
||||
// extern uint8_t ConnectionStatus; //连接状态(当有数据包发送成功后置位为在线状态)
|
||||
|
||||
// void GSM_GPRS_Init(void);
|
||||
// uint8_t GSM_PowerON(void);
|
||||
// uint8_t GSM_PowerOFF(void);
|
||||
|
||||
// void GSM_GPRS_Task(void);
|
||||
#endif
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 CXHY *****END OF FILE*******************/
|
||||
+170
@@ -0,0 +1,170 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :gsm_uart.c
|
||||
* 描 述 :GSM控制串口(串口3)
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/04/26
|
||||
*********************************************************************************/
|
||||
#include "delay.h"
|
||||
#include "usart1.h"
|
||||
#include "stdarg.h"
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
#include "string.h"
|
||||
#include "gsm_uart.h"
|
||||
#include "gsm_uart_conf.h"
|
||||
#include "usart3.h"
|
||||
#include "at_proc.h"
|
||||
#include "tcp_protocol.h"
|
||||
|
||||
//串口发送缓存区
|
||||
__align(8) uint8_t GPRS_TX_BUF[GPRS_MAX_SEND_LEN]; //发送缓冲,最大GPRS_MAX_SEND_LEN字节
|
||||
uint8_t GPRS_RX_BUF[GPRS_MAX_RECV_LEN]; //接收缓冲,最大GPRS_MAX_RECV_LEN字节
|
||||
|
||||
uint8_t GPRS_DATA_BUF[GPRS_MAX_SEND_LEN]; //GPRS数据处理缓冲,最大GPRS_MAX_SEND_LEN字节
|
||||
uint8_t GPRS_RECV_DATA_BUF[GPRS_MAX_RECV_LEN];
|
||||
|
||||
_gsm_msg gsm_msg;
|
||||
uint8_t signal;
|
||||
|
||||
uint16_t total_send_length = 0; //发送数据总长度
|
||||
uint16_t ackedBytes = 0; //收到数据总长度
|
||||
uint16_t unackedbytes = 0; //未收到数据总长度
|
||||
|
||||
uint8_t receiveDataMark = 0;
|
||||
|
||||
uint8_t GSM_ReceiveType = 0; // GSM模块接收到的数据类型(0为AT命令应答,1为TCP数据)
|
||||
|
||||
uint16_t GPRS_RX_STA; //接收数据状态
|
||||
uint16_t GPRS_RX_Cnt = 0;
|
||||
uint16_t recDataLen = 0;
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: GSM_Uart_Init
|
||||
* 功能说明: GSM控制串口初始化
|
||||
* 形 参: 无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void GSM_GPRS_Uart_Init(void)
|
||||
{
|
||||
USART3_Init(115200); //外部需实现些函数
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: GSM_GPRS_SendOne
|
||||
* 功能说明: 向GSM串口发送一次数据
|
||||
* 形 参: 无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void GSM_GPRS_SendOne(uint8_t pDataBuf[], uint16_t len)
|
||||
{
|
||||
UART3_Send_One(len); //外部需实现些函数
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: GSM_GPRS_SendByteData
|
||||
* 功能说明: 向GSM串口输出一字节数据
|
||||
* 形 参: 无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void GSM_GPRS_SendByteData(uint8_t cmd)
|
||||
{
|
||||
while(DMA1_Channel2->CNDTR != 0); //等待通道7传输完成
|
||||
USART3->DR = (uint32_t)cmd;
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: GSM_GPRS_printf
|
||||
* 功能说明: GSM串口输出命令
|
||||
* 形 参: 无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void GSM_GPRS_printf(char* fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
vsprintf((char*)GPRS_TX_BUF, fmt, ap);
|
||||
va_end(ap);
|
||||
// while(DMA1_Channel2->CNDTR!=0); //等待通道7传输完成
|
||||
GSM_GPRS_SendOne(GPRS_TX_BUF, strlen((const char*)GPRS_TX_BUF)); //通过dma发送出去
|
||||
}
|
||||
|
||||
|
||||
void show_buf1(uint8_t num[], uint8_t n)
|
||||
{
|
||||
uint8_t i;
|
||||
printf("\r\n");
|
||||
for(i=0; i<n; i++)
|
||||
{
|
||||
printf("%x ",num[i]);
|
||||
}
|
||||
printf("\r\n");
|
||||
}
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: GSM_GPRS_ReceiveData
|
||||
* 功能说明: GSM串口接收数据
|
||||
* 形 参: 无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void GSM_GPRS_ReceiveData(uint8_t rxData)
|
||||
{
|
||||
static uint8_t i = 0;
|
||||
static uint8_t len = 0;
|
||||
static uint8_t receiveStatus = 0;
|
||||
|
||||
if(GPRS_RX_Cnt < GPRS_MAX_RECV_LEN) //还可以接收数据
|
||||
{
|
||||
GPRS_RX_BUF[GPRS_RX_Cnt++] = rxData; //记录接收到的值
|
||||
|
||||
if(GSM_ReceiveType == 0) //接收到GSM模块的数据为AT命令应答数据
|
||||
{
|
||||
if(GPRS_RX_BUF[GPRS_RX_Cnt - 1] == '\n')
|
||||
{
|
||||
i++;
|
||||
if(GPRS_RX_Cnt >= 4)
|
||||
{
|
||||
GPRS_RX_BUF[GPRS_RX_Cnt] = 0; //在接收到的数据后面增加字符串结束符'\0'
|
||||
|
||||
AT_Protocol(GPRS_RX_BUF, GPRS_RX_Cnt); //进行AT指令应答解析
|
||||
}
|
||||
GPRS_RX_Cnt = 0;
|
||||
}
|
||||
|
||||
if((sendAtCmdNo == AT_CMD_QISEND) && (GPRS_RX_BUF[GPRS_RX_Cnt - 1] == '>'))
|
||||
{
|
||||
GPRS_RX_BUF[GPRS_RX_Cnt] = 0; //在接收到的数据后面增加字符串结束符'\0'
|
||||
AT_Protocol(GPRS_RX_BUF, GPRS_RX_Cnt); //进行AT指令应答解析
|
||||
GPRS_RX_Cnt = 0;
|
||||
}
|
||||
}else{ //接收到模块的URC上报数据
|
||||
if(GPRS_RX_Cnt >= recDataLen)
|
||||
{
|
||||
// show_buf1(GPRS_RX_BUF, GPRS_RX_Cnt);
|
||||
GPRS_RX_BUF[GPRS_RX_Cnt] = 0; //在接收到的数据后面增加字符串结束符'\0'
|
||||
|
||||
TCP_Protocol(GPRS_RX_BUF, GPRS_RX_Cnt);
|
||||
GPRS_RX_Cnt = 0;
|
||||
GSM_ReceiveType = 0;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
GPRS_RX_Cnt = 0;
|
||||
GSM_ReceiveType = 0;
|
||||
receiveStatus = 0x00;
|
||||
printf("\r\nData out\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 CXHY *****END OF FILE*******************/
|
||||
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :gsm_uart.h
|
||||
* 描 述 :GSM控制端口(串口3)
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/04/26
|
||||
*********************************************************************************/
|
||||
#ifndef __GSM_UART_H
|
||||
#define __GSM_UART_H
|
||||
#include "stm32f10x.h"
|
||||
|
||||
void GSM_GPRS_Uart_Init(void); //GSM_GPRS所使用的串口初始化
|
||||
void GSM_GPRS_SendOne(uint8_t pDataBuf[], uint16_t len); //向GSM所使用的串口发送一len长度的数据
|
||||
void GSM_GPRS_SendByteData(uint8_t cmd); //向GSM所使用的串口发送一字节数据
|
||||
void GSM_GPRS_printf(char* fmt, ...); //向GSM所使用的串口发送数据
|
||||
void GSM_GPRS_ReceiveData(uint8_t rxData);
|
||||
|
||||
#endif
|
||||
|
||||
/******************** (C) COPYRIGHT 2014 GLHF *****END OF FILE*******************/
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :gsm_uart.c
|
||||
* 描 述 :GSM控制串口(串口3)
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/04/26
|
||||
*********************************************************************************/
|
||||
#include "delay.h"
|
||||
#include "sys.h"
|
||||
#include "usart.h"
|
||||
#include "stdarg.h"
|
||||
#include "stdio.h"
|
||||
#include "string.h"
|
||||
#include "gsm_uart_conf.h"
|
||||
|
||||
//串口发送缓存区
|
||||
// __align(8) uint8_t GPRS_TX_BUF[GPRS_MAX_SEND_LEN]; //发送缓冲,最大GPRS_MAX_SEND_LEN字节
|
||||
// uint8_t GPRS_RX_BUF[GPRS_MAX_RECV_LEN]; //接收缓冲,最大GPRS_MAX_RECV_LEN字节
|
||||
|
||||
// uint16_t GPRS_RX_STA; //接收数据状态
|
||||
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 CXHY *****END OF FILE*******************/
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :gsm_uart.h
|
||||
* 描 述 :GSM控制端口
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/04/26
|
||||
*********************************************************************************/
|
||||
#ifndef __GSM_UART_CONF_H
|
||||
#define __GSM_UART_CONF_H
|
||||
#include "stdint.h"
|
||||
|
||||
#define TCP_IP_COM "AT+QIOPEN=1,0,\"TCP\",\"112.74.41.228\",9956,0,1"
|
||||
// #define TCP_IP_COM "AT+QIOPEN=1,0,\"TCP\",\"xzp71.xicp.net\",41149,0,1" //花生壳转发内网服务器
|
||||
// #define TCP_IP_COM "AT+QIOPEN=1,0,\"TCP\",\"218.59.175.31\",9956,0,1" //青岛服务器
|
||||
|
||||
// #define TCP_IP_COM "AT+CIPSTART=\"TCP\",\"112.74.41.228\",\"9956\""
|
||||
// #define TCP_IP_COM "AT+CIPSTART=\"TCP\",\"112.74.41.228\",\"1111\""
|
||||
// #define TCP_IP_COM "AT+CIPSTART=\"TCP\",\"115.28.185.180\",\"8956\""
|
||||
// #define TCP_IP_COM "AT+CIPSTART=\"TCP\",\"xzp71.xicp.net\",\"50062\""
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t Running; //GSM模块运行状态
|
||||
char IMEI [16]; //设备号
|
||||
char IMEI_HEX[8]; //IMEI设备号十六进制保存,便于上传到后台
|
||||
uint8_t Operator[16]; //通信运营商
|
||||
uint8_t OperatorType; //0:未知;1:中国移动;2:中国联通
|
||||
char ICCID[24]; //SIM卡ICCID号
|
||||
uint8_t simCardStatus; //sim卡状态(0:未知状态,1:正常,2:无法注册网络,3:没有GPRS业务,4:没有检测到卡)
|
||||
}_gsm_msg;
|
||||
|
||||
extern _gsm_msg gsm_msg;
|
||||
extern uint8_t signal;
|
||||
|
||||
extern uint16_t total_send_length; //发送数据总长度
|
||||
extern uint16_t ackedBytes; //收到数据总长度
|
||||
extern uint16_t unackedbytes; //未收到数据总长度
|
||||
|
||||
extern uint8_t receiveDataMark;
|
||||
|
||||
extern char command_CIPSEND[16];
|
||||
|
||||
#define GPRS_MAX_SEND_LEN 1024 //最大发送缓存字节数
|
||||
#define GPRS_MAX_RECV_LEN 1024 //最大接收缓存字节数
|
||||
|
||||
extern uint8_t GPRS_TX_BUF[GPRS_MAX_SEND_LEN]; //发送缓冲,最大GPRS_MAX_SEND_LEN字节
|
||||
extern uint8_t GPRS_RX_BUF[GPRS_MAX_RECV_LEN]; //接收缓冲,最大GPRS_MAX_RECV_LEN字节
|
||||
|
||||
extern uint8_t GPRS_DATA_BUF[GPRS_MAX_SEND_LEN]; //GPRS数据处理缓冲,最大GPRS_MAX_SEND_LEN字节
|
||||
extern uint8_t GPRS_RECV_DATA_BUF[GPRS_MAX_RECV_LEN];
|
||||
|
||||
extern uint16_t GPRS_RX_STA; //接收数据状态
|
||||
extern uint8_t GSM_ReceiveType; // GSM模块接收到的数据类型(即AT命令应答还是TCP数据)
|
||||
extern uint16_t recDataLen;
|
||||
|
||||
#endif
|
||||
|
||||
/******************** (C) COPYRIGHT 2014 GLHF *****END OF FILE*******************/
|
||||
+341
@@ -0,0 +1,341 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :gsm_uart.c
|
||||
* 描 述 :GSM控制串口(串口2)
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/04/26
|
||||
*********************************************************************************/
|
||||
#include "netwer_appcall.h"
|
||||
#include "timer.h"
|
||||
#include "data_typedef.h"
|
||||
#include "tcp_protocol.h"
|
||||
#include "message.h"
|
||||
#include "gsm_uart_conf.h"
|
||||
#include "ec200x.h"
|
||||
#include "at_proc.h"
|
||||
|
||||
uint8_t isSendDataMark = 0; //是否有数据要发送标志
|
||||
uint8_t isReceiveDataMark = 0; //是否有接收到数据标志
|
||||
uint8_t dataSendSuccessMark = 0; //数据发送成功标志
|
||||
uint8_t dataSendFailureMark = 0; //数据发送失败标志
|
||||
uint8_t dataSendOkButNoAckMark = 0; //数据发送成功但没有收运应答
|
||||
|
||||
uint16_t sendDataLen = 0; //发送的数据长度
|
||||
|
||||
|
||||
void show_hex(uint8_t num[], uint8_t n)
|
||||
{
|
||||
uint8_t i;
|
||||
printf("\r\n");
|
||||
for(i=0; i<n; i++)
|
||||
{
|
||||
printf("%02X ",num[i]);
|
||||
}
|
||||
printf("\r\n");
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: ChackIccidNumber
|
||||
* 功能说明: 判断当前的ICCID号和之前的是否相等
|
||||
* 形 参:
|
||||
* 返 回 值: 不相等返回1,相等返回0
|
||||
***********************************************************************
|
||||
*/
|
||||
uint8_t ChackIccidNumber(char* preId, char* curId)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
for(i = 0; i < 20; i++)
|
||||
{
|
||||
if(preId[i] != curId[i]) return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static uint8_t delaySendMark = 0; //延时发送标志
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: NetReconnectDelaySendHandler
|
||||
* 功能说明: 网络重连后数据延时发送处理
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void NetReconnectDelaySendHandler(void)
|
||||
{
|
||||
uint8_t i;
|
||||
static uint8_t currentStatus = 0x00;
|
||||
static uint8_t nextStatus = 0x00;
|
||||
|
||||
static uint8_t initRandomSendTimerFalg = 0; //初始化随机延迟发送时间标志
|
||||
static uint32_t timeSeed = 0; //生成随机延时时间的种子
|
||||
static char preICCID[24] = {0}; //之前的ICCID号
|
||||
static uint8_t preNetworkConnectionCount = 0; //上一次的建立网络连接次数
|
||||
static uint8_t reuploadICCID = 0; //重新上传ICCID号
|
||||
uint8_t msgBufSurplus = 0; //消息队列还剩余空间
|
||||
|
||||
static timer waitingTimer; //等待时间
|
||||
static timer delayRandomSendTimer; //延迟随机发送时间
|
||||
|
||||
static uint8_t timer_ok = 0;
|
||||
if(timer_ok == 0)
|
||||
{
|
||||
timer_ok = 1;
|
||||
|
||||
timer_set(&waitingTimer, CLOCK_SECOND*60*2);
|
||||
timer_set(&delayRandomSendTimer, CLOCK_SECOND*1);
|
||||
}
|
||||
|
||||
if(gsm_msg.Running == 1) //网络已经建立
|
||||
{
|
||||
if(initRandomSendTimerFalg == 0) //初始化随机延迟发送时间
|
||||
{
|
||||
initRandomSendTimerFalg = 1;
|
||||
|
||||
timeSeed = (uint32_t)(gsm_msg.IMEI_HEX[4] << 24) | (gsm_msg.IMEI_HEX[5] << 16) | (gsm_msg.IMEI_HEX[6] << 8) | gsm_msg.IMEI_HEX[7];
|
||||
printf("\r\ntimeSeed = %llu\r\n", (uint64_t)timeSeed);
|
||||
srand(timeSeed);
|
||||
delayRandomTime = rand()%60; //得到随机延迟发送时间
|
||||
printf("\r\ndelayRandomTime = %d\r\n", delayRandomTime);
|
||||
|
||||
timer_set(&delayRandomSendTimer, CLOCK_SECOND*delayRandomTime);
|
||||
|
||||
memset(preICCID, 0, 24);
|
||||
memcpy(preICCID, gsm_msg.ICCID, 20); //取出当前的ICCID号
|
||||
printf("\r\n延时发送时间初始化成功!\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
//当物联网卡的ICCID号有发生变化,则重新上传
|
||||
if(reuploadICCID == 1)
|
||||
{
|
||||
msgBufSurplus = GetMessageRemainingSpace(MSG_FIFO_PROTOCOL);
|
||||
if(msgBufSurplus >= 5) //发送消息队列有空间时才发送,不然会发送不成功
|
||||
{
|
||||
printf("\r\n当前队列状态:%d\r\n", msgBufSurplus);
|
||||
reuploadICCID = 0;
|
||||
|
||||
sendMsg.msgType = 1003;
|
||||
MessageSend(MSG_FIFO_PROTOCOL, sendMsg);
|
||||
}
|
||||
}
|
||||
|
||||
currentStatus = nextStatus;
|
||||
switch(currentStatus)
|
||||
{
|
||||
case 0x00: //初始状态
|
||||
//判断当前有没有出现网络重连
|
||||
if(preNetworkConnectionCount != networkConnectionCount)
|
||||
{
|
||||
preNetworkConnectionCount = networkConnectionCount;
|
||||
|
||||
if(networkConnectionCount != 1) //不是首次建立网络,标志当前有网络重连
|
||||
{
|
||||
printf("\r\n出现了网络重连!\r\n");
|
||||
delaySendMark = 1; //标志当前网络出现了网络重连
|
||||
|
||||
if(ChackIccidNumber(preICCID, gsm_msg.ICCID))
|
||||
{
|
||||
printf("\r\nICCID号发生改变!\r\n");
|
||||
reuploadICCID = 1;
|
||||
|
||||
printf("\r\n当前队列状态:%d\r\n", GetMessageRemainingSpace(MSG_FIFO_PROTOCOL));
|
||||
|
||||
memcpy(preICCID, gsm_msg.ICCID, 20);
|
||||
}
|
||||
|
||||
timer_restart(&delayRandomSendTimer);
|
||||
timer_restart(&waitingTimer);
|
||||
nextStatus = 0x01;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x01: //有断线重新连接网络,则延迟随机数定时后再发送数据
|
||||
if(timer_expired(&delayRandomSendTimer))
|
||||
{
|
||||
printf("\r\n等待延时发送时间到!\r\n");
|
||||
delaySendMark = 0;
|
||||
nextStatus = 0x00;
|
||||
break;
|
||||
}
|
||||
|
||||
if(timer_expired(&waitingTimer))
|
||||
{
|
||||
printf("\r\n延时发送等待超时!\r\n");
|
||||
delaySendMark = 0;
|
||||
nextStatus = 0x00;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: SendNetworkData
|
||||
* 功能说明: 发送网络数据
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void SendNetworkData(uint8_t *sendBuf, uint16_t dataLength)
|
||||
{
|
||||
sendDataLen = dataLength;
|
||||
// memcpy(GPRS_TX_BUF, sendBuf, GPRS_sendDataLength);
|
||||
isSendDataMark = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: DataUploadPollingTask
|
||||
* 功能说明: 数据上传轮询任务
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void DataUploadPollingTask(void)
|
||||
{
|
||||
static uint8_t currentStatus = 0x00;
|
||||
static uint8_t nextStatus = 0x00;
|
||||
|
||||
uint8_t sendFailureFlag = 0;
|
||||
|
||||
static MESSAGE *pMsg;
|
||||
static uint16_t dataBufLength = 0;
|
||||
|
||||
static uint32_t nowTime = 0; //当前发送指令的时间
|
||||
static uint32_t preSendTime_1001 = 0; //前一次发送指令的时间
|
||||
static uint32_t preSendTime_6004 = 0;
|
||||
uint16_t repeatCmdIntervalTime = 600; //重复指令间隔时间(单位为0.1秒)
|
||||
|
||||
static timer uploadIntervalTime; //心跳上传时间间隔限制(限制同一时间内重复上传心跳包)
|
||||
static timer responseTimeout; //应答超时时间间隔
|
||||
static timer sendTimeout; //发送超时时间间隔
|
||||
|
||||
static uint8_t timer_ok = 0;
|
||||
if(timer_ok == 0)
|
||||
{
|
||||
timer_ok = 1;
|
||||
|
||||
timer_set(&uploadIntervalTime, CLOCK_SECOND*3);
|
||||
timer_set(&responseTimeout, CLOCK_SECOND*3);
|
||||
timer_set(&sendTimeout, CLOCK_SECOND*120);
|
||||
}
|
||||
|
||||
NetReconnectDelaySendHandler();
|
||||
|
||||
currentStatus = nextStatus;
|
||||
switch(currentStatus)
|
||||
{
|
||||
case 0x00:
|
||||
if(ConnectionStatus == ONLINE)
|
||||
{
|
||||
if(delaySendMark == 0) //是否要延迟发送
|
||||
{
|
||||
pMsg = MessageGet(MSG_FIFO_PROTOCOL); //读取消息对列
|
||||
if(pMsg) //如果消息对列中有消息则进行数据发送
|
||||
{
|
||||
sendOrderCode = pMsg->msgType; //取得发送的协议码
|
||||
|
||||
nowTime = time_value; //取出当前发送指令的时间
|
||||
if(sendOrderCode == 1001) //当前发送的是1001指令
|
||||
{
|
||||
if((preSendTime_1001 != 0) && ((nowTime - preSendTime_1001) < repeatCmdIntervalTime))
|
||||
{
|
||||
printf("\r\n重复1001指令取消发送!\r\n");
|
||||
nextStatus = 0x00;
|
||||
break;
|
||||
}
|
||||
preSendTime_1001 = nowTime;
|
||||
}
|
||||
|
||||
if(sendOrderCode == 6004) //当前发送的是6004指令
|
||||
{
|
||||
if((preSendTime_6004 != 0) && ((nowTime - preSendTime_6004) < repeatCmdIntervalTime))
|
||||
{
|
||||
printf("\r\n重复6004指令取消发送!\r\n");
|
||||
nextStatus = 0x00;
|
||||
break;
|
||||
}
|
||||
preSendTime_6004 = nowTime;
|
||||
}
|
||||
|
||||
printf("\r\nTCP Sending data......\r\n");
|
||||
nextStatus = 0x01; //跳转到发送数据
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x01:
|
||||
dataBufLength = SendProtocolPackaging(sendOrderCode); //通过消息的类型进行相应协议打包
|
||||
SendNetworkData(GPRS_DATA_BUF, dataBufLength);
|
||||
|
||||
isReceiveDataMark = 0;
|
||||
dataSendSuccessMark = 0;
|
||||
dataSendFailureMark = 0;
|
||||
timer_restart(&sendTimeout);
|
||||
nextStatus = 0x02;
|
||||
break;
|
||||
|
||||
case 0x02: //等待发送完成
|
||||
if(isReceiveDataMark == 1)
|
||||
{
|
||||
isReceiveDataMark = 0;
|
||||
printf("\r\n数据发送成功!\r\n");
|
||||
// show_hex(GPRS_RECV_DATA_BUF, receiveDataLen);
|
||||
// printf("\r\ndata=%s\r\n", GPRS_DATA_BUF);
|
||||
// TCP_Protocol(GPRS_RECV_DATA_BUF, receiveDataLen);
|
||||
// memset(GPRS_RECV_DATA_BUF, 0x00, 1024);
|
||||
nextStatus = 0x00;
|
||||
break;
|
||||
}
|
||||
|
||||
//数据已发送到服务器,但没有收到应答
|
||||
if(dataSendOkButNoAckMark == 1)
|
||||
{
|
||||
printf("\r\n数据已发送,但没有应答!\r\n");
|
||||
dataSendOkButNoAckMark = 0;
|
||||
|
||||
nextStatus = 0x00;
|
||||
break;
|
||||
}
|
||||
|
||||
//发送失败
|
||||
if(dataSendFailureMark == 1)
|
||||
{
|
||||
dataSendFailureMark = 0;
|
||||
printf("\r\n数据发送失败!\r\n");
|
||||
sendFailureFlag = 1;
|
||||
}
|
||||
|
||||
//发送超时
|
||||
if(timer_expired(&sendTimeout)) //超时还未接收到应答
|
||||
{
|
||||
printf("\r\n发送超时!\r\n");
|
||||
sendFailureFlag = 1;
|
||||
}
|
||||
|
||||
if(sendFailureFlag == 1)
|
||||
{
|
||||
printf("\r\nTCP send data failure!\r\n");
|
||||
nextStatus = 0x00;
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 CXHY *****END OF FILE*******************/
|
||||
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
/*************************** (C) COPYRIGHT 2017 YNHB ****************************
|
||||
* 文件名 :netwer_appcall.h
|
||||
* 描 述 :GSM控制端口(串口3)
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/04/26
|
||||
*********************************************************************************/
|
||||
#ifndef __NETWER_APPCALL_H
|
||||
#define __NETWER_APPCALL_H
|
||||
#include "stdio.h"
|
||||
#include "stdint.h"
|
||||
#include "stdlib.h"
|
||||
|
||||
extern uint8_t isSendDataMark; //是否有数据要发送标志
|
||||
extern uint8_t isReceiveDataMark; //是否有接收到数据标志
|
||||
extern uint8_t dataSendSuccessMark; //数据发送成功标志
|
||||
extern uint8_t dataSendFailureMark; //数据发送失败标志
|
||||
extern uint8_t dataSendOkButNoAckMark; //数据发送成功但没有收运应答
|
||||
|
||||
extern uint16_t sendDataLen; //发送的数据长度
|
||||
|
||||
void DataUploadPollingTask(void);
|
||||
|
||||
#endif
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 YNHB *****END OF FILE*******************/
|
||||
@@ -0,0 +1,421 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :UltrasonicWave.c
|
||||
* 描 述 :HC-SR04超声波驱动代码
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/08/04
|
||||
*********************************************************************************/
|
||||
#include "IR_Distancer.h"
|
||||
#include "timer.h"
|
||||
#include "delay.h"
|
||||
#include "adc.h"
|
||||
#include "my_math.h"
|
||||
#include "data_typedef.h"
|
||||
|
||||
#define IR_AdcValSize 100
|
||||
uint16_t IR_AdcValBuf_1[IR_AdcValSize];
|
||||
uint16_t IR_AdcVal_1 = 0;
|
||||
|
||||
uint16_t IR_AdcValBuf_2[IR_AdcValSize];
|
||||
uint16_t IR_AdcVal_2 = 0;
|
||||
|
||||
uint8_t IR_GetAdcValMake = 0;
|
||||
|
||||
#define IR_GetDataCount 5
|
||||
|
||||
uint8_t ir_Distance1 = 0;
|
||||
uint8_t ir_dataOutState1 = 0;
|
||||
uint8_t ir_Distance2 = 0;
|
||||
uint8_t ir_dataOutState2 = 0;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: show
|
||||
* 功能说明: 以十六进制显示数组里的内容
|
||||
* 形 参: 无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void showBuf(uint16_t num[], uint8_t n)
|
||||
{
|
||||
uint8_t i;
|
||||
printf("\r\n");
|
||||
for(i=0; i<n; i++)
|
||||
{
|
||||
printf("%04d ",num[i]);
|
||||
}
|
||||
printf("\r\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: IR_GetAdcVal_1
|
||||
* 功能说明: 获取红外测距传感器ADC值
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void IR_GetAdcVal_1(void)
|
||||
{
|
||||
Data_collection(IR_AdcValBuf_1, IR_AdcValSize, ADC_Channel_11);
|
||||
sort_16(IR_AdcValBuf_1, IR_AdcValSize); //对存在缓存中的采集数据进行排序
|
||||
IR_AdcVal_1 = average_16(IR_AdcValBuf_1, IR_AdcValSize, 20); //去掉头和尾后,求平均数
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: IR_GetAdcVal_2
|
||||
* 功能说明: 获取红外测距传感器ADC值
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void IR_GetAdcVal_2(void)
|
||||
{
|
||||
Data_collection(IR_AdcValBuf_2, IR_AdcValSize, ADC_Channel_10);
|
||||
sort_16(IR_AdcValBuf_2, IR_AdcValSize); //对存在缓存中的采集数据进行排序
|
||||
IR_AdcVal_2 = average_16(IR_AdcValBuf_2, IR_AdcValSize, 20); //去掉头和尾后,求平均数
|
||||
}
|
||||
|
||||
uint8_t distanceMap[] = { 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150};
|
||||
float voltageMap[14] = {2.49, 1.95, 1.51, 1.21, 1.01, 0.86, 0.76, 0.69, 0.61, 0.53, 0.45, 0.40, 0.34, 0.25};
|
||||
// float voltageMap[14] = {2.50, 1.95, 1.50, 1.20, 1.00, 0.88, 0.77, 0.69, 0.60, 0.55, 0.49, 0.44, 0.38, 0.30};
|
||||
|
||||
// float voltageMap[14] = {2.44, 1.94, 1.50, 1.20, 1.00, 0.85, 0.74, 0.67, 0.60, 0.52, 0.48, 0.44, 0.39, 0.33};
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: LookupTable
|
||||
* 功能说明: 查表得出对应的距离值
|
||||
* 形 参:无
|
||||
* 返 回 值: 对应的距离
|
||||
***********************************************************************
|
||||
*/
|
||||
float LookupTable(float vIn, float vMap1, float vMap2, uint8_t disMap1, uint8_t disMap2)
|
||||
{
|
||||
uint8_t disDifVal; //区间的电压差值
|
||||
float vDifVal; //区间的距离差值
|
||||
float vLtscale; //区间距离比例因子
|
||||
float vIntervalVal; //区间电压值
|
||||
float intervalDistance; //区间的距离
|
||||
|
||||
disDifVal = disMap2 - disMap1;
|
||||
vDifVal = vMap1 - vMap2;
|
||||
vLtscale = disDifVal/vDifVal;
|
||||
|
||||
vIntervalVal = vMap1 - vIn;
|
||||
intervalDistance = vIntervalVal*vLtscale;
|
||||
|
||||
// printf("\r\ndisDif = %d\r\n", disDifVal);
|
||||
// printf("\r\nvDif = %.2f\r\n", vDifVal);
|
||||
// printf("\r\nvLtscale = %.2f\r\n", vLtscale);
|
||||
// printf("\r\nvIntervalVal = %.2f\r\n", vIntervalVal);
|
||||
// printf("\r\nvInvalVal = %.2f\r\n", intervalDistance);
|
||||
|
||||
return disMap1 + intervalDistance;
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: IR_GetDistanceData
|
||||
* 功能说明: 取得一次测距值
|
||||
* 形 参:num -> 对应哪个通道
|
||||
* 返 回 值: 当前通道的测距值
|
||||
***********************************************************************
|
||||
*/
|
||||
uint8_t IR_GetDistanceData(uint8_t num)
|
||||
{
|
||||
float distanceTemp;
|
||||
float adToVdcVal;
|
||||
int index = 0;
|
||||
|
||||
switch(num)
|
||||
{
|
||||
case 1:
|
||||
IR_GetAdcVal_1();
|
||||
|
||||
if(IR_AdcVal_1 < 120)
|
||||
{
|
||||
return 255;
|
||||
}else{
|
||||
adToVdcVal = IR_AdcVal_1/4096.0 * 3.34;
|
||||
// printf("\r\nV1 = %1.2f, ADC1 = %d ", adToVdcVal, IR_AdcVal_1);
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
IR_GetAdcVal_2();
|
||||
|
||||
if(IR_AdcVal_2 < 120)
|
||||
{
|
||||
return 255;
|
||||
}else{
|
||||
adToVdcVal = IR_AdcVal_2/4096.0 * 3.34;
|
||||
// printf("\r\nV2 = %1.2f, ADC2 = %d ", adToVdcVal, IR_AdcVal_2);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// printf("ADC = %4d, %4d, V = %1.2f\r\n", IR_AdcVal_1, IR_AdcVal_2, adToVdcVal);
|
||||
|
||||
for(index = 0; index < 14; index++)
|
||||
{
|
||||
if(adToVdcVal >= voltageMap[index])
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// printf("\r\nindex = %d\r\n", index);
|
||||
if(index == 0)
|
||||
{
|
||||
distanceTemp = 20;
|
||||
}else if(index == 14){
|
||||
distanceTemp = 150;
|
||||
}else{
|
||||
distanceTemp = LookupTable(adToVdcVal, voltageMap[index-1], voltageMap[index], distanceMap[index-1], distanceMap[index]);
|
||||
}
|
||||
|
||||
// printf("D = %d cm\r\n", (uint8_t)distanceTemp);
|
||||
|
||||
return distanceTemp;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: ULT_DataProcessing
|
||||
* 功能说明: 对采集到缓存的数据处理(对其进行排序后求平均数)
|
||||
* 形 参:
|
||||
* *p: 需要处理的数组指针
|
||||
* n: 数组的长度
|
||||
* 返 回 值: 返回最终处理过后的结果
|
||||
***********************************************************************
|
||||
*/
|
||||
uint8_t IR_DataProcessing(uint8_t *p, uint16_t n, uint8_t discardVal)
|
||||
{
|
||||
uint8_t retData = 0;
|
||||
|
||||
sort_8(p, n); //对存在缓存中的采集数据进行排序
|
||||
retData = average_8(p, n, discardVal); //去掉头和尾后,求平均数
|
||||
// printf("\r\nValue = %d\r\n", retData);
|
||||
return retData;
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: IR_GetDistanceTask_01
|
||||
* 功能说明: 获取红外测距任务
|
||||
* 形 参:无
|
||||
* 返 回 值: 数据处理状态 1:已处理完成可以输出、0:尚未处理完成
|
||||
***********************************************************************
|
||||
*/
|
||||
void IR_GetDistanceTask_01(void)
|
||||
{
|
||||
static uint8_t step = 0x00;
|
||||
static uint8_t getDataCnt = 0x00;
|
||||
|
||||
static uint8_t newValue = 0x00;
|
||||
static uint8_t oleValue = 0x00;
|
||||
static uint8_t IR_DistanceDataBuf[IR_GetDataCount];
|
||||
|
||||
static timer waitingTimer;
|
||||
static uint8_t timer_ok = 0;
|
||||
|
||||
if(timer_ok == 0)
|
||||
{
|
||||
timer_ok = 1;
|
||||
timer_set(&waitingTimer, 1);
|
||||
}
|
||||
|
||||
switch(step)
|
||||
{
|
||||
case 0x00:
|
||||
if(timer_expired(&waitingTimer))
|
||||
{
|
||||
newValue = IR_GetDistanceData(1);
|
||||
// printf("\r\nValue = %3.1f cm\r\n",(float)newValue);
|
||||
step = 0x01;
|
||||
timer_restart(&waitingTimer);
|
||||
}
|
||||
break;
|
||||
case 0x01:
|
||||
if(DifferenceCompare(newValue, oleValue, 10)) //比较新旧值的差值,(当前值 - 之前值)> 设定值时重新采集数据
|
||||
{
|
||||
getDataCnt = 0;
|
||||
}
|
||||
// printf("\r\nCnt1 = %d, newValue = %d, oleValue = %d\r\n", getDataCnt, newValue, oleValue);
|
||||
oleValue = newValue;
|
||||
|
||||
IR_DistanceDataBuf[getDataCnt] = newValue;
|
||||
getDataCnt++;
|
||||
if(IR_GetDataCount == getDataCnt) //IR_GetDataCount次数据都相差不大,则认为数据已经稳定可以输出
|
||||
{
|
||||
getDataCnt = 0;
|
||||
step = 0x02; //转到数据处理输出
|
||||
}else{
|
||||
step = 0x00;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x02:
|
||||
ir_Distance1 = IR_DataProcessing(IR_DistanceDataBuf, IR_GetDataCount, 0);
|
||||
// printf("\r\nNo1 ---> %3.1f cm\r\n",(float)ir_Distance1);
|
||||
ir_dataOutState1 = 1;
|
||||
step = 0x00;
|
||||
break;
|
||||
|
||||
default:
|
||||
step = 0x00;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: IR_GetDistanceTask_02
|
||||
* 功能说明: 获取红外测距任务
|
||||
* 形 参:无
|
||||
* 返 回 值: 数据处理状态 1:已处理完成可以输出、0:尚未处理完成
|
||||
***********************************************************************
|
||||
*/
|
||||
void IR_GetDistanceTask_02(void)
|
||||
{
|
||||
static uint8_t step = 0x00;
|
||||
static uint8_t getDataCnt = 0x00;
|
||||
|
||||
static uint8_t newValue = 0x00;
|
||||
static uint8_t oleValue = 0x00;
|
||||
static uint8_t IR_DistanceDataBuf[IR_GetDataCount];
|
||||
|
||||
static timer waitingTimer;
|
||||
static uint8_t timer_ok = 0;
|
||||
|
||||
if(timer_ok == 0)
|
||||
{
|
||||
timer_ok = 1;
|
||||
timer_set(&waitingTimer, 1);
|
||||
}
|
||||
|
||||
switch(step)
|
||||
{
|
||||
case 0x00:
|
||||
if(timer_expired(&waitingTimer))
|
||||
{
|
||||
newValue = IR_GetDistanceData(2);
|
||||
// printf("\r\nValue = %3.1f cm\r\n",(float)newValue);
|
||||
step = 0x01;
|
||||
timer_restart(&waitingTimer);
|
||||
}
|
||||
break;
|
||||
case 0x01:
|
||||
if(DifferenceCompare(newValue, oleValue, 10)) //比较新旧值的差值,(当前值 - 之前值)> 设定值时重新采集数据
|
||||
{
|
||||
getDataCnt = 0;
|
||||
}
|
||||
// printf("\r\nCnt2 = %d, newValue = %d, oleValue = %d\r\n", getDataCnt, newValue, oleValue);
|
||||
oleValue = newValue;
|
||||
|
||||
IR_DistanceDataBuf[getDataCnt] = newValue;
|
||||
getDataCnt++;
|
||||
if(IR_GetDataCount == getDataCnt) //10次数据都相差不大,则认为数据已经稳定可以输出
|
||||
{
|
||||
getDataCnt = 0;
|
||||
step = 0x02; //转到数据处理输出
|
||||
}else{
|
||||
step = 0x00;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x02:
|
||||
ir_Distance2 = IR_DataProcessing(IR_DistanceDataBuf, IR_GetDataCount, 0);
|
||||
// printf("\r\nNo2 ---> %3.1f cm\r\n",(float)ir_Distance2);
|
||||
ir_dataOutState2 = 1;
|
||||
step = 0x00;
|
||||
break;
|
||||
|
||||
default:
|
||||
step = 0x00;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// /*
|
||||
// ***********************************************************************
|
||||
// * 函 数 名: IR_GetDistanceTask
|
||||
// * 功能说明: 红外测距任务
|
||||
// * 形 参:无
|
||||
// * 返 回 值: 无
|
||||
// ***********************************************************************
|
||||
// */
|
||||
// void IR_GetDistanceTask(void)
|
||||
// {
|
||||
// static uint8_t ULT_getDataStatus = 0x00;
|
||||
//
|
||||
// static uint8_t distance_1 = 255;
|
||||
// static uint8_t distance_2 = 255;
|
||||
//
|
||||
// static timer waitingTimer;
|
||||
// static timer responsTimer;
|
||||
// static uint8_t timer_ok = 0;
|
||||
//
|
||||
// if(timer_ok == 0)
|
||||
// {
|
||||
// timer_ok = 1;
|
||||
// timer_set(&waitingTimer, CLOCK_SECOND*2);
|
||||
// timer_set(&responsTimer, 3);
|
||||
// }
|
||||
//
|
||||
// switch(ULT_getDataStatus)
|
||||
// {
|
||||
// case 0x00:
|
||||
// if(timer_expired(&waitingTimer))
|
||||
// {
|
||||
// ULT_getDataStatus = 0x01;
|
||||
// }
|
||||
// break;
|
||||
//
|
||||
// case 0x01:
|
||||
// distance_1 = IR_GetDistanceData(1);
|
||||
// // if(dataOutState1 == 1) //第一路测距数据采集成功
|
||||
// // {
|
||||
// // dataOutState1 = 0;
|
||||
// ULT_getDataStatus = 0x02;
|
||||
// // // printf("\r\n第1路采集OK\r\n");
|
||||
// // }
|
||||
// break;
|
||||
//
|
||||
// case 0x02:
|
||||
// distance_2 = IR_GetDistanceData(2);
|
||||
// // if(dataOutState2 == 1) //第一路测距数据采集成功
|
||||
// // {
|
||||
// // dataOutState2 = 0;
|
||||
// ULT_getDataStatus = 0x03;
|
||||
// // // printf("\r\n第2路采集OK\r\n");
|
||||
// // }
|
||||
// break;
|
||||
//
|
||||
// case 0x03:
|
||||
// getDistance1 = distance_1;
|
||||
// getDistance2 = distance_2;
|
||||
//
|
||||
// // printf("\r\n测距:No1 = %3.1f cm, ", (float)distance_1);
|
||||
// // printf("No2 = %3.1f cm\r\n", (float)distance_2);
|
||||
// // printf("No3 = %3.1f cm, ", (float)distance3);
|
||||
// // printf("No4 = %3.1f cm\r\n", (float)distance4);
|
||||
// ULT_getDataStatus = 0x00;
|
||||
// timer_restart(&waitingTimer);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 CXHY *****END OF FILE*******************/
|
||||
@@ -0,0 +1,25 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :IR_Distancer.h
|
||||
* 描 述 :红外测距驱动代码
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/08/04
|
||||
*********************************************************************************/
|
||||
#ifndef __IR_Distancer_H
|
||||
#define __IR_Distancer_H
|
||||
#include "stm32f10x.h"
|
||||
|
||||
extern uint8_t ir_Distance1;
|
||||
extern uint8_t ir_dataOutState1;
|
||||
extern uint8_t ir_Distance2;
|
||||
extern uint8_t ir_dataOutState2;
|
||||
|
||||
void IR_GetAdc(void);
|
||||
|
||||
uint8_t IR_GetDistanceData(uint8_t num);
|
||||
void IR_GetDistanceTask_01(void);
|
||||
void IR_GetDistanceTask_02(void);
|
||||
|
||||
#endif
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 CXHY *****END OF FILE*******************/
|
||||
Executable
+648
@@ -0,0 +1,648 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :key.c
|
||||
* 描 述 :开关驱动程序
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2020/03/30
|
||||
*********************************************************************************/
|
||||
#include "key.h"
|
||||
#include "timer.h"
|
||||
|
||||
//按键检测接口
|
||||
#define KEY1_PORT_PeriphClock RCC_APB2Periph_GPIOA
|
||||
#define KEY1_PORT GPIOA
|
||||
#define KEY1_PIN GPIO_Pin_5
|
||||
|
||||
#define KEY2_PORT_PeriphClock RCC_APB2Periph_GPIOA
|
||||
#define KEY2_PORT GPIOA
|
||||
#define KEY2_PIN GPIO_Pin_7
|
||||
|
||||
#define KEY3_PORT_PeriphClock RCC_APB2Periph_GPIOC
|
||||
#define KEY3_PORT GPIOC
|
||||
#define KEY3_PIN GPIO_Pin_5
|
||||
|
||||
#define KEY4_PORT_PeriphClock RCC_APB2Periph_GPIOB
|
||||
#define KEY4_PORT GPIOB
|
||||
#define KEY4_PIN GPIO_Pin_1
|
||||
|
||||
//LED指示灯接口
|
||||
#define KEY1_LED_PeriphClock RCC_APB2Periph_GPIOA
|
||||
#define KEY1_LED_PORT GPIOA
|
||||
#define KEY1_LED_PIN GPIO_Pin_4
|
||||
|
||||
#define KEY2_LED_PeriphClock RCC_APB2Periph_GPIOA
|
||||
#define KEY2_LED_PORT GPIOA
|
||||
#define KEY2_LED_PIN GPIO_Pin_6
|
||||
|
||||
#define KEY3_LED_PeriphClock RCC_APB2Periph_GPIOC
|
||||
#define KEY3_LED_PORT GPIOC
|
||||
#define KEY3_LED_PIN GPIO_Pin_4
|
||||
|
||||
#define KEY4_LED_PeriphClock RCC_APB2Periph_GPIOB
|
||||
#define KEY4_LED_PORT GPIOB
|
||||
#define KEY4_LED_PIN GPIO_Pin_0
|
||||
|
||||
//限位开关
|
||||
#define LIMI_KEY1_PeriphClock RCC_APB2Periph_GPIOB
|
||||
#define LIMI_KEY1_PORT GPIOB
|
||||
#define LIMI_KEY1_PIN GPIO_Pin_8
|
||||
|
||||
#define LIMI_KEY2_PeriphClock RCC_APB2Periph_GPIOB
|
||||
#define LIMI_KEY2_PORT GPIOB
|
||||
#define LIMI_KEY2_PIN GPIO_Pin_9
|
||||
|
||||
#define LIMI_KEY3_PeriphClock RCC_APB2Periph_GPIOC
|
||||
#define LIMI_KEY3_PORT GPIOC
|
||||
#define LIMI_KEY3_PIN GPIO_Pin_0
|
||||
|
||||
#define LIMI_KEY4_PeriphClock RCC_APB2Periph_GPIOC
|
||||
#define LIMI_KEY4_PORT GPIOC
|
||||
#define LIMI_KEY4_PIN GPIO_Pin_1
|
||||
|
||||
uint8_t keyBit = 0; //按键采集按位组合后的值
|
||||
uint8_t keyReleaseMark = 0; //按键松开标志
|
||||
uint8_t keyValue; //按钮键值
|
||||
|
||||
uint8_t keyNum = 0; //向外输出的按键编号
|
||||
uint8_t keyStatus = 0; //对应输出的按键状态
|
||||
|
||||
uint8_t optoKeyStatus = 0; //光电开关状态(由MCU2传入)
|
||||
|
||||
uint8_t humanSensingKeyStatus = 0; //人体感应开关状态
|
||||
|
||||
uint8_t keyType = 1; //0:机械按键;1:触摸按键
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: KeyInit
|
||||
* 功能说明: 开关IO口初始化
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void KeyInit(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
|
||||
RCC_APB2PeriphClockCmd(KEY1_PORT_PeriphClock, ENABLE); //使能IO口时钟
|
||||
RCC_APB2PeriphClockCmd(KEY2_PORT_PeriphClock, ENABLE);
|
||||
RCC_APB2PeriphClockCmd(KEY3_PORT_PeriphClock, ENABLE);
|
||||
RCC_APB2PeriphClockCmd(KEY4_PORT_PeriphClock, ENABLE);
|
||||
|
||||
RCC_APB2PeriphClockCmd(KEY1_LED_PeriphClock, ENABLE); //使能IO口时钟
|
||||
RCC_APB2PeriphClockCmd(KEY2_LED_PeriphClock, ENABLE);
|
||||
RCC_APB2PeriphClockCmd(KEY3_LED_PeriphClock, ENABLE);
|
||||
RCC_APB2PeriphClockCmd(KEY4_LED_PeriphClock, ENABLE);
|
||||
|
||||
RCC_APB2PeriphClockCmd(LIMI_KEY1_PeriphClock, ENABLE); //使能IO口时钟
|
||||
RCC_APB2PeriphClockCmd(LIMI_KEY2_PeriphClock, ENABLE);
|
||||
RCC_APB2PeriphClockCmd(LIMI_KEY3_PeriphClock, ENABLE);
|
||||
RCC_APB2PeriphClockCmd(LIMI_KEY4_PeriphClock, ENABLE);
|
||||
|
||||
// GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable , ENABLE); //关闭JTAG的PB3,PB4复用功能
|
||||
|
||||
//按键接口初始化----------------
|
||||
//第一路按键IO口配置
|
||||
GPIO_InitStructure.GPIO_Pin = KEY1_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
|
||||
GPIO_Init(KEY1_PORT, &GPIO_InitStructure);
|
||||
|
||||
//第二路按键IO口配置
|
||||
GPIO_InitStructure.GPIO_Pin = KEY2_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
|
||||
GPIO_Init(KEY2_PORT, &GPIO_InitStructure);
|
||||
|
||||
//第三路按键IO口配置
|
||||
GPIO_InitStructure.GPIO_Pin = KEY3_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
|
||||
GPIO_Init(KEY3_PORT, &GPIO_InitStructure);
|
||||
|
||||
//第四路按键IO口配置
|
||||
GPIO_InitStructure.GPIO_Pin = KEY4_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
|
||||
GPIO_Init(KEY4_PORT, &GPIO_InitStructure);
|
||||
|
||||
//LED灯接口初始化----------------
|
||||
//第一路按键灯IO口配置
|
||||
GPIO_InitStructure.GPIO_Pin = KEY1_LED_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(KEY1_LED_PORT, &GPIO_InitStructure);
|
||||
GPIO_SetBits(KEY1_LED_PORT, KEY1_LED_PIN);
|
||||
|
||||
//第二路按键灯IO口配置
|
||||
GPIO_InitStructure.GPIO_Pin = KEY2_LED_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(KEY2_LED_PORT, &GPIO_InitStructure);
|
||||
GPIO_SetBits(KEY2_LED_PORT, KEY2_LED_PIN);
|
||||
|
||||
//第三路按键灯IO口配置
|
||||
GPIO_InitStructure.GPIO_Pin = KEY3_LED_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(KEY3_LED_PORT, &GPIO_InitStructure);
|
||||
GPIO_SetBits(KEY3_LED_PORT, KEY3_LED_PIN);
|
||||
|
||||
//第四路按键灯IO口配置
|
||||
GPIO_InitStructure.GPIO_Pin = KEY4_LED_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(KEY4_LED_PORT, &GPIO_InitStructure);
|
||||
GPIO_SetBits(KEY4_LED_PORT, KEY4_LED_PIN);
|
||||
|
||||
//限位开关接口初始化----------------
|
||||
//第一路限位开关IO口配置
|
||||
GPIO_InitStructure.GPIO_Pin = LIMI_KEY1_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
|
||||
GPIO_Init(LIMI_KEY1_PORT, &GPIO_InitStructure);
|
||||
|
||||
//第二路限位开关IO口配置
|
||||
GPIO_InitStructure.GPIO_Pin = LIMI_KEY2_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
|
||||
GPIO_Init(LIMI_KEY2_PORT, &GPIO_InitStructure);
|
||||
|
||||
//第三路限位开关IO口配置
|
||||
GPIO_InitStructure.GPIO_Pin = LIMI_KEY3_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
|
||||
GPIO_Init(LIMI_KEY3_PORT, &GPIO_InitStructure);
|
||||
|
||||
//第四路限位开关IO口配置
|
||||
GPIO_InitStructure.GPIO_Pin = LIMI_KEY4_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
|
||||
GPIO_Init(LIMI_KEY4_PORT, &GPIO_InitStructure);
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: KeysCanning
|
||||
* 功能说明: 按键扫描
|
||||
* 形 参:无
|
||||
* 返 回 值: 返回对应开关的键值
|
||||
***********************************************************************
|
||||
*/
|
||||
uint8_t KeyScanning(void)
|
||||
{
|
||||
static uint8_t key_state = 0, key_value;
|
||||
uint8_t key_press, key_return = 0;
|
||||
|
||||
static timer keyLongPressTimer;
|
||||
static uint8_t timer_ok = 0;
|
||||
if(timer_ok == 0)
|
||||
{
|
||||
timer_ok = 1;
|
||||
timer_set(&keyLongPressTimer, CLOCK_SECOND*2); //设定长按时间为2S
|
||||
}
|
||||
|
||||
switch (key_state)
|
||||
{
|
||||
case 0x00: // 按键初始态
|
||||
if(KEY1 == 0)
|
||||
{
|
||||
key_value = 1;
|
||||
key_state = 0x01; // 键被按下,状态转换到键确认态
|
||||
}else if(KEY2 == 0){
|
||||
key_value = 2;
|
||||
key_state = 0x01; // 键被按下,状态转换到键确认态
|
||||
}
|
||||
else if(KEY3 == 0){
|
||||
key_value = 3;
|
||||
key_state = 0x01; // 键被按下,状态转换到键确认态
|
||||
}
|
||||
else if(KEY4 == 0){
|
||||
key_value = 4;
|
||||
key_state = 0x01; // 键被按下,状态转换到键确认态
|
||||
}else{
|
||||
key_value = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x01: // 按键确认态
|
||||
if(KEY1 == 0)
|
||||
{
|
||||
key_press = 1;
|
||||
}else if(KEY2 == 0){
|
||||
key_press = 2;
|
||||
}
|
||||
else if(KEY3 == 0){
|
||||
key_press = 3;
|
||||
}
|
||||
else if(KEY4 == 0){
|
||||
key_press = 4;
|
||||
}else{
|
||||
key_press = 0;
|
||||
}
|
||||
|
||||
if(key_value == key_press)
|
||||
{
|
||||
key_return = key_value;
|
||||
key_state = 0x02; // 键被按下,状态转换到键确认态
|
||||
// printf("\r\n短按KEY = %d\r\n", key_return);
|
||||
timer_restart(&keyLongPressTimer);
|
||||
break;
|
||||
}else{
|
||||
key_state = 0x00;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x02: // 长按检测
|
||||
if(timer_expired(&keyLongPressTimer))
|
||||
{
|
||||
if(key_value == 1) //按键1长按下输出11
|
||||
{
|
||||
key_return = 0x11;
|
||||
}else if(key_value == 2){
|
||||
key_return = 0x22;
|
||||
}else if(key_value == 3){
|
||||
key_return = 0x33;
|
||||
}else if(key_value == 4){
|
||||
key_return = 0x44;
|
||||
}
|
||||
key_state = 0x03;
|
||||
|
||||
// printf("\r\n长按KEY = %d\r\n", key_return);
|
||||
break;
|
||||
}
|
||||
|
||||
if((KEY1 == 1) && (KEY2 == 1) && (KEY3 == 1) && (KEY4 == 1))
|
||||
{
|
||||
keyReleaseMark = 1;
|
||||
key_state = 0x00; // 按键已释放,转换到按键初始态
|
||||
// printf("\r\n短按松开\r\n");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x03: // 按键释放
|
||||
if((KEY1 == 1) && (KEY2 == 1) && (KEY3 == 1) && (KEY4 == 1))
|
||||
{
|
||||
keyReleaseMark = 1;
|
||||
key_state = 0x00; // 按键已释放,转换到按键初始态
|
||||
// printf("\r\n长按松开\r\n");
|
||||
}
|
||||
break;
|
||||
}
|
||||
return key_return;
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: TouchKeyScanning
|
||||
* 功能说明: 触摸按键扫描
|
||||
* 形 参:无
|
||||
* 返 回 值: 返回对应开关的键值
|
||||
***********************************************************************
|
||||
*/
|
||||
uint8_t TouchKeyScanning(void)
|
||||
{
|
||||
static uint8_t key_state = 0, key_value;
|
||||
uint8_t key_press = 0, key_return = 0;
|
||||
|
||||
static timer keyLongPressTimer;
|
||||
static uint8_t timer_ok = 0;
|
||||
if(timer_ok == 0)
|
||||
{
|
||||
timer_ok = 1;
|
||||
timer_set(&keyLongPressTimer, CLOCK_SECOND*2); //设定长按时间为2S
|
||||
}
|
||||
|
||||
keyBit = (KEY3 << 2) | (KEY2 << 1) | KEY1;
|
||||
// printf("\r\nswkey = %x\r\n", keyBit);
|
||||
switch (key_state)
|
||||
{
|
||||
case 0x00: // 按键初始态
|
||||
if(keyBit > 0)
|
||||
{
|
||||
switch(keyBit)
|
||||
{
|
||||
case 0x01: key_value = 1; break;
|
||||
case 0x02: key_value = 2; break;
|
||||
case 0x03: key_value = 3; break;
|
||||
case 0x04: key_value = 4; break;
|
||||
case 0x05: key_value = 5; break;
|
||||
default: key_value = 0; break;
|
||||
}
|
||||
key_state = 0x01; // 键被按下,状态转换到键确认态
|
||||
}else{
|
||||
key_value = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x01: // 按键确认态
|
||||
if(keyBit > 0)
|
||||
{
|
||||
switch(keyBit)
|
||||
{
|
||||
case 0x01: key_press = 1; break;
|
||||
case 0x02: key_press = 2; break;
|
||||
case 0x03: key_press = 3; break;
|
||||
case 0x04: key_press = 4; break;
|
||||
case 0x05: key_press = 5; break;
|
||||
default: key_press = 0; break;
|
||||
}
|
||||
}else{
|
||||
key_value = 0;
|
||||
}
|
||||
|
||||
if(key_value == key_press)
|
||||
{
|
||||
key_return = key_value;
|
||||
key_state = 0x02; // 键被按下,状态转换到键确认态
|
||||
// printf("\r\n短按KEY = %d\r\n", key_return);
|
||||
timer_restart(&keyLongPressTimer);
|
||||
break;
|
||||
}else{
|
||||
key_state = 0x00;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x02: // 长按检测
|
||||
if(timer_expired(&keyLongPressTimer))
|
||||
{
|
||||
if(key_value == 1) //按键1长按下输出11
|
||||
{
|
||||
key_return = 0x11;
|
||||
}else if(key_value == 2){
|
||||
key_return = 0x22;
|
||||
}else if(key_value == 3){
|
||||
key_return = 0x33;
|
||||
}else if(key_value == 4){
|
||||
key_return = 0x44;
|
||||
}else if(key_value == 5){
|
||||
key_return = 0x55;
|
||||
}
|
||||
key_state = 0x03;
|
||||
|
||||
// printf("\r\n长按KEY = %d\r\n", key_return);
|
||||
break;
|
||||
}
|
||||
|
||||
if(keyBit == 0x00)
|
||||
{
|
||||
key_state = 0x00; // 按键已释放,转换到按键初始态
|
||||
keyReleaseMark = 1;
|
||||
// printf("\r\n短按松开\r\n");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x03: // 按键释放
|
||||
if(keyBit == 0x00)
|
||||
{
|
||||
key_state = 0x00; // 按键已释放,转换到按键初始态
|
||||
keyReleaseMark = 1;
|
||||
// printf("\r\n长按松开\r\n");
|
||||
}
|
||||
break;
|
||||
}
|
||||
return key_return;
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: SetKeyLedON
|
||||
* 功能说明: 点亮按键对应的LED灯
|
||||
* 形 参: whichOne -> 指定的LED灯
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void SetKeyLedON(uint8_t whichOne)
|
||||
{
|
||||
switch(whichOne)
|
||||
{
|
||||
case 1:
|
||||
GPIO_ResetBits(KEY1_LED_PORT, KEY1_LED_PIN);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
GPIO_ResetBits(KEY2_LED_PORT, KEY2_LED_PIN);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
GPIO_ResetBits(KEY3_LED_PORT, KEY3_LED_PIN);
|
||||
break;
|
||||
|
||||
case 4:
|
||||
GPIO_ResetBits(KEY4_LED_PORT, KEY4_LED_PIN);
|
||||
break;
|
||||
|
||||
// case 1:
|
||||
// GPIO_SetBits(KEY1_LED_PORT, KEY1_LED_PIN);
|
||||
// break;
|
||||
//
|
||||
// case 2:
|
||||
// GPIO_SetBits(KEY2_LED_PORT, KEY2_LED_PIN);
|
||||
// break;
|
||||
//
|
||||
// case 3:
|
||||
// GPIO_SetBits(KEY3_LED_PORT, KEY3_LED_PIN);
|
||||
// break;
|
||||
//
|
||||
// case 4:
|
||||
// GPIO_SetBits(KEY4_LED_PORT, KEY4_LED_PIN);
|
||||
// break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: SetKeyLedAllON
|
||||
* 功能说明: 点亮全部按键的LED灯
|
||||
* 形 参: 无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void SetKeyLedAllON(void)
|
||||
{
|
||||
GPIO_ResetBits(KEY1_LED_PORT, KEY1_LED_PIN);
|
||||
GPIO_ResetBits(KEY2_LED_PORT, KEY2_LED_PIN);
|
||||
GPIO_ResetBits(KEY3_LED_PORT, KEY3_LED_PIN);
|
||||
GPIO_ResetBits(KEY4_LED_PORT, KEY4_LED_PIN);
|
||||
|
||||
// GPIO_SetBits(KEY1_LED_PORT, KEY1_LED_PIN);
|
||||
// GPIO_SetBits(KEY2_LED_PORT, KEY2_LED_PIN);
|
||||
// GPIO_SetBits(KEY3_LED_PORT, KEY3_LED_PIN);
|
||||
// GPIO_SetBits(KEY4_LED_PORT, KEY4_LED_PIN);
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: SetKeyLedOFF
|
||||
* 功能说明: 熄灯按键对应的LED灯
|
||||
* 形 参: whichOne -> 指定的LED灯
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void SetKeyLedOFF(uint8_t whichOne)
|
||||
{
|
||||
switch(whichOne)
|
||||
{
|
||||
case 1:
|
||||
GPIO_SetBits(KEY1_LED_PORT, KEY1_LED_PIN);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
GPIO_SetBits(KEY2_LED_PORT, KEY2_LED_PIN);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
GPIO_SetBits(KEY3_LED_PORT, KEY3_LED_PIN);
|
||||
break;
|
||||
|
||||
case 4:
|
||||
GPIO_SetBits(KEY4_LED_PORT, KEY4_LED_PIN);
|
||||
break;
|
||||
|
||||
// case 1:
|
||||
// GPIO_ResetBits(KEY1_LED_PORT, KEY1_LED_PIN);
|
||||
// break;
|
||||
//
|
||||
// case 2:
|
||||
// GPIO_ResetBits(KEY2_LED_PORT, KEY2_LED_PIN);
|
||||
// break;
|
||||
//
|
||||
// case 3:
|
||||
// GPIO_ResetBits(KEY3_LED_PORT, KEY3_LED_PIN);
|
||||
// break;
|
||||
//
|
||||
// case 4:
|
||||
// GPIO_ResetBits(KEY4_LED_PORT, KEY4_LED_PIN);
|
||||
// break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: SetKeyLedAllOFF
|
||||
* 功能说明: 熄灯全部按键的LED灯
|
||||
* 形 参: 无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void SetKeyLedAllOFF(void)
|
||||
{
|
||||
GPIO_SetBits(KEY1_LED_PORT, KEY1_LED_PIN);
|
||||
GPIO_SetBits(KEY2_LED_PORT, KEY2_LED_PIN);
|
||||
GPIO_SetBits(KEY3_LED_PORT, KEY3_LED_PIN);
|
||||
GPIO_SetBits(KEY4_LED_PORT, KEY4_LED_PIN);
|
||||
|
||||
// GPIO_ResetBits(KEY1_LED_PORT, KEY1_LED_PIN);
|
||||
// GPIO_ResetBits(KEY2_LED_PORT, KEY2_LED_PIN);
|
||||
// GPIO_ResetBits(KEY3_LED_PORT, KEY3_LED_PIN);
|
||||
// GPIO_ResetBits(KEY4_LED_PORT, KEY4_LED_PIN);
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: KeysTest
|
||||
* 功能说明: 按键及其指示灯测试
|
||||
* 形 参: 无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void KeysTest(void)
|
||||
{
|
||||
static uint8_t keyStatus1 = 0;
|
||||
|
||||
if(keyValue > 0)
|
||||
{
|
||||
SetKeyLedAllOFF();
|
||||
SetKeyLedON(keyValue);
|
||||
|
||||
keyValue = 0;
|
||||
}
|
||||
|
||||
// if((keyStatus1 != keyValue))
|
||||
// {
|
||||
// keyStatus1 = keyValue;
|
||||
//
|
||||
// SetKeyLedAllOFF();
|
||||
// SetKeyLedON(keyValue);
|
||||
// }
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: LimitKeysTest
|
||||
* 功能说明: 限位开关测试
|
||||
* 形 参: 无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void LimitKeysTest(void)
|
||||
{
|
||||
uint8_t limitKeySta1 = 0;
|
||||
uint8_t limitKeySta2 = 0;
|
||||
uint8_t limitKeySta3 = 0;
|
||||
uint8_t limitKeySta4 = 0;
|
||||
|
||||
static uint8_t limitKeyStaPre1 = 0;
|
||||
static uint8_t limitKeyStaPre2 = 0;
|
||||
static uint8_t limitKeyStaPre3 = 0;
|
||||
static uint8_t limitKeyStaPre4 = 0;
|
||||
|
||||
if(LIMI_KEY1 == 0)
|
||||
{
|
||||
limitKeySta1 = 1;
|
||||
}else{
|
||||
limitKeySta1 = 0;
|
||||
}
|
||||
|
||||
if(LIMI_KEY2 == 0)
|
||||
{
|
||||
limitKeySta2 = 1;
|
||||
}else{
|
||||
limitKeySta2 = 0;
|
||||
}
|
||||
|
||||
if(LIMI_KEY3 == 0)
|
||||
{
|
||||
limitKeySta3 = 1;
|
||||
}else{
|
||||
limitKeySta3 = 0;
|
||||
}
|
||||
|
||||
if(LIMI_KEY4 == 0)
|
||||
{
|
||||
limitKeySta4 = 1;
|
||||
}else{
|
||||
limitKeySta4 = 0;
|
||||
}
|
||||
|
||||
|
||||
if((limitKeySta1 != limitKeyStaPre1) ||
|
||||
(limitKeySta2 != limitKeyStaPre2) ||
|
||||
(limitKeySta3 != limitKeyStaPre3) ||
|
||||
(limitKeySta4 != limitKeyStaPre4))
|
||||
{
|
||||
limitKeyStaPre1 = limitKeySta1;
|
||||
limitKeyStaPre2 = limitKeySta2;
|
||||
limitKeyStaPre3 = limitKeySta3;
|
||||
limitKeyStaPre4 = limitKeySta4;
|
||||
|
||||
if(limitKeySta1)
|
||||
{
|
||||
printf("\r\n限位开关1限位\r\n");
|
||||
}
|
||||
if(limitKeySta2)
|
||||
{
|
||||
printf("\r\n限位开关2限位\r\n");
|
||||
}
|
||||
if(limitKeySta3)
|
||||
{
|
||||
printf("\r\n限位开关3限位\r\n");
|
||||
}
|
||||
if(limitKeySta4)
|
||||
{
|
||||
printf("\r\n限位开关4限位\r\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/******************** (C) COPYRIGHT 2018 Ping *****END OF FILE*******************/
|
||||
Executable
+62
@@ -0,0 +1,62 @@
|
||||
/*************************** (C) COPYRIGHT 2018 Ping ****************************
|
||||
* 文件名 :key.h
|
||||
* 描 述 :按键开关驱动程序头文件
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/03/06
|
||||
*********************************************************************************/
|
||||
#ifndef __KEY_H
|
||||
#define __KEY_H
|
||||
#include "stm32f10x.h"
|
||||
#include "stdio.h"
|
||||
#include "device.h"
|
||||
|
||||
#define KEY1 GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_5) //按键1输入
|
||||
#define KEY2 GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_7) //按键2输入
|
||||
#define KEY3 GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_5) //按键3输入
|
||||
#define KEY4 GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_1) //按键4输入
|
||||
|
||||
//注:第2、3、4路的限位根据硬件接口接线顺序来做相应的转换对应
|
||||
//主板原来的顺序
|
||||
#ifdef FOUR_CHANNEL_AND_HARMFUL
|
||||
#define LIMI_KEY1 GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_8) //限位开关1
|
||||
#define LIMI_KEY2 GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_9) //限位开关2
|
||||
#define LIMI_KEY3 GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_0) //限位开关3
|
||||
#define LIMI_KEY4 GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_1) //限位开关4
|
||||
|
||||
#else
|
||||
#define LIMI_KEY1 GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_8) //限位开关1
|
||||
#define LIMI_KEY4 GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_9) //限位开关4
|
||||
#define LIMI_KEY2 GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_0) //限位开关2
|
||||
#define LIMI_KEY3 GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_1) //限位开关3
|
||||
#endif
|
||||
|
||||
extern uint8_t keyBit; //按键采集按位组合后的值
|
||||
extern uint8_t keyReleaseMark; //按键松开标志
|
||||
extern uint8_t keyValue; //按钮键值
|
||||
|
||||
extern uint8_t keyNum; //向外输出的按键编号
|
||||
extern uint8_t keyStatus; //对应输出的按键状态
|
||||
|
||||
extern uint8_t limitKey1Value; //限位开关键值
|
||||
extern uint8_t limitKey2Value; //限位开关键值
|
||||
|
||||
extern uint8_t optoKeyStatus; //光电开关状态(由MCU2传入)
|
||||
extern uint8_t humanSensingKeyStatus; //人体感应开关状态
|
||||
|
||||
extern uint8_t keyType; //0:机械按键;1:触摸按键
|
||||
|
||||
void KeyInit(void); //按键初始化
|
||||
uint8_t KeyScanning(void); //机械按键扫描检测
|
||||
uint8_t TouchKeyScanning(void); //触摸按键扫描检测
|
||||
void SetKeyLedON(uint8_t whichOne); //点亮对应按键的指示灯
|
||||
void SetKeyLedAllON(void); //点亮全部按键的指示灯
|
||||
void SetKeyLedOFF(uint8_t whichOne); //熄灭对应按键的指示灯
|
||||
void SetKeyLedAllOFF(void); //熄灭全部按键的指示灯
|
||||
|
||||
void KeysTest(void);
|
||||
void LimitKeysTest(void);
|
||||
|
||||
#endif
|
||||
|
||||
/******************** (C) COPYRIGHT 2018 Ping *****END OF FILE*******************/
|
||||
+117
@@ -0,0 +1,117 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :key.c
|
||||
* 描 述 :拨码开关驱动程序
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/03/06
|
||||
*********************************************************************************/
|
||||
#include "sw_key.h"
|
||||
#include "delay.h"
|
||||
#include "usart.h"
|
||||
|
||||
//拨码开关
|
||||
#define SW_KEY1_PORT GPIOB
|
||||
#define SW_KEY1_PIN GPIO_Pin_4
|
||||
#define SW_KEY2_PORT GPIOB
|
||||
#define SW_KEY2_PIN GPIO_Pin_3
|
||||
#define SW_KEY3_PORT GPIOD
|
||||
#define SW_KEY3_PIN GPIO_Pin_7
|
||||
#define SW_KEY4_PORT GPIOD
|
||||
#define SW_KEY4_PIN GPIO_Pin_6
|
||||
#define SW_KEY5_PORT GPIOD
|
||||
#define SW_KEY5_PIN GPIO_Pin_5
|
||||
#define SW_KEY6_PORT GPIOD
|
||||
#define SW_KEY6_PIN GPIO_Pin_4
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: SwKeyInit
|
||||
* 功能说明: 拔码开关IO口初始化
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void SwKeyInit(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOD | RCC_APB2Periph_AFIO, ENABLE);
|
||||
|
||||
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable , ENABLE);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = SW_KEY1_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
|
||||
GPIO_Init(SW_KEY1_PORT, &GPIO_InitStructure);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = SW_KEY2_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
|
||||
GPIO_Init(SW_KEY2_PORT, &GPIO_InitStructure);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = SW_KEY3_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
|
||||
GPIO_Init(SW_KEY3_PORT, &GPIO_InitStructure);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = SW_KEY4_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
|
||||
GPIO_Init(SW_KEY4_PORT, &GPIO_InitStructure);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = SW_KEY5_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
|
||||
GPIO_Init(SW_KEY5_PORT, &GPIO_InitStructure);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = SW_KEY6_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
|
||||
GPIO_Init(SW_KEY6_PORT, &GPIO_InitStructure);
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: SwKeysCanning
|
||||
* 功能说明: 拨码开关扫描
|
||||
* 形 参:无
|
||||
* 返 回 值: 返回对应开关的键值
|
||||
***********************************************************************
|
||||
*/
|
||||
uint8_t SwKeysCanning(void)
|
||||
{
|
||||
uint8_t res = 0;
|
||||
|
||||
uint8_t res1 = 0;
|
||||
uint8_t res2 = 0;
|
||||
uint8_t res3 = 0;
|
||||
uint8_t res4 = 0;
|
||||
uint8_t res5 = 0;
|
||||
uint8_t res6 = 0;
|
||||
|
||||
delay_ms(10);
|
||||
if(SW_KEY1 == 0)
|
||||
{
|
||||
res1 = 1;
|
||||
}
|
||||
if(SW_KEY2 == 0)
|
||||
{
|
||||
res2 = 1;
|
||||
}
|
||||
if(SW_KEY3 == 0)
|
||||
{
|
||||
res3 = 1;
|
||||
}
|
||||
if(SW_KEY4 == 0)
|
||||
{
|
||||
res4 = 1;
|
||||
}
|
||||
if(SW_KEY5 == 0)
|
||||
{
|
||||
res5 = 1;
|
||||
}
|
||||
if(SW_KEY6 == 0)
|
||||
{
|
||||
res6 = 1;
|
||||
}
|
||||
|
||||
res = (res6 << 5) | (res5 << 4) | (res4 << 3) | (res3 << 2) | (res2 << 1) | res1;
|
||||
printf("\r\nswkey = %x\r\n", res);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/******************** (C) COPYRIGHT 2018 Ping *****END OF FILE*******************/
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
/*************************** (C) COPYRIGHT 2018 Ping ****************************
|
||||
* 文件名 :key.h
|
||||
* 描 述 :按键开关驱动程序头文件
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/03/06
|
||||
*********************************************************************************/
|
||||
#ifndef __SW_KEY_H
|
||||
#define __SW_KEY_H
|
||||
|
||||
#include "stm32f10x.h"
|
||||
|
||||
#define SW_KEY1 GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_4)
|
||||
#define SW_KEY2 GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_3)
|
||||
#define SW_KEY3 GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_7)
|
||||
#define SW_KEY4 GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_6)
|
||||
#define SW_KEY5 GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_5)
|
||||
#define SW_KEY6 GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_4)
|
||||
|
||||
|
||||
void SwKeyInit(void); //按键初始化
|
||||
uint8_t SwKeysCanning(void);
|
||||
|
||||
#endif
|
||||
|
||||
/******************** (C) COPYRIGHT 2018 Ping *****END OF FILE*******************/
|
||||
Executable
+216
@@ -0,0 +1,216 @@
|
||||
#ifndef __BMP_H__
|
||||
#define __BMP_H__
|
||||
|
||||
|
||||
|
||||
u8 BMP1[]={
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x18,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0x78,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF3,0xF8,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xC0,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xF8,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xF8,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x18,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0x78,
|
||||
0x00,0x00,0x00,0x0F,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x18,
|
||||
0x00,0x00,0x01,0xFF,0xFF,0xFF,0xFF,0xFF,0xF8,0x00,0x00,0x00,0x00,0x00,0xCF,0x98,
|
||||
0x00,0x00,0x1F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0xC6,0x18,
|
||||
0x00,0x00,0x7F,0xFF,0xFF,0xFF,0xFF,0x01,0xFF,0xF0,0x00,0x00,0x00,0x00,0xFF,0xF8,
|
||||
0x00,0x01,0xFF,0xFF,0xFF,0xFF,0xFE,0x00,0x1F,0xFE,0x00,0x00,0x00,0x00,0xFF,0xF8,
|
||||
0x00,0x07,0xFF,0xFF,0xFF,0xFF,0xFE,0x00,0x03,0xFF,0xC0,0x00,0x00,0x00,0x80,0x08,
|
||||
0x00,0x1F,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0xFF,0xF8,0x00,0x00,0x00,0x78,0x00,
|
||||
0x00,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0x80,0x00,0x3F,0xFF,0x00,0x00,0x00,0xE0,0x00,
|
||||
0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xC0,0x00,0x0F,0xFF,0xC0,0x00,0x00,0xC0,0x18,
|
||||
0x03,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xE0,0x00,0x07,0xFF,0xF8,0x00,0x00,0xFF,0xF8,
|
||||
0x07,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF8,0x00,0x01,0xFF,0xFE,0x00,0x00,0xFF,0xF8,
|
||||
0x0F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0x00,0x00,0xFF,0xFF,0x80,0x00,0xC0,0x18,
|
||||
0x1F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xC0,0x00,0x7F,0xFF,0xE0,0x00,0xF8,0x00,
|
||||
0x3F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF0,0x00,0x3F,0xFF,0xF8,0x00,0x00,0x00,
|
||||
0x3F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x1F,0xFF,0xFC,0x00,0xFF,0xF8,
|
||||
0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF0,0x1F,0xFF,0xFF,0x00,0xFF,0xF8,
|
||||
0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x80,0x87,0xE0,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xC0,0x7E,0x00,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xE0,0xF8,0x18,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xE0,0xFF,0xF8,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xC0,0x80,0x08,
|
||||
0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x80,0x10,0xE0,
|
||||
0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF0,0x1F,0xFF,0xFF,0x00,0xF0,0x38,
|
||||
0x3F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x1F,0xFF,0xFE,0x00,0xCF,0x98,
|
||||
0x3F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF0,0x00,0x3F,0xFF,0xF8,0x00,0xC6,0x18,
|
||||
0x1F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xC0,0x00,0x7F,0xFF,0xE0,0x00,0xC6,0x18,
|
||||
0x0F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0x00,0x00,0x7F,0xFF,0x80,0x00,0xFF,0xF8,
|
||||
0x07,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF8,0x00,0x01,0xFF,0xFE,0x00,0x00,0xC0,0x18,
|
||||
0x03,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xE0,0x00,0x03,0xFF,0xF0,0x00,0x00,0x00,0x00,
|
||||
0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xC0,0x00,0x0F,0xFF,0xC0,0x00,0x00,0xC0,0x18,
|
||||
0x00,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0x80,0x00,0x3F,0xFE,0x00,0x00,0x00,0xFF,0xF8,
|
||||
0x00,0x1F,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0xFF,0xF0,0x00,0x00,0x00,0xFF,0xF8,
|
||||
0x00,0x07,0xFF,0xFF,0xFF,0xFF,0xFE,0x00,0x03,0xFF,0xC0,0x00,0x00,0x00,0xC0,0x18,
|
||||
0x00,0x03,0xFF,0xFF,0xFF,0xFF,0xFE,0x00,0x3F,0xFC,0x00,0x00,0x00,0x00,0x00,0xF0,
|
||||
0x00,0x00,0x7F,0xFF,0xFF,0xFF,0xFF,0x03,0xFF,0xF0,0x00,0x00,0x00,0x00,0x00,0x38,
|
||||
0x00,0x00,0x1F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x18,
|
||||
0x00,0x00,0x01,0xFF,0xFF,0xFF,0xFF,0xFF,0xF0,0x00,0x00,0x00,0x00,0x00,0xC0,0x18,
|
||||
0x00,0x00,0x00,0x0F,0xFF,0xFF,0xFF,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xF8,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x18,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xF8,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xD8,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF1,0x80,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x88,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xF8,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
|
||||
|
||||
};
|
||||
|
||||
|
||||
u8 BMP2[]={
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF8,0x03,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xE0,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xC0,0x00,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x80,0x00,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x80,0x00,0x3F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x3F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x3F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF8,0x00,0x00,0x1F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x80,0x00,0x00,0x1F,0xFF,0xFF,0xFF,0xFF,0xFE,0x07,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,0x00,0x00,0x00,0x1F,0xFF,0xFF,0xFF,0xFF,0xC0,0x01,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xF0,0x00,0x00,0x00,0x1F,0xFF,0xFF,0xFC,0x1C,0x00,0x00,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x1F,0xFF,0xFF,0xE0,0x00,0x00,0x00,
|
||||
0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x1F,0xFF,0xFF,0xE0,0x00,0x00,0x00,
|
||||
0xFF,0xFF,0xFF,0xFE,0x00,0x00,0x00,0x00,0x00,0x1F,0xFF,0xFF,0xC0,0x00,0x00,0x00,
|
||||
0xFF,0xFF,0xFF,0xE0,0x00,0x00,0x00,0x00,0x00,0x1F,0xFF,0xF8,0x00,0x00,0x00,0x00,
|
||||
0xFF,0xFF,0xFF,0xC0,0x00,0x00,0x07,0x00,0x00,0x3F,0xFF,0x00,0x00,0x00,0x3F,0xC3,
|
||||
0xFF,0xFF,0xFF,0x00,0x00,0x00,0x1F,0x80,0x00,0x3F,0xF8,0x00,0x00,0x03,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0x00,0x00,0x00,0x3F,0x80,0x00,0x7F,0xE0,0x00,0x00,0x0F,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFE,0x00,0x00,0x00,0xFF,0xC0,0x00,0x7F,0x80,0x00,0x00,0x1F,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFC,0x00,0x00,0x1F,0xFF,0xC0,0x00,0xFE,0x00,0x00,0x03,0xFF,0xFF,0xFF,
|
||||
0xF0,0x7F,0xFC,0x00,0x00,0x1F,0xFF,0xE0,0x01,0xFE,0x00,0x00,0x07,0xF8,0x00,0x7F,
|
||||
0xC0,0x0F,0xFC,0x00,0x03,0xFF,0xFF,0xF8,0x03,0xF8,0x00,0x00,0x1F,0xE0,0x00,0x7F,
|
||||
0x80,0x03,0xF8,0x00,0x0F,0xFF,0xFF,0xFF,0x1E,0x00,0x00,0x00,0x1F,0xC0,0x00,0x7F,
|
||||
0x80,0x01,0xF0,0x00,0x0F,0xFF,0xFF,0xFF,0xF0,0x00,0x00,0x00,0x3F,0x80,0x00,0x7F,
|
||||
0x00,0x00,0xF0,0x00,0x07,0xFF,0xFF,0xC0,0x00,0x00,0x00,0x00,0x7F,0x80,0x07,0xFF,
|
||||
0x00,0x00,0x60,0x00,0x07,0xFF,0xFC,0x00,0x00,0x00,0x00,0x00,0x7F,0x03,0xC7,0xFF,
|
||||
0x00,0x00,0x00,0x00,0x01,0xFF,0xE0,0x00,0x00,0x00,0x00,0x00,0xFF,0x80,0x07,0xFF,
|
||||
0x00,0x00,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,0x01,0xFF,0x80,0x00,0x7F,
|
||||
0x00,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,0x00,0x01,0xFF,0xC0,0x00,0x7F,
|
||||
0x00,0x00,0x00,0x00,0x00,0x1E,0x00,0x00,0x00,0x00,0x00,0x01,0xFF,0xE0,0x00,0x7F,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xFF,0xF8,0x00,0x7F,
|
||||
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xFF,0xFF,0xFF,0xFF,
|
||||
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,0xFF,0xFF,0xFF,
|
||||
0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xFF,0x01,0x00,0x7F,
|
||||
0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xFF,0x00,0x00,0x7F,
|
||||
0xFE,0x3F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xFF,0x00,0x00,0x7F,
|
||||
0xFF,0xFF,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xFF,0x04,0x00,0x7F,
|
||||
0xFF,0xFF,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0x0C,0x38,0x7F,
|
||||
0xFF,0xFF,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0x0C,0x78,0x7F,
|
||||
0xFF,0xFF,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xFF,0xFF,0x00,0x00,0x7F,
|
||||
0xFF,0xFF,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xFF,0xFF,0x00,0x00,0x7F,
|
||||
0xFF,0xFF,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,0xFF,0x00,0x00,0x7F,
|
||||
0xFF,0xFF,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xFF,0xFF,0x00,0x00,0x7F,
|
||||
0xFF,0xFF,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xFF,0xFF,0x00,0x00,0x7F,
|
||||
0xFF,0xFF,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xFF,0xFF,0xFF,0x00,0x00,0x7F,
|
||||
0xFF,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xFF,0xFF,0xFF,0x00,0x00,0x7F,
|
||||
0xFF,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xFF,0xFF,0xFF,0x00,0x00,0x7F,
|
||||
0xFF,0xFF,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xFF,0xFF,0xFF,0xFE,0x00,0x7F,
|
||||
0xFF,0xFF,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xFF,0xFF,0xFF,0xF8,0x01,0xFF,
|
||||
0xFF,0xFF,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xFF,0xFF,0xFF,0xC0,0x0F,0xFF,
|
||||
0xFF,0xFF,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xFF,0xFF,0xFF,0x00,0x1F,0xFF,
|
||||
0xFF,0xFF,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xFF,0xFF,0xFF,0x00,0x00,0x7F,
|
||||
0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x03,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x7F,
|
||||
0xFF,0xFF,0xFF,0xC0,0x00,0x00,0x00,0x00,0x0F,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x7F,
|
||||
0xFF,0xFF,0xFF,0xF0,0x00,0x00,0x80,0x00,0x1F,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x7F,
|
||||
0xFF,0xFF,0xFF,0xFF,0x00,0x00,0xC0,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0x80,0x00,0xE0,0x03,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xC0,0x00,0xFE,0x0F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xE0,0x01,0xFE,0x1F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xF8,0x03,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0x03,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
u8 BMP3[]={
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x01,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x80,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x1F,0xFF,0xFF,0xF0,0x3F,0x00,0x00,0x0F,0xE0,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x07,0xFF,0x80,0x00,0x39,0xE1,0xD8,0x00,0x00,0x78,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x7F,0x80,0x05,0xF0,0x00,0x00,0x01,0xC0,0x00,0x1E,0x00,0x00,0x00,
|
||||
0x00,0x00,0x03,0xF0,0x00,0x00,0x00,0x0B,0xFF,0xA0,0x1C,0x00,0x07,0x80,0x00,0x00,
|
||||
0x00,0x00,0x0F,0x86,0x03,0xFF,0xFF,0x80,0x00,0x03,0x81,0x80,0x03,0xC0,0x00,0x00,
|
||||
0x00,0x00,0x3C,0x00,0x00,0x00,0x00,0x00,0xA0,0xE0,0x18,0x30,0x00,0xE0,0x00,0x00,
|
||||
0x00,0x00,0xF0,0x00,0x1F,0xC0,0x00,0x00,0x40,0x03,0xC3,0x0C,0x00,0x70,0x00,0x00,
|
||||
0x00,0x01,0xE0,0x01,0x80,0x01,0x00,0x00,0x80,0x00,0x1C,0x41,0x00,0x38,0x00,0x00,
|
||||
0x00,0x01,0xC0,0x06,0x00,0x00,0x00,0x01,0x00,0x00,0x03,0x10,0x40,0x38,0x00,0x00,
|
||||
0x00,0x01,0xC0,0x08,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0xC4,0x00,0x1C,0x00,0x00,
|
||||
0x00,0x01,0x80,0x00,0x00,0x03,0x00,0x00,0x00,0x7E,0x00,0x20,0x00,0x0E,0x00,0x00,
|
||||
0x00,0x03,0x80,0x00,0x00,0x01,0x00,0x00,0x1F,0xFF,0xF8,0x00,0x00,0x07,0x00,0x00,
|
||||
0x00,0x07,0x00,0x00,0xFF,0x80,0x00,0x00,0x7C,0x3F,0xFF,0x00,0x00,0x03,0xC0,0x00,
|
||||
0x00,0x1E,0x00,0x07,0xFF,0xF8,0x00,0x01,0xE0,0x3F,0xFB,0xC0,0x00,0x01,0xF0,0x00,
|
||||
0x00,0x78,0x3F,0xEF,0xFF,0xFE,0x00,0x07,0x81,0xFF,0xFF,0xE3,0x80,0x3F,0xF8,0x00,
|
||||
0x00,0xF1,0x00,0x00,0xFF,0xFF,0xF8,0x07,0x1F,0xE0,0x0F,0xC8,0x00,0x00,0x5E,0x00,
|
||||
0x01,0xC4,0x00,0x00,0x00,0x1F,0xE0,0x03,0xFC,0x07,0x00,0x00,0x3F,0xF0,0x37,0x00,
|
||||
0x01,0x91,0x80,0x00,0x00,0x03,0x80,0x00,0xE0,0x03,0xC0,0x03,0xFF,0xFC,0x0B,0x80,
|
||||
0x03,0xA2,0x3F,0xE0,0x00,0x03,0x80,0x00,0x00,0x01,0xF8,0x7F,0xC0,0x0F,0x09,0xC0,
|
||||
0x03,0xA2,0xF8,0xF8,0x60,0x03,0x80,0x00,0x00,0x00,0x3F,0xF8,0x06,0x03,0x84,0xE0,
|
||||
0x03,0x84,0x00,0x3F,0xE0,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x1E,0x01,0x84,0x60,
|
||||
0x03,0xA4,0x01,0x0F,0x80,0x1E,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x01,0xC4,0x60,
|
||||
0x03,0xA6,0x03,0x80,0x00,0xF8,0x00,0x03,0xFB,0x00,0x00,0x03,0xF7,0xE1,0xC4,0x60,
|
||||
0x01,0xF1,0x03,0x80,0x03,0xF0,0x00,0x00,0x3C,0xFF,0x80,0x3F,0x87,0xF9,0xC4,0x60,
|
||||
0x01,0xD8,0x07,0x80,0x0F,0xF0,0x00,0x3E,0x0C,0x00,0x03,0xF8,0x07,0x01,0x88,0xE0,
|
||||
0x00,0xE6,0x0F,0xC0,0x61,0x78,0x00,0xFF,0x1C,0x00,0x7F,0xE0,0x0E,0x03,0x88,0xE0,
|
||||
0x00,0x70,0xCF,0xF1,0x00,0x1E,0x00,0x00,0x38,0x0F,0xF8,0xC0,0x3E,0x03,0x11,0xC0,
|
||||
0x00,0x38,0x0F,0xFC,0x00,0x07,0xF0,0x00,0x03,0xFF,0x00,0xC1,0xFC,0x00,0x63,0x80,
|
||||
0x00,0x38,0x1F,0xBF,0x80,0x01,0xE0,0x00,0x7F,0xE0,0x03,0xCF,0xF8,0x03,0x0F,0x00,
|
||||
0x00,0x1C,0x1F,0xBB,0xFE,0x00,0x01,0xFF,0xFF,0x80,0x07,0xFE,0x70,0x00,0x7C,0x00,
|
||||
0x00,0x0C,0x1F,0x38,0x7F,0xFF,0xFF,0xF8,0x03,0x80,0x7F,0xF0,0xE0,0x00,0x78,0x00,
|
||||
0x00,0x0C,0x1F,0x38,0x70,0x1F,0x81,0xC0,0x01,0xC7,0xFF,0xC3,0xC0,0x00,0xE0,0x00,
|
||||
0x00,0x0C,0x1F,0xF8,0x60,0x0E,0x01,0xC0,0x01,0xFF,0xF9,0x87,0x80,0x01,0xC0,0x00,
|
||||
0x00,0x0C,0x0F,0xFC,0xE0,0x0E,0x01,0xC0,0x1F,0xFF,0x81,0xCE,0x00,0x03,0x80,0x00,
|
||||
0x00,0x0C,0x1F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF0,0x00,0xFC,0x00,0x07,0x00,0x00,
|
||||
0x00,0x0C,0x0F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0xE0,0x00,0xF0,0x00,0x0E,0x00,0x00,
|
||||
0x00,0x0C,0x0F,0xFF,0xFF,0xFF,0xFF,0xFF,0xC0,0xE0,0x03,0xE0,0x00,0x1C,0x00,0x00,
|
||||
0x00,0x0C,0x0E,0xFF,0xFF,0xFF,0xFF,0xF8,0x00,0x70,0x0F,0x80,0x00,0x38,0x00,0x00,
|
||||
0x00,0x0C,0x06,0x67,0xFF,0xFF,0xF8,0x30,0x00,0x70,0x3E,0x00,0x00,0x70,0x00,0x00,
|
||||
0x00,0x0C,0x07,0x73,0x8E,0x07,0x00,0x30,0x00,0x39,0xF0,0x00,0x01,0xE0,0x00,0x00,
|
||||
0x00,0x0C,0x03,0xE1,0xC7,0x03,0x80,0x30,0x00,0x1F,0xC0,0x00,0x07,0x80,0x00,0x00,
|
||||
0x00,0x0C,0x01,0xF1,0xC3,0x83,0x80,0x30,0x01,0xFE,0x01,0x83,0x1F,0x00,0x00,0x00,
|
||||
0x00,0x0C,0x00,0x3F,0xF3,0xC3,0x80,0x38,0xFF,0xE0,0x1C,0x18,0x7C,0x00,0x00,0x00,
|
||||
0x00,0x0C,0x00,0x03,0xFF,0xFF,0xFF,0xFF,0xF8,0x00,0xE0,0xC1,0xF0,0x00,0x00,0x00,
|
||||
0x00,0x1C,0x00,0x00,0x00,0x0F,0xFC,0x00,0x00,0x0E,0x0E,0x0F,0x80,0x00,0x00,0x00,
|
||||
0x00,0x1C,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0xE0,0x60,0x7E,0x00,0x00,0x00,0x00,
|
||||
0x00,0x1C,0x00,0x30,0x00,0x00,0x00,0x00,0x0E,0x0F,0x03,0xF0,0x00,0x00,0x00,0x00,
|
||||
0x00,0x18,0x10,0x06,0x00,0x00,0x00,0x03,0xC0,0xE0,0x3F,0x80,0x00,0x00,0x00,0x00,
|
||||
0x00,0x18,0x0C,0x00,0x5F,0xFF,0xDC,0x00,0xB8,0x03,0xF8,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x18,0x03,0x80,0x00,0x00,0x00,0x78,0x00,0x1F,0x80,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x1C,0x00,0x3F,0xFF,0xFF,0xC0,0x00,0x01,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x03,0x80,0x00,0x00,0x00,0x00,0x7F,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x01,0xF0,0x00,0x00,0x00,0x1F,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x7E,0x00,0x00,0x0F,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x0F,0xFF,0xFF,0xFF,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
+302
@@ -0,0 +1,302 @@
|
||||
/*************************** (C) COPYRIGHT 2017 YNHB ****************************
|
||||
* 文件名 :LCD_SDWe.c
|
||||
* 描 述 :7寸LCD串口显示屏驱动程序
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/10/23
|
||||
*********************************************************************************/
|
||||
#include "SDWe_LCD.h"
|
||||
#include "usart5.h"
|
||||
#include "timer.h"
|
||||
#include "string.h"
|
||||
#include "stdlib.h"
|
||||
#include "delay.h"
|
||||
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: LCD_PackProcotol
|
||||
* 功能说明: LCD显示屏控制传输协议打包函数
|
||||
* 形 参:
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void SDWe_LCD_PackProcotol(uint8_t* data, uint16_t dataLen)
|
||||
{
|
||||
int index = 0;
|
||||
uint8_t buf[128];
|
||||
|
||||
buf[index++] = 0xA5;
|
||||
buf[index++] = 0x5A;
|
||||
buf[index++] = dataLen;
|
||||
if (data != NULL)
|
||||
{
|
||||
memcpy(&buf[index], data, dataLen);
|
||||
index += dataLen;
|
||||
}
|
||||
|
||||
UART5_Printf((uint8_t*)buf, index);
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: LCD_WriteReg
|
||||
* 功能说明: 写LCD寄存器
|
||||
* 形 参:
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void SDWe_LCD_WriteReg(uint8_t addr, uint8_t *data, uint8_t dataLen)
|
||||
{
|
||||
int index = 0;
|
||||
uint8_t buf[128];
|
||||
|
||||
buf[index++] = 0x80;
|
||||
buf[index++] = addr;
|
||||
if (data != NULL)
|
||||
{
|
||||
memcpy(&buf[index], data, dataLen);
|
||||
index += dataLen;
|
||||
}
|
||||
|
||||
SDWe_LCD_PackProcotol(buf, index);
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: LCD_WriteMem
|
||||
* 功能说明: 写LCD存储器
|
||||
* 形 参:
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void SDWe_LCD_WriteMem(uint16_t addr, uint8_t *data, uint8_t dataLen)
|
||||
{
|
||||
int index = 0;
|
||||
uint8_t buf[128];
|
||||
|
||||
buf[index++] = 0x82;
|
||||
buf[index++] = (uint8_t)(addr >> 8); //发送变量地址
|
||||
buf[index++] = (uint8_t)addr;
|
||||
if (data != NULL)
|
||||
{
|
||||
memcpy(&buf[index], data, dataLen);
|
||||
index += dataLen;
|
||||
}
|
||||
|
||||
SDWe_LCD_PackProcotol(buf, index);
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: LCD_SetBacklight
|
||||
* 功能说明: 设置LCD背光亮度
|
||||
* 形 参:val -> 亮度值(0x00-0x40)
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void SDWe_LCD_SetBacklight(uint8_t val)
|
||||
{
|
||||
SDWe_LCD_WriteReg(0x01, &val, 1); //0x01为设置背光亮度
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: LCD_ConfigEN
|
||||
* 功能说明: 屏参配置使能
|
||||
* 形 参:val -> 亮度值(0x00-0x40)
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void SDWe_LCD_ConfigEN(uint8_t cmd)
|
||||
{
|
||||
static uint8_t ctrlReg;
|
||||
if(cmd)
|
||||
{
|
||||
ctrlReg = 0x5A;
|
||||
}else{
|
||||
ctrlReg = 0xA5;
|
||||
}
|
||||
SDWe_LCD_WriteReg(0x1D, &ctrlReg, 1); //0x01为设置背光亮度
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: LCD_SetDisplayPage
|
||||
* 功能说明: 设置显示页面
|
||||
* 形 参:page -> 高度值(0x00-0x40)
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void SDWe_LCD_SetBound(uint32_t baudrate)
|
||||
{
|
||||
uint8_t val;
|
||||
switch(baudrate)
|
||||
{
|
||||
case 1200:
|
||||
val = 0x00;
|
||||
break;
|
||||
|
||||
case 9600:
|
||||
val = 0x03;
|
||||
break;
|
||||
|
||||
case 19200:
|
||||
val = 0x04;
|
||||
break;
|
||||
|
||||
case 38400:
|
||||
val = 0x05;
|
||||
break;
|
||||
|
||||
default:
|
||||
val = 0x07;
|
||||
}
|
||||
SDWe_LCD_WriteReg(0x11, &val, 1); //0x03-0x04为设置显示页面
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: LCD_SetDisplayPage
|
||||
* 功能说明: 设置显示页面
|
||||
* 形 参:page -> 高度值(0x00-0x40)
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void SDWe_LCD_SetDisplayPage(uint16_t page)
|
||||
{
|
||||
uint8_t pageBuf[2];
|
||||
|
||||
pageBuf[0] = (uint8_t)(page >> 8);
|
||||
pageBuf[1] = (uint8_t)page;
|
||||
SDWe_LCD_WriteReg(0x03, pageBuf, 2); //0x03-0x04为设置显示页面
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: SDWe_LCD_ShowNum
|
||||
* 功能说明: 显示数字变量
|
||||
* 形 参:
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void SDWe_LCD_ShowNum(uint16_t addr, uint32_t num)
|
||||
{
|
||||
uint8_t numBuf[4];
|
||||
|
||||
numBuf[0] = (uint8_t)(num >> 24);
|
||||
numBuf[1] = (uint8_t)(num >> 16);
|
||||
numBuf[2] = (uint8_t)(num >> 8);
|
||||
numBuf[3] = (uint8_t)num;
|
||||
|
||||
SDWe_LCD_WriteMem(addr, numBuf, 4);
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: LCD_ShowString
|
||||
* 功能说明: 显示字符串
|
||||
* 形 参:
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void SDWe_LCD_ShowString(uint16_t addr, char *p)
|
||||
{
|
||||
uint8_t len;
|
||||
|
||||
len = strlen(p);
|
||||
|
||||
printf("len = %d ", len);
|
||||
|
||||
SDWe_LCD_WriteMem(addr, (uint8_t *)p, len);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: LCD_GetReturnData
|
||||
* 功能说明: 取得LCD显示屏返回的数据
|
||||
* 形 参:
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void SDWe_LCD_GetReturnData(void)
|
||||
{
|
||||
uint8_t i;
|
||||
uint32_t tempData;
|
||||
uint8_t dataLen; //指令长度
|
||||
uint8_t instructionType; //指令码
|
||||
uint8_t regAddr; //寄存器地址
|
||||
uint16_t memoryAddr; //存储器地址
|
||||
uint8_t returnDataLen; //返回数据长度
|
||||
|
||||
static uint8_t iValue = 0;
|
||||
|
||||
if(USART5_RX_STA == 0xfd) //接收到一次数据了
|
||||
{
|
||||
printf("\r\n收到LCD显示屏返回的数据正在解析:\r\n");
|
||||
USART5_RX_STA = 0; //启动下一次接收
|
||||
|
||||
dataLen = USART5_RX_BUF[0];
|
||||
instructionType = USART5_RX_BUF[1]; //取出指令码
|
||||
|
||||
printf("\r\n指令长度 = %d \r\n", dataLen);
|
||||
printf("\r\n指令码 = 0x%x \r\n", instructionType);
|
||||
|
||||
switch(instructionType)
|
||||
{
|
||||
case 0x81:
|
||||
regAddr = USART5_RX_BUF[2];
|
||||
switch(regAddr)
|
||||
{
|
||||
case 0x00:
|
||||
printf("\r\nVersion = V%x \r\n", USART5_RX_BUF[4]);
|
||||
break;
|
||||
|
||||
case 0x01:
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 0x82:
|
||||
break;
|
||||
|
||||
case 0x83:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: LCD_DisplayControlTask
|
||||
* 功能说明: LCD显示屏测试程序
|
||||
* 形 参:
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void SDWe_LCD_DisplayControlTask(void)
|
||||
{
|
||||
static uint32_t page = 0;
|
||||
|
||||
delay_ms(100);
|
||||
|
||||
// LCD_ShowString(0x0021, "show string");
|
||||
|
||||
|
||||
// LCD_SetDisplayPage(page);
|
||||
// delay_ms(100);
|
||||
// page++;
|
||||
// if(page > 0xfffffffe)
|
||||
// {
|
||||
// page = 0;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
// printf("\r\n向LCD发送数据\r\n");
|
||||
}
|
||||
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 YNHB *****END OF FILE*******************/
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
/*************************** (C) COPYRIGHT 2017 YNHB ****************************
|
||||
* 文件名 :LCD_SDWe.h
|
||||
* 描 述 :7寸LCD串口显示屏驱动头文件
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/10/23
|
||||
*********************************************************************************/
|
||||
#ifndef __LCD_SDWe_H
|
||||
#define __LCD_SDWe_H
|
||||
#include "sys.h"
|
||||
|
||||
void SDWe_LCD_SetDisplayPage(uint16_t page);
|
||||
void SDWe_LCD_ShowNum(uint16_t addr, uint32_t num);
|
||||
void SDWe_LCD_ShowString(uint16_t addr, char *p);
|
||||
void SDWe_LCD_GetReturnData(void);
|
||||
void SDWe_LCD_DisplayControlTask(void);
|
||||
|
||||
#endif
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 YNHB *****END OF FILE*******************/
|
||||
+1082
File diff suppressed because it is too large
Load Diff
+33
@@ -0,0 +1,33 @@
|
||||
/*************************** (C) COPYRIGHT 2017 YNHB ****************************
|
||||
* 文件名 :display.h
|
||||
* 描 述 :显示程序
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/10/16
|
||||
*********************************************************************************/
|
||||
#ifndef __DISPLAY_H
|
||||
#define __DISPLAY_H
|
||||
#include "stdint.h"
|
||||
|
||||
void Screen_SystemInit(void);
|
||||
void Screen_ShowDeviceInfo(char *ver, uint8_t type1, uint8_t type2, uint8_t type3, uint8_t type4);
|
||||
void Screen_Default(void);
|
||||
void Screen_DeviceDisable(void);
|
||||
void Screen_Landing(void);
|
||||
void Screen_Query(uint8_t auth, uint8_t mode, uint8_t *icCard, uint32_t inputAccount, uint32_t inputBalance);
|
||||
void Screen_UserInfo(uint8_t auth, uint8_t mode, uint8_t *icCard, uint32_t inputAccount, uint32_t inputBalance);
|
||||
void Screen_Countdown(uint8_t timerVal);
|
||||
void Screen_ShowPutInInfo(uint8_t type, uint8_t leftType, uint8_t rightType, uint16_t leftVal, uint16_t rightVal);
|
||||
void Screen_ShowPutInInfo2(uint16_t val1, uint16_t val2, uint16_t val3, uint16_t val4);
|
||||
void Screen_ShowPutInReward(uint32_t beforeCapital, uint32_t afterCapital);
|
||||
void Screen_Exit(void);
|
||||
void Screen_ShowFull(void);
|
||||
void Screen_Error(uint8_t type, uint8_t pre1, uint8_t pre2);
|
||||
|
||||
void Screen_ScaleCalibraEnter(uint8_t num);
|
||||
void Screen_ScaleCalibraStart(uint8_t num);
|
||||
void Screen_ScaleCalibraFinish(uint8_t num);
|
||||
|
||||
void DispalyTask(void);
|
||||
|
||||
#endif
|
||||
Executable
+192
@@ -0,0 +1,192 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :icon.h
|
||||
* 描 述 :图片信息头文件
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/10/17
|
||||
*********************************************************************************/
|
||||
#ifndef __ICON_H__
|
||||
#define __ICON_H__
|
||||
#include "stdint.h"
|
||||
|
||||
//横向取模
|
||||
//信号图标
|
||||
const unsigned char signalIcon[8][32] = {
|
||||
{0x00,0x00,0x7C,0x00,0x38,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //无信号
|
||||
|
||||
{0x00,0x00,0x7C,0x00,0x38,0x00,0x10,0x00,0x10,0x00,0x12,0x00,0x12,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //1格信号
|
||||
|
||||
{0x00,0x00,0x7C,0x00,0x38,0x00,0x10,0x00,0x10,0x80,0x12,0x80,0x12,0x80,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //2格信号
|
||||
|
||||
{0x00,0x00,0x7C,0x00,0x38,0x00,0x10,0x20,0x10,0xA0,0x12,0xA0,0x12,0xA0,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //3格信号
|
||||
|
||||
{0x00,0x00,0x7C,0x00,0x38,0x08,0x10,0x28,0x10,0xA8,0x12,0xA8,0x12,0xA8,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //4格信号
|
||||
|
||||
{0x00,0x00,0x7C,0x00,0x38,0x11,0x10,0x0A,0x10,0x84,0x12,0x8A,0x12,0x91,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //无法注册网络(卡识别正常)
|
||||
|
||||
{0x00,0x00,0x7C,0x04,0x38,0x04,0x10,0x04,0x10,0x84,0x12,0x80,0x12,0x84,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //没有GPRS业务
|
||||
|
||||
{0x00,0x00,0x7C,0x74,0x38,0x94,0x11,0x14,0x11,0x14,0x11,0x10,0x11,0xF4,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //没有检测到卡
|
||||
};
|
||||
|
||||
//温度符号℃
|
||||
const uint8_t temperatureIcon[32] = {
|
||||
0x00,0x00,0x00,0x00,0x00,0x60,0x00,0x6E,0x00,0x1B,0x00,0x31,0x00,0x30,0x00,0x30,
|
||||
0x00,0x30,0x00,0x31,0x00,0x1B,0x00,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
|
||||
|
||||
//垃圾桶图标
|
||||
const uint8_t Icon2[11][192] = {
|
||||
{ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x78,0x3F,0xFF,0xFF,0xF8,
|
||||
0x3F,0xFF,0xFF,0xFC,0x08,0x00,0x00,0xD4,0x08,0x00,0x00,0x94,0x08,0x00,0x00,0x94,
|
||||
0x08,0x00,0x00,0x94,0x08,0x00,0x00,0xA4,0x08,0x00,0x00,0xA4,0x08,0x00,0x00,0xA4,
|
||||
0x08,0x00,0x00,0xA4,0x08,0x00,0x00,0xA4,0x08,0x00,0x00,0xA4,0x08,0x00,0x00,0xA4,
|
||||
0x08,0x00,0x00,0x94,0x08,0x00,0x00,0x94,0x08,0x00,0x00,0x94,0x08,0x00,0x00,0x94,
|
||||
0x08,0x00,0x00,0x8C,0x08,0x00,0x00,0x8C,0x04,0x00,0x01,0x0C,0x04,0x00,0x01,0x1C,
|
||||
0x04,0x00,0x01,0x04,0x04,0x00,0x01,0x04,0x04,0x00,0x01,0x00,0x04,0x00,0x01,0x00,
|
||||
0x04,0x00,0x01,0x00,0x04,0x00,0x01,0x00,0x04,0x00,0x01,0x00,0x04,0x00,0x01,0x00,
|
||||
0x04,0x00,0x01,0x00,0x04,0x00,0x03,0x80,0x04,0x00,0x04,0x40,0x04,0x00,0x09,0x20,
|
||||
0x04,0x00,0x0B,0xA0,0x07,0xFF,0xF9,0x20,0x03,0x80,0x04,0x40,0x03,0x80,0x03,0x80,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //0%
|
||||
|
||||
{ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x78,0x3F,0xFF,0xFF,0xF8,
|
||||
0x3F,0xFF,0xFF,0xFC,0x08,0x00,0x00,0xD4,0x08,0x00,0x00,0x94,0x08,0x00,0x00,0x94,
|
||||
0x08,0x00,0x00,0x94,0x08,0x00,0x00,0xA4,0x08,0x00,0x00,0xA4,0x08,0x00,0x00,0xA4,
|
||||
0x08,0x00,0x00,0xA4,0x08,0x00,0x00,0xA4,0x08,0x00,0x00,0xA4,0x08,0x00,0x00,0xA4,
|
||||
0x08,0x00,0x00,0x94,0x08,0x00,0x00,0x94,0x08,0x00,0x00,0x94,0x08,0x00,0x00,0x94,
|
||||
0x08,0x00,0x00,0x8C,0x08,0x00,0x00,0x8C,0x04,0x00,0x01,0x0C,0x04,0x00,0x01,0x1C,
|
||||
0x04,0x00,0x01,0x04,0x04,0x00,0x01,0x04,0x04,0x00,0x01,0x00,0x04,0x00,0x01,0x00,
|
||||
0x04,0x00,0x01,0x00,0x04,0x00,0x01,0x00,0x04,0x00,0x01,0x00,0x04,0x00,0x01,0x00,
|
||||
0x04,0x00,0x01,0x00,0x05,0xFF,0xFB,0x80,0x05,0xFF,0xF4,0x40,0x05,0xFF,0xE9,0x20,
|
||||
0x04,0x00,0x0B,0xA0,0x07,0xFF,0xF9,0x20,0x03,0x80,0x04,0x40,0x03,0x80,0x03,0x80,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //10%
|
||||
|
||||
{ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x78,0x3F,0xFF,0xFF,0xF8,
|
||||
0x3F,0xFF,0xFF,0xFC,0x08,0x00,0x00,0xD4,0x08,0x00,0x00,0x94,0x08,0x00,0x00,0x94,
|
||||
0x08,0x00,0x00,0x94,0x08,0x00,0x00,0xA4,0x08,0x00,0x00,0xA4,0x08,0x00,0x00,0xA4,
|
||||
0x08,0x00,0x00,0xA4,0x08,0x00,0x00,0xA4,0x08,0x00,0x00,0xA4,0x08,0x00,0x00,0xA4,
|
||||
0x08,0x00,0x00,0x94,0x08,0x00,0x00,0x94,0x08,0x00,0x00,0x94,0x08,0x00,0x00,0x94,
|
||||
0x08,0x00,0x00,0x8C,0x08,0x00,0x00,0x8C,0x04,0x00,0x01,0x0C,0x04,0x00,0x01,0x1C,
|
||||
0x04,0x00,0x01,0x04,0x04,0x00,0x01,0x04,0x04,0x00,0x01,0x00,0x04,0x00,0x01,0x00,
|
||||
0x04,0x00,0x01,0x00,0x04,0x00,0x01,0x00,0x05,0xFF,0xFD,0x00,0x05,0xFF,0xFD,0x00,
|
||||
0x05,0xFF,0xFD,0x00,0x05,0xFF,0xFB,0x80,0x05,0xFF,0xF4,0x40,0x05,0xFF,0xE9,0x20,
|
||||
0x04,0x00,0x0B,0xA0,0x07,0xFF,0xF9,0x20,0x03,0x80,0x04,0x40,0x03,0x80,0x03,0x80,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //20%
|
||||
|
||||
{ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x78,0x3F,0xFF,0xFF,0xF8,
|
||||
0x3F,0xFF,0xFF,0xFC,0x08,0x00,0x00,0xD4,0x08,0x00,0x00,0x94,0x08,0x00,0x00,0x94,
|
||||
0x08,0x00,0x00,0x94,0x08,0x00,0x00,0xA4,0x08,0x00,0x00,0xA4,0x08,0x00,0x00,0xA4,
|
||||
0x08,0x00,0x00,0xA4,0x08,0x00,0x00,0xA4,0x08,0x00,0x00,0xA4,0x08,0x00,0x00,0xA4,
|
||||
0x08,0x00,0x00,0x94,0x08,0x00,0x00,0x94,0x08,0x00,0x00,0x94,0x08,0x00,0x00,0x94,
|
||||
0x08,0x00,0x00,0x8C,0x08,0x00,0x00,0x8C,0x04,0x00,0x01,0x0C,0x04,0x00,0x01,0x1C,
|
||||
0x04,0x00,0x01,0x04,0x04,0x00,0x01,0x04,0x04,0x00,0x01,0x00,0x05,0xFF,0xFD,0x00,
|
||||
0x05,0xFF,0xFD,0x00,0x05,0xFF,0xFD,0x00,0x05,0xFF,0xFD,0x00,0x05,0xFF,0xFD,0x00,
|
||||
0x05,0xFF,0xFD,0x00,0x05,0xFF,0xFB,0x80,0x05,0xFF,0xF4,0x40,0x05,0xFF,0xE9,0x20,
|
||||
0x04,0x00,0x0B,0xA0,0x07,0xFF,0xF9,0x20,0x03,0x80,0x04,0x40,0x03,0x80,0x03,0x80,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //30%
|
||||
|
||||
{ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x78,0x3F,0xFF,0xFF,0xF8,
|
||||
0x3F,0xFF,0xFF,0xFC,0x08,0x00,0x00,0xD4,0x08,0x00,0x00,0x94,0x08,0x00,0x00,0x94,
|
||||
0x08,0x00,0x00,0x94,0x08,0x00,0x00,0xA4,0x08,0x00,0x00,0xA4,0x08,0x00,0x00,0xA4,
|
||||
0x08,0x00,0x00,0xA4,0x08,0x00,0x00,0xA4,0x08,0x00,0x00,0xA4,0x08,0x00,0x00,0xA4,
|
||||
0x08,0x00,0x00,0x94,0x08,0x00,0x00,0x94,0x08,0x00,0x00,0x94,0x08,0x00,0x00,0x94,
|
||||
0x08,0x00,0x00,0x8C,0x08,0x00,0x00,0x8C,0x04,0x00,0x01,0x0C,0x04,0x00,0x01,0x1C,
|
||||
0x05,0xFF,0xFD,0x04,0x05,0xFF,0xFD,0x04,0x05,0xFF,0xFD,0x00,0x05,0xFF,0xFD,0x00,
|
||||
0x05,0xFF,0xFD,0x00,0x05,0xFF,0xFD,0x00,0x05,0xFF,0xFD,0x00,0x05,0xFF,0xFD,0x00,
|
||||
0x05,0xFF,0xFD,0x00,0x05,0xFF,0xFB,0x80,0x05,0xFF,0xF4,0x40,0x05,0xFF,0xE9,0x20,
|
||||
0x04,0x00,0x0B,0xA0,0x07,0xFF,0xF9,0x20,0x03,0x80,0x04,0x40,0x03,0x80,0x03,0x80,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //40%
|
||||
|
||||
{ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x78,0x3F,0xFF,0xFF,0xF8,
|
||||
0x3F,0xFF,0xFF,0xFC,0x08,0x00,0x00,0xD4,0x08,0x00,0x00,0x94,0x08,0x00,0x00,0x94,
|
||||
0x08,0x00,0x00,0x94,0x08,0x00,0x00,0xA4,0x08,0x00,0x00,0xA4,0x08,0x00,0x00,0xA4,
|
||||
0x08,0x00,0x00,0xA4,0x08,0x00,0x00,0xA4,0x08,0x00,0x00,0xA4,0x08,0x00,0x00,0xA4,
|
||||
0x08,0x00,0x00,0x94,0x08,0x00,0x00,0x94,0x08,0x00,0x00,0x94,0x08,0x00,0x00,0x94,
|
||||
0x08,0x00,0x00,0x8C,0x0B,0xFF,0xFE,0x8C,0x05,0xFF,0xFD,0x0C,0x05,0xFF,0xFD,0x1C,
|
||||
0x05,0xFF,0xFD,0x04,0x05,0xFF,0xFD,0x04,0x05,0xFF,0xFD,0x00,0x05,0xFF,0xFD,0x00,
|
||||
0x05,0xFF,0xFD,0x00,0x05,0xFF,0xFD,0x00,0x05,0xFF,0xFD,0x00,0x05,0xFF,0xFD,0x00,
|
||||
0x05,0xFF,0xFD,0x00,0x05,0xFF,0xFB,0x80,0x05,0xFF,0xF4,0x40,0x05,0xFF,0xE9,0x20,
|
||||
0x04,0x00,0x0B,0xA0,0x07,0xFF,0xF9,0x20,0x03,0x80,0x04,0x40,0x03,0x80,0x03,0x80,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //50%
|
||||
|
||||
{ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x78,0x3F,0xFF,0xFF,0xF8,
|
||||
0x3F,0xFF,0xFF,0xFC,0x08,0x00,0x00,0xD4,0x08,0x00,0x00,0x94,0x08,0x00,0x00,0x94,
|
||||
0x08,0x00,0x00,0x94,0x08,0x00,0x00,0xA4,0x08,0x00,0x00,0xA4,0x08,0x00,0x00,0xA4,
|
||||
0x08,0x00,0x00,0xA4,0x08,0x00,0x00,0xA4,0x08,0x00,0x00,0xA4,0x08,0x00,0x00,0xA4,
|
||||
0x08,0x00,0x00,0x94,0x08,0x00,0x00,0x94,0x0B,0xFF,0xFE,0x94,0x0B,0xFF,0xFE,0x94,
|
||||
0x0B,0xFF,0xFE,0x8C,0x0B,0xFF,0xFE,0x8C,0x05,0xFF,0xFD,0x0C,0x05,0xFF,0xFD,0x1C,
|
||||
0x05,0xFF,0xFD,0x04,0x05,0xFF,0xFD,0x04,0x05,0xFF,0xFD,0x00,0x05,0xFF,0xFD,0x00,
|
||||
0x05,0xFF,0xFD,0x00,0x05,0xFF,0xFD,0x00,0x05,0xFF,0xFD,0x00,0x05,0xFF,0xFD,0x00,
|
||||
0x05,0xFF,0xFD,0x00,0x05,0xFF,0xFB,0x80,0x05,0xFF,0xF4,0x40,0x05,0xFF,0xE9,0x20,
|
||||
0x04,0x00,0x0B,0xA0,0x07,0xFF,0xF9,0x20,0x03,0x80,0x04,0x40,0x03,0x80,0x03,0x80,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //60%
|
||||
|
||||
{ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x78,0x3F,0xFF,0xFF,0xF8,
|
||||
0x3F,0xFF,0xFF,0xFC,0x08,0x00,0x00,0xD4,0x08,0x00,0x00,0x94,0x08,0x00,0x00,0x94,
|
||||
0x08,0x00,0x00,0x94,0x08,0x00,0x00,0xA4,0x08,0x00,0x00,0xA4,0x08,0x00,0x00,0xA4,
|
||||
0x08,0x00,0x00,0xA4,0x08,0x00,0x00,0xA4,0x08,0x00,0x00,0xA4,0x0B,0xFF,0xFE,0xA4,
|
||||
0x0B,0xFF,0xFE,0x94,0x0B,0xFF,0xFE,0x94,0x0B,0xFF,0xFE,0x94,0x0B,0xFF,0xFE,0x94,
|
||||
0x0B,0xFF,0xFE,0x8C,0x0B,0xFF,0xFE,0x8C,0x05,0xFF,0xFD,0x0C,0x05,0xFF,0xFD,0x1C,
|
||||
0x05,0xFF,0xFD,0x04,0x05,0xFF,0xFD,0x04,0x05,0xFF,0xFD,0x00,0x05,0xFF,0xFD,0x00,
|
||||
0x05,0xFF,0xFD,0x00,0x05,0xFF,0xFD,0x00,0x05,0xFF,0xFD,0x00,0x05,0xFF,0xFD,0x00,
|
||||
0x05,0xFF,0xFD,0x00,0x05,0xFF,0xFB,0x80,0x05,0xFF,0xF4,0x40,0x05,0xFF,0xE9,0x20,
|
||||
0x04,0x00,0x0B,0xA0,0x07,0xFF,0xF9,0x20,0x03,0x80,0x04,0x40,0x03,0x80,0x03,0x80,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //70%
|
||||
|
||||
{ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x78,0x3F,0xFF,0xFF,0xF8,
|
||||
0x3F,0xFF,0xFF,0xFC,0x08,0x00,0x00,0xD4,0x08,0x00,0x00,0x94,0x08,0x00,0x00,0x94,
|
||||
0x08,0x00,0x00,0x94,0x08,0x00,0x00,0xA4,0x08,0x00,0x00,0xA4,0x08,0x00,0x00,0xA4,
|
||||
0x0B,0xFF,0xFE,0xA4,0x0B,0xFF,0xFE,0xA4,0x0B,0xFF,0xFE,0xA4,0x0B,0xFF,0xFE,0xA4,
|
||||
0x0B,0xFF,0xFE,0x94,0x0B,0xFF,0xFE,0x94,0x0B,0xFF,0xFE,0x94,0x0B,0xFF,0xFE,0x94,
|
||||
0x0B,0xFF,0xFE,0x8C,0x0B,0xFF,0xFE,0x8C,0x05,0xFF,0xFD,0x0C,0x05,0xFF,0xFD,0x1C,
|
||||
0x05,0xFF,0xFD,0x04,0x05,0xFF,0xFD,0x04,0x05,0xFF,0xFD,0x00,0x05,0xFF,0xFD,0x00,
|
||||
0x05,0xFF,0xFD,0x00,0x05,0xFF,0xFD,0x00,0x05,0xFF,0xFD,0x00,0x05,0xFF,0xFD,0x00,
|
||||
0x05,0xFF,0xFD,0x00,0x05,0xFF,0xFB,0x80,0x05,0xFF,0xF4,0x40,0x05,0xFF,0xE9,0x20,
|
||||
0x04,0x00,0x0B,0xA0,0x07,0xFF,0xF9,0x20,0x03,0x80,0x04,0x40,0x03,0x80,0x03,0x80,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //80%
|
||||
|
||||
{ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x78,0x3F,0xFF,0xFF,0xF8,
|
||||
0x3F,0xFF,0xFF,0xFC,0x08,0x00,0x00,0xD4,0x08,0x00,0x00,0x94,0x08,0x00,0x00,0x94,
|
||||
0x08,0x00,0x00,0x94,0x0B,0xFF,0xFE,0xA4,0x0B,0xFF,0xFE,0xA4,0x0B,0xFF,0xFE,0xA4,
|
||||
0x0B,0xFF,0xFE,0xA4,0x0B,0xFF,0xFE,0xA4,0x0B,0xFF,0xFE,0xA4,0x0B,0xFF,0xFE,0xA4,
|
||||
0x0B,0xFF,0xFE,0x94,0x0B,0xFF,0xFE,0x94,0x0B,0xFF,0xFE,0x94,0x0B,0xFF,0xFE,0x94,
|
||||
0x0B,0xFF,0xFE,0x8C,0x0B,0xFF,0xFE,0x8C,0x05,0xFF,0xFD,0x0C,0x05,0xFF,0xFD,0x1C,
|
||||
0x05,0xFF,0xFD,0x04,0x05,0xFF,0xFD,0x04,0x05,0xFF,0xFD,0x00,0x05,0xFF,0xFD,0x00,
|
||||
0x05,0xFF,0xFD,0x00,0x05,0xFF,0xFD,0x00,0x05,0xFF,0xFD,0x00,0x05,0xFF,0xFD,0x00,
|
||||
0x05,0xFF,0xFD,0x00,0x05,0xFF,0xFB,0x80,0x05,0xFF,0xF4,0x40,0x05,0xFF,0xE9,0x20,
|
||||
0x04,0x00,0x0B,0xA0,0x07,0xFF,0xF9,0x20,0x03,0x80,0x04,0x40,0x03,0x80,0x03,0x80,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //90%
|
||||
|
||||
{ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x78,0x3F,0xFF,0xFF,0xF8,
|
||||
0x3F,0xFF,0xFF,0xFC,0x08,0x00,0x00,0xD4,0x0B,0xFF,0xFE,0x94,0x0B,0xFF,0xFE,0x94,
|
||||
0x0B,0xFF,0xFE,0x94,0x0B,0xFF,0xFE,0xA4,0x0B,0xFF,0xFE,0xA4,0x0B,0xFF,0xFE,0xA4,
|
||||
0x0B,0xFF,0xFE,0xA4,0x0B,0xFF,0xFE,0xA4,0x0B,0xFF,0xFE,0xA4,0x0B,0xFF,0xFE,0xA4,
|
||||
0x0B,0xFF,0xFE,0x94,0x0B,0xFF,0xFE,0x94,0x0B,0xFF,0xFE,0x94,0x0B,0xFF,0xFE,0x94,
|
||||
0x0B,0xFF,0xFE,0x8C,0x0B,0xFF,0xFE,0x8C,0x05,0xFF,0xFD,0x0C,0x05,0xFF,0xFD,0x1C,
|
||||
0x05,0xFF,0xFD,0x04,0x05,0xFF,0xFD,0x04,0x05,0xFF,0xFD,0x00,0x05,0xFF,0xFD,0x00,
|
||||
0x05,0xFF,0xFD,0x00,0x05,0xFF,0xFD,0x00,0x05,0xFF,0xFD,0x00,0x05,0xFF,0xFD,0x00,
|
||||
0x05,0xFF,0xFD,0x00,0x05,0xFF,0xFB,0x80,0x05,0xFF,0xF4,0x40,0x05,0xFF,0xE9,0x20,
|
||||
0x04,0x00,0x0B,0xA0,0x07,0xFF,0xF9,0x20,0x03,0x80,0x04,0x40,0x03,0x80,0x03,0x80,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00} //100%
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Executable
+136
@@ -0,0 +1,136 @@
|
||||
/*************************** (C) COPYRIGHT 2017 YNHB ****************************
|
||||
* 文件名 :lcd.c
|
||||
* 描 述 :LCD显示屏接口应用程序
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/10/23
|
||||
*********************************************************************************/
|
||||
#include "lcd.h"
|
||||
#include "lcd12864.h"
|
||||
#include "string.h"
|
||||
#include "stdlib.h"
|
||||
#include "delay.h"
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: LCD_SetBacklight
|
||||
* 功能说明: LCD显示屏初始化
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void LCD_Init(void)
|
||||
{
|
||||
LCD12864_Init();
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: LCD_SetBacklight
|
||||
* 功能说明: 设置LCD背光亮度
|
||||
* 形 参:val -> 亮度值(百分比)
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void LCD_SetBacklight(uint8_t val)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: LCD_Clear
|
||||
* 功能说明: 显示清屏
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void LCD_Clear(void)
|
||||
{
|
||||
LCD12864_Clear();
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: LCD_DrawModeCtrl
|
||||
* 功能说明: 绘图模式控制
|
||||
* 形 参:param -> 0:关闭绘图模式;1:打开绘图模式
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void LCD_DrawModeCtrl(uint8_t param)
|
||||
{
|
||||
LCD12864_DrawModeCtrl(param);
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: LCD_ShowChar
|
||||
* 功能说明: 显示一个字符
|
||||
* 形 参:num -> 要显示的字符
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void LCD_ShowChar(uint8_t num)
|
||||
{
|
||||
LCD12864_ShowChar(num);
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: LCD_ShowString
|
||||
* 功能说明: 显示字符串
|
||||
* 形 参:x -> 行坐标
|
||||
* y -> 纵坐标
|
||||
* p -> 要显示的内容指针
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void LCD_ShowString(uint8_t x, uint8_t y, char *p)
|
||||
{
|
||||
LCD12864_ShowString(x, y, p);
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: LCD_ShowNum
|
||||
* 功能说明: 显示数字变量
|
||||
* 形 参:
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void LCD_ShowNum(uint8_t num)
|
||||
{
|
||||
LCD12864_ShowNum(num);
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: LCD_ShowxNum
|
||||
* 功能说明: 显示数字
|
||||
* 形 参:x,y -> 显示坐标
|
||||
* num -> 要显示的内容
|
||||
* len -> 显示的长度(即位数)
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void LCD_ShowxNum(uint8_t x, uint8_t y, uint32_t num, uint8_t len)
|
||||
{
|
||||
LCD12864_ShowxNum(x, y, num, len);
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: LCD_ShowSignal
|
||||
* 功能说明: 显示GSM信号强度
|
||||
* 形 参:val -> 信号的强度(0-4格显示)
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void LCD_ShowSignal(uint8_t val)
|
||||
{
|
||||
LCD12864_ShowSignal(val);
|
||||
}
|
||||
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 YNHB *****END OF FILE*******************/
|
||||
Executable
+25
@@ -0,0 +1,25 @@
|
||||
/*************************** (C) COPYRIGHT 2017 YNHB ****************************
|
||||
* 文件名 :lcd.h
|
||||
* 描 述 :LCD显示屏接口应用程序
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/10/23
|
||||
*********************************************************************************/
|
||||
#ifndef __LCD_H
|
||||
#define __LCD_H
|
||||
#include "stdint.h"
|
||||
#include "string.h"
|
||||
|
||||
void LCD_Init(void);
|
||||
void LCD_SetBacklight(uint8_t val);
|
||||
void LCD_Clear(void);
|
||||
void LCD_DrawModeCtrl(uint8_t param);
|
||||
void LCD_ShowChar(uint8_t num);
|
||||
void LCD_ShowString(uint8_t x, uint8_t y, char *p);
|
||||
void LCD_ShowNum(uint8_t num);
|
||||
void LCD_ShowxNum(uint8_t x, uint8_t y, uint32_t num, uint8_t len);
|
||||
void LCD_ShowSignal(uint8_t val);
|
||||
|
||||
#endif
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 YNHB *****END OF FILE*******************/
|
||||
+523
@@ -0,0 +1,523 @@
|
||||
/*************************** (C) COPYRIGHT 2017 YNHB ****************************
|
||||
* 文件名 :lcd12864.c
|
||||
* 描 述 :lcd12864显示驱动程序
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/10/16
|
||||
*********************************************************************************/
|
||||
#include "lcd12864.h"
|
||||
#include "delay.h"
|
||||
#include "icon.h"
|
||||
|
||||
#define LCD12864_E_PORT_PeriphClock RCC_APB2Periph_GPIOB
|
||||
#define LCD12864_E_PORT GPIOB
|
||||
#define LCD12864_E_PORT_PIN GPIO_Pin_5
|
||||
|
||||
#define LCD12864_RW_PORT_PeriphClock RCC_APB2Periph_GPIOB
|
||||
#define LCD12864_RW_PORT GPIOB
|
||||
#define LCD12864_RW_PORT_PIN GPIO_Pin_6
|
||||
|
||||
#define LCD12864_RS_PORT_PeriphClock RCC_APB2Periph_GPIOB
|
||||
#define LCD12864_RS_PORT GPIOB
|
||||
#define LCD12864_RS_PORT_PIN GPIO_Pin_7
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: LCD12864_Init
|
||||
* 功能说明: LCD12864接初始化
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void LCD12864_Init(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
|
||||
RCC_APB2PeriphClockCmd(LCD12864_E_PORT_PeriphClock, ENABLE);
|
||||
RCC_APB2PeriphClockCmd(LCD12864_RW_PORT_PeriphClock, ENABLE);
|
||||
RCC_APB2PeriphClockCmd(LCD12864_RS_PORT_PeriphClock, ENABLE);
|
||||
|
||||
//E(CLK),输出
|
||||
GPIO_InitStructure.GPIO_Pin = LCD12864_E_PORT_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(LCD12864_E_PORT, &GPIO_InitStructure);
|
||||
|
||||
//R/W(SID),数据
|
||||
GPIO_InitStructure.GPIO_Pin = LCD12864_RW_PORT_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(LCD12864_RW_PORT, &GPIO_InitStructure);
|
||||
|
||||
//RS/CS,片选
|
||||
GPIO_InitStructure.GPIO_Pin = LCD12864_RS_PORT_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(LCD12864_RS_PORT, &GPIO_InitStructure);
|
||||
|
||||
|
||||
|
||||
/*--------------------LCD基本指令-----------------------*/
|
||||
delay_ms(2);
|
||||
LCD12864_WriteCommand(0x30); //30--基本指令动作
|
||||
delay_ms(5);
|
||||
LCD12864_WriteCommand(0x0c); //光标右移画面不动
|
||||
delay_ms(5);
|
||||
LCD12864_WriteCommand(0x01); //清屏
|
||||
delay_ms(5); //清屏时间较长
|
||||
LCD12864_WriteCommand(0x06); //显示打开,光标开,反白关
|
||||
delay_ms(5);
|
||||
|
||||
// LCD12864_WriteCommand(0x34); // 扩充指令
|
||||
// LCD12864_WriteCommand(0x36); // 打开绘图指令
|
||||
LCD12864_Clear(); // 清屏
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: LCD12864_SendByte
|
||||
* 功能说明: 写一字节数据到LCD
|
||||
* 形 参:zdata -> 要写的数据
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void LCD12864_SendByte(uint8_t zdata)
|
||||
{
|
||||
uint16_t i;
|
||||
for(i=0; i<8; i++)
|
||||
{
|
||||
if((zdata << i) & 0x80)
|
||||
{
|
||||
SID_H;
|
||||
}else{
|
||||
SID_L;
|
||||
}
|
||||
|
||||
SCLK_H;
|
||||
SCLK_L;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: LCD12864_ReceiveByte
|
||||
* 功能说明: 读LCD数据
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
uint8_t LCD12864_ReceiveByte(void)
|
||||
{
|
||||
uint8_t i, temp1, temp2, value;
|
||||
// temp1 = 0;
|
||||
// temp2 = 0;
|
||||
// for(i = 0; i < 8; i++)
|
||||
// {
|
||||
// temp1 = temp1<<1;
|
||||
// SCLK_L;
|
||||
// SCLK_H;
|
||||
// SCLK_L;
|
||||
// if(PAout(7) == 1)
|
||||
// {
|
||||
// temp1++;
|
||||
// }
|
||||
// }
|
||||
// for(i = 0; i < 8; i++)
|
||||
// {
|
||||
// temp2 = temp2<<1;
|
||||
// SCLK_L;
|
||||
// SCLK_H;
|
||||
// SCLK_L;
|
||||
// if(PAout(7) == 1)
|
||||
// {
|
||||
// temp2++;
|
||||
// }
|
||||
// }
|
||||
// temp1 = 0xf0&temp1;
|
||||
// temp2 = 0x0f&temp2;
|
||||
// value = temp1+temp2;
|
||||
return value;
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: LCD12864_CheckBusy
|
||||
* 功能说明: LCD忙检查
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void LCD12864_CheckBusy(void)
|
||||
{
|
||||
do{
|
||||
LCD12864_SendByte(0xfc); //11111,RW(1),RS(0),0
|
||||
}while(0x80 & LCD12864_ReceiveByte());
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: LCD12864_WriteCommand
|
||||
* 功能说明: 写命令到LCD
|
||||
* 形 参:cmdcode -> 待写入的命令数据
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void LCD12864_WriteCommand(uint8_t cmdcode)
|
||||
{
|
||||
CS_H;
|
||||
LCD12864_CheckBusy();
|
||||
LCD12864_SendByte(0xf8);
|
||||
LCD12864_SendByte(cmdcode & 0xf0);
|
||||
LCD12864_SendByte((cmdcode << 4) & 0xf0);
|
||||
delay_us(100);
|
||||
CS_L;
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: LCD12864_WriteData
|
||||
* 功能说明: 写显示内容到LCD
|
||||
* 形 参:dispdata -> 待写入的命令数据
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void LCD12864_WriteData(uint8_t dispdata)
|
||||
{
|
||||
CS_H;
|
||||
LCD12864_CheckBusy();
|
||||
LCD12864_SendByte(0xfa); //11111,RW(0),RS(1),0
|
||||
LCD12864_SendByte(dispdata & 0xf0);
|
||||
LCD12864_SendByte((dispdata << 4) & 0xf0);
|
||||
delay_us(100);
|
||||
CS_L;
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: LCD12864_ReadData
|
||||
* 功能说明: 读取LCD显示内容
|
||||
* 形 参:无
|
||||
* 返 回 值: LCD收到的数据
|
||||
***********************************************************************
|
||||
*/
|
||||
uint8_t LCD12864_ReadData(void)
|
||||
{
|
||||
LCD12864_CheckBusy();
|
||||
LCD12864_SendByte(0xfe); //11111,RW(1),RS(1),0 LCD->MCU
|
||||
return LCD12864_ReceiveByte();
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: LCD12864_SetPos
|
||||
* 功能说明: 设置显示位置
|
||||
* 形 参:x,y显示坐标
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void LCD12864_SetPos(uint8_t x, uint8_t y)
|
||||
{
|
||||
uint8_t pos;
|
||||
switch(x)
|
||||
{
|
||||
case 0: x=0x80;break;
|
||||
case 1: x=0x90;break;
|
||||
case 2: x=0x88;break;
|
||||
case 3: x=0x98;break;
|
||||
}
|
||||
pos = x + y;
|
||||
LCD12864_WriteCommand(pos);
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: LCD12864_DrawPoint
|
||||
* 功能说明: LCD画点
|
||||
* 形 参: x,y->坐标
|
||||
* color -> 颜色,0不显示,1显示
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void LCD12864_DrawPoint(uint16_t x, uint16_t y, uint8_t color)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: LCD12864_DrawLine
|
||||
* 功能说明: 画直线
|
||||
* 形 参: x1,y1->起点坐标
|
||||
* x2,y2->终点坐标
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void LCD12864_DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: LCD12864_DrawRectangle
|
||||
* 功能说明: 画矩形
|
||||
* 形 参: x1,y1->左上角坐标
|
||||
* x2,y2->右下角坐标
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void LCD12864_DrawRectangle(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: LCD12864_Clear
|
||||
* 功能说明: 显示清屏
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void LCD12864_Clear(void)
|
||||
{
|
||||
uint8_t i, j;
|
||||
LCD12864_WriteCommand(0x34); //8Bit扩充指令集,即使是36H也要写两次
|
||||
LCD12864_WriteCommand(0x36); //绘图ON,基本指令集里面36H不能开绘图
|
||||
for(i = 0; i < 32; i++) //12864实际为256x32
|
||||
{
|
||||
LCD12864_WriteCommand(0x80|i); //行位置
|
||||
LCD12864_WriteCommand(0x80); //列位置
|
||||
for(j = 0; j < 32; j++) //256/8=32 byte
|
||||
{
|
||||
LCD12864_WriteData(0x00);
|
||||
}
|
||||
}
|
||||
LCD12864_WriteCommand(0x36);
|
||||
LCD12864_WriteCommand(0x30);
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: LCD12864_DrawModeCtrl
|
||||
* 功能说明: 绘图模式控制
|
||||
* 形 参:param -> 0:关闭绘图模式;1:打开绘图模式
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void LCD12864_DrawModeCtrl(uint8_t param)
|
||||
{
|
||||
if(param == 1)
|
||||
{
|
||||
LCD12864_WriteCommand(0x36);
|
||||
LCD12864_WriteCommand(0x30);
|
||||
}else{
|
||||
LCD12864_WriteCommand(0x34);
|
||||
LCD12864_WriteCommand(0x30);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: LCD12864_ShowChar
|
||||
* 功能说明: 显示一个字符
|
||||
* 形 参:num -> 要显示的字符
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void LCD12864_ShowChar(uint8_t num)
|
||||
{
|
||||
LCD12864_WriteData(num);
|
||||
delay_us(50);
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: LCD12864_ShowString
|
||||
* 功能说明: 显示字符串
|
||||
* 形 参:x -> 行坐标(0对应第一行)
|
||||
* y -> 纵坐标(0对应显示第一个字的位置,最多能显示8个汉字)
|
||||
* p -> 要显示的内容指针
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void LCD12864_ShowString(uint8_t x, uint8_t y, char *p)
|
||||
{
|
||||
uint8_t addr;
|
||||
switch(x)
|
||||
{
|
||||
case 0:
|
||||
addr = 0x80;
|
||||
break;
|
||||
case 1:
|
||||
addr = 0x90;
|
||||
break;
|
||||
case 2:
|
||||
addr = 0x88;
|
||||
break;
|
||||
case 3:
|
||||
addr = 0x98;
|
||||
break;
|
||||
}
|
||||
LCD12864_WriteCommand(addr + y);
|
||||
|
||||
while(*p>0)
|
||||
{
|
||||
LCD12864_WriteData(*p);
|
||||
p++;
|
||||
delay_us(50);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static uint64_t LCD_Pow(uint8_t m, uint8_t n)
|
||||
{
|
||||
uint64_t result = 1;
|
||||
while(n--)result *= m;
|
||||
return result;
|
||||
}
|
||||
|
||||
const uint8_t numCode[11] = {"0123456789"};
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: LCD12864_ShowNum
|
||||
* 功能说明: 显示单个数字
|
||||
* 形 参:num -> 要显示的数字
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void LCD12864_ShowNum(uint8_t num)
|
||||
{
|
||||
LCD12864_WriteData(numCode[num]);
|
||||
delay_us(50);
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: LCD12864_ShowxNum
|
||||
* 功能说明: 显示数字
|
||||
* 形 参:x,y -> 显示坐标
|
||||
* num -> 要显示的内容
|
||||
* len -> 显示的长度(即位数)
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void LCD12864_ShowxNum(uint8_t x, uint8_t y, uint32_t num, uint8_t len)
|
||||
{
|
||||
uint8_t t, temp;
|
||||
|
||||
LCD12864_SetPos(x, y); //设置显示坐标
|
||||
for(t = 0; t < len; t++)
|
||||
{
|
||||
temp = (num/LCD_Pow(10, len-t-1))%10;
|
||||
LCD12864_ShowNum(temp);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: LCD12864_ShowSignal
|
||||
* 功能说明: 显示GSM信号强度
|
||||
* 形 参:val -> 信号的强度(0-4格显示,5-6为异常情况显示)
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void LCD12864_ShowSignal(uint8_t val)
|
||||
{
|
||||
uint8_t i=0, j=0;
|
||||
LCD12864_WriteCommand(0x34); //8Bit扩充指令集,即使是36H也要写两次
|
||||
LCD12864_WriteCommand(0x36); //绘图ON,基本指令集里面36H不能开绘图
|
||||
|
||||
for(i = 0; i < 16; i++)
|
||||
{
|
||||
LCD12864_WriteCommand(0x83 + i); //行位置(说明:不是从第一行开始显示)
|
||||
LCD12864_WriteCommand(0x80); //列位置
|
||||
|
||||
LCD12864_WriteData((uint8_t)signalIcon[val][j++]);
|
||||
LCD12864_WriteData((uint8_t)signalIcon[val][j++]);
|
||||
}
|
||||
LCD12864_WriteCommand(0x36);
|
||||
LCD12864_WriteCommand(0x30);
|
||||
}
|
||||
|
||||
|
||||
void LCD_ShowTrash(uint8_t num, uint8_t val)
|
||||
{
|
||||
uint8_t i;
|
||||
uint16_t addr = 0;
|
||||
LCD12864_WriteCommand(0x34); //8Bit扩充指令集,即使是36H也要写两次
|
||||
LCD12864_WriteCommand(0x36); //绘图ON,基本指令集里面36H不能开绘图
|
||||
|
||||
for(i = 0; i < 16; i++)
|
||||
{
|
||||
LCD12864_WriteCommand(0x90 | i); //行位置
|
||||
if(num == 1)
|
||||
{
|
||||
LCD12864_WriteCommand(0x92); //列位置
|
||||
}else{
|
||||
LCD12864_WriteCommand(0x96); //列位置
|
||||
}
|
||||
LCD12864_WriteData((uint8_t)Icon2[val][addr++]);
|
||||
LCD12864_WriteData((uint8_t)Icon2[val][addr++]);
|
||||
LCD12864_WriteData((uint8_t)Icon2[val][addr++]);
|
||||
LCD12864_WriteData((uint8_t)Icon2[val][addr++]);
|
||||
}
|
||||
|
||||
for(i = 0; i < 16; i++)
|
||||
{
|
||||
LCD12864_WriteCommand(0x80 | i); //行位置
|
||||
if(num == 1)
|
||||
{
|
||||
LCD12864_WriteCommand(0x8A); //列位置
|
||||
}else{
|
||||
LCD12864_WriteCommand(0x8E); //列位置
|
||||
}
|
||||
LCD12864_WriteData((uint8_t)Icon2[val][addr++]);
|
||||
LCD12864_WriteData((uint8_t)Icon2[val][addr++]);
|
||||
LCD12864_WriteData((uint8_t)Icon2[val][addr++]);
|
||||
LCD12864_WriteData((uint8_t)Icon2[val][addr++]);
|
||||
}
|
||||
|
||||
for(i = 0; i < 16; i++)
|
||||
{
|
||||
LCD12864_WriteCommand(0x90 | i); //行位置
|
||||
if(num == 1)
|
||||
{
|
||||
LCD12864_WriteCommand(0x9A); //列位置
|
||||
}else{
|
||||
LCD12864_WriteCommand(0x9E); //列位置
|
||||
}
|
||||
LCD12864_WriteData((uint8_t)Icon2[val][addr++]);
|
||||
LCD12864_WriteData((uint8_t)Icon2[val][addr++]);
|
||||
LCD12864_WriteData((uint8_t)Icon2[val][addr++]);
|
||||
LCD12864_WriteData((uint8_t)Icon2[val][addr++]);
|
||||
}
|
||||
|
||||
LCD12864_WriteCommand(0x36);
|
||||
LCD12864_WriteCommand(0x30);
|
||||
}
|
||||
|
||||
void LCD_ShowTemperatureSymbol(uint8_t num)
|
||||
{
|
||||
uint8_t i;
|
||||
uint16_t addr = 0;
|
||||
LCD12864_WriteCommand(0x34); //8Bit扩充指令集,即使是36H也要写两次
|
||||
LCD12864_WriteCommand(0x36); //绘图ON,基本指令集里面36H不能开绘图
|
||||
|
||||
for(i = 0; i < 16; i++)
|
||||
{
|
||||
LCD12864_WriteCommand(0x90 | i); //行位置
|
||||
if(num == 1)
|
||||
{
|
||||
LCD12864_WriteCommand(0x91); //列位置
|
||||
}else{
|
||||
LCD12864_WriteCommand(0x95); //列位置
|
||||
}
|
||||
LCD12864_WriteData((uint8_t)temperatureIcon[addr++]);
|
||||
LCD12864_WriteData((uint8_t)temperatureIcon[addr++]);
|
||||
}
|
||||
LCD12864_WriteCommand(0x36);
|
||||
LCD12864_WriteCommand(0x30);
|
||||
}
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 YNHB *****END OF FILE*******************/
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
/*************************** (C) COPYRIGHT 2017 YNHB ****************************
|
||||
* 文件名 :lcd12864.h
|
||||
* 描 述 :lcd12864显示驱动程序
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/10/16
|
||||
*********************************************************************************/
|
||||
#ifndef __LCD12864_H
|
||||
#define __LCD12864_H
|
||||
#include "stm32f10x.h"
|
||||
#include "stdio.h"
|
||||
|
||||
#define CS_H GPIO_SetBits(GPIOB, GPIO_Pin_7) //RS(CS)
|
||||
#define CS_L GPIO_ResetBits(GPIOB, GPIO_Pin_7)
|
||||
#define SID_H GPIO_SetBits(GPIOB, GPIO_Pin_6) //R/W(SID)
|
||||
#define SID_L GPIO_ResetBits(GPIOB, GPIO_Pin_6)
|
||||
#define SCLK_H GPIO_SetBits(GPIOB, GPIO_Pin_5) //E(SCLK)
|
||||
#define SCLK_L GPIO_ResetBits(GPIOB, GPIO_Pin_5)
|
||||
// #define PSB_L GPIO_ResetBits(GPIOD, GPIO_Pin_4) //PSB
|
||||
|
||||
void LCD12864_Init(void);
|
||||
void LCD12864_SendByte(uint8_t zdata);
|
||||
uint8_t LCD12864_ReceiveByte(void);
|
||||
void LCD12864_CheckBusy(void);
|
||||
void LCD12864_WriteCommand(uint8_t cmdcode);
|
||||
void LCD12864_WriteData(uint8_t dispdata);
|
||||
uint8_t LCD12864_ReadData(void);
|
||||
void LCD12864_SetPos(uint8_t x, uint8_t y);
|
||||
void LCD12864_DrawPoint(uint16_t x, uint16_t y, uint8_t color);
|
||||
void LCD12864_DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
|
||||
void LCD12864_DrawRectangle(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2);
|
||||
void LCD12864_Clear(void);
|
||||
void LCD12864_DrawModeCtrl(uint8_t param);
|
||||
|
||||
void LCD12864_ShowChar(uint8_t num);
|
||||
void LCD12864_ShowString(uint8_t x, uint8_t y, char *p);
|
||||
void LCD12864_ShowNum(uint8_t num);
|
||||
void LCD12864_ShowxNum(uint8_t x, uint8_t y, uint32_t num, uint8_t len);
|
||||
void LCD12864_ShowSignal(uint8_t val);
|
||||
|
||||
#endif
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 YNHB *****END OF FILE*******************/
|
||||
Executable
+137
@@ -0,0 +1,137 @@
|
||||
/*************************** (C) COPYRIGHT 2017 YNHB ****************************
|
||||
* 文件名 :led.c
|
||||
* 描 述 :LED驱动代码
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/09/02
|
||||
*********************************************************************************/
|
||||
#include "led.h"
|
||||
#include "timer.h"
|
||||
|
||||
#define SYS_RUNNING_LED_PeriphClock RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO
|
||||
#define SYS_RUNNING_LED_PORT GPIOB
|
||||
#define SYS_RUNNING_LED_PORT_PIN GPIO_Pin_4
|
||||
|
||||
uint8_t ledON_OFF_Status = 0;
|
||||
uint8_t fillLightMask = 0;
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: LED_Init
|
||||
* 功能说明: 初始化LED灯接口
|
||||
* 形 参: 无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void LED_Init(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
|
||||
RCC_APB2PeriphClockCmd(SYS_RUNNING_LED_PeriphClock, ENABLE);
|
||||
|
||||
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable , ENABLE);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = SYS_RUNNING_LED_PORT_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(SYS_RUNNING_LED_PORT, &GPIO_InitStructure);
|
||||
|
||||
GPIO_SetBits(SYS_RUNNING_LED_PORT, SYS_RUNNING_LED_PORT_PIN);
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: SetLedOn
|
||||
* 功能说明: 点亮LED灯
|
||||
* 形 参: 无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void SetLedOn(void)
|
||||
{
|
||||
GPIO_ResetBits(SYS_RUNNING_LED_PORT, SYS_RUNNING_LED_PORT_PIN);
|
||||
ledON_OFF_Status = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: SetLedOff
|
||||
* 功能说明: 熄灭LED灯
|
||||
* 形 参: 无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void SetLedOff(void)
|
||||
{
|
||||
GPIO_SetBits(SYS_RUNNING_LED_PORT, SYS_RUNNING_LED_PORT_PIN);
|
||||
ledON_OFF_Status = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: SetLedToggle
|
||||
* 功能说明: LED灯反转
|
||||
* 形 参: 无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void SetLedToggle(void)
|
||||
{
|
||||
if(ledON_OFF_Status)
|
||||
{
|
||||
SetLedOff();
|
||||
}else{
|
||||
SetLedOn();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: LED_Task
|
||||
* 功能说明: LED灯运行状态指示灯
|
||||
* 形 参: 无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void LED_Task(void)
|
||||
{
|
||||
static uint8_t ledStatus = 0;
|
||||
|
||||
static timer ledOnTimer;
|
||||
static timer ledOffTimer;
|
||||
static uint8_t timer_ok = 0;
|
||||
|
||||
if(timer_ok == 0)
|
||||
{
|
||||
timer_ok = 1;
|
||||
timer_set(&ledOnTimer, 1);
|
||||
timer_set(&ledOffTimer, 19);
|
||||
}
|
||||
|
||||
switch(ledStatus)
|
||||
{
|
||||
case 0x00:
|
||||
SetLedOff();
|
||||
if(timer_expired(&ledOffTimer))
|
||||
{
|
||||
timer_restart(&ledOnTimer);
|
||||
ledStatus = 0x01;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x01:
|
||||
SetLedOn();
|
||||
if(timer_expired(&ledOnTimer))
|
||||
{
|
||||
timer_restart(&ledOffTimer);
|
||||
ledStatus = 0x00;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
ledStatus = 0x00;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 YNHB *****END OF FILE*******************/
|
||||
Executable
+24
@@ -0,0 +1,24 @@
|
||||
/*************************** (C) COPYRIGHT 2017 YNHB ****************************
|
||||
* 文件名 :led.h
|
||||
* 描 述 :LED驱动代码
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/09/02
|
||||
*********************************************************************************/
|
||||
#ifndef __LED_H
|
||||
#define __LED_H
|
||||
|
||||
#include "stm32f10x.h"
|
||||
|
||||
extern uint8_t fillLightMask;
|
||||
|
||||
void LED_Init(void); //初始化
|
||||
void SetLedOn(void);
|
||||
void SetLedOff(void);
|
||||
|
||||
void SetLedToggle(void);
|
||||
void LED_Task(void);
|
||||
|
||||
#endif
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 YNHB *****END OF FILE*******************/
|
||||
+1469
File diff suppressed because it is too large
Load Diff
+26
@@ -0,0 +1,26 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :door_ctrl.h
|
||||
* 描 述 :投放口控制程序
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/03/06
|
||||
*********************************************************************************/
|
||||
#ifndef __DOOR_CTRL_H
|
||||
#define __DOOR_CTRL_H
|
||||
|
||||
#include "stm32f10x.h"
|
||||
#include "stdio.h"
|
||||
|
||||
extern uint8_t doorResetMark; //门复位状态
|
||||
|
||||
void OpenDoorControlTask(void);
|
||||
|
||||
uint8_t DoorReset_1(void);
|
||||
uint8_t DoorReset_2(void);
|
||||
uint8_t DoorReset_3(void);
|
||||
uint8_t DoorReset_4(void);
|
||||
void DoorResetTask(void);
|
||||
|
||||
#endif
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 YNHB *****END OF FILE*******************/
|
||||
+474
@@ -0,0 +1,474 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :motor.c
|
||||
* 描 述 :电机控制程序
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/03/06
|
||||
*********************************************************************************/
|
||||
#include "motor.h"
|
||||
#include "delay.h"
|
||||
#include "timer.h"
|
||||
#include "adc.h"
|
||||
#include "my_math.h"
|
||||
#include "device.h"
|
||||
|
||||
//电机使用的IO口定义
|
||||
#define MOTOR1_PORT_PeriphClock_A RCC_APB2Periph_GPIOB
|
||||
#define MOTOR1_PORT_A GPIOB
|
||||
#define MOTOR1_CTRL_PIN_A GPIO_Pin_15
|
||||
#define MOTOR1_PORT_PeriphClock_B RCC_APB2Periph_GPIOC
|
||||
#define MOTOR1_PORT_B GPIOC
|
||||
#define MOTOR1_CTRL_PIN_B GPIO_Pin_6
|
||||
|
||||
#define MOTOR2_PORT_PeriphClock_A RCC_APB2Periph_GPIOC
|
||||
#define MOTOR2_PORT_A GPIOC
|
||||
#define MOTOR2_CTRL_PIN_A GPIO_Pin_7
|
||||
#define MOTOR2_PORT_PeriphClock_B RCC_APB2Periph_GPIOC
|
||||
#define MOTOR2_PORT_B GPIOC
|
||||
#define MOTOR2_CTRL_PIN_B GPIO_Pin_8
|
||||
|
||||
#define MOTOR3_PORT_PeriphClock_A RCC_APB2Periph_GPIOC
|
||||
#define MOTOR3_PORT_A GPIOC
|
||||
#define MOTOR3_CTRL_PIN_A GPIO_Pin_9
|
||||
#define MOTOR3_PORT_PeriphClock_B RCC_APB2Periph_GPIOA
|
||||
#define MOTOR3_PORT_B GPIOA
|
||||
#define MOTOR3_CTRL_PIN_B GPIO_Pin_8
|
||||
|
||||
#define MOTOR4_PORT_PeriphClock_A RCC_APB2Periph_GPIOA
|
||||
#define MOTOR4_PORT_A GPIOA
|
||||
#define MOTOR4_CTRL_PIN_A GPIO_Pin_11
|
||||
#define MOTOR4_PORT_PeriphClock_B RCC_APB2Periph_GPIOA
|
||||
#define MOTOR4_PORT_B GPIOA
|
||||
#define MOTOR4_CTRL_PIN_B GPIO_Pin_12
|
||||
|
||||
|
||||
#define CurrentValSize 50
|
||||
uint16_t motorCurrentValBuf_1[CurrentValSize];
|
||||
uint16_t motorCurrentVal_1 = 0;
|
||||
uint8_t motorRunningStatus_1 = 0;
|
||||
uint8_t motorPreStatus_1 = 0;
|
||||
|
||||
uint16_t motorCurrentValBuf_2[CurrentValSize];
|
||||
uint16_t motorCurrentVal_2 = 0;
|
||||
uint8_t motorRunningStatus_2 = 0;
|
||||
uint8_t motorPreStatus_2 = 0;
|
||||
|
||||
uint8_t motorRunningStatus_3 = 0;
|
||||
uint8_t motorRunningStatus_4 = 0;
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: MotorInit
|
||||
* 功能说明: 电机控制IO口初始化
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void MotorInit(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
|
||||
RCC_APB2PeriphClockCmd(MOTOR1_PORT_PeriphClock_A, ENABLE);
|
||||
RCC_APB2PeriphClockCmd(MOTOR1_PORT_PeriphClock_B, ENABLE);
|
||||
RCC_APB2PeriphClockCmd(MOTOR2_PORT_PeriphClock_A, ENABLE);
|
||||
RCC_APB2PeriphClockCmd(MOTOR2_PORT_PeriphClock_B, ENABLE);
|
||||
RCC_APB2PeriphClockCmd(MOTOR3_PORT_PeriphClock_A, ENABLE);
|
||||
RCC_APB2PeriphClockCmd(MOTOR3_PORT_PeriphClock_B, ENABLE);
|
||||
RCC_APB2PeriphClockCmd(MOTOR4_PORT_PeriphClock_A, ENABLE);
|
||||
RCC_APB2PeriphClockCmd(MOTOR4_PORT_PeriphClock_B, ENABLE);
|
||||
|
||||
//电机1动作控制IO口初始化
|
||||
GPIO_InitStructure.GPIO_Pin = MOTOR1_CTRL_PIN_A;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(MOTOR1_PORT_A, &GPIO_InitStructure);
|
||||
GPIO_ResetBits(MOTOR1_PORT_A, MOTOR1_CTRL_PIN_A);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = MOTOR1_CTRL_PIN_B;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(MOTOR1_PORT_B, &GPIO_InitStructure);
|
||||
GPIO_ResetBits(MOTOR1_PORT_B, MOTOR1_CTRL_PIN_B);
|
||||
|
||||
//电机2动作控制IO口初始化
|
||||
GPIO_InitStructure.GPIO_Pin = MOTOR2_CTRL_PIN_A;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(MOTOR2_PORT_A, &GPIO_InitStructure);
|
||||
GPIO_ResetBits(MOTOR2_PORT_A, MOTOR2_CTRL_PIN_A);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = MOTOR2_CTRL_PIN_B;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(MOTOR2_PORT_B, &GPIO_InitStructure);
|
||||
GPIO_ResetBits(MOTOR2_PORT_B, MOTOR2_CTRL_PIN_B);
|
||||
|
||||
//电机3动作控制IO口初始化
|
||||
GPIO_InitStructure.GPIO_Pin = MOTOR3_CTRL_PIN_A;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(MOTOR3_PORT_A, &GPIO_InitStructure);
|
||||
GPIO_ResetBits(MOTOR3_PORT_A, MOTOR3_CTRL_PIN_A);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = MOTOR3_CTRL_PIN_B;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(MOTOR3_PORT_B, &GPIO_InitStructure);
|
||||
GPIO_ResetBits(MOTOR3_PORT_B, MOTOR3_CTRL_PIN_B);
|
||||
|
||||
//电机4动作控制IO口初始化
|
||||
GPIO_InitStructure.GPIO_Pin = MOTOR4_CTRL_PIN_A;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(MOTOR4_PORT_A, &GPIO_InitStructure);
|
||||
GPIO_ResetBits(MOTOR4_PORT_A, MOTOR4_CTRL_PIN_A);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = MOTOR4_CTRL_PIN_B;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(MOTOR4_PORT_B, &GPIO_InitStructure);
|
||||
GPIO_ResetBits(MOTOR4_PORT_B, MOTOR4_CTRL_PIN_B);
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: DoorOpen
|
||||
* 功能说明: 开门
|
||||
* 形 参:num -> 哪一个门
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void DoorOpen(uint8_t num)
|
||||
{
|
||||
printf("\r\n电机(%d)正转!\r\n", num);
|
||||
switch(num)
|
||||
{
|
||||
case 0x01:
|
||||
GPIO_ResetBits(MOTOR1_PORT_A, MOTOR1_CTRL_PIN_A);
|
||||
GPIO_SetBits(MOTOR1_PORT_B, MOTOR1_CTRL_PIN_B);
|
||||
motorRunningStatus_1 = 1;
|
||||
break;
|
||||
|
||||
case 0x02:
|
||||
GPIO_ResetBits(MOTOR2_PORT_A, MOTOR2_CTRL_PIN_A);
|
||||
GPIO_SetBits(MOTOR2_PORT_B, MOTOR2_CTRL_PIN_B);
|
||||
motorRunningStatus_2 = 1;
|
||||
break;
|
||||
|
||||
case 0x03:
|
||||
GPIO_ResetBits(MOTOR3_PORT_A, MOTOR3_CTRL_PIN_A);
|
||||
GPIO_SetBits(MOTOR3_PORT_B, MOTOR3_CTRL_PIN_B);
|
||||
motorRunningStatus_3 = 1;
|
||||
break;
|
||||
|
||||
case 0x04:
|
||||
GPIO_ResetBits(MOTOR4_PORT_A, MOTOR4_CTRL_PIN_A);
|
||||
GPIO_SetBits(MOTOR4_PORT_B, MOTOR4_CTRL_PIN_B);
|
||||
motorRunningStatus_4 = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: DoorClose
|
||||
* 功能说明: 关门
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void DoorClose(uint8_t num)
|
||||
{
|
||||
printf("\r\n电机(%d)反转!\r\n", num);
|
||||
switch(num)
|
||||
{
|
||||
case 0x01:
|
||||
GPIO_SetBits(MOTOR1_PORT_A, MOTOR1_CTRL_PIN_A);
|
||||
GPIO_ResetBits(MOTOR1_PORT_B, MOTOR1_CTRL_PIN_B);
|
||||
motorRunningStatus_1 = 2;
|
||||
break;
|
||||
|
||||
case 0x02:
|
||||
GPIO_SetBits(MOTOR2_PORT_A, MOTOR2_CTRL_PIN_A);
|
||||
GPIO_ResetBits(MOTOR2_PORT_B, MOTOR2_CTRL_PIN_B);
|
||||
motorRunningStatus_2 = 2;
|
||||
break;
|
||||
|
||||
case 0x03:
|
||||
GPIO_SetBits(MOTOR3_PORT_A, MOTOR3_CTRL_PIN_A);
|
||||
GPIO_ResetBits(MOTOR3_PORT_B, MOTOR3_CTRL_PIN_B);
|
||||
motorRunningStatus_3 = 2;
|
||||
break;
|
||||
|
||||
case 0x04:
|
||||
GPIO_SetBits(MOTOR4_PORT_A, MOTOR4_CTRL_PIN_A);
|
||||
GPIO_ResetBits(MOTOR4_PORT_B, MOTOR4_CTRL_PIN_B);
|
||||
motorRunningStatus_4 = 2;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: DoorStop
|
||||
* 功能说明: 停止
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void DoorStop(uint8_t num)
|
||||
{
|
||||
switch(num)
|
||||
{
|
||||
case 0x01:
|
||||
GPIO_ResetBits(MOTOR1_PORT_A, MOTOR1_CTRL_PIN_A);
|
||||
GPIO_ResetBits(MOTOR1_PORT_B, MOTOR1_CTRL_PIN_B);
|
||||
|
||||
if(motorRunningStatus_1 > 0) //原来状态由转动变成停止才打印显示
|
||||
{
|
||||
printf("\r\n电机(%d)停止!\r\n", num);
|
||||
}
|
||||
motorRunningStatus_1 = 0;
|
||||
break;
|
||||
|
||||
case 0x02:
|
||||
GPIO_ResetBits(MOTOR2_PORT_A, MOTOR2_CTRL_PIN_A);
|
||||
GPIO_ResetBits(MOTOR2_PORT_B, MOTOR2_CTRL_PIN_B);
|
||||
|
||||
if(motorRunningStatus_2 > 0) //原来状态由转动变成停止才打印显示
|
||||
{
|
||||
printf("\r\n电机(%d)停止!\r\n", num);
|
||||
}
|
||||
motorRunningStatus_2 = 0;
|
||||
break;
|
||||
|
||||
case 0x03:
|
||||
GPIO_ResetBits(MOTOR3_PORT_A, MOTOR3_CTRL_PIN_A);
|
||||
GPIO_ResetBits(MOTOR3_PORT_B, MOTOR3_CTRL_PIN_B);
|
||||
|
||||
if(motorRunningStatus_3 > 0) //原来状态由转动变成停止才打印显示
|
||||
{
|
||||
printf("\r\n电机(%d)停止!\r\n", num);
|
||||
}
|
||||
motorRunningStatus_3 = 0;
|
||||
break;
|
||||
|
||||
case 0x04:
|
||||
GPIO_ResetBits(MOTOR4_PORT_A, MOTOR4_CTRL_PIN_A);
|
||||
GPIO_ResetBits(MOTOR4_PORT_B, MOTOR4_CTRL_PIN_B);
|
||||
|
||||
if(motorRunningStatus_4 > 0) //原来状态由转动变成停止才打印显示
|
||||
{
|
||||
printf("\r\n电机(%d)停止!\r\n", num);
|
||||
}
|
||||
motorRunningStatus_4 = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: Get_MotorCurrentVal
|
||||
* 功能说明: 获取电机1电流采样数据
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void Get_MotorCurrentVal_1(void)
|
||||
{
|
||||
Data_collection(motorCurrentValBuf_1, CurrentValSize, ADC_Channel_8);
|
||||
sort_16(motorCurrentValBuf_1, CurrentValSize); //对存在缓存中的采集数据进行排序
|
||||
motorCurrentVal_1 = average_16(motorCurrentValBuf_1, CurrentValSize, 20); //去掉头和尾后,求平均数
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: Get_MotorCurrentVal
|
||||
* 功能说明: 获取电机2电流采样数据
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void Get_MotorCurrentVal_2(void)
|
||||
{
|
||||
Data_collection(motorCurrentValBuf_2, CurrentValSize, ADC_Channel_9);
|
||||
sort_16(motorCurrentValBuf_2, CurrentValSize); //对存在缓存中的采集数据进行排序
|
||||
motorCurrentVal_2 = average_16(motorCurrentValBuf_2, CurrentValSize, 20); //去掉头和尾后,求平均数
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: Get_MotorCurrentVal
|
||||
* 功能说明: 获取电机电流采样数据
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void Get_MotorCurrentVal(void)
|
||||
{
|
||||
Get_MotorCurrentVal_1();
|
||||
Get_MotorCurrentVal_2();
|
||||
// printf("%4d, %4d\r\n", motorCurrentVal_1, motorCurrentVal_2);
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: MotorTest
|
||||
* 功能说明: 电机控制测试程序
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void MotorTest(void)
|
||||
{
|
||||
static uint8_t motorNum = 1;
|
||||
static uint8_t motorStatus = 0;
|
||||
|
||||
static timer timer_01, timer_02;
|
||||
static uint8_t timer_ok = 0;
|
||||
|
||||
if(timer_ok == 0)
|
||||
{
|
||||
timer_ok = 1;
|
||||
timer_set(&timer_01, 20);
|
||||
timer_set(&timer_02, CLOCK_SECOND*2);
|
||||
}
|
||||
switch(motorStatus)
|
||||
{
|
||||
case 0x00:
|
||||
if(timer_expired(&timer_01))
|
||||
{
|
||||
DoorOpen(motorNum);
|
||||
timer_restart(&timer_01);
|
||||
motorStatus = 0x01;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x01:
|
||||
if(timer_expired(&timer_01))
|
||||
{
|
||||
DoorStop(motorNum);
|
||||
timer_restart(&timer_02);
|
||||
motorStatus = 0x02;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x02:
|
||||
if(timer_expired(&timer_02))
|
||||
{
|
||||
DoorClose(motorNum);
|
||||
timer_restart(&timer_01);
|
||||
motorStatus = 0x03;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x03:
|
||||
if(timer_expired(&timer_01))
|
||||
{
|
||||
DoorStop(motorNum);
|
||||
timer_restart(&timer_02);
|
||||
motorStatus = 0x04;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x04:
|
||||
if(timer_expired(&timer_02))
|
||||
{
|
||||
motorNum++;
|
||||
if(motorNum >= 5)
|
||||
{
|
||||
motorNum = 1;
|
||||
}
|
||||
motorStatus = 0x00;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: Get_MotorCurrentVal
|
||||
* 功能说明: 获取电机电流采样数据
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void MotorCtrlTask2(void)
|
||||
{
|
||||
static timer timer_01, timer_02;
|
||||
static uint8_t timer_ok = 0;
|
||||
static uint8_t motorStatus = 0;
|
||||
|
||||
if(timer_ok == 0)
|
||||
{
|
||||
timer_ok = 1;
|
||||
timer_set(&timer_01, 1);
|
||||
timer_set(&timer_02, CLOCK_SECOND*2);
|
||||
}
|
||||
switch(motorStatus)
|
||||
{
|
||||
case 0x00:
|
||||
if(motorRunningStatus_2)
|
||||
{
|
||||
motorStatus = 0x01;
|
||||
timer_restart(&timer_01);
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x01:
|
||||
if(timer_expired(&timer_01))
|
||||
{
|
||||
motorStatus = 0x02;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x02:
|
||||
if(motorCurrentVal_2 > 600)
|
||||
{
|
||||
motorPreStatus_2 = motorRunningStatus_2;
|
||||
motorRunningStatus_2 = 0;
|
||||
motorStatus = 0x03;
|
||||
timer_restart(&timer_02);
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x03:
|
||||
if(timer_expired(&timer_02))
|
||||
{
|
||||
if(motorPreStatus_2 == 1)
|
||||
{
|
||||
motorRunningStatus_2 = 2;
|
||||
}else{
|
||||
motorRunningStatus_2 = 1;
|
||||
}
|
||||
motorStatus = 0x00;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if(motorRunningStatus_2 == 0)
|
||||
{
|
||||
DoorStop(2);
|
||||
}else if(motorRunningStatus_2 == 1){
|
||||
DoorClose(2);
|
||||
}else{
|
||||
DoorOpen(2);
|
||||
}
|
||||
}
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 ping *****END OF FILE*******************/
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :motor.h
|
||||
* 描 述 :电机控制程序
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/03/06
|
||||
*********************************************************************************/
|
||||
#ifndef __MOTOR_H
|
||||
#define __MOTOR_H
|
||||
|
||||
#include "stm32f10x.h"
|
||||
|
||||
#define M1_OPEN_MAX_CurrentVal 3000
|
||||
#define M1_CLOSE_MAX_CurrentVal 3000
|
||||
|
||||
#define M2_OPEN_MAX_CurrentVal 3000
|
||||
#define M2_CLOSE_MAX_CurrentVal 3000
|
||||
|
||||
extern uint16_t motorCurrentVal_1;
|
||||
extern uint8_t motorRunningStatus_1;
|
||||
|
||||
extern uint16_t motorCurrentVal_2;
|
||||
extern uint8_t motorRunningStatus_2;
|
||||
|
||||
extern uint8_t motorRunningStatus_3;
|
||||
extern uint8_t motorRunningStatus_4;
|
||||
|
||||
void MotorInit(void);
|
||||
void DoorOpen(uint8_t num);
|
||||
void DoorClose(uint8_t num);
|
||||
void DoorStop(uint8_t num);
|
||||
|
||||
void Get_MotorCurrentVal(void);
|
||||
|
||||
void MotorTest(void);
|
||||
|
||||
#endif
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 YNHB *****END OF FILE*******************/
|
||||
+113
@@ -0,0 +1,113 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :adc.c
|
||||
* 描 述 :ADC驱动程序
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/04/30
|
||||
*********************************************************************************/
|
||||
#include "adc.h"
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: Adc_Init
|
||||
* 功能说明: 初始化ADC
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void Adc_Init(void)
|
||||
{
|
||||
ADC_InitTypeDef ADC_InitStructure;
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOC | RCC_APB2Periph_ADC1, ENABLE); //使能ADC1通道时钟
|
||||
|
||||
RCC_ADCCLKConfig(RCC_PCLK2_Div6); //72M/6=12,ADC最大时间不能超过14M
|
||||
|
||||
//外部温度检测
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; //模拟输入引脚
|
||||
GPIO_Init(GPIOC, &GPIO_InitStructure);
|
||||
|
||||
//主板温度检测
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; //模拟输入引脚
|
||||
GPIO_Init(GPIOA, &GPIO_InitStructure);
|
||||
|
||||
//电机电流检测
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; //模拟输入引脚
|
||||
GPIO_Init(GPIOB, &GPIO_InitStructure);
|
||||
|
||||
//红外测距ADC引脚
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; //模拟输入引脚
|
||||
GPIO_Init(GPIOC, &GPIO_InitStructure);
|
||||
|
||||
ADC_DeInit(ADC1); //将外设 ADC1 的全部寄存器重设为缺省值
|
||||
|
||||
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; //ADC工作模式:ADC1和ADC2工作在独立模式
|
||||
ADC_InitStructure.ADC_ScanConvMode = DISABLE; //模数转换工作在单通道模式
|
||||
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; //模数转换工作在单次转换模式
|
||||
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; //转换由软件而不是外部触发启动
|
||||
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; //ADC数据右对齐
|
||||
ADC_InitStructure.ADC_NbrOfChannel = 1; //顺序进行规则转换的ADC通道的数目
|
||||
ADC_Init(ADC1, &ADC_InitStructure); //根据ADC_InitStruct中指定的参数初始化外设ADCx的寄存器
|
||||
|
||||
|
||||
ADC_Cmd(ADC1, ENABLE); //使能指定的ADC1
|
||||
|
||||
ADC_ResetCalibration(ADC1); //重置指定的ADC1的校准寄存器
|
||||
|
||||
while(ADC_GetResetCalibrationStatus(ADC1)); //获取ADC1重置校准寄存器的状态,设置状态则等待
|
||||
|
||||
ADC_StartCalibration(ADC1); //开始指定ADC1的校准状态
|
||||
|
||||
while(ADC_GetCalibrationStatus(ADC1)); //获取指定ADC1的校准程序,设置状态则等待
|
||||
|
||||
ADC_SoftwareStartConvCmd(ADC1, ENABLE); //使能指定的ADC1的软件转换启动功能
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: Get_Adc
|
||||
* 功能说明: 获得ADC值
|
||||
* 形 参:ch:通道值 0~3
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
uint16_t GetADC(uint8_t ch)
|
||||
{
|
||||
//设置指定ADC的规则组通道,设置它们的转化顺序和采样时间
|
||||
ADC_RegularChannelConfig(ADC1, ch, 1, ADC_SampleTime_28Cycles5);
|
||||
// ADC_RegularChannelConfig(ADC1, ch, 1, ADC_SampleTime_239Cycles5 ); //ADC1,ADC通道3,规则采样顺序值为1,采样时间为239.5周期
|
||||
|
||||
ADC_SoftwareStartConvCmd(ADC1, ENABLE); //使能指定的ADC1的软件转换启动功能
|
||||
|
||||
while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC)); //等待转换结束
|
||||
|
||||
return ADC_GetConversionValue(ADC1); //返回最近一次ADC1规则组的转换结果
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: Data_collection
|
||||
* 功能说明: 数据采集
|
||||
* 形 参:
|
||||
* x[]:需要处理的数组
|
||||
* n:采集的次数
|
||||
* ch:需采集的通道
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void Data_collection(uint16_t x[], uint16_t n, uint8_t ch)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
for(i=0; i<n; i++)
|
||||
{
|
||||
x[i] = GetADC(ch); //采样数据送缓存
|
||||
}
|
||||
}
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 CXHY *****END OF FILE*******************/
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :adc.j
|
||||
* 描 述 :ADC驱动程序
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/04/30
|
||||
*********************************************************************************/
|
||||
#ifndef __ADC_H
|
||||
#define __ADC_H
|
||||
#include "stm32f10x.h"
|
||||
|
||||
void Adc_Init(void);
|
||||
uint16_t GetADC(uint8_t ch);
|
||||
void Data_collection(uint16_t x[], uint16_t n, uint8_t ch);
|
||||
|
||||
#endif
|
||||
/******************** (C) COPYRIGHT 2017 CXHY *****END OF FILE*******************/
|
||||
+149
@@ -0,0 +1,149 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :ntc.c
|
||||
* 描 述 :NTC热敏电阻温度传感器处理程序
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/04/30
|
||||
*********************************************************************************/
|
||||
#include "ntc.h"
|
||||
#include "my_math.h"
|
||||
#include "timer.h"
|
||||
#include "delay.h"
|
||||
#include "ntc_10K_tab.h"
|
||||
#include "usart2.h"
|
||||
|
||||
#define ADC_SIZE 20 //一次采集几次AD值
|
||||
#define FILTER_SIZE 10 //滤波深度
|
||||
|
||||
uint16_t adc_buf[ADC_SIZE]; //用于ADC采集缓存数据
|
||||
|
||||
|
||||
uint16_t NTC1_value = 0;
|
||||
uint16_t NTC2_value = 0;
|
||||
uint16_t NTC3_value = 0; //各通道采集处理后的数值
|
||||
|
||||
uint8_t temperature = 0; //温度
|
||||
uint8_t temperature_A = 0; //A路温度
|
||||
uint8_t temperature_B = 0; //B路温度
|
||||
uint8_t temperature_C = 0; //C路温度
|
||||
|
||||
uint8_t fanRunningStatus = 0; //风扇运转状态
|
||||
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: data_input
|
||||
* 功能说明: 采集n次数据并对其进行排序后求平均数处理
|
||||
* 形 参:
|
||||
* x[]:需要处理的数组
|
||||
* n: 采集的次数
|
||||
* ch: 需采集的通道
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
uint16_t data_input(uint16_t *p, uint16_t n, uint8_t ch)
|
||||
{
|
||||
uint16_t x;
|
||||
Data_collection(p, n, ch); //连续采集n次数据,暂存到P指定的地方
|
||||
sort_16(p, n); //对存在缓存中的采集数据进行排序
|
||||
x = average_16(p, n, 2); //去掉头和尾后,求平均数
|
||||
return x;
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: filter
|
||||
* 功能说明: 数据滤波处理
|
||||
* 形 参:
|
||||
* value -> 需要滤波的值
|
||||
* ch -> 需采集的通道
|
||||
* 返 回 值: 滤波后的结果
|
||||
***********************************************************************
|
||||
*/
|
||||
uint16_t filter(uint16_t value, uint8_t ch)
|
||||
{
|
||||
uint8_t count=0;
|
||||
uint16_t new_value;
|
||||
new_value = data_input(adc_buf, ADC_SIZE, ch);
|
||||
while (value != new_value)
|
||||
{
|
||||
count++;
|
||||
if (count >= FILTER_SIZE) return new_value;
|
||||
new_value = data_input(adc_buf, ADC_SIZE, ch);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: Get_NTC_values
|
||||
* 功能说明: 获取AD8,AD9采集处理后的数据
|
||||
* 形 参:
|
||||
* 返 回 值:
|
||||
***********************************************************************
|
||||
*/
|
||||
void Get_NTC_values(void)
|
||||
{
|
||||
NTC1_value = filter(NTC1_value, ADC_Channel_14);
|
||||
NTC2_value = filter(NTC2_value, ADC_Channel_15);
|
||||
NTC3_value = filter(NTC3_value, ADC_Channel_4);
|
||||
// printf("\r\nNTC1_value = %d NTC2_value = %d\r\n", NTC1_value, NTC2_value);
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: GetTemperatureTask
|
||||
* 功能说明: 温度采集任务
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void GetTemperatureTask(void)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
static timer getTemperatureTimer; //距离采集时间间隔
|
||||
static timer waitingTimer;
|
||||
|
||||
static uint8_t timer_ok = 0;
|
||||
if(timer_ok == 0)
|
||||
{
|
||||
timer_ok = 1;
|
||||
timer_set(&getTemperatureTimer, CLOCK_SECOND*10);
|
||||
timer_set(&waitingTimer, CLOCK_SECOND*30);
|
||||
}
|
||||
|
||||
if(timer_expired(&getTemperatureTimer)) //每10S采集一次温度
|
||||
{
|
||||
timer_restart(&getTemperatureTimer);
|
||||
|
||||
|
||||
// if((temperature_A > 0) || (temperature_B > 0) || (temperature_C > 0))
|
||||
// {
|
||||
// printf("\r\n温度:No1 = %2.1f ℃, No2 = %2.1f ℃, No3 = %2.1f ℃, Out = %2.1f ℃\r\n", (float)temperature_A, (float)temperature_B, (float)temperature_C, (float)temperature);
|
||||
// }
|
||||
|
||||
// printf("\r\n主板温度:%2.1f ℃\r\n", (float)temperature_C);
|
||||
|
||||
}
|
||||
|
||||
if(temperature_A > temperature_B){
|
||||
temperature = temperature_A;
|
||||
}else{
|
||||
temperature = temperature_B;
|
||||
}
|
||||
|
||||
if(temperature < temperature_C)
|
||||
{
|
||||
temperature = temperature_C;
|
||||
}
|
||||
|
||||
if(timer_expired(&waitingTimer))
|
||||
{
|
||||
timer_restart(&waitingTimer);
|
||||
|
||||
printf("\r\n主板温度:%2.1f ℃\r\n", (float)temperature);
|
||||
}
|
||||
}
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 CXHY *****END OF FILE*******************/
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :ntc.h
|
||||
* 描 述 :NTC热敏电阻温度传感器处理程序头文件
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/04/30
|
||||
*********************************************************************************/
|
||||
#ifndef __ADC_INPUT_h
|
||||
#define __ADC_INPUT_h
|
||||
|
||||
#include "adc.h"
|
||||
|
||||
extern uint16_t NTC1_value, NTC2_value; //各通道采集处理后的数值
|
||||
|
||||
extern uint8_t temperature; //温度
|
||||
extern uint8_t temperature_A; //A路温度
|
||||
extern uint8_t temperature_B; //B路温度
|
||||
extern uint8_t temperature_C; //B路温度
|
||||
|
||||
|
||||
void Get_NTC_values(void); //获取传感器采集到的数据
|
||||
void GetTemperatureTask(void); //温度采集任务
|
||||
|
||||
#endif
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 CXHY *****END OF FILE*******************/
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :ntc_10K_tab.h
|
||||
* 描 述 :NTC热敏电阻对应ADC值表
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/04/30
|
||||
*********************************************************************************/
|
||||
#ifndef __NTC_10K_TAB_h
|
||||
#define __NTC_10K_TAB_h
|
||||
|
||||
#include "stdint.h"
|
||||
|
||||
#define TempSize 100 //定义表长度
|
||||
|
||||
const uint16_t TabNTC_10K[TempSize] =
|
||||
{
|
||||
2548,2498,2448,2398,2348,2297,2247,2197,2147,2097,
|
||||
2047,1998,1949,1900,1852,1805,1758,1711,1666,1620,
|
||||
1576,1532,1489,1447,1406,1365,1326,1287,1249,1212,
|
||||
1175,1140,1105,1072,1039,1007, 976, 945, 916, 887,
|
||||
859, 833, 806, 781, 756, 732, 709, 686, 665, 644,
|
||||
623, 603, 584, 565, 547, 530, 513, 497, 481, 466,
|
||||
451, 437, 423, 410, 397, 385, 372, 361, 350, 339,
|
||||
328, 318, 308, 299, 289, 281, 272, 264, 256, 248,
|
||||
241, 233, 226, 220, 213, 207, 201, 195, 189, 183,
|
||||
178, 173, 168, 163, 158, 154, 150, 145, 141, 137
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 CXHY *****END OF FILE*******************/
|
||||
+367
@@ -0,0 +1,367 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :opto_sw_key.c
|
||||
* 描 述 :光电开关驱动程序
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/03/06
|
||||
*********************************************************************************/
|
||||
#include "opto_sw_key.h"
|
||||
#include "delay.h"
|
||||
#include "timer.h"
|
||||
#include "device.h"
|
||||
#include "data_typedef.h"
|
||||
|
||||
//红外光电开关
|
||||
#define OPTO_KEY1_PORT GPIOA
|
||||
#define OPTO_KEY1_PIN GPIO_Pin_8
|
||||
|
||||
#define OPTO_KEY2_PORT GPIOB
|
||||
#define OPTO_KEY2_PIN GPIO_Pin_7
|
||||
|
||||
#define OPTO_KEY3_PORT GPIOD
|
||||
#define OPTO_KEY3_PIN GPIO_Pin_0
|
||||
|
||||
#define OPTO_KEY4_PORT GPIOD
|
||||
#define OPTO_KEY4_PIN GPIO_Pin_3
|
||||
|
||||
|
||||
uint8_t optoKeyValue1 = 0; //红外光电开关键值
|
||||
uint8_t optoKeyValue2 = 0; //红外光电开关键值
|
||||
uint8_t optoKeyValue3 = 0; //红外光电开关键值
|
||||
uint8_t optoKeyValue4 = 0; //红外光电开关键值
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: OptoKeyInit
|
||||
* 功能说明: 红外光电开关IO口初始化
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void OptoKeyInit(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA |
|
||||
RCC_APB2Periph_GPIOB |
|
||||
RCC_APB2Periph_GPIOD, ENABLE); //使能PORTA时钟
|
||||
|
||||
//第一路红外光电开关IO口配置
|
||||
GPIO_InitStructure.GPIO_Pin = OPTO_KEY1_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
|
||||
GPIO_Init(OPTO_KEY1_PORT, &GPIO_InitStructure);
|
||||
|
||||
//第二路红外光电开关IO口配置
|
||||
GPIO_InitStructure.GPIO_Pin = OPTO_KEY2_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
|
||||
GPIO_Init(OPTO_KEY2_PORT, &GPIO_InitStructure);
|
||||
|
||||
//第三路红外光电开关IO口配置
|
||||
GPIO_InitStructure.GPIO_Pin = OPTO_KEY3_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
|
||||
GPIO_Init(OPTO_KEY3_PORT, &GPIO_InitStructure);
|
||||
|
||||
//第四路红外光电开关IO口配置
|
||||
GPIO_InitStructure.GPIO_Pin = OPTO_KEY4_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
|
||||
GPIO_Init(OPTO_KEY4_PORT, &GPIO_InitStructure);
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: OptoKeysCanning
|
||||
* 功能说明: 红外光电开关检测
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void OptoKeysCanning(void)
|
||||
{
|
||||
static uint8_t key1_state = 0;
|
||||
static uint8_t key2_state = 0;
|
||||
|
||||
//第1路红外光电开关检测
|
||||
switch (key1_state)
|
||||
{
|
||||
case 0x00:
|
||||
if(OPTO_KEY1 == 0)
|
||||
{
|
||||
key1_state = 0x01;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x01:
|
||||
if(OPTO_KEY1 == 0)
|
||||
{
|
||||
optoKeyValue1 = 1;
|
||||
}else{
|
||||
optoKeyValue1 = 0;
|
||||
key1_state = 0x00;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
key1_state = 0x00;
|
||||
break;
|
||||
}
|
||||
|
||||
//第2路红外光电开关检测
|
||||
switch (key2_state)
|
||||
{
|
||||
case 0x00:
|
||||
if(OPTO_KEY2 == 0)
|
||||
{
|
||||
key2_state = 0x01;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x01:
|
||||
if(OPTO_KEY2 == 0)
|
||||
{
|
||||
optoKeyValue2 = 1;
|
||||
}else{
|
||||
optoKeyValue2 = 0;
|
||||
key2_state = 0x00;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
key2_state = 0x00;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: BottleScanning
|
||||
* 功能说明: 瓶子投放扫描检测
|
||||
* 形 参:无
|
||||
* 返 回 值: 返回对应开关的键值
|
||||
***********************************************************************
|
||||
*/
|
||||
void BottleScanning(void)
|
||||
{
|
||||
static uint8_t bottleType = 0;
|
||||
static uint16_t count;
|
||||
static uint8_t testStatus = 0x00;
|
||||
|
||||
static timer timerOut;
|
||||
static timer waitingTimer;
|
||||
static timer wrongOperationTimer;
|
||||
|
||||
static uint8_t timer_ok = 0;
|
||||
|
||||
if(timer_ok == 0)
|
||||
{
|
||||
timer_ok = 1;
|
||||
timer_set(&timerOut, 4);
|
||||
timer_set(&waitingTimer, CLOCK_SECOND*5);
|
||||
timer_set(&wrongOperationTimer, CLOCK_SECOND*3);
|
||||
}
|
||||
|
||||
switch(testStatus)
|
||||
{
|
||||
case 0x00:
|
||||
if((OPTO_KEY3 == 1) && (OPTO_KEY4 == 0))
|
||||
{
|
||||
// printf("\r\n错误操作\r\n");
|
||||
// printf("%d %d\r\n", OPTO_KEY3, OPTO_KEY4);
|
||||
timer_restart(&wrongOperationTimer);
|
||||
testStatus = 0x10;
|
||||
break;
|
||||
}
|
||||
if((OPTO_KEY3 == 0) && (OPTO_KEY4 == 1)) //检测到开始投瓶
|
||||
{
|
||||
// printf("\r\n开始投瓶\r\n");
|
||||
// printf("%d %d\r\n", OPTO_KEY3, OPTO_KEY4);
|
||||
timer_restart(&waitingTimer);
|
||||
testStatus = 0x01;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x01: //等待瓶子经过第一个检测探头
|
||||
if(timer_expired(&waitingTimer))
|
||||
{
|
||||
printf("\r\n0x01投放超时返回\r\n");
|
||||
testStatus = 0x00;
|
||||
break;
|
||||
}
|
||||
// if((OPTO_KEY3 == 0) || (OPTO_KEY4 == 0))
|
||||
// {
|
||||
// printf("%d %d\r\n", OPTO_KEY3, OPTO_KEY4);
|
||||
// }
|
||||
if((OPTO_KEY3 == 0) && (OPTO_KEY4 == 0)) //两个探头同时检测到瓶子说明为大瓶子
|
||||
{
|
||||
bottleType = 1; //标志为大瓶子
|
||||
}
|
||||
if((OPTO_KEY3 == 1) && (OPTO_KEY4 == 0)) //等待瓶子完全通过第一个探头
|
||||
{
|
||||
timer_restart(&waitingTimer);
|
||||
testStatus = 0x02;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x02: //检测瓶子完全通过两个探头(说明已经完整通过了通道)
|
||||
if(timer_expired(&waitingTimer))
|
||||
{
|
||||
printf("\r\n0x02投放超时返回\r\n");
|
||||
testStatus = 0x00;
|
||||
break;
|
||||
}
|
||||
|
||||
// if((OPTO_KEY3 == 0) || (OPTO_KEY4 == 0))
|
||||
// {
|
||||
// printf("%d %d\r\n", OPTO_KEY3, OPTO_KEY4);
|
||||
// }
|
||||
if((OPTO_KEY3 == 0) && (OPTO_KEY4 == 0)) //两个探头同时检测到瓶子说明为大瓶子
|
||||
{
|
||||
bottleType = 1; //标志为大瓶子
|
||||
}
|
||||
if((OPTO_KEY3 == 1) && (OPTO_KEY4 == 1))
|
||||
{
|
||||
timer_restart(&timerOut);
|
||||
timer_restart(&waitingTimer);
|
||||
testStatus = 0x03;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x03: //判断已经完全通过检测通道(相隔一小段时间后都没有检测到瓶子说明已经投放成功)
|
||||
if(timer_expired(&timerOut))
|
||||
{
|
||||
if(timer_expired(&waitingTimer))
|
||||
{
|
||||
printf("\r\n0x03投放超时返回\r\n");
|
||||
testStatus = 0x00;
|
||||
break;
|
||||
}
|
||||
|
||||
if((OPTO_KEY3 == 1) || (OPTO_KEY4 == 1)) //瓶子已经完全离开通道
|
||||
{
|
||||
printf("\r\n投放成功!!!\r\n");
|
||||
beep_shortBeepMark = 1;
|
||||
|
||||
//目前只按小瓶子来计算
|
||||
// if(bottleType)
|
||||
// {
|
||||
// bigBottleCount++;
|
||||
// }else{
|
||||
// smallBottleCount++;
|
||||
// }
|
||||
|
||||
smallBottleCount++;
|
||||
|
||||
// printf("\r\n大瓶子(数量:%d),小瓶子(数量:%d)\r\n", bigBottleCount, smallBottleCount);
|
||||
bottleType = 0;
|
||||
testStatus = 0x00;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x10: //错误操作
|
||||
if(timer_expired(&wrongOperationTimer))
|
||||
{
|
||||
testStatus = 0x00;
|
||||
printf("\r\nerror return!\r\n");
|
||||
break;
|
||||
}
|
||||
// if((OPTO_KEY3 == 0) || (OPTO_KEY4 == 0))
|
||||
// {
|
||||
// printf("%d %d\r\n", OPTO_KEY3, OPTO_KEY4);
|
||||
// }
|
||||
if((OPTO_KEY3 == 0) && (OPTO_KEY4 == 1))
|
||||
{
|
||||
testStatus = 0x11;
|
||||
timer_restart(&waitingTimer);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x11:
|
||||
if(timer_expired(&waitingTimer))
|
||||
{
|
||||
printf("\r\n0x11time out return!\r\n");
|
||||
testStatus = 0x00;
|
||||
break;
|
||||
}
|
||||
// if((OPTO_KEY3 == 0) || (OPTO_KEY4 == 0))
|
||||
// {
|
||||
// printf("%d %d\r\n", OPTO_KEY3, OPTO_KEY4);
|
||||
// }
|
||||
if((OPTO_KEY3 == 1) && (OPTO_KEY4 == 1))
|
||||
{
|
||||
timer_restart(&timerOut);
|
||||
timer_restart(&waitingTimer);
|
||||
testStatus = 0x12;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x12:
|
||||
if(timer_expired(&timerOut))
|
||||
{
|
||||
if(timer_expired(&waitingTimer))
|
||||
{
|
||||
printf("\r\n0x12time out return!\r\n");
|
||||
testStatus = 0x00;
|
||||
break;
|
||||
}
|
||||
|
||||
if((OPTO_KEY3 == 1) || (OPTO_KEY4 == 1))
|
||||
{
|
||||
printf("\r\nwarning!\r\n");
|
||||
beep_warningBeepMark = 1; //标志警告声
|
||||
|
||||
if(smallBottleCount > 0)
|
||||
{
|
||||
smallBottleCount--;
|
||||
}
|
||||
testStatus = 0x00;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: OptoKeysTest
|
||||
* 功能说明: 红外光电开关测试
|
||||
* 形 参: 无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void OptoKeysTest(void)
|
||||
{
|
||||
static uint8_t optoKeyStatus1 = 0;
|
||||
static uint8_t optoKeyStatus2 = 0;
|
||||
|
||||
if(optoKeyStatus1 != optoKeyValue1)
|
||||
{
|
||||
optoKeyStatus1 = optoKeyValue1;
|
||||
|
||||
if(optoKeyValue1)
|
||||
{
|
||||
printf("\r\n红外光电开关1触发\r\n");
|
||||
}else{
|
||||
printf("\r\n红外光电开关1恢复正常\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
if(optoKeyStatus2 != optoKeyValue2)
|
||||
{
|
||||
optoKeyStatus2 = optoKeyValue2;
|
||||
|
||||
if(optoKeyValue2)
|
||||
{
|
||||
printf("\r\n红外光电开关2触发\r\n");
|
||||
}else{
|
||||
printf("\r\n红外光电开关2恢复正常\r\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/******************** (C) COPYRIGHT 2018 Ping *****END OF FILE*******************/
|
||||
@@ -0,0 +1,30 @@
|
||||
/*************************** (C) COPYRIGHT 2018 Ping ****************************
|
||||
* 文件名 :opto_sw_key.h
|
||||
* 描 述 :光电开关开关驱动程序头文件
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/03/06
|
||||
*********************************************************************************/
|
||||
#ifndef __OPTO_SW_KEY_H
|
||||
#define __OPTO_SW_KEY_H
|
||||
|
||||
#include "stm32f10x.h"
|
||||
|
||||
#define OPTO_KEY1 GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_8) //红外光电开关1输入
|
||||
#define OPTO_KEY2 GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_7) //红外光电开关2输入
|
||||
#define OPTO_KEY3 GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_0) //红外光电开关3输入
|
||||
#define OPTO_KEY4 GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_3) //红外光电开关4输入
|
||||
|
||||
extern uint8_t optoKeyValue1; //红外光电开关键值
|
||||
extern uint8_t optoKeyValue2; //红外光电开关键值
|
||||
extern uint8_t optoKeyValue3; //红外光电开关键值
|
||||
extern uint8_t optoKeyValue4; //红外光电开关键值
|
||||
|
||||
void OptoKeyInit(void);
|
||||
void OptoKeysCanning(void);
|
||||
void BottleScanning(void);
|
||||
void OptoKeysTest(void);
|
||||
|
||||
#endif
|
||||
|
||||
/******************** (C) COPYRIGHT 2018 Ping *****END OF FILE*******************/
|
||||
+202
@@ -0,0 +1,202 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :2code.c
|
||||
* 描 述 :二维码处理程序
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/03/06
|
||||
*********************************************************************************/
|
||||
#include "qr_code.h"
|
||||
#include "usart1.h"
|
||||
#include "timer.h"
|
||||
#include "string.h"
|
||||
#include "RFID_IC.h"
|
||||
#include "my_math.h"
|
||||
|
||||
//各种有效二维码识别成功标志状态
|
||||
uint8_t sweep2CodeState = 0; //扫描二维码状态,成功后为1,由外部程序读取后清除
|
||||
uint8_t scanBarCodeState = 0; //扫描垃圾袋条型码或二维码状态,成功后为1,由外部程序读取后清除
|
||||
uint8_t scanLabelCodeState = 0; //扫描标签二维码状态,成功后为1,由外部程序读取后清除
|
||||
uint8_t scanIC_2CodeState = 0; //扫描IC卡二维码开门状态,成功后为1,由外部程序读取后清除
|
||||
uint8_t devSetQrCodeState = 0; //参数设置二维码
|
||||
|
||||
uint8_t codeBuf[128]; //保存读取到的有效二维码内容
|
||||
uint8_t codeDataLength = 0; //保存读取到的有效二维码内容长度
|
||||
|
||||
uint8_t IC_Code[17]; //IC卡二维码
|
||||
uint8_t IC_HEX_Code[17]; //IC卡二维码十六进制数据
|
||||
uint8_t IC_HEX_ID[9];
|
||||
|
||||
uint8_t setParamCmd; //设置参数指令
|
||||
uint8_t setParamCount; //参数的个数
|
||||
char setParamList[16][16]; //参数缓存列表
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: DeleteStrEndingCode
|
||||
* 功能说明: 删除字符串结尾的回车及换行
|
||||
* 形 参:待处理的字符串首地址
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
static void DeleteStrEndingCode(char *pStr)
|
||||
{
|
||||
uint16_t i = 0;
|
||||
uint16_t len1 = 0, len2;
|
||||
|
||||
len1 = strlen(pStr);
|
||||
|
||||
for(i = 0; i < len1; i++)
|
||||
{
|
||||
if((*(pStr + i) == 0x0D) || ((*(pStr + i) == 0x0A)))
|
||||
{
|
||||
*(pStr + i) = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
len2 = strlen(pStr);
|
||||
printf("\r\nqrLen %d, %d\r\n", len1, len2);
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: QR_CodeDecode_StandardFormat
|
||||
* 功能说明: 标准格式二维码内容解析
|
||||
* 形 参:pStr -> 待解析的二维码
|
||||
* pCheckStr -> 解析格式
|
||||
* 返 回 值: 解码成功返回1,失败返回0
|
||||
***********************************************************************
|
||||
*/
|
||||
uint8_t QR_CodeDecode_StandardFormat(char *pStr, char *pCheckStr)
|
||||
{
|
||||
uint8_t returnMark = 0;
|
||||
uint8_t i = 0;
|
||||
uint8_t len = 0;
|
||||
char *p;
|
||||
char *pQRcode; //符合格式的二维码
|
||||
|
||||
pQRcode = (char*)strstr((const char*)pStr, pCheckStr);
|
||||
|
||||
if(pQRcode != NULL)
|
||||
{
|
||||
p = (char*)strstr((const char*)pQRcode, "="); //取出用户信息
|
||||
|
||||
if(p != NULL)
|
||||
{
|
||||
len = strlen(p + 1); //计算用户信息长度
|
||||
if((len > 0) && (len <= 128)) //当为用户APP二维码才能打开门
|
||||
{
|
||||
codeDataLength = len; //更新用户信息长度
|
||||
memset(codeBuf, 0x00, 128);
|
||||
memcpy(codeBuf, p+1, codeDataLength);
|
||||
|
||||
printf("\r\nLen:%d, data:%s\r\n", codeDataLength, codeBuf);
|
||||
|
||||
returnMark = 1; //标志解码成功
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return returnMark;
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: QR_CodeDecode
|
||||
* 功能说明: 二维码内容解析
|
||||
* 形 参:待解析的二维码
|
||||
* 返 回 值: 无(影响相应的有效二维码标志位)
|
||||
***********************************************************************
|
||||
*/
|
||||
void QR_CodeDecode(char *pStr)
|
||||
{
|
||||
uint8_t i;
|
||||
char *p;
|
||||
|
||||
char *pAppQRcode; //APP二维码
|
||||
char *pAppQRcode2; //中联APP二维码
|
||||
char *pBagQRcode; //垃圾袋二维码
|
||||
char *pBagQRcodeAtCD; //成都垃圾袋二维码
|
||||
char *pIcCardQRcode; //成都IC卡二维码
|
||||
char *pDevSetQRcode; //参数设置二维码
|
||||
|
||||
uint8_t len = 0;
|
||||
|
||||
uint32_t IC_HEX01, IC_HEX02;
|
||||
uint8_t IC_HEX03, IC_HEX04;
|
||||
|
||||
uint8_t successMark = 0; //扫码有效标志
|
||||
|
||||
// printf("\r\n2code = %s\r\n", (const char*)pStr);
|
||||
|
||||
DeleteStrEndingCode(pStr); //去掉二维码内容字符串结尾的回车及换行
|
||||
|
||||
// pAppQRcode = (char*)strstr((const char*)pStr, "www.kinglive.com.cn");
|
||||
// pAppQRcode2 = (char*)strstr((const char*)pStr, "zoomlion");
|
||||
// pBagQRcode = (char*)strstr((const char*)pStr, "YN");
|
||||
// pBagQRcodeAtCD = (char*)strstr((const char*)pStr, "yueng");
|
||||
// pIcCardQRcode = (char*)strstr((const char*)pStr, "510104");
|
||||
//
|
||||
pDevSetQRcode = (char*)strstr((const char*)pStr, "devSet:");
|
||||
|
||||
//---------------------------------------------------------------------------------------
|
||||
if(strlen(pStr) >= 128)
|
||||
{
|
||||
printf("\r\n超出长度!\r\n");
|
||||
}else{
|
||||
if(pDevSetQRcode != NULL) //参数设置二维码
|
||||
{
|
||||
len = strlen(pDevSetQRcode); //计算长度
|
||||
|
||||
devSetQrCodeState = 1; //标志扫垃圾袋二维码成功
|
||||
successMark = 1;
|
||||
|
||||
codeDataLength = len; //更新用户信息长度
|
||||
memcpy(codeBuf, pDevSetQRcode, codeDataLength);
|
||||
*(codeBuf+len) = '\0';
|
||||
|
||||
printf("\r\n设置二维码!\r\n");
|
||||
printf("\r\ndata = %s\r\n", codeBuf);
|
||||
printf("\r\ndataLen = %d\r\n", codeDataLength);
|
||||
}if(QR_CodeDecode_StandardFormat(pStr, "https://www.wastereduction.gov.hk")){
|
||||
printf("\r\n香港客户二维码!\r\n");
|
||||
|
||||
sweep2CodeState = 1;
|
||||
successMark = 1;
|
||||
}else{
|
||||
len = strlen(pStr);
|
||||
codeDataLength = len;
|
||||
memset(codeBuf, 0x00, 128);
|
||||
memcpy(codeBuf, pStr, codeDataLength);
|
||||
|
||||
sweep2CodeState = 1; //标志为用户APP二维码开门
|
||||
successMark = 1;
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------------------
|
||||
|
||||
if(successMark == 0)
|
||||
{
|
||||
printf("\r\n无效二维码!!!\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
// /*
|
||||
// ***********************************************************************
|
||||
// * 函 数 名: Get2Code
|
||||
// * 功能说明: 取得身份二维码数据
|
||||
// * 形 参:无
|
||||
// * 返 回 值: 无
|
||||
// ***********************************************************************
|
||||
// */
|
||||
// void Get2Code(void)
|
||||
// {
|
||||
// if(USART1_RX_STA & 0X8000) //接收到一次数据了
|
||||
// {
|
||||
// QR_CodeDecode((char*)USART_RX_BUF);
|
||||
//
|
||||
// memset(USART_RX_BUF, 0x00, 128); //清除缓存内容
|
||||
// USART1_RX_STA = 0; //启动下一次接收
|
||||
// }
|
||||
// }
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 CXHY *****END OF FILE*******************/
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :2code.h
|
||||
* 描 述 :称驱动程序
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/03/06
|
||||
*********************************************************************************/
|
||||
#ifndef __2CODE_H
|
||||
#define __2CODE_H
|
||||
#include "stdint.h"
|
||||
#include "string.h"
|
||||
|
||||
//各种有效二维码识别成功标志状态
|
||||
extern uint8_t sweep2CodeState; //扫描二维码状态,成功后为1,由外部程序读取后清除
|
||||
extern uint8_t scanBarCodeState; //扫描垃圾袋条型码或二维码状态,成功后为1,由外部程序读取后清除
|
||||
extern uint8_t scanLabelCodeState; //扫描标签二维码状态,成功后为1,由外部程序读取后清除
|
||||
extern uint8_t scanIC_2CodeState; //扫描IC卡二维码开门状态,成功后为1,由外部程序读取后清除
|
||||
extern uint8_t devSetQrCodeState; //参数设置二维码
|
||||
|
||||
extern uint8_t codeBuf[128]; //保存读取到的有效二维码内容
|
||||
extern uint8_t codeDataLength; //保存读取到的有效二维码内容长度
|
||||
|
||||
extern uint8_t setParamCmd; //设置参数指令
|
||||
extern uint8_t setParamCount; //参数的个数
|
||||
extern char setParamList[16][16]; //参数缓存列表
|
||||
|
||||
void QR_CodeDecode(char *pStr);
|
||||
void Get2Code(void);
|
||||
#endif
|
||||
+331
@@ -0,0 +1,331 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :RFID_IC.c
|
||||
* 描 述 :RFID_IC卡驱动程序
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/03/06
|
||||
*********************************************************************************/
|
||||
#include "RFID_IC.h"
|
||||
#include "rfid_decode_yn.h"
|
||||
#include "rfid_decode_yhk.h"
|
||||
#include "rfid_decode_zl.h"
|
||||
#include "delay.h"
|
||||
#include "usart1.h"
|
||||
#include "stdio.h"
|
||||
#include "string.h"
|
||||
#include "stdlib.h"
|
||||
#include "my_math.h"
|
||||
|
||||
#define RFID_PW_CTRL_PORT_PeriphClock RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO
|
||||
#define RFID_PW_CTRL_PORT GPIOA
|
||||
#define RFID_PW_CTRL_PIN GPIO_Pin_15
|
||||
|
||||
|
||||
uint8_t RFID_ID[16] = {0}; //存放RFID卡号,刚从IC卡块区读出来的数据(十六进制保存)
|
||||
uint8_t cardNumberBit[32] = {0}; //解析分离出来的卡号(十进制表示)
|
||||
uint8_t cardNumberStr[33] = {0}; //解析分离出来的卡号(字符串表示)
|
||||
uint8_t createCardNum[16] = {0}; //生成的IC卡号保存内容
|
||||
uint8_t cardNumberLen = 0; //IC卡号内容长度
|
||||
uint8_t RFID_state = 0; //RFID_IC刷卡状态(有无刷卡1:有刷卡,0:无刷卡,2:收运卡)
|
||||
|
||||
uint8_t cardSetWorkMode = 0; //IC卡模块工作模式
|
||||
uint8_t cardSetReadBlock = 0; //IC卡模块读取的块号
|
||||
uint8_t cardSetUploadMode = 0; //IC卡数据上传模式
|
||||
|
||||
uint8_t cardSetKeyA[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; //IC卡读写KeyA
|
||||
uint8_t cardSetKeyCtrlBit[4] = {0xFF, 0x07, 0x80, 0x69}; //IC卡读写控制位
|
||||
uint8_t cardSetKeyB[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; //IC卡读写KeyB
|
||||
|
||||
uint8_t originalPassword[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; //IC卡原始密码
|
||||
|
||||
uint32_t cardNumberAreaCode = 0; //IC卡号区号(前6位)
|
||||
uint32_t cardNumberSerialNum = 0; //IC卡号流水号(第7-14位)
|
||||
|
||||
//IC卡模块操作相关
|
||||
uint8_t Cmd_WorkMode[8] = {0x03, 0x08, 0xC1, 0x20, 0x00, 0x00, 0x00, 0x00};
|
||||
uint8_t Cmd_SECRET_KEY[21] = {0x03, 0x15, 0xC3, 0x20, 0xFF, 0xFF, 0xFF, 0xFF, //设置IC卡读卡模块密钥
|
||||
0xFF, 0xFF, 0xFF, 0x07, 0x80, 0x69, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0x1B};
|
||||
|
||||
uint8_t Cmd_Write_Block[23] = {0x01,0x17,0xA4,0x20,0x00,0x01,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00}; //写块数据
|
||||
|
||||
uint8_t Cmd_SectorEncryption[8] = {0x01, 0x08, 0xA5, 0x20, 0x00, 0x01, 0x00, 0x00}; //扇区加密
|
||||
|
||||
//粤能IC卡模块配参数(默认参数)
|
||||
uint8_t YN_IC_MODE[8] = {0x03, 0x08, 0xC1, 0x20, 0x03, 0x09, 0x00, 0x1F}; //设置IC卡读卡模块工作模式
|
||||
uint8_t YN_SECRET_KEY[21] = {0x03, 0x15, 0xC3, 0x20, 0x7F, 0xFF, 0xFF, 0xFF, //设置IC卡读卡模块密钥
|
||||
0xFF, 0xFF, 0xFF, 0x07, 0x80, 0x69, 0x6F, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0x0B};
|
||||
|
||||
//粤能IC卡模块配参数(默认参数)
|
||||
uint8_t SET_IC_MODE[8] = {0x03, 0x08, 0xC1, 0x20, 0x03, 0x09, 0x00, 0x1F}; //设置IC卡读卡模块工作模式
|
||||
uint8_t SET_SECRET_KEY[21] = {0x03, 0x15, 0xC3, 0x20, 0x7F, 0xFF, 0xFF, 0xFF, //设置IC卡读卡模块密钥
|
||||
0xFF, 0xFF, 0xFF, 0x07, 0x80, 0x69, 0x6F, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0x0B};
|
||||
|
||||
//中联IC卡模块参数
|
||||
// uint8_t SET_IC_MODE[8] = {0x03, 0x08, 0xC1, 0x20, 0x03, 0x02, 0x00, 0x14}; //设置IC卡读卡模块工作模式
|
||||
// uint8_t SET_SECRET_KEY[21] = {0x03, 0x15, 0xC3, 0x20, 0xFF, 0xFF, 0xFF, 0xFF, //设置IC卡读卡模块密钥
|
||||
// 0xFF, 0xFF, 0xFF, 0x07, 0x80, 0x69, 0xFF, 0xFF,
|
||||
// 0xFF, 0xFF, 0xFF, 0xFF, 0x1B};
|
||||
|
||||
// //成都
|
||||
// uint8_t SET_IC_MODE[8] = {0x03, 0x08, 0xC1, 0x20, 0x03, 0x16, 0x00, 0x00}; //设置IC卡读卡模块工作模式
|
||||
// uint8_t SET_SECRET_KEY[21] = {0x03, 0x15, 0xC3, 0x20, 0x8F, 0x7F, 0x6F, 0x5F, //设置IC卡读卡模块密钥
|
||||
// 0x4F, 0x3F, 0xFF, 0x07, 0x80, 0x69, 0x1F, 0x2F,
|
||||
// 0x3F, 0x4F, 0x5F, 0x6F, 0xDB};
|
||||
|
||||
void showCardHex(uint8_t *buf, uint8_t len)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
printf("\r\n");
|
||||
for(i=0; i<len; i++)
|
||||
{
|
||||
printf("%02X ",buf[i]);
|
||||
}
|
||||
printf("\r\n");
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: RFID_Init
|
||||
* 功能说明: RFID设备初始化
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void RFID_Init(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
RCC_APB2PeriphClockCmd(RFID_PW_CTRL_PORT_PeriphClock, ENABLE);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = RFID_PW_CTRL_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(RFID_PW_CTRL_PORT, &GPIO_InitStructure);
|
||||
|
||||
GPIO_SetBits(RFID_PW_CTRL_PORT, RFID_PW_CTRL_PIN);
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: RFID_PowerON
|
||||
* 功能说明: 打开RFID设备电源
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void RFID_PowerON(void)
|
||||
{
|
||||
GPIO_SetBits(RFID_PW_CTRL_PORT, RFID_PW_CTRL_PIN);
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: RFID_PowerOFF
|
||||
* 功能说明: 关闭RFID设备电源
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void RFID_PowerOFF(void)
|
||||
{
|
||||
GPIO_ResetBits(RFID_PW_CTRL_PORT, RFID_PW_CTRL_PIN);
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: IC_CardDecode
|
||||
* 功能说明: IC卡解码
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void IC_CardDecode(void)
|
||||
{
|
||||
if(IC_CardDecode_YN())
|
||||
{
|
||||
printf("\r\n粤能IC卡!\r\n");
|
||||
}else if(IC_CardDecode_YHK()){
|
||||
printf("\r\n银行卡!\r\n");
|
||||
}else if(IC_CardDecode_ZL()){
|
||||
printf("\r\n中联IC卡!\r\n");
|
||||
}else{
|
||||
printf("\r\n无效卡!\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------
|
||||
//IC卡模块相关操作
|
||||
|
||||
void TxCheckSum(uint8_t *ptr, uint8_t len)
|
||||
{
|
||||
uint8_t i = 0;
|
||||
uint8_t checksum = 0;
|
||||
|
||||
checksum = 0;
|
||||
for(i=0; i<(len-1); i++)
|
||||
{
|
||||
checksum ^= ptr[i];
|
||||
}
|
||||
checksum = ~checksum;
|
||||
ptr[len-1] = checksum;
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: IC_CardReset
|
||||
* 功能说明: IC模块参数恢复出厂默认值
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void IC_CarderReset(void)
|
||||
{
|
||||
delay_ms(300);
|
||||
USART1_SendFrameData(YN_IC_MODE, 8);
|
||||
delay_ms(300);
|
||||
USART1_SendFrameData(YN_SECRET_KEY, 21);
|
||||
delay_ms(300);
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: IC_CardWorkModeSet
|
||||
* 功能说明: IC模块工作模式设置
|
||||
* 形 参:mode -> 工作模式
|
||||
* block -> 读取的块号
|
||||
* outputMode -> 输出模式
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void IC_CarderWorkModeSet(uint8_t mode, uint8_t block, uint8_t outputMode)
|
||||
{
|
||||
Cmd_WorkMode[4] = mode;
|
||||
Cmd_WorkMode[5] = block;
|
||||
Cmd_WorkMode[6] = outputMode;
|
||||
TxCheckSum(Cmd_WorkMode, 8);
|
||||
|
||||
delay_ms(300);
|
||||
USART1_SendFrameData(Cmd_WorkMode, 8);
|
||||
delay_ms(300);
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: IC_CarderWorkModeSet
|
||||
* 功能说明: IC模块读写密码设置
|
||||
* 形 参:keyA -> keyA密码
|
||||
* keyCtrlBit -> 密码控制位
|
||||
* keyB -> keyB密码
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void IC_CarderKeySet(uint8_t *keyA, uint8_t *keyCtrlBit, uint8_t *keyB)
|
||||
{
|
||||
memcpy(&Cmd_SECRET_KEY[4], keyA, 6);
|
||||
memcpy(&Cmd_SECRET_KEY[10], keyCtrlBit, 4);
|
||||
memcpy(&Cmd_SECRET_KEY[14], keyA, 6);
|
||||
TxCheckSum(Cmd_SECRET_KEY, 21);
|
||||
|
||||
delay_ms(300);
|
||||
USART1_SendFrameData(Cmd_SECRET_KEY, 21);
|
||||
delay_ms(300);
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: RFID_SectorEncrypt
|
||||
* 功能说明: 扇区加密
|
||||
* 形 参:blockNumber -> 扇区块号
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void RFID_SectorEncrypt(uint8_t blockNumber)
|
||||
{
|
||||
Cmd_SectorEncryption[4] = blockNumber;
|
||||
TxCheckSum(Cmd_SectorEncryption, Cmd_SectorEncryption[1]); //计算数据校验位
|
||||
|
||||
delay_ms(500);
|
||||
USART1_SendFrameData(Cmd_SectorEncryption, Cmd_SectorEncryption[1]);
|
||||
delay_ms(500);
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: RFID_WriteDataToBlock
|
||||
* 功能说明: 写卡数据
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void RFID_WriteDataToBlock(uint8_t *datain, uint8_t block)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
Cmd_Write_Block[4] = block;
|
||||
|
||||
for(i=0; i<16; i++)
|
||||
{
|
||||
Cmd_Write_Block[6+i] = datain[i];
|
||||
}
|
||||
TxCheckSum(Cmd_Write_Block, Cmd_Write_Block[1]); //计算数据校验位
|
||||
|
||||
delay_ms(500);
|
||||
USART1_SendFrameData(Cmd_Write_Block, Cmd_Write_Block[1]);
|
||||
delay_ms(500);
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: SetRFID_Param
|
||||
* 功能说明: 设置IC卡模块参数
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void SetRFID_Param(void)
|
||||
{
|
||||
delay_ms(200);
|
||||
USART1_SendFrameData(SET_IC_MODE, 8);
|
||||
delay_ms(200);
|
||||
USART1_SendFrameData(SET_SECRET_KEY, 21);
|
||||
delay_ms(200);
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: ConfigureDoorKey
|
||||
* 功能说明: 配置收运IC卡钥匙
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void ConfigureDoorKey(uint32_t id)
|
||||
{
|
||||
IC_CardEncode_YN(id, 1, 55);
|
||||
RFID_WriteDataToBlock(createCardNum, 9);
|
||||
printf("\r\n配置收运IC卡钥匙!\r\n");
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: WriteIC_CardNumber
|
||||
* 功能说明: 写IC卡号
|
||||
* 形 参:areaCode -> IC卡区号(前6位)
|
||||
* serialNum -> IC卡流水号(第7-14位)
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void WriteIC_CardNumber(uint32_t areaCode, uint32_t serialNum)
|
||||
{
|
||||
IC_CardEncode_YN(areaCode, serialNum, 1);
|
||||
RFID_WriteDataToBlock(createCardNum, 9);
|
||||
printf("\r\n写IC卡!\r\n");
|
||||
}
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 ping *****END OF FILE*******************/
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :RFID_IC.h
|
||||
* 描 述 :RFID_IC卡驱动程序
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/03/06
|
||||
*********************************************************************************/
|
||||
#ifndef __RFID_IC_H
|
||||
#define __RFID_IC_H
|
||||
#include "stm32f10x.h"
|
||||
|
||||
extern uint8_t RFID_ID[16]; //存放RFID卡号,刚从IC卡块区读出来的数据(十六进制保存)
|
||||
extern uint8_t cardNumberBit[32]; //解析分离出来的卡号(十进制表示)
|
||||
extern uint8_t cardNumberStr[33]; //解析分离出来的卡号(字符串表示)
|
||||
extern uint8_t createCardNum[16]; //生成的IC卡号保存内容
|
||||
extern uint8_t cardNumberLen; //IC卡号内容长度
|
||||
extern uint8_t RFID_state; //RFID_IC刷卡状态(有无刷卡1:有刷卡,0:无刷卡)
|
||||
|
||||
extern uint8_t cardSetWorkMode; //IC卡模块工作模式
|
||||
extern uint8_t cardSetReadBlock; //IC卡模块读取的块号
|
||||
extern uint8_t cardSetUploadMode; //IC卡数据上传模式
|
||||
|
||||
extern uint8_t cardSetKeyA[6]; //IC卡读写KeyA
|
||||
extern uint8_t cardSetKeyCtrlBit[4]; //IC卡读写控制位
|
||||
extern uint8_t cardSetKeyB[6]; //IC卡读写KeyB
|
||||
|
||||
extern uint8_t originalPassword[6]; //IC卡原始密码
|
||||
|
||||
extern uint32_t cardNumberAreaCode; //IC卡号区号(前6位)
|
||||
extern uint32_t cardNumberSerialNum; //IC卡号流水号(第7-14位)
|
||||
|
||||
void RFID_Init(void);
|
||||
void RFID_PowerON(void);
|
||||
void RFID_PowerOFF(void);
|
||||
void IC_CardDecode(void);
|
||||
|
||||
void IC_CarderReset(void);
|
||||
void IC_CarderWorkModeSet(uint8_t mode, uint8_t block, uint8_t outputMode);
|
||||
void IC_CarderKeySet(uint8_t *keyA, uint8_t *keyCtrlBit, uint8_t *keyB);
|
||||
void RFID_SectorEncrypt(uint8_t blockNumber);
|
||||
void RFID_WriteDataToBlock(uint8_t *datain, uint8_t block);
|
||||
void SetRFID_Param(void);
|
||||
void ConfigureDoorKey(uint32_t id);
|
||||
void WriteIC_CardNumber(uint32_t areaCode, uint32_t serialNum);
|
||||
#endif
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 CXHY *****END OF FILE*******************/
|
||||
+127
@@ -0,0 +1,127 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :rfid_decode_yhk.c
|
||||
* 描 述 :银行卡解码程序
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/03/06
|
||||
*********************************************************************************/
|
||||
#include "rfid_decode_yhk.h"
|
||||
#include "RFID_IC.h"
|
||||
#include "string.h"
|
||||
#include "stdlib.h"
|
||||
#include "stdbool.h"
|
||||
#include "my_math.h"
|
||||
#include "data_typedef.h"
|
||||
|
||||
|
||||
void showBufHex1(uint8_t *buf, uint8_t len)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
printf("\r\n");
|
||||
for(i=0; i<len; i++)
|
||||
{
|
||||
printf("%02X ",buf[i]);
|
||||
}
|
||||
printf("\r\n");
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: CheckLuhn
|
||||
* 功能说明: 检测卡号校验位
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
static bool CheckLuhn(const char *pPurported)
|
||||
{
|
||||
uint8_t i = 0;
|
||||
int nSum = 0;
|
||||
int nDigit = 0;
|
||||
int nDigits = 0;
|
||||
int nParity = 0;
|
||||
char cDigit[2] = {0};
|
||||
|
||||
nDigits = strlen(pPurported);
|
||||
nParity = (nDigits-1) % 2;
|
||||
|
||||
for (i = nDigits; i > 0 ; i--)
|
||||
{
|
||||
cDigit[0] = pPurported[i-1];
|
||||
nDigit = atoi(cDigit);
|
||||
|
||||
if (nParity == i % 2)
|
||||
{
|
||||
nDigit = nDigit * 2;
|
||||
}
|
||||
|
||||
nSum += nDigit/10;
|
||||
nSum += nDigit%10;
|
||||
}
|
||||
return 0 == nSum % 10;
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: IC_CardDecode_YHK
|
||||
* 功能说明: 银行IC卡解码
|
||||
* 形 参:无
|
||||
* 返 回 值: 解码成功返回1,不成功返回0
|
||||
***********************************************************************
|
||||
*/
|
||||
uint8_t IC_CardDecode_YHK(void)
|
||||
{
|
||||
uint8_t res = 0;
|
||||
uint8_t i, j;
|
||||
uint32_t dataTemp;
|
||||
uint8_t icCardBitBuf[32] = {0};
|
||||
uint8_t icCardLen = 0; //卡号内容长度
|
||||
uint32_t supplierID = 0; //供应商代码
|
||||
|
||||
//卡号分离
|
||||
//卡号分离
|
||||
j = 0;
|
||||
memset(cardNumberStr, 0x00, 33);
|
||||
memset(cardNumberBit, 0x00, 32);
|
||||
for(i = 0; i < 16; i++)
|
||||
{
|
||||
sprintf((char*)&cardNumberStr[j], "%01X", RFID_ID[i] >> 4);
|
||||
cardNumberBit[j++] = RFID_ID[i] >> 4;
|
||||
|
||||
sprintf((char*)&cardNumberStr[j], "%01X", RFID_ID[i] & 0x0F);
|
||||
cardNumberBit[j++] = RFID_ID[i] & 0x0F;
|
||||
}
|
||||
|
||||
//计算卡号长度
|
||||
for(i = 0; i < 32; i++)
|
||||
{
|
||||
if(cardNumberStr[i] == 'F')
|
||||
{
|
||||
cardNumberLen = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
printf("\r\nlen = %d\r\n", cardNumberLen);
|
||||
showBufHex1(cardNumberBit, cardNumberLen);
|
||||
printf("\r\nIC = %s\r\n", cardNumberStr);
|
||||
|
||||
if((cardNumberLen >= 10) && (cardNumberLen <= 20)) //IC卡头部信息校验
|
||||
{
|
||||
memcpy(icCardBitBuf, cardNumberStr, cardNumberLen);
|
||||
if(CheckLuhn((const char*)icCardBitBuf))
|
||||
{
|
||||
RFID_state = 3; //RFID_IC刷卡状态
|
||||
printf("\r\n银行卡用户!\r\n");
|
||||
res = 1;
|
||||
}else{
|
||||
printf("\r\n校验错误!\r\n");
|
||||
}
|
||||
}else{
|
||||
// printf("\r\n中联卡解码无效!!!\r\n");
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
/******************** (C) COPYRIGHT 2017 ping *****END OF FILE*******************/
|
||||
@@ -0,0 +1,16 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :rfid_decode_yhk.h
|
||||
* 描 述 :银行卡解码头文件
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/03/06
|
||||
*********************************************************************************/
|
||||
#ifndef __RFID_DECODE_YHK_H
|
||||
#define __RFID_DECODE_YHK_H
|
||||
|
||||
#include "stm32f10x.h"
|
||||
|
||||
uint8_t IC_CardDecode_YHK(void);
|
||||
#endif
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 CXHY *****END OF FILE*******************/
|
||||
+259
@@ -0,0 +1,259 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :RFID_IC.c
|
||||
* 描 述 :RFID_IC卡驱动程序
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/03/06
|
||||
*********************************************************************************/
|
||||
#include "rfid_decode_yn.h"
|
||||
#include "RFID_IC.h"
|
||||
#include "string.h"
|
||||
#include "stdlib.h"
|
||||
#include "my_math.h"
|
||||
#include "data_typedef.h"
|
||||
|
||||
#define secretKey "1357975312468642" //IC卡号密钥1357975312468642
|
||||
// #define secretKey "2468642135797531" //IC卡号密钥2468642135797531
|
||||
|
||||
uint8_t secretKeyBit[16]; //分离出来的16位十进制密钥
|
||||
uint8_t checkBit; //卡号校验位
|
||||
|
||||
|
||||
static void SecretCardNumHEX2Bit(uint8_t outputBuf[], uint8_t inputBuf[]);
|
||||
|
||||
|
||||
void showCardHex1(uint8_t *buf, uint8_t len)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
printf("\r\n");
|
||||
for(i=0; i<len; i++)
|
||||
{
|
||||
printf("%02X ",buf[i]);
|
||||
}
|
||||
printf("\r\n");
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: SecretCardNumHEX2Bit
|
||||
* 功能说明: 16进制卡号分离出17位10进制数
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
static void SecretCardNumHEX2Bit(uint8_t outputBuf[], uint8_t inputBuf[])
|
||||
{
|
||||
uint8_t i;
|
||||
uint32_t dataTemp;
|
||||
|
||||
//区号
|
||||
dataTemp = inputBuf[0] << 16;
|
||||
dataTemp |= inputBuf[1] << 8;
|
||||
dataTemp |= inputBuf[2];
|
||||
|
||||
//分离区号
|
||||
outputBuf[0] = dataTemp/Pow(10, 5);
|
||||
outputBuf[1] = (dataTemp/Pow(10, 4))%10;
|
||||
outputBuf[2] = (dataTemp/Pow(10, 3))%10;
|
||||
outputBuf[3] = (dataTemp/Pow(10, 2))%10;
|
||||
outputBuf[4] = (dataTemp/Pow(10, 1))%10;
|
||||
outputBuf[5] = (dataTemp%10);
|
||||
|
||||
// printf("\r\n%6d", dataTemp);
|
||||
|
||||
//流水号
|
||||
dataTemp = inputBuf[3] << 24;
|
||||
dataTemp |= inputBuf[4] << 16;
|
||||
dataTemp |= inputBuf[5] << 8;
|
||||
dataTemp |= inputBuf[6];
|
||||
|
||||
// printf("%8d", dataTemp);
|
||||
|
||||
//分离出流水号
|
||||
outputBuf[6] = dataTemp/Pow(10, 7);
|
||||
outputBuf[7] = (dataTemp/Pow(10, 6))%10;
|
||||
outputBuf[8] = (dataTemp/Pow(10, 5))%10;
|
||||
outputBuf[9] = (dataTemp/Pow(10, 4))%10;
|
||||
outputBuf[10] = (dataTemp/Pow(10, 3))%10;
|
||||
outputBuf[11] = (dataTemp/Pow(10, 2))%10;
|
||||
outputBuf[12] = (dataTemp/Pow(10, 1))%10;
|
||||
outputBuf[13] = (dataTemp%10);
|
||||
|
||||
//分离出预留号
|
||||
outputBuf[14] = inputBuf[7]/10;
|
||||
outputBuf[15] = inputBuf[7]%10;
|
||||
|
||||
// printf("%2d", inputBuf[7]);
|
||||
|
||||
//分离出校验位
|
||||
outputBuf[16] = (inputBuf[8]%10);
|
||||
|
||||
// printf("%1d", inputBuf[8]);
|
||||
|
||||
// printf("\r\n卡号为:");
|
||||
// for(i = 0; i < 17; i++)
|
||||
// {
|
||||
// printf("%d ", outputBuf[i]);
|
||||
// }
|
||||
// printf("\r\n");
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: SecretKeyHEX2Bit
|
||||
* 功能说明: 16进制密钥分离出16位10进制数
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void SecretKeyHEX2Bit(uint8_t outputBuf[], char *inputStr)
|
||||
{
|
||||
uint16_t i;
|
||||
char keyStr[17];
|
||||
|
||||
sprintf(keyStr, "%s", inputStr);
|
||||
|
||||
// printf("\r\n密钥为:");
|
||||
for(i = 0; i < 16; i++)
|
||||
{
|
||||
outputBuf[i] = keyStr[i] - '0';
|
||||
// printf("%d ", outputBuf[i]);
|
||||
}
|
||||
// printf("\r\n");
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: CalculateCheckDigit
|
||||
* 功能说明: 计算卡号校验位
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
uint8_t CalculateCheckDigit(uint8_t cardNumBit[], uint8_t keyBit[])
|
||||
{
|
||||
uint8_t crc = 0;
|
||||
uint16_t i;
|
||||
uint16_t encryptionSum = 0;
|
||||
uint16_t sum = 0;
|
||||
uint8_t remainder = 0;
|
||||
|
||||
//计算校验位
|
||||
for(i = 0; i < 16; i++)
|
||||
{
|
||||
sum = cardNumBit[i] * keyBit[i];
|
||||
encryptionSum += sum;
|
||||
}
|
||||
// printf("\r\n%d \r\n", encryptionSum);
|
||||
remainder = encryptionSum % 11;
|
||||
// printf("\r\n%d \r\n", remainder);
|
||||
|
||||
if(remainder == 10)
|
||||
{
|
||||
crc = 0;
|
||||
}else if(remainder == 0){
|
||||
crc = 5;
|
||||
}else{
|
||||
crc = remainder;
|
||||
}
|
||||
|
||||
// printf("\r\nIC卡校验信息:校验和 = %d, 余数 = %d, 校验位 = %d\r\n", encryptionSum, remainder, crc);
|
||||
|
||||
return crc;
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: IC_CardEncode
|
||||
* 功能说明: IC卡编码
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void IC_CardEncode_YN(uint32_t areaCode, uint32_t serialNum, uint8_t cardType)
|
||||
{
|
||||
uint8_t i;
|
||||
uint8_t cardNumBitBuf[17]; //卡号分离出来的17位十进制数据,用于计算校验位
|
||||
uint8_t checkBit = 0;
|
||||
|
||||
memset(createCardNum, 0, 16);
|
||||
|
||||
//生成区域号
|
||||
createCardNum[0] = (uint8_t)(areaCode >> 16);
|
||||
createCardNum[1] = (uint8_t)(areaCode >> 8);
|
||||
createCardNum[2] = (uint8_t)areaCode;
|
||||
|
||||
//生成流水号
|
||||
createCardNum[3] = (uint8_t)(serialNum >> 24);
|
||||
createCardNum[4] = (uint8_t)(serialNum >> 16);
|
||||
createCardNum[5] = (uint8_t)(serialNum >> 8);
|
||||
createCardNum[6] = (uint8_t)serialNum;
|
||||
|
||||
//生成卡类型
|
||||
createCardNum[7] = cardType;
|
||||
|
||||
//生成校验位
|
||||
SecretCardNumHEX2Bit(cardNumBitBuf, createCardNum);
|
||||
SecretKeyHEX2Bit(secretKeyBit, secretKey);
|
||||
checkBit = CalculateCheckDigit(cardNumBitBuf, secretKeyBit);
|
||||
createCardNum[8] = checkBit;
|
||||
cardNumBitBuf[16] = checkBit;
|
||||
|
||||
printf("\r\n生成卡号为:");
|
||||
for(i = 0; i < 17; i++)
|
||||
{
|
||||
printf("%d", cardNumBitBuf[i]);
|
||||
}
|
||||
printf("\r\n");
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: IC_CardDecode_YN
|
||||
* 功能说明: 粤能IC卡解码
|
||||
* 形 参:无
|
||||
* 返 回 值: 解码成功返回1,不成功返回0
|
||||
***********************************************************************
|
||||
*/
|
||||
uint8_t IC_CardDecode_YN(void)
|
||||
{
|
||||
uint8_t res = 0;
|
||||
uint8_t i;
|
||||
uint8_t checkBit;
|
||||
|
||||
SecretCardNumHEX2Bit(cardNumberBit, RFID_ID);
|
||||
SecretKeyHEX2Bit(secretKeyBit, secretKey);
|
||||
checkBit = CalculateCheckDigit(cardNumberBit, secretKeyBit);
|
||||
|
||||
if(checkBit == cardNumberBit[16]) //IC卡的校验正确,则标志刷卡有效
|
||||
{
|
||||
printf("\r\nIC卡号:");
|
||||
for(i = 0; i < 17; i++)
|
||||
{
|
||||
cardNumberStr[i] = cardNumberBit[i] + '0';
|
||||
printf("%d", cardNumberBit[i]);
|
||||
}
|
||||
printf("\r\n");
|
||||
|
||||
if((cardNumberBit[14] == 0) && (cardNumberBit[15] == 1))
|
||||
{
|
||||
RFID_state = 1; //RFID_IC刷卡状态(有无刷卡:1->有刷卡,0->无刷卡,2->开门卡)外部程序调取后清除
|
||||
printf("\r\nIC卡有效,用户卡!!!\r\n");
|
||||
res = 1;
|
||||
}else if((cardNumberBit[14] == 5) && (cardNumberBit[15] == 5)){
|
||||
RFID_state = 2; //RFID_IC刷卡状态(有无刷卡:1->有刷卡,0->无刷卡,2->开门卡)外部程序调取后清除
|
||||
printf("\r\nIC卡有效,收运卡!!!\r\n");
|
||||
res = 1;
|
||||
}else{
|
||||
RFID_state = 0;
|
||||
}
|
||||
|
||||
}else{
|
||||
// printf("\r\nIC卡无效!!!\r\n");
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 ping *****END OF FILE*******************/
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :rfid_decode_yn.h
|
||||
* 描 述 :粤能IC卡解码头文件
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/03/06
|
||||
*********************************************************************************/
|
||||
#ifndef __RFID_DECODE_YN_H
|
||||
#define __RFID_DECODE_YN_H
|
||||
|
||||
#include "stm32f10x.h"
|
||||
|
||||
void SecretKeyHEX2Bit(uint8_t outputBuf[], char *inputStr);
|
||||
uint8_t CalculateCheckDigit(uint8_t cardNumBit[], uint8_t keyBit[]);
|
||||
void IC_CardEncode_YN(uint32_t areaCode, uint32_t serialNum, uint8_t cardType);
|
||||
uint8_t IC_CardDecode_YN(void);
|
||||
#endif
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 CXHY *****END OF FILE*******************/
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :rfid_decode_zl.c
|
||||
* 描 述 :中联IC卡解码
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/03/06
|
||||
*********************************************************************************/
|
||||
#include "rfid_decode_zl.h"
|
||||
#include "RFID_IC.h"
|
||||
#include "string.h"
|
||||
#include "stdio.h"
|
||||
#include "data_typedef.h"
|
||||
|
||||
|
||||
void showCardHex2(uint8_t *buf, uint8_t len)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
printf("\r\n");
|
||||
for(i=0; i<len; i++)
|
||||
{
|
||||
printf("%02X ",buf[i]);
|
||||
}
|
||||
printf("\r\n");
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: IC_CardDecode_ZL
|
||||
* 功能说明: 中联IC卡解码
|
||||
* 形 参:无
|
||||
* 返 回 值: 解码成功返回1,不成功返回0
|
||||
***********************************************************************
|
||||
*/
|
||||
uint8_t IC_CardDecode_ZL(void)
|
||||
{
|
||||
uint8_t res = 0;
|
||||
uint8_t i, j;
|
||||
|
||||
|
||||
if((RFID_ID[0] == 0x7A) && (RFID_ID[1] == 0x6C)) //IC卡头部信息校验
|
||||
{
|
||||
//卡号分离
|
||||
j = 0;
|
||||
memset(cardNumberStr, 0x00, 33);
|
||||
memset(cardNumberBit, 0x00, 32);
|
||||
for(i = 0; i < 16; i++)
|
||||
{
|
||||
sprintf((char*)&cardNumberStr[j], "%01X", RFID_ID[i] >> 4);
|
||||
cardNumberBit[j++] = RFID_ID[i] >> 4;
|
||||
|
||||
sprintf((char*)&cardNumberStr[j], "%01X", RFID_ID[i] & 0x0F);
|
||||
cardNumberBit[j++] = RFID_ID[i] & 0x0F;
|
||||
}
|
||||
|
||||
//计算卡号长度
|
||||
cardNumberLen = ((cardNumberBit[4]*10) + cardNumberBit[5])*2 + 6;
|
||||
|
||||
// showCardHex2(cardNumberBit, 32);
|
||||
printf("\r\nIC = %s len = %d\r\n", cardNumberStr, cardNumberLen);
|
||||
|
||||
RFID_state = 3; //RFID_IC刷卡状态
|
||||
printf("\r\n中联IC卡,用户卡!\r\n");
|
||||
res = 1;
|
||||
}else{
|
||||
// printf("\r\n中联卡解码无效!!!\r\n");
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 YNHB *****END OF FILE*******************/
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :rfid_decode_zl.h
|
||||
* 描 述 :中联IC卡解码头文件
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/03/06
|
||||
*********************************************************************************/
|
||||
|
||||
|
||||
#ifndef __RFID_DECODE_ZL_H
|
||||
#define __RFID_DECODE_ZL_H
|
||||
|
||||
#include "stm32f10x.h"
|
||||
|
||||
uint8_t IC_CardDecode_ZL(void);
|
||||
#endif
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 CXHY *****END OF FILE*******************/
|
||||
+672
@@ -0,0 +1,672 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :RS485.c
|
||||
* 描 述 :RS485通信处理函数,包含3部分:接收帧程序、发送帧程序及执行命令程序。
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/02/10
|
||||
*********************************************************************************/
|
||||
#include "delay.h"
|
||||
#include "sys.h"
|
||||
#include "RS485.h"
|
||||
// #include "usart5.h"
|
||||
#include "usart.h"
|
||||
#include "timer.h"
|
||||
#include "message.h"
|
||||
#include "device.h"
|
||||
#include "data_typedef.h"
|
||||
|
||||
/*通讯变量定义*/
|
||||
#define BaudRate 9600 //波特率
|
||||
#define DATA_SIZE 32 //通讯缓存区长度
|
||||
|
||||
uint8_t Address = 0x00; //设备地址
|
||||
uint8_t Serial_buf[DATA_SIZE]; //定义通讯缓存区
|
||||
uint8_t RS485_RX_BUF[64]; //接收缓冲,最大64个字节
|
||||
uint8_t RS485_TX_BUF[64]; //发送缓冲,最大64个字节
|
||||
|
||||
//主程序变量定义
|
||||
uint8_t RS485_RX_STA = 0x00; //RS485接收状态标记
|
||||
uint8_t RS485_CommunicationState; //RS485通讯成功与否标志
|
||||
uint8_t radioCom = 0; //广播命令标志
|
||||
uint8_t responseMark = 0; //主机应答标志
|
||||
uint16_t RS485_serialNumber; //RS485通信流水号
|
||||
uint8_t rxCmd; //从机返回的指令码
|
||||
|
||||
uint8_t slaveAddress = 0; //从机返回的地址
|
||||
|
||||
uint8_t getMCU2DataStatus; //取得MCU2的数据状态
|
||||
uint8_t getMCU2DistanceStatus; //取得MCU2的测距数据状态
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: RS485_Init
|
||||
* 功能说明: 初始化RS485接口
|
||||
* 形 参: 无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void RS485_Init(void)
|
||||
{
|
||||
//GPIO端口设置
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); //使能GPIOA时钟
|
||||
|
||||
|
||||
//RS485_TX_EN RS485发送接收控制脚
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(GPIOC, &GPIO_InitStructure);
|
||||
|
||||
GPIO_ResetBits(GPIOC, GPIO_Pin_2); //输出0,默认接收状态
|
||||
|
||||
USART5_Init(BaudRate); //RS485对应的串口初始化
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: RS485_ReceiveData
|
||||
* 功能说明: RS485接收数据
|
||||
* 形 参: rxData -> 接收到的数据
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void RS485_ReceiveData(uint8_t rxData)
|
||||
{
|
||||
static uint8_t RX_State = 0; //接收状态
|
||||
static uint8_t CS = 0; //接收核验和
|
||||
static uint8_t RX_Size = 0; //接收通讯数据长度
|
||||
static uint8_t Byte_Count = 0; //接收数据字节计数
|
||||
|
||||
// printf("R = %x\r\n", rxData);
|
||||
switch(RX_State)
|
||||
{
|
||||
case 0: //第一前导字节
|
||||
if(rxData == 0xfe){
|
||||
RX_State = 1;
|
||||
}else{
|
||||
RX_State = 0;
|
||||
}
|
||||
break;
|
||||
case 1: //第二前导字节
|
||||
if(rxData == 0xfe){
|
||||
RX_State = 1; //转到接收帧头
|
||||
}else{
|
||||
if(rxData == 0x68)
|
||||
{
|
||||
RX_State = 3; //转到接收设备通讯地址
|
||||
CS = 0x68;
|
||||
}else{
|
||||
RX_State = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 2: //接收帧头
|
||||
if(rxData == 0x68){
|
||||
RX_State = 3; //转到接收设备通讯地址
|
||||
CS = 0x68;
|
||||
}else{
|
||||
RX_State = 0;
|
||||
}
|
||||
break;
|
||||
case 3: //接收设备通讯地址
|
||||
RS485_RX_BUF[0] = rxData;
|
||||
CS += rxData;
|
||||
RX_State = 4;
|
||||
break;
|
||||
case 4: //接收帧头
|
||||
if(rxData == 0x68){
|
||||
RX_State = 5; //转到接收通讯命令
|
||||
CS += 0x68;
|
||||
}else{
|
||||
RX_State = 0;
|
||||
}
|
||||
break;
|
||||
case 5: //接收通讯命令
|
||||
RS485_RX_BUF[1] = rxData;
|
||||
CS += rxData;
|
||||
RX_State = 6; //转到接收数据长度
|
||||
break;
|
||||
case 6: //接收通讯数据长度
|
||||
RS485_RX_BUF[2] = rxData;
|
||||
CS += rxData;
|
||||
RX_Size = rxData; //接收的数据长度
|
||||
if(RX_Size == 0x00){ //如果数据长度为0,则直接转到接收校验码
|
||||
RX_State = 8;
|
||||
}else{
|
||||
RX_State = 7; //转到接收数据
|
||||
}
|
||||
break;
|
||||
case 7: //接收N个字节数据
|
||||
if(Byte_Count < RX_Size-1){
|
||||
RS485_RX_BUF[Byte_Count + 3] = rxData;
|
||||
CS += rxData;
|
||||
Byte_Count++;
|
||||
}else{
|
||||
RS485_RX_BUF[Byte_Count + 3] = rxData;
|
||||
CS += rxData;
|
||||
Byte_Count = 0; //已完成N个字节的数据接收计数归0
|
||||
RX_State = 8; //转到接收核验码
|
||||
}
|
||||
break;
|
||||
case 8: //接收校验
|
||||
if(CS != rxData){
|
||||
RX_State = 0;
|
||||
}else{
|
||||
RX_State = 9; //转到接收帧尾码0x16
|
||||
}
|
||||
break;
|
||||
case 9: //接收帧尾
|
||||
if(rxData == 0x16){ //是帧尾吗?
|
||||
RS485_RX_STA = 0xfd; //一帧接收成功,标记USART_RX_STA=0xfd通知主程序进行通讯处理
|
||||
}
|
||||
RX_State = 0;
|
||||
break;
|
||||
default: //其它
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: Receive_One
|
||||
* 功能说明: 接收一帧通讯函数
|
||||
* 形 参: 接收存取地址指针
|
||||
* 返 回 值: 接收正确标志,1 为接收到一帧数据,0 未接收到数据
|
||||
***********************************************************************
|
||||
*/
|
||||
// uint8_t Receive_One(uint8_t *s)
|
||||
// {
|
||||
// if(RS485_RX_STA == 0xfd)
|
||||
// {
|
||||
// return 1; //一帧接收成功,关闭接收通讯,处理一帧完后再打开
|
||||
// }else{
|
||||
// return 0;
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: RS485_SendData
|
||||
* 功能说明: 发送一个字节数据
|
||||
* 形 参: 发送数据
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void RS485_SendData(uint8_t Serial_data)
|
||||
{
|
||||
// CTRL485 = 1; //设置为发送模式
|
||||
UART5_Send_Data(Serial_data);
|
||||
// CTRL485 = 0; //恢复为接收模式
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: RS485_SendOne
|
||||
* 功能说明: 通过RS485发送一帧数据
|
||||
* 形 参: 发送数据帧地址指针
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void RS485_SendOne(uint8_t *s)
|
||||
{
|
||||
uint8_t i;
|
||||
uint8_t CS = 0x68; //接收核验和
|
||||
uint8_t TX_Size = 0; //接收通讯数据长度
|
||||
|
||||
printf("\r\nRS485 --> %x\r\n", *(s+1));
|
||||
|
||||
CTRL485 = 1; //RS-485 通讯,切换为发送状态
|
||||
|
||||
delay_ms(1);
|
||||
RS485_SendData(0xfe); //发送前导字节
|
||||
RS485_SendData(0xfe);
|
||||
RS485_SendData(0xfe);
|
||||
RS485_SendData(0xfe);
|
||||
RS485_SendData(0x68); //发送帧头
|
||||
RS485_SendData(*s); //发送地址
|
||||
CS += *s;
|
||||
RS485_SendData(0x68); //发送帧头
|
||||
CS += 0x68;
|
||||
RS485_SendData(*(s+1)); //发送帧命令
|
||||
CS += *(s+1);
|
||||
TX_Size = *(s+2); //取出通讯数据长度
|
||||
RS485_SendData(TX_Size); //发送数据长度
|
||||
CS += *(s+2);
|
||||
for(i=0; i<TX_Size; i++) //发送数据
|
||||
{
|
||||
RS485_SendData(*(s+i+3));
|
||||
CS += (*(s+i+3));
|
||||
}
|
||||
RS485_SendData(CS); //发送校验字节
|
||||
RS485_SendData(0x16); //发送帧尾
|
||||
|
||||
delay_ms(1);
|
||||
|
||||
CTRL485 = 0; //一帧发送完毕,恢复信道切换功能
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: Serial_AddrxDatas
|
||||
* 功能说明: 通讯地址判断
|
||||
* 形 参: s 指向从通讯地址
|
||||
* 返 回 值: 0x00 错误,0x01 正确,0x02 广播地址
|
||||
***********************************************************************
|
||||
*/
|
||||
static uint8_t Serial_Address(uint8_t *s)
|
||||
{
|
||||
// printf("\r\n地址:%x\r\n", *s);
|
||||
if(*s == 0x99)
|
||||
{
|
||||
// printf("\r\n收到广播指令\r\n");
|
||||
return(0x02); //是广播地址
|
||||
}
|
||||
if(*s == Address)
|
||||
{
|
||||
// printf("\r\n地址匹配正确\r\n");
|
||||
return(0x01); //地址匹配正确
|
||||
}
|
||||
// printf("\r\n地址匹配不正确\r\n");
|
||||
return(0x00); //地址匹配不正确
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: RS485_CommandDecoding
|
||||
* 功能说明: 执行通讯命令
|
||||
* 形 参: s 发送数据帧地址指针
|
||||
* 返 回 值: 0 错误,1 正确
|
||||
***********************************************************************
|
||||
*/
|
||||
uint8_t RS485_CommandDecoding(uint8_t *pRxBuf, uint8_t *pTxBuf)
|
||||
{
|
||||
printf("\r\nRS485_%x <-- %x\r\n", *(pRxBuf+3), *(pRxBuf+1));
|
||||
rxCmd = *(pRxBuf+1);
|
||||
|
||||
switch(Serial_Address(pRxBuf)) //判断地址是否正确
|
||||
{
|
||||
case 0x02: //广播地址0x99
|
||||
switch(*(pRxBuf+1)) //通讯命令译码
|
||||
{
|
||||
case 0x20: //主机广播开门命令
|
||||
printf("\r\n收到广播开门指令\r\n");
|
||||
radioCom = 1;
|
||||
isOpenDoor = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x01: //正常地址
|
||||
slaveAddress = *(pRxBuf+3); //取出应答从机的地址
|
||||
|
||||
switch(*(pRxBuf+1)) //通讯命令译码
|
||||
{
|
||||
case 0x00: //应答命令
|
||||
|
||||
break;
|
||||
|
||||
case 0x01: //读取超声波测量值
|
||||
|
||||
break;
|
||||
|
||||
case 0x10: //开门指令
|
||||
// switch(slaveAddress)
|
||||
// {
|
||||
// case 0x11: //从机1的分机1返回数据
|
||||
// devRunningStatusNO_1 = 1;
|
||||
// break;
|
||||
//
|
||||
// case 0x12: //从机1的分机2返回数据
|
||||
// devRunningStatusNO_2 = 1;
|
||||
// break;
|
||||
//
|
||||
// case 0x21: //从机2的分机1返回数据
|
||||
// devRunningStatusNO_3 = 1;
|
||||
// break;
|
||||
//
|
||||
// case 0x22: //从机2的分机2返回数据
|
||||
// devRunningStatusNO_4 = 1;
|
||||
// break;
|
||||
//
|
||||
// default:
|
||||
// printf("\r\nError_0x10指令出错\r\n");
|
||||
// break;
|
||||
// }
|
||||
|
||||
break;
|
||||
|
||||
case 0x11: //获取开门控制运行状态指令
|
||||
// switch(slaveAddress)
|
||||
// {
|
||||
// case 0x11: //从机1的分机1返回数据
|
||||
// devRunningStatusNO_1 = *(pRxBuf+4);
|
||||
// printf("\r\nRX_Data = 0x%02X\r\n", *(pRxBuf+4));
|
||||
// break;
|
||||
//
|
||||
// case 0x12: //从机1的分机2返回数据
|
||||
// devRunningStatusNO_2 = *(pRxBuf+4);
|
||||
// printf("\r\nRX_Data = 0x%02X\r\n", *(pRxBuf+4));
|
||||
// break;
|
||||
//
|
||||
// case 0x21: //从机2的分机1返回数据
|
||||
// devRunningStatusNO_3 = *(pRxBuf+4);
|
||||
// printf("\r\nRX_Data = 0x%02X\r\n", *(pRxBuf+4));
|
||||
// break;
|
||||
//
|
||||
// case 0x22: //从机2的分机2返回数据
|
||||
// devRunningStatusNO_4 = *(pRxBuf+4);
|
||||
// printf("\r\nRX_Data = 0x%02X\r\n", *(pRxBuf+4));
|
||||
// break;
|
||||
//
|
||||
// default:
|
||||
// printf("\r\nError_0x10指令出错\r\n");
|
||||
// break;
|
||||
// }
|
||||
break;
|
||||
|
||||
case 0x12: //获取从机测距数据指令
|
||||
// switch(slaveAddress)
|
||||
// {
|
||||
// case 0x10:
|
||||
// case 0x11:
|
||||
// case 0x12:
|
||||
// getDistance1 = *(pRxBuf+4); //玻璃
|
||||
// getDistance2 = *(pRxBuf+5); //金属
|
||||
// break;
|
||||
//
|
||||
// case 0x20:
|
||||
// case 0x21:
|
||||
// case 0x22:
|
||||
// getDistance3 = *(pRxBuf+4); //瓶子
|
||||
// getDistance4 = *(pRxBuf+5); //塑料
|
||||
// break;
|
||||
//
|
||||
// }
|
||||
// printf("\r\nRX_Data = %d, %d\r\n", *(pRxBuf+4), *(pRxBuf+5));
|
||||
break;
|
||||
|
||||
case 0x13: //获取从机投放数据指令
|
||||
// switch(slaveAddress)
|
||||
// {
|
||||
// case 0x11: //从机1的分机1返回数据(注意:此称重由第2路秤返回)
|
||||
// getWeight4 = (uint16_t)(*(pRxBuf+4)) << 8; //取出重量高8位数据
|
||||
// getWeight4 |= *(pRxBuf+5); //取出重量低8位数据
|
||||
//
|
||||
// getWeightBefore4 = (uint16_t)(*(pRxBuf+6)) << 8; //取出重量高8位数据
|
||||
// getWeightBefore4 |= *(pRxBuf+7); //取出重量低8位数据
|
||||
//
|
||||
// getWeightAfter4 = (uint16_t)(*(pRxBuf+8)) << 8; //取出重量高8位数据
|
||||
// getWeightAfter4 |= *(pRxBuf+9); //取出重量低8位数据
|
||||
//
|
||||
// getDistance1 = *(pRxBuf+10); //取出测距数据
|
||||
//
|
||||
// faultCodeNO_1 = *(pRxBuf+11); //取出设备故障码
|
||||
//
|
||||
// devRunningStatusNO_1 = 3;
|
||||
// printf("\r\nRX_Data1 = %d, %d, %d, %d, %d\r\n", getWeight4, getWeightBefore4, getWeightAfter4, getDistance1, faultCodeNO_1);
|
||||
// break;
|
||||
//
|
||||
// case 0x12: //从机1的分机2返回数据(注意:此称重由第3路秤返回)
|
||||
// getWeight3 = (uint16_t)(*(pRxBuf+4)) << 8; //取出重量高8位数据
|
||||
// getWeight3 |= *(pRxBuf+5); //取出重量低8位数据
|
||||
//
|
||||
// getWeightBefore3 = (uint16_t)(*(pRxBuf+6)) << 8; //取出重量高8位数据
|
||||
// getWeightBefore3 |= *(pRxBuf+7); //取出重量低8位数据
|
||||
//
|
||||
// getWeightAfter3 = (uint16_t)(*(pRxBuf+8)) << 8; //取出重量高8位数据
|
||||
// getWeightAfter3 |= *(pRxBuf+9); //取出重量低8位数据
|
||||
//
|
||||
// getDistance2 = *(pRxBuf+10); //取出测距数据
|
||||
//
|
||||
// faultCodeNO_2 = *(pRxBuf+11); //取出设备故障码
|
||||
//
|
||||
// devRunningStatusNO_2 = 3;
|
||||
// printf("\r\nRX_Data2 = %d, %d, %d, %d, %d\r\n", getWeight3, getWeightBefore3, getWeightAfter3, getDistance2, faultCodeNO_2);
|
||||
// break;
|
||||
//
|
||||
// case 0x21: //从机2的分机1返回数据(注意:此称重由第3路秤返回)
|
||||
// getWeight2 = (uint16_t)(*(pRxBuf+4)) << 8; //取出重量高8位数据
|
||||
// getWeight2 |= *(pRxBuf+5); //取出重量低8位数据
|
||||
//
|
||||
// getWeightBefore2 = (uint16_t)(*(pRxBuf+6)) << 8; //取出重量高8位数据
|
||||
// getWeightBefore2 |= *(pRxBuf+7); //取出重量低8位数据
|
||||
//
|
||||
// getWeightAfter2 = (uint16_t)(*(pRxBuf+8)) << 8; //取出重量高8位数据
|
||||
// getWeightAfter2 |= *(pRxBuf+9); //取出重量低8位数据
|
||||
//
|
||||
// getDistance3 = *(pRxBuf+10); //取出测距数据
|
||||
//
|
||||
// faultCodeNO_3 = *(pRxBuf+11); //取出设备故障码
|
||||
//
|
||||
// devRunningStatusNO_3 = 3;
|
||||
// printf("\r\nRX_Data3 = %d, %d, %d, %d, %d\r\n", getWeight2, getWeightBefore2, getWeightAfter2, getDistance3, faultCodeNO_3);
|
||||
// break;
|
||||
//
|
||||
// case 0x22: //从机2的分机2返回数据
|
||||
// getWeight1 = (uint16_t)(*(pRxBuf+4)) << 8; //取出重量高8位数据
|
||||
// getWeight1 |= *(pRxBuf+5); //取出重量低8位数据
|
||||
//
|
||||
// getWeightBefore1 = (uint16_t)(*(pRxBuf+6)) << 8; //取出重量高8位数据
|
||||
// getWeightBefore1 |= *(pRxBuf+7); //取出重量低8位数据
|
||||
//
|
||||
// getWeightAfter1 = (uint16_t)(*(pRxBuf+8)) << 8; //取出重量高8位数据
|
||||
// getWeightAfter1 |= *(pRxBuf+9); //取出重量低8位数据
|
||||
//
|
||||
// getDistance4 = *(pRxBuf+10); //取出测距数据
|
||||
//
|
||||
// faultCodeNO_4 = *(pRxBuf+11); //取出设备故障码
|
||||
//
|
||||
// devRunningStatusNO_4 = 3;
|
||||
// printf("\r\nRX_Data4 = %d, %d, %d, %d, %d\r\n", getWeight1, getWeightBefore1, getWeightAfter1, getDistance4, faultCodeNO_4);
|
||||
// break;
|
||||
//
|
||||
// default:
|
||||
// printf("\r\nError_0x10指令出错\r\n");
|
||||
// break;
|
||||
// }
|
||||
|
||||
break;
|
||||
|
||||
case 0x14: //获取从机投放数据数据指令(这里只获取瓶子+塑料箱的数据)
|
||||
|
||||
// getWeight2 = (uint16_t)(*(pRxBuf+4)) << 8; //取出重量高8位数据
|
||||
// getWeight2 |= *(pRxBuf+5); //取出重量低8位数据
|
||||
//
|
||||
// getWeightBefore2 = (uint16_t)(*(pRxBuf+6)) << 8; //取出重量高8位数据
|
||||
// getWeightBefore2 |= *(pRxBuf+7); //取出重量低8位数据
|
||||
//
|
||||
// getWeightAfter2 = (uint16_t)(*(pRxBuf+8)) << 8; //取出重量高8位数据
|
||||
// getWeightAfter2 |= *(pRxBuf+9); //取出重量低8位数据
|
||||
//
|
||||
// getDistance3 = *(pRxBuf+10); //取出测距数据
|
||||
// faultCodeNO_3 = *(pRxBuf+11); //取出设备故障码
|
||||
//
|
||||
// devRunningStatusNO_3 = 3;
|
||||
//
|
||||
// getSmallBottleCount = (uint16_t)(*(pRxBuf+12)) << 8; //取出瓶子高8位数据
|
||||
// getSmallBottleCount |= *(pRxBuf+13); //取出瓶子低8位数据
|
||||
// getDistance5 = *(pRxBuf+14); //取出测距数据
|
||||
|
||||
// printf("\r\nRX_Data3 = %d, %d, %d, %d, %d\r\n", getWeight2, getWeightBefore2, getWeightAfter2, getDistance3, faultCodeNO_3);
|
||||
//
|
||||
break;
|
||||
|
||||
case 0x20: //获取从机设备的当前状态指令
|
||||
// switch(slaveAddress)
|
||||
// {
|
||||
// case 0x11: //从机1的分机1返回数据
|
||||
// deviceStatusNO_1 = *(pRxBuf+4);
|
||||
// break;
|
||||
//
|
||||
// case 0x12: //从机1的分机2返回数据
|
||||
// deviceStatusNO_2 = *(pRxBuf+4);
|
||||
// break;
|
||||
//
|
||||
// case 0x21: //从机2的分机1返回数据
|
||||
// deviceStatusNO_3 = *(pRxBuf+4);
|
||||
// break;
|
||||
//
|
||||
// case 0x22: //从机2的分机2返回数据
|
||||
// deviceStatusNO_4 = *(pRxBuf+4);
|
||||
// break;
|
||||
//
|
||||
// default:
|
||||
// printf("\r\nError_0x20指令出错\r\n");
|
||||
// break;
|
||||
// }
|
||||
break;
|
||||
|
||||
case 0x30: //主机发送用户信息应答
|
||||
break;
|
||||
|
||||
case 0x31: //主机发送用户投放奖励信息应答
|
||||
break;
|
||||
|
||||
case 0x32: //主机发送退出显示界面应答
|
||||
break;
|
||||
|
||||
case 0x39: //主机发送退出操作应答
|
||||
break;
|
||||
|
||||
default: //其他命令
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x00: //地址错误
|
||||
return 0;
|
||||
}
|
||||
return 1; //帧执行正确,返回
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: RS485_PackSendProtocol
|
||||
* 功能说明: 根据RS485消息打包发送命令帧
|
||||
* 形 参: msg -> RS485发送消息
|
||||
* (其中msg->msgType为指令,msg->msgData为要发送的从机地址)
|
||||
* 0x01->读取超声波测量值;
|
||||
* 0x02->读取重量值
|
||||
* 0x03->读取温度值
|
||||
* 0x10->读取温度、测距、水位、重量、身份信息的组合
|
||||
* 0x20->主机广播开门指令
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void RS485_PackSendProtocol(Com_ProtocolMessage *msg)
|
||||
{
|
||||
RS485_TX_BUF[0] = msg->msgData; //设置从机通讯地址
|
||||
RS485_TX_BUF[1] = msg->msgType; //存入指令码
|
||||
RS485_TX_BUF[2] = 0; //存入数据长度
|
||||
|
||||
// switch(msg->msgType)
|
||||
// {
|
||||
// case 0x30:
|
||||
// RS485_TX_BUF[2] = 27; //存入数据长度
|
||||
//
|
||||
// RS485_TX_BUF[3] = isAuth; //存入数据
|
||||
// RS485_TX_BUF[4] = putInType;
|
||||
// memcpy(&RS485_TX_BUF[5], icCardNumberBit, 17);
|
||||
// RS485_TX_BUF[5+17] = (uint8_t)(accountNum >> 24);
|
||||
// RS485_TX_BUF[6+17] = (uint8_t)(accountNum >> 16);
|
||||
// RS485_TX_BUF[7+17] = (uint8_t)(accountNum >> 8);
|
||||
// RS485_TX_BUF[8+17] = (uint8_t)accountNum;
|
||||
//
|
||||
// RS485_TX_BUF[9+17] = (uint8_t)(capital >> 24);
|
||||
// RS485_TX_BUF[10+17] = (uint8_t)(capital >> 16);
|
||||
// RS485_TX_BUF[11+17] = (uint8_t)(capital >> 8);
|
||||
// RS485_TX_BUF[12+17] = (uint8_t)capital;
|
||||
// break;
|
||||
//
|
||||
// case 0x31:
|
||||
// RS485_TX_BUF[2] = 8; //存入数据长度
|
||||
//
|
||||
// RS485_TX_BUF[3] = (uint8_t)(capital >> 24);
|
||||
// RS485_TX_BUF[4] = (uint8_t)(capital >> 16);
|
||||
// RS485_TX_BUF[5] = (uint8_t)(capital >> 8);
|
||||
// RS485_TX_BUF[6] = (uint8_t)capital;
|
||||
//
|
||||
// RS485_TX_BUF[7] = (uint8_t)(capitalAfter >> 24);
|
||||
// RS485_TX_BUF[8] = (uint8_t)(capitalAfter >> 16);
|
||||
// RS485_TX_BUF[9] = (uint8_t)(capitalAfter >> 8);
|
||||
// RS485_TX_BUF[10] = (uint8_t)capitalAfter;
|
||||
// break;
|
||||
//
|
||||
// default:
|
||||
// break;
|
||||
// }
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: RS485_Task
|
||||
* 功能说明: RS485通讯任务
|
||||
* 形 参: 无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void RS485_Task(void)
|
||||
{
|
||||
uint8_t rs485succeedFlag = 0;
|
||||
uint8_t timerOut = 0;
|
||||
static Com_ProtocolMessage *pMsg;
|
||||
static timer timer_01;
|
||||
static uint8_t timer_ok = 0;
|
||||
|
||||
if(timer_ok == 0)
|
||||
{
|
||||
timer_ok = 1;
|
||||
timer_set(&timer_01, 4); //创建1个定时器
|
||||
}
|
||||
|
||||
pMsg = MessageGet(MSG_FIFO_RS485_PROTOCOL); //从消息对列中取出RS485通讯协议消息
|
||||
if(pMsg)
|
||||
{
|
||||
// printf("\r\n----->RS485有数据要发送正在加载数据......\r\n");
|
||||
// printf("\r\n----->RS485msgType = %x\r\n", pMsg->msgType);
|
||||
// printf("\r\n----->RS485msgData = %x\r\n", pMsg->msgData);
|
||||
|
||||
RS485_PackSendProtocol(pMsg);
|
||||
RS485_SendOne(RS485_TX_BUF); //给从机发送一帧数据
|
||||
|
||||
if(pMsg->msgData == 0x99) //广播地址无需等待应答
|
||||
{
|
||||
RS485_RX_STA = 0;
|
||||
}else{
|
||||
timer_restart(&timer_01);
|
||||
while(!timerOut && !rs485succeedFlag)
|
||||
{
|
||||
if(timer_expired(&timer_01)) //超时未接收到数据
|
||||
{
|
||||
timerOut = 1; //超时返回初始状态
|
||||
printf("\r\n----->RS485TimerOut\r\n");
|
||||
RS485_RX_STA = 0;
|
||||
}
|
||||
if(RS485_RX_STA == 0xfd) //有接收到从机返回的数据,进行地址和数据验证
|
||||
{
|
||||
RS485_RX_STA = 0;
|
||||
if(RS485_CommandDecoding(RS485_RX_BUF, RS485_TX_BUF)) //解释返回的数据
|
||||
{
|
||||
// printf("\r\nmsgType = %x, rxCmd = %x\r\n", pMsg->msgType, rxCmd);
|
||||
if(pMsg->msgType == rxCmd)
|
||||
{
|
||||
rs485succeedFlag = 1;
|
||||
RS485_CommunicationState = 1; //设置本次发送的命令帧成功
|
||||
|
||||
printf("\r\n----->RS485<--OK\r\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 YNHB *****END OF FILE*******************/
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :RS485.h
|
||||
* 描 述 :RS485通信处理头文件
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/02/10
|
||||
*********************************************************************************/
|
||||
#ifndef __RS485_H
|
||||
#define __RS485_H
|
||||
|
||||
#include "stdio.h"
|
||||
#include "sys.h"
|
||||
|
||||
#define CTRL485 PCout(2) //485模式控制引脚
|
||||
|
||||
extern uint8_t Address;
|
||||
|
||||
extern uint8_t RS485_RX_BUF[64]; //接收缓冲,最大63个字节.末字节为换行符
|
||||
extern uint8_t RS485_TX_BUF[64]; //发送缓冲,最大64个字节.
|
||||
|
||||
extern uint8_t RS485_RX_STA; //RS485接收状态标记
|
||||
extern uint8_t RS485_CommunicationState; //RS485通讯成功与否标志
|
||||
extern uint8_t radioCom; //广播命令
|
||||
extern uint8_t responseMark; //主机应答标志
|
||||
extern uint16_t RS485_serialNumber; //RS485通信流水号
|
||||
|
||||
extern uint8_t getMCU2DataStatus; //取得MCU2的数据状态
|
||||
extern uint8_t getMCU2DistanceStatus; //取得MCU2的测距数据状态
|
||||
|
||||
void RS485_Init(void);
|
||||
void RS485_1(void);
|
||||
void RS485_ReceiveData(uint8_t rxData);
|
||||
|
||||
void SendDoorCtrlCMD(void); //向从机发送开门控制指令
|
||||
void SendGetPutInMsgCMD(void); //向从机发送请求用户投放数据
|
||||
void SendReadyPutInCMD(void);
|
||||
void SendEndPutInCMD(void);
|
||||
|
||||
void RS485_Task(void);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 CXHY *****END OF FILE*******************/
|
||||
+177
@@ -0,0 +1,177 @@
|
||||
/*************************** (C) COPYRIGHT 2017 Ping ****************************
|
||||
* 文件名 :scale.c
|
||||
* 描 述 :称驱动程序
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/03/06
|
||||
*********************************************************************************/
|
||||
#include "stdio.h"
|
||||
#include "scale.h"
|
||||
#include "timer.h"
|
||||
|
||||
uint16_t weight1 = 0; //当前称上面的重量,放大100倍,单位kg
|
||||
uint16_t weight2 = 0;
|
||||
uint16_t weight3 = 0;
|
||||
uint16_t weight4 = 0;
|
||||
|
||||
uint8_t scaleNum = 0; //称盘编号
|
||||
uint8_t receiveScaleNum = 0; //取得的称盘编号
|
||||
|
||||
uint8_t calibrationParam1[16]; //校准时接收到的数据
|
||||
uint8_t calibrationParam2[16];
|
||||
|
||||
uint8_t getCalibraDataMark1 = 0; //取得校准指令数据
|
||||
uint8_t getCalibraZeroMark1 = 0; //取得校准零点
|
||||
uint8_t getCalibraParamOkMark1 = 0; //取得校准完成
|
||||
|
||||
uint8_t getCalibraDataMark2 = 0;
|
||||
uint8_t getCalibraZeroMark2 = 0;
|
||||
uint8_t getCalibraParamOkMark2 = 0;
|
||||
|
||||
void ScaleCmdRun1(uint8_t* pRxBuf);
|
||||
void ScaleCmdRun2(uint8_t* pRxBuf);
|
||||
void ScaleCmdDecodeTask(void);
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: Scale_Init
|
||||
* 功能说明: 称 电源控制IO口初始化
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void ScaleInit(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: ScalePowerON
|
||||
* 功能说明: 打开称电源
|
||||
* 形 参:选择哪一路秤称电源打开
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void ScalePowerON(uint8_t whichOne)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: ScalePowerOFF
|
||||
* 功能说明: 关闭称电源
|
||||
* 形 参:whichOne -> 选择哪一路秤称电源打开
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void ScalePowerOFF(uint8_t whichOne)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: GetWeight
|
||||
* 功能说明: 取得秤上面的重量
|
||||
* 形 参:无
|
||||
* 返 回 值: 无(调用此函数后会改变全局变量currentWeight、currentWeight2)
|
||||
***********************************************************************
|
||||
*/
|
||||
void SendCalibraCmd(uint8_t num)
|
||||
{
|
||||
uint8_t cmd[10] = {0xfe, 0xfe, 0xfe, 0x68, 0x00, 0x68, 0xa1, 0x00, 0x71, 0x16};
|
||||
|
||||
if(num ==1)
|
||||
{
|
||||
USART4_SendFrameData(cmd, 10);
|
||||
}else if(num == 2){
|
||||
USART5_SendFrameData(cmd, 10);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: ScaleCmdRun1
|
||||
* 功能说明: 称盘校准指令执行
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void ScaleCmdRun1(uint8_t* pRxBuf)
|
||||
{
|
||||
uint8_t proNum;
|
||||
|
||||
proNum = *(pRxBuf+1);
|
||||
|
||||
printf("\r\nS1 <-- 0x%02X\r\n", proNum);
|
||||
switch(proNum) //通讯命令译码
|
||||
{
|
||||
case 0xA2: //收到校准零点
|
||||
getCalibraZeroMark1 = 1;
|
||||
break;
|
||||
|
||||
case 0xA3:
|
||||
getCalibraParamOkMark1 = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: ScaleCmdRun2
|
||||
* 功能说明: 称盘校准指令执行
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void ScaleCmdRun2(uint8_t* pRxBuf)
|
||||
{
|
||||
uint8_t proNum;
|
||||
|
||||
proNum = *(pRxBuf+1);
|
||||
|
||||
printf("\r\nS2 <-- 0x%02X\r\n", proNum);
|
||||
switch(proNum) //通讯命令译码
|
||||
{
|
||||
case 0xA2: //收到校准零点
|
||||
getCalibraZeroMark2 = 1;
|
||||
break;
|
||||
|
||||
case 0xA3:
|
||||
getCalibraParamOkMark2 = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: ScaleCmdDecodeTask
|
||||
* 功能说明: 称重模块操作指令解码任务
|
||||
* 形 参: 无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void ScaleCmdDecodeTask(void)
|
||||
{
|
||||
if(getCalibraDataMark1 == 1) //有接收到数据
|
||||
{
|
||||
ScaleCmdRun1(calibrationParam1); //解释返回的数据
|
||||
getCalibraDataMark1 = 0;
|
||||
}
|
||||
|
||||
if(getCalibraDataMark2 == 1) //有接收到数据
|
||||
{
|
||||
ScaleCmdRun2(calibrationParam2); //解释返回的数据
|
||||
getCalibraDataMark2 = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 Ping *****END OF FILE*******************/
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :scale.h
|
||||
* 描 述 :称驱动程序
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/03/06
|
||||
*********************************************************************************/
|
||||
#ifndef __SCALE_H
|
||||
#define __SCALE_H
|
||||
|
||||
#include "stm32f10x.h"
|
||||
#include "usart1.h"
|
||||
#include "usart3.h"
|
||||
#include "usart4.h"
|
||||
#include "usart5.h"
|
||||
|
||||
extern uint16_t weight1; //当前称上面的重量,放大100倍,单位kg
|
||||
extern uint16_t weight2;
|
||||
extern uint16_t weight3;
|
||||
extern uint16_t weight4;
|
||||
|
||||
extern uint8_t scaleNum;
|
||||
extern uint8_t receiveScaleNum; //取得的称盘编号
|
||||
|
||||
extern uint8_t calibrationParam1[16];
|
||||
extern uint8_t calibrationParam2[16];
|
||||
|
||||
extern uint8_t getCalibraDataMark1; //取得校准指令数据
|
||||
extern uint8_t getCalibraZeroMark1; //取得校准零点
|
||||
extern uint8_t getCalibraParamOkMark1; //取得校准完成
|
||||
|
||||
extern uint8_t getCalibraDataMark2;
|
||||
extern uint8_t getCalibraZeroMark2;
|
||||
extern uint8_t getCalibraParamOkMark2;
|
||||
|
||||
|
||||
|
||||
void ScaleInit(void); //相关接口初始化
|
||||
void ScalePowerON(uint8_t whichOne); //秤电源打开
|
||||
void ScalePowerOFF(uint8_t whichOne); //秤电源关闭
|
||||
void Clear_01(void); //第一路秤清零
|
||||
void Clear_02(void); //第二路秤清零
|
||||
void ClearWeight(void); //清除称重数据
|
||||
|
||||
void WeightDetection(void); //称重检测
|
||||
void UpdateWeight(void); //更新当前秤上面的重量(没有投放操作时的称重变化)
|
||||
void GetWeight(void); //取得当前秤上面的重量(投放过程中的称重变化)
|
||||
|
||||
void SendCalibraCmd(uint8_t num);
|
||||
|
||||
#endif
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 CXHY *****END OF FILE*******************/
|
||||
Executable
+87
@@ -0,0 +1,87 @@
|
||||
/*************************** (C) COPYRIGHT 2014 GLHF ****************************
|
||||
* 文件名 :spi.h
|
||||
* 描 述 :SPI接口驱动程序
|
||||
* 版 本 :V1.0
|
||||
* 日 期 :2018-11-24
|
||||
* 作 者 :XuZhongPing
|
||||
* 更新记录 :
|
||||
*********************************************************************************/
|
||||
#include "spi.h"
|
||||
|
||||
/*
|
||||
* 函数名:SPI1_Init
|
||||
* 描述 :ENC28J60 SPI 接口初始化
|
||||
* 输入 :无
|
||||
* 输出 :无
|
||||
* 返回 :无
|
||||
*/
|
||||
void SPI1_Init(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
SPI_InitTypeDef SPI_InitStructure;
|
||||
|
||||
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOE, ENABLE );
|
||||
RCC_APB2PeriphClockCmd( RCC_APB2Periph_SPI1, ENABLE );//SPI1时钟使能
|
||||
|
||||
//PA5 -> SCK PA6 -> MISO PA7 -> MOSI
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //PA5/6/7复用推挽输出
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(GPIOA, &GPIO_InitStructure);
|
||||
|
||||
/* PC4-SPI1-NSS:SD-CS */ // 片选
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; // 推免输出
|
||||
GPIO_Init(GPIOE, &GPIO_InitStructure);
|
||||
GPIO_SetBits(GPIOE, GPIO_Pin_8); // 先把片选拉高,真正用的时候再拉低
|
||||
|
||||
/* PA4-SPI1-NSS:FLASH-CS */ // 片选
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; // 推免输出
|
||||
GPIO_Init(GPIOE, &GPIO_InitStructure);
|
||||
GPIO_SetBits(GPIOE, GPIO_Pin_7); // 先把片选拉高,真正用的时候再拉低
|
||||
|
||||
|
||||
/* SPI1 配置 */
|
||||
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
|
||||
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
|
||||
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
|
||||
SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
|
||||
SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
|
||||
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
|
||||
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_64;
|
||||
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
|
||||
SPI_InitStructure.SPI_CRCPolynomial = 7;
|
||||
SPI_Init(SPI1, &SPI_InitStructure);
|
||||
|
||||
/* 使能 SPI1 */
|
||||
SPI_Cmd(SPI1, ENABLE);
|
||||
}
|
||||
|
||||
/*
|
||||
* 函数名:SPI1_ReadWrite
|
||||
* 描述 :SPI1读写一字节数据
|
||||
* 输入 :
|
||||
* 输出 :
|
||||
* 返回 :SPI1_ReadWriteByte
|
||||
*/
|
||||
uint8_t SPI1_ReadWriteByte(uint8_t writedat)
|
||||
{
|
||||
uint8_t retry=0;
|
||||
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET) //检查指定的SPI标志位设置与否:发送缓存空标志位
|
||||
{
|
||||
retry++;
|
||||
if(retry>200)return 0;
|
||||
}
|
||||
SPI_I2S_SendData(SPI1, writedat); //通过外设SPIx发送一个数据
|
||||
retry=0;
|
||||
|
||||
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET) //检查指定的SPI标志位设置与否:接受缓存非空标志位
|
||||
{
|
||||
retry++;
|
||||
if(retry>200)return 0;
|
||||
}
|
||||
return SPI_I2S_ReceiveData(SPI1); //返回通过SPIx最近接收的数据
|
||||
}
|
||||
Executable
+10
@@ -0,0 +1,10 @@
|
||||
#ifndef __SPI1_H
|
||||
#define __SPI1_H
|
||||
|
||||
#include "stm32f10x.h"
|
||||
|
||||
void SPI1_Init(void);
|
||||
uint8_t SPI1_ReadWriteByte(uint8_t writedat);
|
||||
|
||||
|
||||
#endif
|
||||
+459
@@ -0,0 +1,459 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :stmflash.c
|
||||
* 描 述 :STM32-FLASH操作函数
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/07/23
|
||||
*********************************************************************************/
|
||||
#include "stmflash.h"
|
||||
#include "stdio.h"
|
||||
#include "delay.h"
|
||||
#include "timer.h"
|
||||
#include "gsm_gprs.h"
|
||||
#include "data_typedef.h"
|
||||
|
||||
#if STM32_FLASH_SIZE < 256 //中容量和小容量的MCU一页的大小都为1K字节
|
||||
#define STM_SECTOR_SIZE 1024 //一页字节数
|
||||
#else
|
||||
#define STM_SECTOR_SIZE 2048
|
||||
#endif
|
||||
|
||||
uint16_t STMFLASH_BUF[STM_SECTOR_SIZE/2]; //用于保存一个扇区的数据缓存,擦除扇区时需先读取原来保存的数据,然后再重新写入
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: STMFLASH_ReadHalfWord
|
||||
* 功能说明: 读取指定地址的半字(16位数据)
|
||||
* 形 参:faddr:读地址(此地址必须为2的倍数!!)
|
||||
* 返 回 值: 对应地址保存的数据
|
||||
***********************************************************************
|
||||
*/
|
||||
uint16_t STMFLASH_ReadHalfWord(uint32_t faddr)
|
||||
{
|
||||
return *(vu16*)faddr;
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: STMFLASH_Write_NoCheck
|
||||
* 功能说明: 不检查的向指定地址写入数据
|
||||
* 形 参:WriteAddr:起始地址
|
||||
* pBuffer:数据指针
|
||||
* NumToWrite:半字(16位)数
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void STMFLASH_Write_NoCheck(uint32_t WriteAddr, uint16_t *pBuffer, uint16_t NumToWrite)
|
||||
{
|
||||
uint16_t i;
|
||||
|
||||
for(i = 0; i < NumToWrite; i++)
|
||||
{
|
||||
FLASH_ProgramHalfWord(WriteAddr, pBuffer[i]);
|
||||
WriteAddr += 2; //地址增加2.
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: STMFLASH_Write
|
||||
* 功能说明: 从指定地址开始写入指定长度的数据
|
||||
* 形 参:WriteAddr:起始地址(此地址必须为2的倍数!!)
|
||||
* pBuffer:数据指针
|
||||
* NumToWrite:半字(16位)数(就是要写入的16位数据的个数.)
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void STMFLASH_Write(uint32_t WriteAddr, uint16_t *pBuffer, uint16_t NumToWrite)
|
||||
{
|
||||
uint32_t secpos; //扇区地址
|
||||
uint16_t secoff; //扇区内偏移地址(16位字计算)
|
||||
uint16_t secremain; //扇区内剩余地址(16位字计算)
|
||||
uint32_t offaddr; //去掉0X08000000后的地址
|
||||
uint16_t i;
|
||||
|
||||
if((WriteAddr < STM32_FLASH_BASE) || (WriteAddr >= (STM32_FLASH_BASE + 1024*STM32_FLASH_SIZE)))return; //非法地址
|
||||
FLASH_Unlock(); //解锁
|
||||
offaddr = WriteAddr-STM32_FLASH_BASE; //实际偏移地址.
|
||||
secpos = offaddr/STM_SECTOR_SIZE; //扇区地址 0~127 for STM32F103RBT6
|
||||
secoff = (offaddr%STM_SECTOR_SIZE)/2; //在扇区内的偏移(2个字节为基本单位.)
|
||||
secremain = STM_SECTOR_SIZE/2 - secoff; //扇区剩余空间大小
|
||||
if(NumToWrite <= secremain) //不大于该扇区范围
|
||||
{
|
||||
secremain = NumToWrite;
|
||||
}
|
||||
while(1)
|
||||
{
|
||||
STMFLASH_Read(secpos * STM_SECTOR_SIZE + STM32_FLASH_BASE, STMFLASH_BUF, STM_SECTOR_SIZE/2); //读出整个扇区的内容
|
||||
for(i = 0; i < secremain; i++) //校验数据
|
||||
{
|
||||
if(STMFLASH_BUF[secoff + i] != 0XFFFF)break; //需要擦除
|
||||
}
|
||||
if(i<secremain) //需要擦除
|
||||
{
|
||||
FLASH_ErasePage(secpos * STM_SECTOR_SIZE + STM32_FLASH_BASE); //擦除这个扇区
|
||||
for(i = 0; i < secremain; i++) //复制要写入的数据
|
||||
{
|
||||
STMFLASH_BUF[i + secoff] = pBuffer[i];
|
||||
}
|
||||
STMFLASH_Write_NoCheck(secpos * STM_SECTOR_SIZE + STM32_FLASH_BASE, STMFLASH_BUF, STM_SECTOR_SIZE/2); //写入整个扇区
|
||||
}else{ //写已经擦除了的,直接写入扇区剩余区间.
|
||||
STMFLASH_Write_NoCheck(WriteAddr,pBuffer,secremain);
|
||||
}
|
||||
|
||||
if(NumToWrite == secremain) //写入结束了
|
||||
{
|
||||
break;
|
||||
}else{ //写入未结束
|
||||
secpos++; //扇区地址增1
|
||||
secoff = 0; //偏移位置为0
|
||||
pBuffer += secremain; //指针偏移
|
||||
WriteAddr += secremain; //写地址偏移
|
||||
NumToWrite -= secremain; //字节(16位)数递减
|
||||
if(NumToWrite > (STM_SECTOR_SIZE/2)) //下一个扇区还是写不完
|
||||
{
|
||||
secremain = STM_SECTOR_SIZE/2;
|
||||
}else{ //下一个扇区可以写完了
|
||||
secremain = NumToWrite;
|
||||
}
|
||||
}
|
||||
}
|
||||
FLASH_Lock(); //上锁
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: STMFLASH_Read
|
||||
* 功能说明: 从指定地址开始读出指定长度的数据
|
||||
* 形 参:ReadAddr:起始地址
|
||||
* pBuffer:数据指针
|
||||
* NumToRead:半字(16位)数
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void STMFLASH_Read(uint32_t ReadAddr, uint16_t *pBuffer, uint16_t NumToRead)
|
||||
{
|
||||
uint16_t i;
|
||||
|
||||
for(i = 0; i < NumToRead; i++)
|
||||
{
|
||||
pBuffer[i] = STMFLASH_ReadHalfWord(ReadAddr); //读取2个字节.
|
||||
ReadAddr += 2; //偏移2个字节.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: STMFLASH_WriteHalfWord
|
||||
* 功能说明: 向指定FLASH地址写入一个16位数据
|
||||
* 形 参:WriteAddr:起始地址
|
||||
* WriteData:要写入的数据
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void STMFLASH_WriteHalfWord(uint32_t WriteAddr, uint16_t WriteData)
|
||||
{
|
||||
// STMFLASH_Write(WriteAddr, &WriteData, 1); //写入一个字(16位)
|
||||
FLASH_ProgramHalfWord(WriteAddr, WriteData);
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: DeviceConfigErase
|
||||
* 功能说明: 擦除参数保存区的flash
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void DeviceConfigErase(uint32_t WriteAddr)
|
||||
{
|
||||
uint32_t secpos; //扇区地址
|
||||
uint16_t secoff; //扇区内偏移地址(16位字计算)
|
||||
uint32_t offaddr; //去掉0X08000000后的地址
|
||||
|
||||
if((WriteAddr < STM32_FLASH_BASE) || (WriteAddr >= (STM32_FLASH_BASE + 1024*STM32_FLASH_SIZE)))return; //非法地址
|
||||
|
||||
offaddr = WriteAddr-STM32_FLASH_BASE; //实际偏移地址.
|
||||
secpos = offaddr/STM_SECTOR_SIZE; //扇区地址 0~127 for STM32F103RBT6
|
||||
|
||||
FLASH_ErasePage(secpos * STM_SECTOR_SIZE + STM32_FLASH_BASE); //擦除这个扇区
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: SaveDeviceConfig
|
||||
* 功能说明: 保存设备配置的参数
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void SaveDeviceConfig(void)
|
||||
{
|
||||
uint8_t i = 0;
|
||||
uint16_t uTempData = 0;
|
||||
uint32_t flashSaveAddr = 0;
|
||||
|
||||
flashSaveAddr = FLASH_SAVE_ADDR;
|
||||
printf("\r\nTime1 = %d\r\n", time_value);
|
||||
|
||||
FLASH_Unlock(); //解锁
|
||||
DeviceConfigErase(FLASH_SAVE_ADDR);
|
||||
|
||||
//数据保存成功标志位
|
||||
uTempData = 0xFFFF;
|
||||
STMFLASH_WriteHalfWord(flashSaveAddr, uTempData);
|
||||
flashSaveAddr += 2;
|
||||
|
||||
//设备操作密码
|
||||
uTempData = (uint16_t)(setPassword >> 16);
|
||||
STMFLASH_WriteHalfWord(flashSaveAddr, uTempData);
|
||||
flashSaveAddr += 2;
|
||||
uTempData = (uint16_t)setPassword;
|
||||
STMFLASH_WriteHalfWord(flashSaveAddr, uTempData);
|
||||
flashSaveAddr += 2;
|
||||
|
||||
//设备客户号
|
||||
uTempData = (uint16_t)(setCustomerID >> 16);
|
||||
STMFLASH_WriteHalfWord(flashSaveAddr, uTempData);
|
||||
flashSaveAddr += 2;
|
||||
uTempData = (uint16_t)setCustomerID;
|
||||
STMFLASH_WriteHalfWord(flashSaveAddr, uTempData);
|
||||
flashSaveAddr += 2;
|
||||
|
||||
//设备类型及通道数量
|
||||
uTempData = (uint16_t)(setDeviceType << 8) | setDevChannelNumbers;
|
||||
STMFLASH_WriteHalfWord(flashSaveAddr, uTempData);
|
||||
flashSaveAddr += 2;
|
||||
|
||||
//第1路投口相关参数
|
||||
uTempData = (uint16_t)(setDevChannel1Type << 8) | setDevChannel1DisDepthVal;
|
||||
STMFLASH_WriteHalfWord(flashSaveAddr, uTempData);
|
||||
flashSaveAddr += 2;
|
||||
uTempData = (uint16_t)(setDevChannel1DisMaxVal << 8) | setDevChannel1DisAlarmPercent;
|
||||
STMFLASH_WriteHalfWord(flashSaveAddr, uTempData);
|
||||
flashSaveAddr += 2;
|
||||
|
||||
//第2路投口相关参数
|
||||
uTempData = (uint16_t)(setDevChannel2Type << 8) | setDevChannel2DisDepthVal;
|
||||
STMFLASH_WriteHalfWord(flashSaveAddr, uTempData);
|
||||
flashSaveAddr += 2;
|
||||
uTempData = (uint16_t)(setDevChannel2DisMaxVal << 8) | setDevChannel2DisAlarmPercent;
|
||||
STMFLASH_WriteHalfWord(flashSaveAddr, uTempData);
|
||||
flashSaveAddr += 2;
|
||||
|
||||
//第3路投口相关参数
|
||||
uTempData = (uint16_t)(setDevChannel3Type << 8) | setDevChannel3DisDepthVal;
|
||||
STMFLASH_WriteHalfWord(flashSaveAddr, uTempData);
|
||||
flashSaveAddr += 2;
|
||||
uTempData = (uint16_t)(setDevChannel3DisMaxVal << 8) | setDevChannel3DisAlarmPercent;
|
||||
STMFLASH_WriteHalfWord(flashSaveAddr, uTempData);
|
||||
flashSaveAddr += 2;
|
||||
|
||||
//第4路投口相关参数
|
||||
uTempData = (uint16_t)(setDevChannel4Type << 8) | setDevChannel4DisDepthVal;
|
||||
STMFLASH_WriteHalfWord(flashSaveAddr, uTempData);
|
||||
flashSaveAddr += 2;
|
||||
uTempData = (uint16_t)(setDevChannel4DisMaxVal << 8) | setDevChannel4DisAlarmPercent;
|
||||
STMFLASH_WriteHalfWord(flashSaveAddr, uTempData);
|
||||
flashSaveAddr += 2;
|
||||
|
||||
flashSaveAddr += 24; //预留32个字节用于保存投口通道参数
|
||||
|
||||
//禁用IC卡用户功能和启用收运IC卡二维码功能标志位
|
||||
uTempData = (uint16_t)(setDisableICCardFunStatus << 8) | setEnableCleanQRCodeStatus;
|
||||
STMFLASH_WriteHalfWord(flashSaveAddr, uTempData);
|
||||
flashSaveAddr += 2;
|
||||
|
||||
//设备编号长度
|
||||
STMFLASH_WriteHalfWord(flashSaveAddr, setDeviceIdLength);
|
||||
flashSaveAddr += 2;
|
||||
|
||||
printf("\r\nTime2 = %d\r\n", time_value);
|
||||
//设备编号
|
||||
for(i = 0; i < 32; i+=2)
|
||||
{
|
||||
uTempData = (uint16_t)(setDeviceIdBuf[i] << 8) | setDeviceIdBuf[i+1];
|
||||
STMFLASH_WriteHalfWord(flashSaveAddr, uTempData);
|
||||
flashSaveAddr += 2;
|
||||
}
|
||||
printf("\r\nTime3 = %d\r\n", time_value);
|
||||
|
||||
//服务器IP地址及端口号
|
||||
uTempData = (uint16_t)(setIpAddr0 << 8) | setIpAddr1;
|
||||
STMFLASH_WriteHalfWord(flashSaveAddr, uTempData);
|
||||
flashSaveAddr += 2;
|
||||
uTempData = (uint16_t)(setIpAddr2 << 8) | setIpAddr3;
|
||||
STMFLASH_WriteHalfWord(flashSaveAddr, uTempData);
|
||||
flashSaveAddr += 2;
|
||||
STMFLASH_WriteHalfWord(flashSaveAddr, setIpPort);
|
||||
flashSaveAddr += 2;
|
||||
|
||||
//标志参数保存完成
|
||||
uTempData = 0x0A0B;
|
||||
STMFLASH_WriteHalfWord(FLASH_SAVE_ADDR, uTempData);
|
||||
FLASH_Lock(); //上锁
|
||||
|
||||
printf("\r\nTime4 = %d\r\n", time_value);
|
||||
printf("\r\n参数保存成功!\r\n");
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: GetDeviceConfig
|
||||
* 功能说明: 取得设备配置参数
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
uint8_t GetDeviceConfig(void)
|
||||
{
|
||||
uint8_t i = 0;
|
||||
uint16_t uTempData = 0;
|
||||
uint32_t flashSaveAddr = 0;
|
||||
|
||||
flashSaveAddr = FLASH_SAVE_ADDR;
|
||||
|
||||
uTempData = STMFLASH_ReadHalfWord(flashSaveAddr);
|
||||
flashSaveAddr += 2;
|
||||
|
||||
if(uTempData == 0x0A0B)
|
||||
{
|
||||
//设备操作密码
|
||||
uTempData = STMFLASH_ReadHalfWord(flashSaveAddr);
|
||||
flashSaveAddr += 2;
|
||||
setPassword = uTempData;
|
||||
uTempData = STMFLASH_ReadHalfWord(flashSaveAddr);
|
||||
flashSaveAddr += 2;
|
||||
setPassword = (setPassword << 16) | uTempData;
|
||||
|
||||
//设备客户号
|
||||
uTempData = STMFLASH_ReadHalfWord(flashSaveAddr);
|
||||
flashSaveAddr += 2;
|
||||
setCustomerID = uTempData;
|
||||
uTempData = STMFLASH_ReadHalfWord(flashSaveAddr);
|
||||
flashSaveAddr += 2;
|
||||
setCustomerID = (setCustomerID << 16) | uTempData;
|
||||
|
||||
//设备类型
|
||||
uTempData = STMFLASH_ReadHalfWord(flashSaveAddr);
|
||||
flashSaveAddr += 2;
|
||||
setDeviceType = uTempData >> 8;
|
||||
setDevChannelNumbers = (uint8_t)uTempData;
|
||||
|
||||
//第1路投口相关参数
|
||||
uTempData = STMFLASH_ReadHalfWord(flashSaveAddr);
|
||||
flashSaveAddr += 2;
|
||||
setDevChannel1Type = uTempData >> 8;
|
||||
setDevChannel1DisDepthVal = (uint8_t)uTempData;
|
||||
uTempData = STMFLASH_ReadHalfWord(flashSaveAddr);
|
||||
flashSaveAddr += 2;
|
||||
setDevChannel1DisMaxVal = uTempData >> 8;
|
||||
setDevChannel1DisAlarmPercent = (uint8_t)uTempData;
|
||||
|
||||
//第2路投口相关参数
|
||||
uTempData = STMFLASH_ReadHalfWord(flashSaveAddr);
|
||||
flashSaveAddr += 2;
|
||||
setDevChannel2Type = uTempData >> 8;
|
||||
setDevChannel2DisDepthVal = (uint8_t)uTempData;
|
||||
uTempData = STMFLASH_ReadHalfWord(flashSaveAddr);
|
||||
flashSaveAddr += 2;
|
||||
setDevChannel2DisMaxVal = uTempData >> 8;
|
||||
setDevChannel2DisAlarmPercent = (uint8_t)uTempData;
|
||||
|
||||
//第3路投口相关参数
|
||||
uTempData = STMFLASH_ReadHalfWord(flashSaveAddr);
|
||||
flashSaveAddr += 2;
|
||||
setDevChannel3Type = uTempData >> 8;
|
||||
setDevChannel3DisDepthVal = (uint8_t)uTempData;
|
||||
uTempData = STMFLASH_ReadHalfWord(flashSaveAddr);
|
||||
flashSaveAddr += 2;
|
||||
setDevChannel3DisMaxVal = uTempData >> 8;
|
||||
setDevChannel3DisAlarmPercent = (uint8_t)uTempData;
|
||||
|
||||
//第4路投口相关参数
|
||||
uTempData = STMFLASH_ReadHalfWord(flashSaveAddr);
|
||||
flashSaveAddr += 2;
|
||||
setDevChannel4Type = uTempData >> 8;
|
||||
setDevChannel4DisDepthVal = (uint8_t)uTempData;
|
||||
uTempData = STMFLASH_ReadHalfWord(flashSaveAddr);
|
||||
flashSaveAddr += 2;
|
||||
setDevChannel4DisMaxVal = uTempData >> 8;
|
||||
setDevChannel4DisAlarmPercent = (uint8_t)uTempData;
|
||||
|
||||
flashSaveAddr += 24;
|
||||
|
||||
//禁用IC卡用户功能和启用收运IC卡二维码功能标志位
|
||||
uTempData = STMFLASH_ReadHalfWord(flashSaveAddr);
|
||||
flashSaveAddr += 2;
|
||||
setDisableICCardFunStatus = uTempData >> 8;
|
||||
setEnableCleanQRCodeStatus = (uint8_t)uTempData;
|
||||
|
||||
//设备编号长度
|
||||
uTempData = STMFLASH_ReadHalfWord(flashSaveAddr);
|
||||
flashSaveAddr += 2;
|
||||
setDeviceIdLength = uTempData;
|
||||
|
||||
//设备编号
|
||||
for(i = 0; i < 32; i+=2)
|
||||
{
|
||||
uTempData = STMFLASH_ReadHalfWord(flashSaveAddr);
|
||||
flashSaveAddr += 2;
|
||||
setDeviceIdBuf[i] = uTempData >> 8;
|
||||
setDeviceIdBuf[i+1] = (uint8_t)uTempData;
|
||||
}
|
||||
|
||||
//服务器IP地址及端口号
|
||||
uTempData = STMFLASH_ReadHalfWord(flashSaveAddr);
|
||||
flashSaveAddr += 2;
|
||||
setIpAddr0 = uTempData >> 8;
|
||||
setIpAddr1 = (uint8_t)uTempData;
|
||||
uTempData = STMFLASH_ReadHalfWord(flashSaveAddr);
|
||||
flashSaveAddr += 2;
|
||||
setIpAddr2 = uTempData >> 8;
|
||||
setIpAddr3 = (uint8_t)uTempData;
|
||||
uTempData = STMFLASH_ReadHalfWord(flashSaveAddr);
|
||||
flashSaveAddr += 2;
|
||||
setIpPort = uTempData;
|
||||
|
||||
printf("\r\n参数读取成功!\r\n");
|
||||
|
||||
printf("\r\nSet P=%d; ID=%d; Type=%d; Cnt=%d; T1=%d, h1=%d, H1=%d, A1=%d; T2=%d, h2=%d, H2=%d, A2=%d, ICE=%d; ICQR=%d; "\
|
||||
"devLen=%d; devID=%s; IP=%d.%d.%d.%d:%d\r\n",
|
||||
setPassword,
|
||||
setCustomerID,
|
||||
setDeviceType,
|
||||
setDevChannelNumbers,
|
||||
setDevChannel1Type, setDevChannel1DisDepthVal, setDevChannel1DisMaxVal, setDevChannel1DisAlarmPercent,
|
||||
setDevChannel2Type, setDevChannel2DisDepthVal, setDevChannel2DisMaxVal, setDevChannel2DisAlarmPercent,
|
||||
setDisableICCardFunStatus,
|
||||
setEnableCleanQRCodeStatus,
|
||||
setDeviceIdLength,
|
||||
setDeviceIdBuf,
|
||||
setIpAddr0,setIpAddr1,setIpAddr2,setIpAddr3,setIpPort
|
||||
);
|
||||
|
||||
return 0;
|
||||
}else{
|
||||
printf("\r\n还没有保存过设备参数!\r\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: ResetDeviceConfig
|
||||
* 功能说明: 恢复设备配置参数到出厂设置
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void ResetDeviceConfig(void)
|
||||
{
|
||||
FLASH_Unlock(); //解锁
|
||||
DeviceConfigErase(FLASH_SAVE_ADDR);
|
||||
FLASH_Lock(); //上锁
|
||||
printf("\r\n设备配置参数已恢复成出厂设置!\r\n");
|
||||
}
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 CXHY *****END OF FILE*******************/
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :stmflash.c
|
||||
* 描 述 :STM32-FLASH操作函数
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/07/23
|
||||
*********************************************************************************/
|
||||
#ifndef __STMFLASH_H__
|
||||
#define __STMFLASH_H__
|
||||
#include "stm32f10x.h"
|
||||
|
||||
#define STM32_FLASH_SIZE 512 //所选STM32的FLASH容量大小(单位为K)
|
||||
#define STM32_FLASH_WREN 1 //使能FLASH写入(0,不是能;1,使能)
|
||||
|
||||
//FLASH地址
|
||||
#define STM32_FLASH_BASE 0x08000000 //STM32 FLASH的起始地址
|
||||
#define FLASH_SAVE_ADDR 0X0807F800 //设置FLASH 保存地址(必须为偶数)
|
||||
|
||||
|
||||
uint16_t STMFLASH_ReadHalfWord(uint32_t faddr); //读出半字
|
||||
uint32_t STMFLASH_ReadLenByte(uint32_t ReadAddr, uint16_t Len); //指定地址开始读取指定长度数据
|
||||
void STMFLASH_Write(uint32_t WriteAddr, uint16_t *pBuffer, uint16_t NumToWrite); //从指定地址开始写入指定长度的数据
|
||||
void STMFLASH_Read(uint32_t ReadAddr, uint16_t *pBuffer, uint16_t NumToRead); //从指定地址开始读出指定长度的数据
|
||||
void STMFLASH_WriteHalfWord(uint32_t WriteAddr, uint16_t WriteData); //从指定地址开写入一个半字(16位)
|
||||
|
||||
void SaveDeviceConfig(void);
|
||||
uint8_t GetDeviceConfig(void);
|
||||
void ResetDeviceConfig(void);
|
||||
|
||||
#endif
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 CXHY *****END OF FILE*******************/
|
||||
+353
@@ -0,0 +1,353 @@
|
||||
/*************************** (C) COPYRIGHT 2018 Ping ****************************
|
||||
* 文件名 :timer.c
|
||||
* 描 述 :定时器驱动代码
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/02/07
|
||||
*********************************************************************************/
|
||||
#include "timer.h"
|
||||
#include "usart1.h"
|
||||
#include "device.h"
|
||||
#include "data_typedef.h"
|
||||
|
||||
uint32_t time_value = 0;//uip 计时器,每10ms增加1.
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: clock_time
|
||||
* 功能说明: 取得当前计时值
|
||||
* 形 参: 无
|
||||
* 返 回 值: 当前计时值
|
||||
***********************************************************************
|
||||
*/
|
||||
clock_time_t clock_time(void)
|
||||
{
|
||||
return time_value; /* 10ms 单位 */
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: timer_set
|
||||
* 功能说明: 设置一个定时间隔
|
||||
* 形 参:
|
||||
* t:定时变量
|
||||
* interval:定时间隔值
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void timer_set(timer *t, clock_time_t interval)
|
||||
{
|
||||
t->interval = interval;
|
||||
t->start = clock_time();
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: timer_reset
|
||||
* 功能说明: 对定时变量进行复位
|
||||
* 形 参:
|
||||
* t:定时变量
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void timer_reset(timer *t)
|
||||
{
|
||||
t->start += t->interval;
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: timer_reset_interval
|
||||
* 功能说明: 重新设置定时时间
|
||||
* 形 参:
|
||||
* t:定时变量
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void timer_reset_interval(timer *t, clock_time_t interval)
|
||||
{
|
||||
t->interval = interval;
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: timer_restart
|
||||
* 功能说明: 从当前时间点重新启动定时器
|
||||
* 形 参:
|
||||
* t:定时变量
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void timer_restart(timer *t)
|
||||
{
|
||||
t->start = clock_time();
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: timer_expired
|
||||
* 功能说明: 判断一个定时器是否达到定时时间
|
||||
* 形 参:
|
||||
* t:定时变量
|
||||
* 返 回 值: 非零则已经到了定时时间,零则定时还未到
|
||||
***********************************************************************
|
||||
*/
|
||||
int timer_expired(timer *t)
|
||||
{
|
||||
return (clock_time_t)(clock_time() - t->start) >= (clock_time_t)t->interval;
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: timer_remaining
|
||||
* 功能说明: 判断一个定时器还剩下多少时间达到定时时间
|
||||
* 形 参:
|
||||
* t:定时变量
|
||||
* 返 回 值: 返回定时器剩余时间
|
||||
***********************************************************************
|
||||
*/
|
||||
uint32_t timer_remaining(timer *t)
|
||||
{
|
||||
uint32_t res = 0;
|
||||
|
||||
if(clock_time() < (t->start + (clock_time_t)t->interval))
|
||||
{
|
||||
res = (t->start + (clock_time_t)t->interval) - clock_time();
|
||||
return res;
|
||||
}else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
//定时器定时器2用于开始一个软件定时供外部程序使用
|
||||
//单位为100ms(0.1S)
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: TIM2_Int_Init
|
||||
* 功能说明: 定时器2初始化配置
|
||||
* 形 参:arr:自动重装值
|
||||
* psc:时钟预分频数
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void TIM2_Int_Init(uint16_t arr,uint16_t psc)
|
||||
{
|
||||
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); //时钟使能
|
||||
|
||||
TIM_TimeBaseStructure.TIM_Period = arr; //设置在下一个更新事件装入活动的自动重装载寄存器周期的值 计数到5000为500ms
|
||||
TIM_TimeBaseStructure.TIM_Prescaler = psc; //设置用来作为TIMx时钟频率除数的预分频值 10Khz的计数频率(即0.1ms周期)
|
||||
TIM_TimeBaseStructure.TIM_ClockDivision = 0; //设置时钟分割:TDTS = Tck_tim
|
||||
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //TIM向上计数模式
|
||||
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); //根据TIM_TimeBaseInitStruct中指定的参数初始化TIMx的时间基数单位
|
||||
|
||||
TIM_ITConfig( TIM2, TIM_IT_Update|TIM_IT_Trigger, ENABLE); //使能定时器2更新触发中断
|
||||
TIM_Cmd(TIM2, ENABLE); //使能TIMx外设
|
||||
|
||||
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn; //TIM3中断
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //先占优先级0级
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //从优先级3级
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道被使能
|
||||
NVIC_Init(&NVIC_InitStructure); //根据NVIC_InitStruct中指定的参数初始化外设NVIC寄存器
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: TIM2_IRQHandler
|
||||
* 功能说明: 定时器2中断服务子程序
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void TIM2_IRQHandler(void) //TIM2中断
|
||||
{
|
||||
if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET) //检查指定的TIM中断发生与否:TIM 中断源
|
||||
{
|
||||
time_value++; //计时器增加1
|
||||
}
|
||||
TIM_ClearITPendingBit(TIM2, TIM_IT_Update); //清除TIMx的中断待处理位:TIM 中断源
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//定时器3部分(用于按键扫描)每10ms中断一次
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: TIM3_Int_Init
|
||||
* 功能说明: 定时器3初始化配置
|
||||
* 形 参:arr:自动重装值
|
||||
* psc:时钟预分频数
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void TIM3_Int_Init(uint16_t arr,uint16_t psc)
|
||||
{
|
||||
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); //时钟使能
|
||||
|
||||
TIM_TimeBaseStructure.TIM_Period = arr; //设置在下一个更新事件装入活动的自动重装载寄存器周期的值
|
||||
TIM_TimeBaseStructure.TIM_Prescaler = psc; //设置用来作为TIMx时钟频率除数的预分频值 10Khz的计数频率(即0.1ms周期)
|
||||
TIM_TimeBaseStructure.TIM_ClockDivision = 0; //设置时钟分割:TDTS = Tck_tim
|
||||
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //TIM向上计数模式
|
||||
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); //根据TIM_TimeBaseInitStruct中指定的参数初始化TIMx的时间基数单位
|
||||
|
||||
TIM_ITConfig( TIM3, TIM_IT_Update|TIM_IT_Trigger, ENABLE); //使能定时器2更新触发中断
|
||||
TIM_Cmd(TIM3, ENABLE); //使能TIMx外设
|
||||
|
||||
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; //TIM3中断
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; //先占优先级0级
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; //从优先级3级
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道被使能
|
||||
NVIC_Init(&NVIC_InitStructure); //根据NVIC_InitStruct中指定的参数初始化外设NVIC寄存器
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: TIM3_IRQHandler
|
||||
* 功能说明: 定时器2中断服务子程序
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void TIM3_IRQHandler(void) //TIM3中断
|
||||
{
|
||||
uint8_t keyTemp = 0;
|
||||
static uint8_t timerCut = 0;
|
||||
|
||||
if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET) //检查指定的TIM中断发生与否:TIM 中断源
|
||||
{
|
||||
if(deviceInitFlag == 1)
|
||||
{
|
||||
// OptoKeyScanning();
|
||||
// BottleScanning(); //调用瓶子扫描检测函数
|
||||
|
||||
if(keyType == 0)
|
||||
{
|
||||
keyTemp = KeyScanning();
|
||||
}else if(keyType == 1){
|
||||
keyTemp = TouchKeyScanning();
|
||||
}
|
||||
|
||||
if(keyTemp != 0)
|
||||
{
|
||||
keyValue = keyTemp; //输出键值由外部读取后清除
|
||||
}
|
||||
}
|
||||
}
|
||||
TIM_ClearITPendingBit(TIM3, TIM_IT_Update); //清除TIMx的中断待处理位:TIM 中断源
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//定时器4部分(用于超声波测距)
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: TIM4_Int_Init
|
||||
* 功能说明: 定时器4初始化配置
|
||||
* 形 参:arr:自动重装值
|
||||
* psc:时钟预分频数
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void TIM4_Int_Init(u16 arr,u16 psc)
|
||||
{
|
||||
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE); //时钟使能
|
||||
|
||||
//定时器TIM4初始化
|
||||
TIM_TimeBaseStructure.TIM_Period = arr; //设置在下一个更新事件装入活动的自动重装载寄存器周期的值
|
||||
TIM_TimeBaseStructure.TIM_Prescaler =psc; //设置用来作为TIMx时钟频率除数的预分频值
|
||||
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; //设置时钟分割:TDTS = Tck_tim
|
||||
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //TIM向上计数模式
|
||||
TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure); //根据指定的参数初始化TIMx的时间基数单位
|
||||
|
||||
TIM_ITConfig(TIM4, TIM_IT_Update | TIM_IT_Trigger, ENABLE); //使能指定的TIM4中断,允许更新中断
|
||||
|
||||
//中断优先级NVIC设置
|
||||
NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
|
||||
TIM_Cmd(TIM4, DISABLE);
|
||||
// TIM_Cmd(TIM4, ENABLE);
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: TIM4_IRQHandler
|
||||
* 功能说明: 定时器4中断服务子程序
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void TIM4_IRQHandler(void) //TIM4中断
|
||||
{
|
||||
if (TIM_GetITStatus(TIM4, TIM_IT_Update) != RESET) //检查TIM4更新中断发生与否
|
||||
{
|
||||
TIM_ClearITPendingBit(TIM4, TIM_IT_Update); //清除TIMx更新中断标志
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//定时器4部分(用于二维码读头数据接收完成标记用)
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: TIM5_Int_Init
|
||||
* 功能说明: 定时器5初始化配置
|
||||
* 形 参:arr:自动重装值
|
||||
* psc:时钟预分频数
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void TIM5_Int_Init(uint16_t arr, uint16_t psc)
|
||||
{
|
||||
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5, ENABLE);
|
||||
|
||||
//定时器TIM5初始化
|
||||
TIM_TimeBaseStructure.TIM_Period = arr; //设置在下一个更新事件装入活动的自动重装载寄存器周期的值
|
||||
TIM_TimeBaseStructure.TIM_Prescaler =psc; //设置用来作为TIMx时钟频率除数的预分频值
|
||||
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; //设置时钟分割:TDTS = Tck_tim
|
||||
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //TIM向上计数模式
|
||||
TIM_TimeBaseInit(TIM5, &TIM_TimeBaseStructure); //根据指定的参数初始化TIMx的时间基数单位
|
||||
|
||||
TIM_ITConfig(TIM5,TIM_IT_Update,ENABLE ); //使能指定的TIM4中断,允许更新中断
|
||||
|
||||
//中断优先级NVIC设置
|
||||
NVIC_InitStructure.NVIC_IRQChannel = TIM5_IRQn; //TIM5中断
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3; //先占优先级3级
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; //从优先级2级
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道被使能
|
||||
NVIC_Init(&NVIC_InitStructure); //初始化NVIC寄存器
|
||||
|
||||
TIM_Cmd(TIM5, DISABLE); //失能TIMx外设
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: TIM5_IRQHandler
|
||||
* 功能说明: 定时器4中断服务子程序
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void TIM5_IRQHandler(void)
|
||||
{
|
||||
if(TIM_GetITStatus(TIM5, TIM_IT_Update) != RESET) //检查TIM5更新中断发生与否
|
||||
{
|
||||
USART1_RX_STA |= 1<<15; //标记接收完成
|
||||
TIM_ClearITPendingBit(TIM5, TIM_IT_Update); //清除TIMx更新中断标志
|
||||
TIM_Cmd(TIM5, DISABLE); //关闭TIMx
|
||||
}
|
||||
}
|
||||
|
||||
/******************** (C) COPYRIGHT 2018 Ping *****END OF FILE*******************/
|
||||
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
#ifndef __TIMER_H
|
||||
#define __TIMER_H
|
||||
|
||||
#include "stm32f10x.h"
|
||||
|
||||
typedef uint32_t clock_time_t;
|
||||
#define CLOCK_CONF_SECOND 10
|
||||
#define CLOCK_SECOND CLOCK_CONF_SECOND
|
||||
extern uint32_t time_value; //¼ÆÊ±Æ÷Öµ
|
||||
|
||||
|
||||
typedef struct _timer {
|
||||
clock_time_t start;
|
||||
clock_time_t interval;
|
||||
}timer;
|
||||
|
||||
void timer_set(timer *t, clock_time_t interval);
|
||||
void timer_reset(timer *t);
|
||||
void timer_reset_interval(timer *t, clock_time_t interval);
|
||||
void timer_restart(timer *t);
|
||||
int timer_expired(timer *t);
|
||||
uint32_t timer_remaining(timer *t);
|
||||
|
||||
void TIM2_Int_Init(u16 arr,u16 psc);
|
||||
|
||||
// void TIM2_Int_Init(u16 arr,u16 psc);
|
||||
void TIM3_Int_Init(u16 arr,u16 psc);
|
||||
void TIM3_Period_Reset(u16 arr);
|
||||
|
||||
void TIM4_Int_Init(u16 arr,u16 psc);
|
||||
void TIM5_Int_Init(u16 arr,u16 psc);
|
||||
|
||||
void TIM6_Int_Init(u16 arr,u16 psc);
|
||||
|
||||
#endif
|
||||
+453
@@ -0,0 +1,453 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :RS485.c
|
||||
* 描 述 :RS485通信处理函数,包含3部分:接收帧程序、发送帧程序及执行命令程序。
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/02/10
|
||||
*********************************************************************************/
|
||||
#include "delay.h"
|
||||
#include "sys.h"
|
||||
#include "RS485.h"
|
||||
#include "usart.h"
|
||||
#include "timer.h"
|
||||
#include "DataProcessing.h"
|
||||
#include "message.h"
|
||||
|
||||
/*通讯变量定义*/
|
||||
#define BaudRate 19200 //波特率1200bps
|
||||
|
||||
uint8_t Address = 0x00; //设备地址
|
||||
uint8_t RS485_RX_BUF[128]; //接收缓冲,最大64个字节
|
||||
uint8_t RS485_TX_BUF[64]; //发送缓冲,最大64个字节
|
||||
|
||||
//主程序变量定义
|
||||
uint8_t RS485_RX_STA = 0x00; //RS485接收状态标记
|
||||
uint8_t RS485_communicationStatus; //RS485通讯成功与否标志
|
||||
uint16_t RS485_serialNumber; //RS485通信流水号
|
||||
uint16_t RS485_RX_serialNumber; //RS485通信流水号
|
||||
uint8_t rxCmd; //从机返回的指令码
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: RS485_Init
|
||||
* 功能说明: 初始化RS485接口
|
||||
* 形 参: 无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void RS485_Init(void)
|
||||
{
|
||||
//GPIO端口设置
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
USART_InitTypeDef USART_InitStructure;
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); //使能GPIOA时钟
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); //使能USART2时钟
|
||||
|
||||
//RS485_TX_EN PA.0 RS485发送接收控制脚
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; //PA0端口配置
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(GPIOA, &GPIO_InitStructure);
|
||||
GPIO_ResetBits(GPIOA, GPIO_Pin_0); //输出0,默认接收状态
|
||||
|
||||
//USART2_TX PA.2
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; //PA.2
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出
|
||||
GPIO_Init(GPIOA, &GPIO_InitStructure); //初始化PA2
|
||||
|
||||
//USART2_RX PA.3
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //浮空输入
|
||||
GPIO_Init(GPIOA, &GPIO_InitStructure); //初始化PA3
|
||||
|
||||
//USART 初始化设置
|
||||
|
||||
USART_InitStructure.USART_BaudRate = BaudRate; //一般设置为9600;
|
||||
USART_InitStructure.USART_WordLength = USART_WordLength_8b; //字长为8位数据格式
|
||||
USART_InitStructure.USART_StopBits = USART_StopBits_1; //一个停止位
|
||||
USART_InitStructure.USART_Parity = USART_Parity_No; //无奇偶校验位
|
||||
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; //无硬件数据流控制
|
||||
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //收发模式
|
||||
USART_Init(USART2, &USART_InitStructure); //初始化串口
|
||||
|
||||
//Usart2 NVIC 配置
|
||||
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0 ; //抢占优先级0
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; //子优先级0
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
|
||||
NVIC_Init(&NVIC_InitStructure); //根据指定的参数初始化VIC寄存器
|
||||
|
||||
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE); //开启中断
|
||||
USART_Cmd(USART2, ENABLE); //使能串口
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: USART2_IRQHandler
|
||||
* 功能说明: 串口2中断服务子函数,用于RS485接收
|
||||
* 形 参: 无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void USART2_IRQHandler(void)
|
||||
{
|
||||
uint8_t res;
|
||||
static uint8_t RX_State = 0; //接收状态
|
||||
static uint8_t CS = 0; //接收核验和
|
||||
static uint8_t RX_Size = 0; //接收通讯数据长度
|
||||
static uint8_t Byte_Count = 0; //接收数据字节计数
|
||||
|
||||
if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET)
|
||||
{
|
||||
res = USART_ReceiveData(USART2); //读取接收到的数据
|
||||
// printf("RX_DATA = %x\r\n", res);
|
||||
switch(RX_State)
|
||||
{
|
||||
case 0: //第一前导字节
|
||||
if(res == 0xfe){
|
||||
RX_State = 1;
|
||||
}else{
|
||||
RX_State = 0;
|
||||
}
|
||||
break;
|
||||
case 1: //第二前导字节
|
||||
if(res == 0xfe){
|
||||
RX_State = 1; //转到接收帧头
|
||||
}else{
|
||||
if(res == 0x68)
|
||||
{
|
||||
RX_State = 3; //转到接收设备通讯地址
|
||||
CS = 0x68;
|
||||
}else{
|
||||
RX_State = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
// case 2: //接收帧头
|
||||
// if(res == 0x68){
|
||||
// RX_State = 3; //转到接收设备通讯地址
|
||||
// CS = 0x68;
|
||||
// }else{
|
||||
// RX_State = 0;
|
||||
// }
|
||||
// break;
|
||||
case 3: //接收设备通讯地址
|
||||
RS485_RX_BUF[0] = res;
|
||||
CS += res;
|
||||
RX_State = 4;
|
||||
break;
|
||||
case 4: //接收帧头
|
||||
if(res == 0x68){
|
||||
RX_State = 5; //转到接收通讯命令
|
||||
CS += 0x68;
|
||||
}else{
|
||||
RX_State = 0;
|
||||
}
|
||||
break;
|
||||
case 5: //接收通讯命令
|
||||
RS485_RX_BUF[1] = res;
|
||||
CS += res;
|
||||
RX_State = 6; //转到接收数据长度
|
||||
break;
|
||||
case 6: //接收通讯数据长度
|
||||
RS485_RX_BUF[2] = res;
|
||||
CS += res;
|
||||
RX_Size = res; //接收的数据长度
|
||||
if(RX_Size == 0x00){ //如果数据长度为0,则直接转到接收校验码
|
||||
RX_State = 8;
|
||||
}else{
|
||||
RX_State = 7; //转到接收数据
|
||||
}
|
||||
break;
|
||||
case 7: //接收N个字节数据
|
||||
if(Byte_Count < RX_Size-1){
|
||||
RS485_RX_BUF[Byte_Count + 3] = res;
|
||||
CS += res;
|
||||
Byte_Count++;
|
||||
}else{
|
||||
RS485_RX_BUF[Byte_Count + 3] = res;
|
||||
CS += res;
|
||||
Byte_Count = 0; //已完成N个字节的数据接收计数归0
|
||||
RX_State = 8; //转到接收核验码
|
||||
}
|
||||
break;
|
||||
case 8: //接收校验
|
||||
if(CS != res){
|
||||
RX_State = 0;
|
||||
}else{
|
||||
RX_State = 9; //转到接收帧尾码0x16
|
||||
}
|
||||
break;
|
||||
case 9: //接收帧尾
|
||||
if(res == 0x16){ //是帧尾吗?
|
||||
RS485_RX_STA = 0xfd; //一帧接收成功,标记USART_RX_STA=0xfd通知主程序进行通讯处理
|
||||
// printf("\r\n<--\r\n");
|
||||
}
|
||||
RX_State = 0;
|
||||
break;
|
||||
default: //其它
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: Send_Data
|
||||
* 功能说明: 发送一个字节数据
|
||||
* 形 参: 发送数据
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void Send_Data(uint8_t Serial_data)
|
||||
{
|
||||
// CTRL485 = 1; //设置为发送模式
|
||||
USART_SendData(USART2, Serial_data); //向串口发送数据
|
||||
while(USART_GetFlagStatus(USART2, USART_FLAG_TC) != SET);//等待发送结束
|
||||
// CTRL485 = 0; //恢复为接收模式
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: Send_One
|
||||
* 功能说明: 发送一帧数据
|
||||
* 形 参: 发送数据帧地址指针
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void Send_One(uint8_t *s)
|
||||
{
|
||||
uint8_t i;
|
||||
uint8_t CS = 0x68; //接收核验和
|
||||
uint8_t TX_Size = 0; //接收通讯数据长度
|
||||
printf("\r\n----->RS485--> %x\r\n", *(s+1));
|
||||
CTRL485 = 1; //RS-485 通讯,切换为发送状态
|
||||
|
||||
delay_ms(1);
|
||||
Send_Data(0xfe); //发送2个前导字节
|
||||
Send_Data(0xfe);
|
||||
Send_Data(0xfe);
|
||||
Send_Data(0x68); //发送帧头
|
||||
Send_Data(*s); //发送地址
|
||||
CS += *s;
|
||||
Send_Data(0x68); //发送帧头
|
||||
CS += 0x68;
|
||||
Send_Data(*(s+1)); //发送帧命令
|
||||
CS += *(s+1);
|
||||
TX_Size = *(s+2); //取出通讯数据长度
|
||||
Send_Data(TX_Size); //发送数据长度
|
||||
CS += *(s+2);
|
||||
for(i=0; i<TX_Size; i++) //发送数据
|
||||
{
|
||||
Send_Data(*(s+i+3));
|
||||
CS += (*(s+i+3));
|
||||
}
|
||||
Send_Data(CS); //发送校验字节
|
||||
Send_Data(0x16); //发送帧尾
|
||||
|
||||
delay_ms(1);
|
||||
CTRL485 = 0; //一帧发送完毕,恢复信道切换功能
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: Serial_Address
|
||||
* 功能说明: 通讯地址判断
|
||||
* 形 参: s 指向从通讯地址
|
||||
* 返 回 值: 0x00 错误,0x01 正确,0x02 广播地址
|
||||
***********************************************************************
|
||||
*/
|
||||
static uint8_t Serial_Address(uint8_t *s)
|
||||
{
|
||||
if(*s == 0x99)
|
||||
{
|
||||
return(0x02); //是广播地址
|
||||
}
|
||||
if(*s == Address)
|
||||
{
|
||||
return(0x01); //地址匹配正确
|
||||
}
|
||||
return(0x00); //地址匹配不正确
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: Serial_Command_Run
|
||||
* 功能说明: 执行通讯命令
|
||||
* 形 参: s 发送数据帧地址指针
|
||||
* 返 回 值: 0 错误,1 正确
|
||||
***********************************************************************
|
||||
*/
|
||||
uint8_t Serial_Command_Run(uint8_t *s)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
// printf("\r\n<-- %x\r\n", *(s+1));
|
||||
rxCmd = *(s+1);
|
||||
switch(Serial_Address(s)) //判断地址是否正确
|
||||
{
|
||||
case 0x02: //广播地址0x99
|
||||
break;
|
||||
|
||||
case 0x01: //正常地址
|
||||
printf("\r\n<-- %x\r\n", *(s+1));
|
||||
|
||||
switch(*(s+1)) //通讯命令译码
|
||||
{
|
||||
case 0x00: //应答命令
|
||||
break;
|
||||
|
||||
case 0x01: //读取超声波测量值
|
||||
distance = *(s+3);
|
||||
break;
|
||||
|
||||
case 0x02: //读取重量值
|
||||
|
||||
break;
|
||||
|
||||
case 0x03: //读取温度值
|
||||
temperature = *(s+3); //取出测距数据
|
||||
break;
|
||||
|
||||
case 0x10: //读取温度、测距、水位、重量、身份信息的组合
|
||||
// temperature = *(s+3); //取出温度数据
|
||||
// distance = *(s+4); //取出测距数据
|
||||
// water = *(s+5); //取出水位数据
|
||||
// weight = (uint16_t)(*(s+6)) << 8; //取出重量高8位数据
|
||||
// weight |= *(s+7); //取出重量低8位数据
|
||||
//
|
||||
// receivePutInType = *(s+8); //取出开门身份类型
|
||||
// receiveDataLength = *(s+9); //取出开门身份信息的数据长度
|
||||
//
|
||||
// memcpy(receiveDataBuf, (s+10), 33); //取出开门身份信息内容
|
||||
break;
|
||||
|
||||
case 0x21: //主机请求获取用户输入
|
||||
// temperature = *(s+3); //取出温度数据
|
||||
// getUserInfoMark = *(s+4); //读取从机过程处理的状态(判断从机是否已经获取到用户投放请求信息)
|
||||
// if(getUserInfoMark) //取出用户相关信息
|
||||
// {
|
||||
// receivePutInType = *(s+5); //取出开门身份类型(0x00->无;0x01->IC卡;0x02->二维码)
|
||||
// receiveDataLength = *(s+6); //取出开门身份信息的数据长度
|
||||
// memcpy(receiveDataBuf, (s+7), 33); //取出开门身份信息内容
|
||||
// }
|
||||
break;
|
||||
|
||||
case 0x22: //主机要求从机清除上次的用户输入状态信息
|
||||
// if(*(s+3))
|
||||
// {
|
||||
// clearPutInInfoMark = 1;
|
||||
// }
|
||||
break;
|
||||
|
||||
case 0x23: //读取测距、重量的组合
|
||||
// getPutInInfoMark = *(s+3); //读取从机过程处理的状态
|
||||
// if(getPutInInfoMark) //从机已经完成过程处理
|
||||
// {
|
||||
// receiveDistance_a = *(s+4); //取出测距数据
|
||||
// receiveDistance_b = *(s+5); //取出测距数据
|
||||
|
||||
// receiveWeight_a = (uint16_t)(*(s+6)) << 8; //取出重量高8位数据
|
||||
// receiveWeight_a |= *(s+7); //取出重量低8位数据
|
||||
//
|
||||
// receiveWeight_b = (uint16_t)(*(s+8)) << 8; //取出重量高8位数据
|
||||
// receiveWeight_b |= *(s+9); //取出重量低8位数据
|
||||
//
|
||||
// printf("\r\n<- 重量 = %2.2f Kg; %2.2f Kg\r\n", (float)receiveWeight_a/100, (float)receiveWeight_b/100);
|
||||
// printf("\r\n<- 测距1 = %3.1f cm\r\n", (float)receiveDistance_a);
|
||||
// printf("\r\n<- 测距2 = %3.1f cm\r\n", (float)receiveDistance_b);
|
||||
//
|
||||
// }
|
||||
break;
|
||||
|
||||
case 0x24: //收到MCU2发送来的需上传到后台的数据(用户投放信息)
|
||||
memset(receiveDataBuf, 0x00, 33); //接收数据前先把之前的缓存内容清空
|
||||
|
||||
//取出用户身份信息
|
||||
receivePutInType = *(s+3); //取出开门身份类型(0x00->无;0x01->IC卡;0x02->二维码)
|
||||
receiveDataLength = *(s+4); //取出开门身份信息的数据长度
|
||||
memcpy(receiveDataBuf, (s+5), 33); //取出开门身份信息内容
|
||||
|
||||
//取出第一组称重和测距数据
|
||||
weight_paper = (uint16_t)(*(s+38)) << 8; //取出重量高8位数据
|
||||
weight_paper |= *(s+39); //取出重量低8位数据
|
||||
distance_paper = *(s+40); //取出测距数据
|
||||
|
||||
//取出第二组称重和测距数据
|
||||
weight_plastic = (uint16_t)(*(s+41)) << 8; //取出重量高8位数据
|
||||
weight_plastic |= *(s+42); //取出重量低8位数据
|
||||
distance_plastic = *(s+43); //取出测距数据
|
||||
|
||||
//取出第三组称重和测距数据
|
||||
weight_metal = (uint16_t)(*(s+44)) << 8; //取出重量高8位数据
|
||||
weight_metal |= *(s+45); //取出重量低8位数据
|
||||
distance_metal = *(s+46); //取出测距数据
|
||||
|
||||
//取出第四组称重和测距数据
|
||||
weight_glass = (uint16_t)(*(s+47)) << 8; //取出重量高8位数据
|
||||
weight_glass |= *(s+48); //取出重量低8位数据
|
||||
distance_glass = *(s+49); //取出测距数据
|
||||
|
||||
receiveDataStatus = 1; //收到MCU2发送的投放信息,将该标志位置1,由外部读取后清除
|
||||
|
||||
break;
|
||||
|
||||
case 0x25: //接收到MCU2发送过来的设备工作信息(包含测距、温度)
|
||||
temperature = *(s+3); //取出温度数据
|
||||
|
||||
distance_paper = *(s+4); //取出纸类桶测距数据
|
||||
distance_plastic = *(s+5); //取出塑料桶测距数据
|
||||
distance_metal = *(s+6); //取出金属桶测距数据
|
||||
distance_glass = *(s+7); //取出玻璃桶测距数据
|
||||
|
||||
recDeviceStatus = 1; //收到MCU2发送的设备工作信息,将该标志位置1,由外部读取后清除
|
||||
|
||||
break;
|
||||
|
||||
default: //其他命令
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 0x00: //地址错误
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
return 1; //帧执行正确,返回
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: RS485_Task
|
||||
* 功能说明: RS485通讯任务
|
||||
* 形 参: 无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void RS485_Task(void)
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: Receive_One
|
||||
* 功能说明: RS485接收一次通讯任务
|
||||
* 形 参: 无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void RS485_ReceiveTask(void)
|
||||
{
|
||||
if(RS485_RX_STA == 0xfd) //有接收到从机返回的数据,但要进行数据验证
|
||||
{
|
||||
Serial_Command_Run(RS485_RX_BUF); //解释返回的数据
|
||||
RS485_RX_STA = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 CXHY *****END OF FILE*******************/
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
/*************************** (C) COPYRIGHT 2014 GLHF ****************************
|
||||
* 文件名 :USART5.c
|
||||
* 描 述 :串口5驱动代码(称重传感器2控制)
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/03/15
|
||||
*********************************************************************************/
|
||||
#include "usart.h"
|
||||
#include "UsarInterface.h"
|
||||
#include "rs485.h"
|
||||
|
||||
|
||||
void USART5_ReceiveDataHandler(uint8_t res)
|
||||
{
|
||||
}
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 CXHY *****END OF FILE*******************/
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :usart5.h
|
||||
* 描 述 :串口5驱动头文件代码
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/03/15
|
||||
*********************************************************************************/
|
||||
#ifndef __USART_InterFace_H
|
||||
#define __USART_InterFace_H
|
||||
|
||||
#include "stm32f10x.h"
|
||||
#include "stdio.h"
|
||||
|
||||
void USART5_ReceiveDataHandler(uint8_t res);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 CXHY *****END OF FILE*******************/
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "stdio.h"
|
||||
#include "crc16.h"
|
||||
|
||||
const unsigned char auchCRCLo[]={
|
||||
0x00, 0xC0, 0xC1, 0x01, 0xC3, 0x03, 0x02, 0xC2, 0xC6, 0x06, 0x07, 0xC7, 0x05, 0xC5, 0xC4,
|
||||
0x04, 0xCC, 0x0C, 0x0D, 0xCD, 0x0F, 0xCF, 0xCE, 0x0E, 0x0A, 0xCA, 0xCB, 0x0B, 0xC9, 0x09,
|
||||
0x08, 0xC8, 0xD8, 0x18, 0x19, 0xD9, 0x1B, 0xDB, 0xDA, 0x1A, 0x1E, 0xDE, 0xDF, 0x1F, 0xDD,
|
||||
0x1D, 0x1C, 0xDC, 0x14, 0xD4, 0xD5, 0x15, 0xD7, 0x17, 0x16, 0xD6, 0xD2, 0x12, 0x13, 0xD3,
|
||||
0x11, 0xD1, 0xD0, 0x10, 0xF0, 0x30, 0x31, 0xF1, 0x33, 0xF3, 0xF2, 0x32, 0x36, 0xF6, 0xF7,
|
||||
0x37, 0xF5, 0x35, 0x34, 0xF4, 0x3C, 0xFC, 0xFD, 0x3D, 0xFF, 0x3F, 0x3E, 0xFE, 0xFA, 0x3A,
|
||||
0x3B, 0xFB, 0x39, 0xF9, 0xF8, 0x38, 0x28, 0xE8, 0xE9, 0x29, 0xEB, 0x2B, 0x2A, 0xEA, 0xEE,
|
||||
0x2E, 0x2F, 0xEF, 0x2D, 0xED, 0xEC, 0x2C, 0xE4, 0x24, 0x25, 0xE5, 0x27, 0xE7, 0xE6, 0x26,
|
||||
0x22, 0xE2, 0xE3, 0x23, 0xE1, 0x21, 0x20, 0xE0, 0xA0, 0x60, 0x61, 0xA1, 0x63, 0xA3, 0xA2,
|
||||
0x62, 0x66, 0xA6, 0xA7, 0x67, 0xA5, 0x65, 0x64, 0xA4, 0x6C, 0xAC, 0xAD, 0x6D, 0xAF, 0x6F,
|
||||
0x6E, 0xAE, 0xAA, 0x6A, 0x6B, 0xAB, 0x69, 0xA9, 0xA8, 0x68, 0x78, 0xB8, 0xB9, 0x79, 0xBB,
|
||||
0x7B, 0x7A, 0xBA, 0xBE, 0x7E, 0x7F, 0xBF, 0x7D, 0xBD, 0xBC, 0x7C, 0xB4, 0x74, 0x75, 0xB5,
|
||||
0x77, 0xB7, 0xB6, 0x76, 0x72, 0xB2, 0xB3, 0x73, 0xB1, 0x71, 0x70, 0xB0, 0x50, 0x90, 0x91,
|
||||
0x51, 0x93, 0x53, 0x52, 0x92, 0x96, 0x56, 0x57, 0x97, 0x55, 0x95, 0x94, 0x54, 0x9C, 0x5C,
|
||||
0x5D, 0x9D, 0x5F, 0x9F, 0x9E, 0x5E, 0x5A, 0x9A, 0x9B, 0x5B, 0x99, 0x59, 0x58, 0x98, 0x88,
|
||||
0x48, 0x49, 0x89, 0x4B, 0x8B, 0x8A, 0x4A, 0x4E, 0x8E, 0x8F, 0x4F, 0x8D, 0x4D, 0x4C, 0x8C,
|
||||
0x44, 0x84, 0x85, 0x45, 0x87, 0x47, 0x46, 0x86, 0x82, 0x42, 0x43, 0x83, 0x41, 0x81, 0x80,
|
||||
0x40
|
||||
};
|
||||
|
||||
/* Table of CRC values for high–order byte */
|
||||
const unsigned char auchCRCHi[]={
|
||||
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81,
|
||||
0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,
|
||||
0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01,
|
||||
0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
|
||||
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81,
|
||||
0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,
|
||||
0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01,
|
||||
0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
|
||||
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81,
|
||||
0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,
|
||||
0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01,
|
||||
0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
|
||||
0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81,
|
||||
0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,
|
||||
0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01,
|
||||
0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
|
||||
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81,
|
||||
0x40
|
||||
};
|
||||
|
||||
/*---------------------------------------------------------
|
||||
*函数名称:unsigned int getCRC16(unsigned char array[],unsigned int length)
|
||||
*函数功能:CRC16校验
|
||||
*输入参数:校验的数据、校验长度
|
||||
*输出参数:无
|
||||
*返回参数:返回校验值
|
||||
*-------------------------------------------------------*/
|
||||
unsigned int GetCRC16(unsigned char *array,unsigned int length)
|
||||
{
|
||||
unsigned char uchCRCHi = 0xFF ; /* 初始化高字节*/
|
||||
unsigned char uchCRCLo = 0xFF ; /* 初始化低字节*/
|
||||
unsigned char uIndex ; /*CRC表索引*/
|
||||
unsigned char *p = array;
|
||||
while(length--)
|
||||
{
|
||||
uIndex = uchCRCHi^*(p++);
|
||||
uchCRCHi = uchCRCLo^auchCRCHi[uIndex];
|
||||
uchCRCLo = auchCRCLo[uIndex];
|
||||
}
|
||||
return ((uchCRCHi<<8)|uchCRCLo);
|
||||
|
||||
//某些情况下校验值会出现高8位或低8位为0x00的情况,
|
||||
//从而导致程序没法处理,这时可以像下面这样将0x00替换掉任意一个非0x00的值
|
||||
//return ((((uchCRCHi<<8) == 0)?(0xAA<<8):(uchCRCHi<<8)) | ((uchCRCLo == 0)?0xAA:uchCRCLo));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
#ifndef __CRC16_H
|
||||
#define __CRC16_H
|
||||
|
||||
unsigned int GetCRC16(unsigned char *array,unsigned int length);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
*
|
||||
* 模块名称 : printf模块
|
||||
* 文件名称 : printf.c
|
||||
* 说 明 : 实现printf和scanf函数重定向到串口1,即支持printf信息到USART1
|
||||
* 实现重定向,只需要添加2个函数:
|
||||
* int fputc(int ch, FILE *f);
|
||||
* int fgetc(FILE *f);
|
||||
* 对于KEIL MDK编译器,编译选项中需要在MicorLib前面打钩,否则不会有数据打印到USART1。
|
||||
*
|
||||
* 这个c模块无对应的h文件。
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <stdio.h>
|
||||
#include "sys.h"
|
||||
|
||||
#if 1
|
||||
|
||||
struct __FILE
|
||||
{
|
||||
int handle;
|
||||
};
|
||||
|
||||
FILE __stdout;
|
||||
//定义_sys_exit()以避免使用半主机模式
|
||||
_sys_exit(int x)
|
||||
{
|
||||
x = x;
|
||||
}
|
||||
|
||||
/*********************************************************
|
||||
* @function fputc
|
||||
* @role 重定义putc函数,这样可以使用printf函数从串口1打印输出
|
||||
* @input None
|
||||
* @output None
|
||||
* @return None
|
||||
********************************************************/
|
||||
int fputc(int ch, FILE *f)
|
||||
{
|
||||
while((USART1->SR&0X40)==0);//循环发送,直到发送完毕
|
||||
USART1->DR = (u8) ch;
|
||||
return ch;
|
||||
}
|
||||
|
||||
///*********************************************************
|
||||
// * @function fgetc
|
||||
// * @role 重定义getc函数,这样可以使用scanff函数从串口1输入数据
|
||||
// * @input None
|
||||
// * @output None
|
||||
// * @return None
|
||||
// ********************************************************/
|
||||
//int fgetc(FILE *f)
|
||||
//{
|
||||
// /* 等待串口1输入数据 */
|
||||
// while (USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET);
|
||||
// return (int)USART_ReceiveData(USART1);
|
||||
//}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :RS485.h
|
||||
* 描 述 :RS485通信处理头文件
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/02/10
|
||||
*********************************************************************************/
|
||||
#ifndef __RS485_H
|
||||
#define __RS485_H
|
||||
#include "stdio.h"
|
||||
#include "stdint.h"
|
||||
|
||||
#define CTRL485 PAout(0) //485模式控制引脚
|
||||
extern uint8_t Address;
|
||||
|
||||
extern uint8_t RS485_RX_BUF[128]; //接收缓冲
|
||||
extern uint8_t RS485_TX_BUF[64]; //发送缓冲
|
||||
|
||||
extern uint8_t RS485_RX_STA; //RS485接收状态标记
|
||||
extern uint8_t RS485_communicationStatus; //RS485通讯成功与否标志
|
||||
extern uint16_t RS485_serialNumber; //RS485通信流水号
|
||||
extern uint16_t RS485_RX_serialNumber; //RS485通信流水号
|
||||
extern uint8_t rxCmd; //从机返回的指令码
|
||||
|
||||
void RS485_Init(void);
|
||||
uint8_t Receive_One(uint8_t *s);
|
||||
void Send_Data(uint8_t Serial_data);
|
||||
void Send_One(uint8_t *s);
|
||||
uint8_t Serial_Command_Run(uint8_t *s);
|
||||
void Serial_Command(void);
|
||||
void RS485_Task(void);
|
||||
void RS485_ReceiveTask(void);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 CXHY *****END OF FILE*******************/
|
||||
+125
@@ -0,0 +1,125 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :usart.c
|
||||
* 描 述 :串口1驱动程序
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/03/06
|
||||
*********************************************************************************/
|
||||
#include "usart1.h"
|
||||
|
||||
uint8_t USART1_RX_BUF[USART1_RECV_LEN]; //接收缓冲,最大USART_REC_LEN个字节.
|
||||
uint16_t USART1_RX_STA = 0; //接收状态标记
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: USART1_Init
|
||||
* 功能说明: 串口1初始化
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void USART1_Init(uint32_t bound)
|
||||
{
|
||||
//GPIO端口设置
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
USART_InitTypeDef USART_InitStructure;
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE); //使能USART1,GPIOA时钟
|
||||
USART_DeInit(USART1); //复位串口1
|
||||
|
||||
//USART1_TX PA.9
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出
|
||||
GPIO_Init(GPIOA, &GPIO_InitStructure);
|
||||
|
||||
//USART1_RX PA.10
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //浮空输入
|
||||
GPIO_Init(GPIOA, &GPIO_InitStructure);
|
||||
|
||||
//USART 初始化设置
|
||||
USART_InitStructure.USART_BaudRate = bound; //设置波特率
|
||||
USART_InitStructure.USART_WordLength = USART_WordLength_8b; //字长为8位数据格式
|
||||
USART_InitStructure.USART_StopBits = USART_StopBits_1; //一个停止位
|
||||
USART_InitStructure.USART_Parity = USART_Parity_No; //无奇偶校验位
|
||||
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//无硬件数据流控制
|
||||
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //收发模式
|
||||
USART_Init(USART1, &USART_InitStructure); //初始化串口
|
||||
|
||||
//Usart1 NVIC 配置
|
||||
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1 ; //抢占优先级
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; //子优先级
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
|
||||
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); //开启中断
|
||||
USART_Cmd(USART1, ENABLE);
|
||||
USART1_RX_STA = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: USART1_IRQHandler
|
||||
* 功能说明: 串口中断服务程序
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void USART1_IRQHandler(void)
|
||||
{
|
||||
uint8_t res = 0;
|
||||
|
||||
if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) //接收中断(接收到的数据必须是0x0d 0x0a结尾)
|
||||
{
|
||||
res = USART_ReceiveData(USART1); //读取接收到的数据
|
||||
if(USART1_RX_STA < USART1_RECV_LEN) //还可以接收数据
|
||||
{
|
||||
TIM_SetCounter(TIM5, 0); //计数器清空
|
||||
if(USART1_RX_STA == 0)
|
||||
{
|
||||
TIM_Cmd(TIM5, ENABLE); //使能定时器5的中断
|
||||
}
|
||||
USART1_RX_BUF[USART1_RX_STA++] = res; //记录接收到的值
|
||||
}else{
|
||||
USART1_RX_STA |= 1<<15; //强制标记接收完成
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: USART1_SendByteData
|
||||
* 功能说明: 发送一字节数据
|
||||
* 形 参: 无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void USART1_SendByteData(uint8_t bData)
|
||||
{
|
||||
USART_SendData(USART1, bData);
|
||||
while(USART_GetFlagStatus(USART1, USART_FLAG_TC) != SET); //等待发送结束
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: USART1_SendFrameData
|
||||
* 功能说明: 发送一帧数据
|
||||
* 形 参: pData -> 数据的首地址;len -> 数据的长度
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void USART1_SendFrameData(uint8_t pDataBuf[], uint16_t len)
|
||||
{
|
||||
uint16_t i = 0;
|
||||
|
||||
USART_ClearFlag(USART1, USART_FLAG_TC);
|
||||
for(i = 0; i < len; i++)
|
||||
{
|
||||
USART1_SendByteData(pDataBuf[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 ping *****END OF FILE*******************/
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
/*************************** (C) COPYRIGHT 2017 CXHY ****************************
|
||||
* 文件名 :usart.h
|
||||
* 描 述 :串口1驱动程序
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/03/06
|
||||
*********************************************************************************/
|
||||
#ifndef __USART_H
|
||||
#define __USART_H
|
||||
#include "stm32f10x.h"
|
||||
|
||||
#define USART1_RECV_LEN 128 //最大接收缓存字节数
|
||||
#define USART1_SEND_LEN 128 //最大发送缓存字节数
|
||||
|
||||
extern uint8_t USART1_RX_BUF[USART1_RECV_LEN]; //接收缓冲,最大USART_REC_LEN个字节
|
||||
extern uint16_t USART1_RX_STA; //接收状态标记
|
||||
|
||||
void USART1_Init(uint32_t bound);
|
||||
void USART1_SendByteData(uint8_t bData);
|
||||
void USART1_SendFrameData(uint8_t pDataBuf[], uint16_t len);
|
||||
|
||||
#endif
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 YNHB *****END OF FILE*******************/
|
||||
|
||||
+220
@@ -0,0 +1,220 @@
|
||||
/*************************** (C) COPYRIGHT 2017 Ping ****************************
|
||||
* 文件名 :usart2.c
|
||||
* 描 述 :串口2驱动代码
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/09/04
|
||||
*********************************************************************************/
|
||||
#include "usart2.h"
|
||||
|
||||
uint8_t USART2_RX_BUF[USART2_RECV_LEN]; //最大接收缓存
|
||||
uint8_t USART2_TX_BUF[USART2_SEND_LEN]; //最大发收缓存
|
||||
uint8_t USART2_RX_STA = 0; //接收状态标记
|
||||
|
||||
void USART2_ReceiveHandler(uint8_t res);
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: USART2_Init
|
||||
* 功能说明: 串口2初始化
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void USART2_Init(uint32_t bound)
|
||||
{
|
||||
//GPIO端口设置
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
USART_InitTypeDef USART_InitStructure;
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); //使能GPIOA时钟
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); //使能USART2时钟
|
||||
|
||||
//USART2_TX PA.2
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; //PA.2
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出
|
||||
GPIO_Init(GPIOA, &GPIO_InitStructure); //初始化PA2
|
||||
|
||||
//USART2_RX PA.3
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //浮空输入
|
||||
GPIO_Init(GPIOA, &GPIO_InitStructure); //初始化PA3
|
||||
|
||||
//USART 初始化设置
|
||||
USART_InitStructure.USART_BaudRate = bound; //一般设置为9600;
|
||||
USART_InitStructure.USART_WordLength = USART_WordLength_8b; //字长为8位数据格式
|
||||
USART_InitStructure.USART_StopBits = USART_StopBits_1; //一个停止位
|
||||
USART_InitStructure.USART_Parity = USART_Parity_No; //无奇偶校验位
|
||||
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; //无硬件数据流控制
|
||||
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //收发模式
|
||||
USART_Init(USART2, &USART_InitStructure); //初始化串口
|
||||
|
||||
//Usart1 NVIC 配置
|
||||
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0 ; //抢占优先级0
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //子优先级0
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
|
||||
NVIC_Init(&NVIC_InitStructure); //根据指定的参数初始化VIC寄存器
|
||||
|
||||
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE); //开启中断
|
||||
USART_Cmd(USART2, ENABLE); //使能串口
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: USART2_IRQHandler
|
||||
* 功能说明: 串口2中断服务程序
|
||||
* 形 参:无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void USART2_IRQHandler(void)
|
||||
{
|
||||
uint8_t res = 0;
|
||||
|
||||
if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET) //接收到数据
|
||||
{
|
||||
res = USART_ReceiveData(USART2); //读取接收到的数据
|
||||
USART2_ReceiveHandler(res);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: USART2_SendByteData
|
||||
* 功能说明: 发送一字节数据
|
||||
* 形 参: 无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void USART2_SendByteData(uint8_t bData)
|
||||
{
|
||||
USART_SendData(USART2, bData);
|
||||
while(USART_GetFlagStatus(USART2, USART_FLAG_TC) != SET); //等待发送结束
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: USART2_SendFrameData
|
||||
* 功能说明: 发送一帧数据
|
||||
* 形 参: pData -> 数据的首地址;len -> 数据的长度
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void USART2_SendFrameData(uint8_t pDataBuf[], uint16_t len)
|
||||
{
|
||||
uint16_t i = 0;
|
||||
|
||||
USART_ClearFlag(USART2, USART_FLAG_TC);
|
||||
for(i = 0; i < len; i++)
|
||||
{
|
||||
USART2_SendByteData(pDataBuf[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: USART2_ReceiveHandler
|
||||
* 功能说明: 串口数据接收处理程序
|
||||
* 形 参: 传入串口接收到的数据
|
||||
* 返 回 值: 无(影响串口接收状态USART2_RX_STA)
|
||||
***********************************************************************
|
||||
*/
|
||||
void USART2_ReceiveHandler(uint8_t res)
|
||||
{
|
||||
static uint8_t RX_Status = 0; //接收状态
|
||||
static uint8_t CS = 0; //接收核验和
|
||||
static uint8_t RX_Size = 0; //接收通讯数据长度
|
||||
static uint8_t RX_ByteCount = 0; //接收数据字节计数
|
||||
|
||||
// printf("U2 = %02X\r\n", res);
|
||||
|
||||
switch(RX_Status)
|
||||
{
|
||||
case 0: //第一前导字节
|
||||
if(res == 0xfe){
|
||||
RX_Status = 1;
|
||||
}else{
|
||||
RX_Status = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case 1: //第二前导字节
|
||||
if(res == 0xfe){
|
||||
RX_Status = 1; //还是前导字节
|
||||
}else if(res == 0x68){
|
||||
RX_Status = 3; //转到接收设备通讯地址
|
||||
CS = 0x68;
|
||||
}else{
|
||||
RX_Status = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case 3: //接收设备通讯地址
|
||||
USART2_RX_BUF[0] = res;
|
||||
CS += res;
|
||||
RX_Status = 4;
|
||||
break;
|
||||
|
||||
case 4: //接收帧头
|
||||
if(res == 0x68){
|
||||
RX_Status = 5; //转到接收通讯命令
|
||||
CS += 0x68;
|
||||
}else{
|
||||
RX_Status = 0;
|
||||
}
|
||||
break;
|
||||
case 5: //接收通讯命令
|
||||
USART2_RX_BUF[1] = res;
|
||||
CS += res;
|
||||
RX_Status = 6; //转到接收数据长度
|
||||
break;
|
||||
|
||||
case 6: //接收通讯数据长度
|
||||
USART2_RX_BUF[2] = res;
|
||||
CS += res;
|
||||
RX_Size = res; //接收的数据长度
|
||||
if(RX_Size == 0x00){ //如果数据长度为0,则直接转到接收校验码
|
||||
RX_Status = 8;
|
||||
}else{
|
||||
RX_Status = 7; //转到接收数据
|
||||
}
|
||||
break;
|
||||
|
||||
case 7: //接收N个字节数据
|
||||
if(RX_ByteCount < RX_Size-1){
|
||||
USART2_RX_BUF[RX_ByteCount + 3] = res;
|
||||
CS += res;
|
||||
RX_ByteCount++;
|
||||
}else{
|
||||
USART2_RX_BUF[RX_ByteCount + 3] = res;
|
||||
CS += res;
|
||||
RX_ByteCount = 0; //已完成N个字节的数据接收计数归0
|
||||
RX_Status = 8; //转到接收核验码
|
||||
}
|
||||
break;
|
||||
|
||||
case 8: //接收校验
|
||||
if(CS != res){
|
||||
RX_Status = 0;
|
||||
}else{
|
||||
RX_Status = 9; //转到接收帧尾码0x16
|
||||
}
|
||||
break;
|
||||
|
||||
case 9: //接收帧尾
|
||||
if(res == 0x16){ //是帧尾吗?
|
||||
USART2_RX_STA = 0xfd; //一帧接收成功,标记接收到一帧数据通知主程序进行通讯处理
|
||||
}
|
||||
RX_Status = 0;
|
||||
break;
|
||||
|
||||
default: //其它
|
||||
RX_Status = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 Ping *****END OF FILE*******************/
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
/*************************** (C) COPYRIGHT 2017 Ping ****************************
|
||||
* 文件名 :usart2.h
|
||||
* 描 述 :串口2驱动头文件
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/09/04
|
||||
*********************************************************************************/
|
||||
#ifndef __USART2_H
|
||||
#define __USART2_H
|
||||
#include "stm32f10x.h"
|
||||
#include "stdio.h"
|
||||
|
||||
#define USART2_RECV_LEN 128 //最大接收缓存字节数
|
||||
#define USART2_SEND_LEN 128 //最大发送缓存字节数
|
||||
|
||||
extern uint8_t USART2_RX_BUF[USART2_RECV_LEN];
|
||||
extern uint8_t USART2_TX_BUF[USART2_SEND_LEN];
|
||||
extern uint8_t USART2_RX_STA;
|
||||
|
||||
void USART2_Init(uint32_t bound);
|
||||
void USART2_SendByteData(uint8_t bData);
|
||||
void USART2_SendFrameData(uint8_t pDataBuf[], uint16_t len);
|
||||
|
||||
#endif
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 Ping *****END OF FILE*******************/
|
||||
+156
@@ -0,0 +1,156 @@
|
||||
/*************************** (C) COPYRIGHT 2014 GLHF ****************************
|
||||
* 文件名 :usart3.c
|
||||
* 描 述 :串口3驱动代码(GPRS控制)
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2013/11/21
|
||||
*********************************************************************************/
|
||||
#include "stm32f10x.h"
|
||||
#include "delay.h"
|
||||
#include "usart3.h"
|
||||
#include "stdarg.h"
|
||||
#include "stdio.h"
|
||||
#include "string.h"
|
||||
#include "gsm_uart.h"
|
||||
#include "gsm_uart_conf.h"
|
||||
|
||||
static void UART3_DMA_Config(void);
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: USART3_Init
|
||||
* 功能说明: 串口3初始化
|
||||
* 形 参: 无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void USART3_Init(u32 bound)
|
||||
{
|
||||
//GPIO端口设置
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
USART_InitTypeDef USART_InitStructure;
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
|
||||
//开启所使用的时钟
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); //使能GPIOB时钟
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE); //使能USART3时钟
|
||||
|
||||
USART_DeInit(USART3); //复位串口3
|
||||
|
||||
//USART3_TX PB.10
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出
|
||||
GPIO_Init(GPIOB, &GPIO_InitStructure); //初始化PB10
|
||||
|
||||
//USART3_RX PB.11
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //浮空输入
|
||||
GPIO_Init(GPIOB, &GPIO_InitStructure); //初始化PB11
|
||||
|
||||
|
||||
//USART 初始化设置
|
||||
USART_InitStructure.USART_BaudRate = bound; //设置波特率;
|
||||
USART_InitStructure.USART_WordLength = USART_WordLength_8b; //字长为8位数据格式
|
||||
USART_InitStructure.USART_StopBits = USART_StopBits_1; //一个停止位
|
||||
USART_InitStructure.USART_Parity = USART_Parity_No; //无奇偶校验位
|
||||
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; //无硬件数据流控制
|
||||
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //收发模式
|
||||
|
||||
USART_Init(USART3, &USART_InitStructure); //初始化串口
|
||||
|
||||
UART3_DMA_Config(); //DMA1通道2,外设为串口3,存储器为USART3_TX_BUF
|
||||
|
||||
//Usart3 NVIC 配置
|
||||
NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0 ; //抢占优先级0
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //子优先级1
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
|
||||
NVIC_Init(&NVIC_InitStructure); //根据指定的参数初始化VIC寄存器
|
||||
|
||||
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE); //开启中断
|
||||
|
||||
USART_Cmd(USART3, ENABLE); //使能串口
|
||||
GPRS_RX_STA = 0; //接收状态清零
|
||||
TIM_Cmd(TIM4, DISABLE); //关闭TIMx
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: USART3_IRQHandler
|
||||
* 功能说明: 串口3中断(用于接收GSM_GPRS数据)
|
||||
* 通过判断接收连续2个字符之间的时间差不大于10ms来决定是不是一次连续的数据.
|
||||
* 如果2个字符接收间隔超过10ms,则认为不是1次连续数据.也就是超过10ms没有接收到
|
||||
* 任何数据,则表示此次接收完毕.
|
||||
* 形 参: 无
|
||||
* 返 回 值: 影响全局变量GPRS_RX_STA,结果如下:
|
||||
* [15]:0,没有接收到数据;1,接收到了一批数据.
|
||||
* [14:0]:接收到的数据长度
|
||||
***********************************************************************
|
||||
*/
|
||||
void USART3_IRQHandler(void)
|
||||
{
|
||||
uint8_t res;
|
||||
if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET) //接收到数据
|
||||
{
|
||||
res = USART_ReceiveData(USART3); //读取接收到的数据
|
||||
GSM_GPRS_ReceiveData(res);
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////USART3 DMA发送配置部分//////////////////////////////////
|
||||
//DMA1的各通道配置
|
||||
//这里的传输形式是固定的,这点要根据不同的情况来修改
|
||||
//从存储器->外设模式/8位数据宽度/存储器增量模式
|
||||
//DMA_CHx:DMA通道CHx
|
||||
//cpar:外设地址
|
||||
//cmar:存储器地址
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: UART3_DMA_Config
|
||||
* 功能说明: GSM串口输出命令
|
||||
* 形 参: 无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
static void UART3_DMA_Config(void)
|
||||
{
|
||||
DMA_InitTypeDef DMA_InitStructure;
|
||||
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); //使能DMA传输
|
||||
|
||||
delay_us(5);
|
||||
DMA_DeInit(DMA1_Channel2); //将DMA的通道2寄存器重设为缺省值
|
||||
// DMA1_MEM_LEN=cndtr;
|
||||
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&USART3->DR; //DMA外设ADC基地址
|
||||
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)GPRS_TX_BUF; //DMA内存基地址
|
||||
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST; //数据传输方向,从内存读取发送到外设
|
||||
// DMA_InitStructure.DMA_BufferSize = cndtr; //DMA通道的DMA缓存的大小
|
||||
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; //外设地址寄存器不变
|
||||
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; //内存地址寄存器递增
|
||||
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte; //数据宽度为8位
|
||||
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; //数据宽度为8位
|
||||
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; //工作在正常缓存模式
|
||||
DMA_InitStructure.DMA_Priority = DMA_Priority_Medium; //DMA通道 x拥有中优先级
|
||||
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; //DMA通道x没有设置为内存到内存传输
|
||||
DMA_Init(DMA1_Channel2, &DMA_InitStructure); //根据DMA_InitStruct中指定的参数初始化DMA的通道USART1_Tx_DMA_Channel所标识的寄存器
|
||||
|
||||
USART_DMACmd(USART3, USART_DMAReq_Tx, ENABLE); //使能串口3的DMA发送
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: UART3_Send_One
|
||||
* 功能说明: 通过DMA向串口3发送一次数据
|
||||
* 形 参: 无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void UART3_Send_One(uint16_t len)
|
||||
{
|
||||
DMA_Cmd(DMA1_Channel2, DISABLE); //关闭USART3 TX DMA1 所指示的通道
|
||||
DMA_SetCurrDataCounter(DMA1_Channel2, len); //DMA通道的DMA缓存的大小
|
||||
DMA_Cmd(DMA1_Channel2, ENABLE); //使能USART3 TX DMA1 所指示的通道
|
||||
}
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 CXHY *****END OF FILE*******************/
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user