feat: add STM32 four-channel weighing firmware

This commit is contained in:
FinleyHsu
2026-07-28 11:01:55 +08:00
commit 1282b9b77e
205 changed files with 80376 additions and 0 deletions
@@ -0,0 +1,22 @@
# Keil build outputs and user-local settings
Output/
Listing/
Objects/
*.o
*.d
*.crf
*.axf
*.elf
*.map
*.lst
*.dep
*.uvgui*
*.uvopt*
JLinkLog.txt
# GCC build outputs
gcc_build/build/
# macOS metadata
.DS_Store
._*
@@ -0,0 +1,26 @@
# STM32 四投口四路称重固件
这是用于 Git 提交的精简工程包,保留了重新编译所需的源码、头文件、Keil 工程、STM32 标准外设库、CMSIS 和 GCC 构建配置。
## 目录
- `src/Project/Project.uvprojx`Keil MDK 工程入口
- `src/USER/`:主程序与业务逻辑
- `src/HARDWARE/`:硬件驱动
- `src/CMSIS/`CMSIS 与启动文件
- `src/STM32F10x_FWLib/`STM32F10x 标准外设库
- `src/SYSTEM/`:系统基础模块
- `gcc_build/`ARM GCC 构建脚本与链接脚本
- `Release/V2.1_260709_4CH.hex`:可烧录固件
## 构建
Keil MDK:打开 `src/Project/Project.uvprojx`
ARM GCC
```sh
make -C gcc_build
```
版本标识:`V2.1_260709_4CH`
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,76 @@
PROJECT_XML := ../src/Project/Project.uvprojx
BUILD_DIR := build
TARGET := $(BUILD_DIR)/V2.1_260709_4CH
CC := arm-none-eabi-gcc
OBJCOPY := arm-none-eabi-objcopy
SIZE := arm-none-eabi-size
C_SOURCES := $(filter-out ../src/CMSIS/core_cm3.c,$(shell perl extract_sources.pl $(PROJECT_XML)))
S_SOURCES := startup_stm32f10x_hd_gcc.S
OBJECTS := $(patsubst ../src/%.c,$(BUILD_DIR)/%.o,$(C_SOURCES))
OBJECTS += $(BUILD_DIR)/gcc_syscalls.o
OBJECTS += $(BUILD_DIR)/startup_stm32f10x_hd_gcc.o
INCLUDES := \
-I../src/USER -I../src/CORE -I../src/CMSIS \
-I../src/SYSTEM/delay -I../src/SYSTEM/debug -I../src/SYSTEM/usart \
-I../src/STM32F10x_FWLib/inc \
-I../src/HARDWARE/LED -I../src/HARDWARE/KEY -I../src/HARDWARE/LCD \
-I../src/HARDWARE/24CXX -I../src/HARDWARE/FLASH -I../src/HARDWARE/IIC \
-I../src/HARDWARE/SPI -I../src/HARDWARE/BUZZER -I../src/HARDWARE/RFID \
-I../src/HARDWARE/EXTI -I../src/HARDWARE/TIMER \
-I../src/HARDWARE/UltrasonicWave -I../src/HARDWARE/USART \
-I../src/HARDWARE/GPS -I../src/HARDWARE/GSM -I../src/HARDWARE/QR_Code \
-I../src/HARDWARE/DEVICE -I../src/HARDWARE/NTC_ADC -I../src/HARDWARE/WDG \
-I../src/HARDWARE/SCALE -I../src/HARDWARE/ElectronicLock \
-I../src/HARDWARE/MOTOR -I../src/HARDWARE/AUDIO -I../src/HARDWARE/OPTO_SWITCH \
-I../src/HARDWARE/IR_Distancer -I../src/HARDWARE/RS485 \
-I../src/HARDWARE/STMFLASH -I../src/HARDWARE/Disinfection
ARCH_FLAGS := -mcpu=cortex-m3 -mthumb
DEFINES := -DSTM32F10X_HD -DUSE_STDPERIPH_DRIVER -Dsignal=gsm_signal_strength
WARNINGS := -Wall -Wextra -Wno-unused-parameter -Wno-unused-variable \
-Wno-unused-but-set-variable -Wno-sign-compare -Wno-implicit-int \
-Wno-unknown-pragmas -Wno-format
CFLAGS := $(ARCH_FLAGS) -std=gnu99 -Os -g3 -ffunction-sections -fdata-sections \
-fcommon -fno-strict-aliasing -fno-builtin -include gcc_compat.h $(DEFINES) $(INCLUDES) $(WARNINGS)
ASFLAGS := $(ARCH_FLAGS) -x assembler-with-cpp -g3
LDFLAGS := $(ARCH_FLAGS) -T stm32f103rc.ld -Wl,--gc-sections \
-Wl,-Map=$(TARGET).map,--cref -Wl,--print-memory-usage \
--specs=nano.specs --specs=nosys.specs -u _printf_float
LDLIBS := -Wl,--start-group -lc -lm -Wl,--end-group
.PHONY: all clean verify
all: $(TARGET).hex $(TARGET).bin
$(SIZE) $(TARGET).elf
$(TARGET).elf: $(OBJECTS) stm32f103rc.ld | $(BUILD_DIR)
$(CC) $(OBJECTS) $(LDFLAGS) $(LDLIBS) -o $@
$(TARGET).hex: $(TARGET).elf
$(OBJCOPY) -O ihex $< $@
$(TARGET).bin: $(TARGET).elf
$(OBJCOPY) -O binary $< $@
$(BUILD_DIR)/%.o: ../src/%.c gcc_compat.h
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -MMD -MP -c $< -o $@
$(BUILD_DIR)/startup_stm32f10x_hd_gcc.o: startup_stm32f10x_hd_gcc.S
@mkdir -p $(dir $@)
$(CC) $(ASFLAGS) -c $< -o $@
$(BUILD_DIR)/gcc_syscalls.o: gcc_syscalls.c gcc_compat.h
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -MMD -MP -c $< -o $@
$(BUILD_DIR):
mkdir -p $@
clean:
rm -rf $(BUILD_DIR)
-include $(OBJECTS:.o=.d)
@@ -0,0 +1,13 @@
#!/usr/bin/env perl
use strict;
use warnings;
my $project = shift @ARGV or die "usage: $0 Project.uvprojx\n";
open my $fh, '<', $project or die "cannot open $project: $!\n";
while (my $line = <$fh>) {
next unless $line =~ m{<FilePath>\.\.\\(.+\.c)</FilePath>};
my $path = $1;
$path =~ s{\\}{/}g;
print "../src/$path ";
}
close $fh;
@@ -0,0 +1,12 @@
#ifndef GCC_COMPAT_H
#define GCC_COMPAT_H
#ifndef __align
#define __align(n) __attribute__((aligned(n)))
#endif
#ifndef __packed
#define __packed __attribute__((packed))
#endif
#endif
@@ -0,0 +1,17 @@
#include "stm32f10x.h"
int _write(int file, char *data, int length)
{
int index;
(void)file;
for (index = 0; index < length; ++index)
{
while (USART_GetFlagStatus(UART5, USART_FLAG_TC) == RESET)
{
}
USART_SendData(UART5, (uint8_t)data[index]);
}
return length;
}
@@ -0,0 +1,201 @@
.syntax unified
.cpu cortex-m3
.thumb
.global g_pfnVectors
.global Reset_Handler
.extern SystemInit
.extern main
.extern __libc_init_array
.section .isr_vector,"a",%progbits
.type g_pfnVectors, %object
g_pfnVectors:
.word _estack
.word Reset_Handler
.word NMI_Handler
.word HardFault_Handler
.word MemManage_Handler
.word BusFault_Handler
.word UsageFault_Handler
.word 0, 0, 0, 0
.word SVC_Handler
.word DebugMon_Handler
.word 0
.word PendSV_Handler
.word SysTick_Handler
.word WWDG_IRQHandler
.word PVD_IRQHandler
.word TAMPER_IRQHandler
.word RTC_IRQHandler
.word FLASH_IRQHandler
.word RCC_IRQHandler
.word EXTI0_IRQHandler
.word EXTI1_IRQHandler
.word EXTI2_IRQHandler
.word EXTI3_IRQHandler
.word EXTI4_IRQHandler
.word DMA1_Channel1_IRQHandler
.word DMA1_Channel2_IRQHandler
.word DMA1_Channel3_IRQHandler
.word DMA1_Channel4_IRQHandler
.word DMA1_Channel5_IRQHandler
.word DMA1_Channel6_IRQHandler
.word DMA1_Channel7_IRQHandler
.word ADC1_2_IRQHandler
.word USB_HP_CAN1_TX_IRQHandler
.word USB_LP_CAN1_RX0_IRQHandler
.word CAN1_RX1_IRQHandler
.word CAN1_SCE_IRQHandler
.word EXTI9_5_IRQHandler
.word TIM1_BRK_IRQHandler
.word TIM1_UP_IRQHandler
.word TIM1_TRG_COM_IRQHandler
.word TIM1_CC_IRQHandler
.word TIM2_IRQHandler
.word TIM3_IRQHandler
.word TIM4_IRQHandler
.word I2C1_EV_IRQHandler
.word I2C1_ER_IRQHandler
.word I2C2_EV_IRQHandler
.word I2C2_ER_IRQHandler
.word SPI1_IRQHandler
.word SPI2_IRQHandler
.word USART1_IRQHandler
.word USART2_IRQHandler
.word USART3_IRQHandler
.word EXTI15_10_IRQHandler
.word RTCAlarm_IRQHandler
.word USBWakeUp_IRQHandler
.word TIM8_BRK_IRQHandler
.word TIM8_UP_IRQHandler
.word TIM8_TRG_COM_IRQHandler
.word TIM8_CC_IRQHandler
.word ADC3_IRQHandler
.word FSMC_IRQHandler
.word SDIO_IRQHandler
.word TIM5_IRQHandler
.word SPI3_IRQHandler
.word UART4_IRQHandler
.word UART5_IRQHandler
.word TIM6_IRQHandler
.word TIM7_IRQHandler
.word DMA2_Channel1_IRQHandler
.word DMA2_Channel2_IRQHandler
.word DMA2_Channel3_IRQHandler
.word DMA2_Channel4_5_IRQHandler
.size g_pfnVectors, .-g_pfnVectors
.section .text.Reset_Handler,"ax",%progbits
.thumb_func
Reset_Handler:
ldr r0, =_sidata
ldr r1, =_sdata
ldr r2, =_edata
1:
cmp r1, r2
bcc 2f
b 3f
2:
ldr r3, [r0], #4
str r3, [r1], #4
b 1b
3:
ldr r1, =_sbss
ldr r2, =_ebss
movs r3, #0
4:
cmp r1, r2
bcc 5f
b 6f
5:
str r3, [r1], #4
b 4b
6:
bl SystemInit
bl __libc_init_array
bl main
7:
b 7b
.section .text.Default_Handler,"ax",%progbits
.thumb_func
Default_Handler:
b Default_Handler
.macro weak_handler name
.weak \name
.thumb_set \name, Default_Handler
.endm
weak_handler NMI_Handler
weak_handler HardFault_Handler
weak_handler MemManage_Handler
weak_handler BusFault_Handler
weak_handler UsageFault_Handler
weak_handler SVC_Handler
weak_handler DebugMon_Handler
weak_handler PendSV_Handler
weak_handler SysTick_Handler
weak_handler WWDG_IRQHandler
weak_handler PVD_IRQHandler
weak_handler TAMPER_IRQHandler
weak_handler RTC_IRQHandler
weak_handler FLASH_IRQHandler
weak_handler RCC_IRQHandler
weak_handler EXTI0_IRQHandler
weak_handler EXTI1_IRQHandler
weak_handler EXTI2_IRQHandler
weak_handler EXTI3_IRQHandler
weak_handler EXTI4_IRQHandler
weak_handler DMA1_Channel1_IRQHandler
weak_handler DMA1_Channel2_IRQHandler
weak_handler DMA1_Channel3_IRQHandler
weak_handler DMA1_Channel4_IRQHandler
weak_handler DMA1_Channel5_IRQHandler
weak_handler DMA1_Channel6_IRQHandler
weak_handler DMA1_Channel7_IRQHandler
weak_handler ADC1_2_IRQHandler
weak_handler USB_HP_CAN1_TX_IRQHandler
weak_handler USB_LP_CAN1_RX0_IRQHandler
weak_handler CAN1_RX1_IRQHandler
weak_handler CAN1_SCE_IRQHandler
weak_handler EXTI9_5_IRQHandler
weak_handler TIM1_BRK_IRQHandler
weak_handler TIM1_UP_IRQHandler
weak_handler TIM1_TRG_COM_IRQHandler
weak_handler TIM1_CC_IRQHandler
weak_handler TIM2_IRQHandler
weak_handler TIM3_IRQHandler
weak_handler TIM4_IRQHandler
weak_handler I2C1_EV_IRQHandler
weak_handler I2C1_ER_IRQHandler
weak_handler I2C2_EV_IRQHandler
weak_handler I2C2_ER_IRQHandler
weak_handler SPI1_IRQHandler
weak_handler SPI2_IRQHandler
weak_handler USART1_IRQHandler
weak_handler USART2_IRQHandler
weak_handler USART3_IRQHandler
weak_handler EXTI15_10_IRQHandler
weak_handler RTCAlarm_IRQHandler
weak_handler USBWakeUp_IRQHandler
weak_handler TIM8_BRK_IRQHandler
weak_handler TIM8_UP_IRQHandler
weak_handler TIM8_TRG_COM_IRQHandler
weak_handler TIM8_CC_IRQHandler
weak_handler ADC3_IRQHandler
weak_handler FSMC_IRQHandler
weak_handler SDIO_IRQHandler
weak_handler TIM5_IRQHandler
weak_handler SPI3_IRQHandler
weak_handler UART4_IRQHandler
weak_handler UART5_IRQHandler
weak_handler TIM6_IRQHandler
weak_handler TIM7_IRQHandler
weak_handler DMA2_Channel1_IRQHandler
weak_handler DMA2_Channel2_IRQHandler
weak_handler DMA2_Channel3_IRQHandler
weak_handler DMA2_Channel4_5_IRQHandler
.section .note.GNU-stack,"",%progbits
@@ -0,0 +1,95 @@
ENTRY(Reset_Handler)
MEMORY
{
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 256K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 48K
}
_estack = ORIGIN(RAM) + LENGTH(RAM);
_Min_Heap_Size = 0x200;
_Min_Stack_Size = 0x400;
SECTIONS
{
.isr_vector :
{
. = ALIGN(4);
KEEP(*(.isr_vector))
. = ALIGN(4);
} > FLASH
.text :
{
. = ALIGN(4);
*(.text .text.*)
*(.rodata .rodata.*)
KEEP(*(.init))
KEEP(*(.fini))
. = ALIGN(4);
_etext = .;
} > FLASH
.ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } > FLASH
.ARM.exidx :
{
__exidx_start = .;
*(.ARM.exidx*)
__exidx_end = .;
} > FLASH
.preinit_array :
{
PROVIDE_HIDDEN(__preinit_array_start = .);
KEEP(*(.preinit_array*))
PROVIDE_HIDDEN(__preinit_array_end = .);
} > FLASH
.init_array :
{
PROVIDE_HIDDEN(__init_array_start = .);
KEEP(*(SORT(.init_array.*)))
KEEP(*(.init_array*))
PROVIDE_HIDDEN(__init_array_end = .);
} > FLASH
.fini_array :
{
PROVIDE_HIDDEN(__fini_array_start = .);
KEEP(*(SORT(.fini_array.*)))
KEEP(*(.fini_array*))
PROVIDE_HIDDEN(__fini_array_end = .);
} > FLASH
_sidata = LOADADDR(.data);
.data :
{
. = ALIGN(4);
_sdata = .;
*(.data .data.*)
. = ALIGN(4);
_edata = .;
} > RAM AT > FLASH
.bss (NOLOAD) :
{
. = ALIGN(4);
_sbss = .;
__bss_start__ = _sbss;
*(.bss .bss.*)
*(COMMON)
. = ALIGN(4);
_ebss = .;
__bss_end__ = _ebss;
} > RAM
._user_heap_stack (NOLOAD) :
{
. = ALIGN(8);
PROVIDE(end = .);
PROVIDE(_end = .);
. += _Min_Heap_Size;
. += _Min_Stack_Size;
. = ALIGN(8);
} > RAM
/DISCARD/ : { *(.note.GNU-stack) }
}
@@ -0,0 +1,368 @@
;******************** (C) COPYRIGHT 2011 STMicroelectronics ********************
;* File Name : startup_stm32f10x_cl.s
;* Author : MCD Application Team
;* Version : V3.5.0
;* Date : 11-March-2011
;* Description : STM32F10x Connectivity line devices vector table for MDK-ARM
;* toolchain.
;* This module performs:
;* - Set the initial SP
;* - Set the initial PC == Reset_Handler
;* - Set the vector table entries with the exceptions ISR address
;* - Configure the clock system
;* - Branches to __main in the C library (which eventually
;* calls main()).
;* After Reset the CortexM3 processor is in Thread mode,
;* priority is Privileged, and the Stack is set to Main.
;* <<< Use Configuration Wizard in Context Menu >>>
;*******************************************************************************
; THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
; WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
; AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
; INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
; CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
; INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
;*******************************************************************************
; Amount of memory (in bytes) allocated for Stack
; Tailor this value to your application needs
; <h> Stack Configuration
; <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>
Stack_Size EQU 0x00000400
AREA STACK, NOINIT, READWRITE, ALIGN=3
Stack_Mem SPACE Stack_Size
__initial_sp
; <h> Heap Configuration
; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>
Heap_Size EQU 0x00000200
AREA HEAP, NOINIT, READWRITE, ALIGN=3
__heap_base
Heap_Mem SPACE Heap_Size
__heap_limit
PRESERVE8
THUMB
; Vector Table Mapped to Address 0 at Reset
AREA RESET, DATA, READONLY
EXPORT __Vectors
EXPORT __Vectors_End
EXPORT __Vectors_Size
__Vectors DCD __initial_sp ; Top of Stack
DCD Reset_Handler ; Reset Handler
DCD NMI_Handler ; NMI Handler
DCD HardFault_Handler ; Hard Fault Handler
DCD MemManage_Handler ; MPU Fault Handler
DCD BusFault_Handler ; Bus Fault Handler
DCD UsageFault_Handler ; Usage Fault Handler
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD SVC_Handler ; SVCall Handler
DCD DebugMon_Handler ; Debug Monitor Handler
DCD 0 ; Reserved
DCD PendSV_Handler ; PendSV Handler
DCD SysTick_Handler ; SysTick Handler
; External Interrupts
DCD WWDG_IRQHandler ; Window Watchdog
DCD PVD_IRQHandler ; PVD through EXTI Line detect
DCD TAMPER_IRQHandler ; Tamper
DCD RTC_IRQHandler ; RTC
DCD FLASH_IRQHandler ; Flash
DCD RCC_IRQHandler ; RCC
DCD EXTI0_IRQHandler ; EXTI Line 0
DCD EXTI1_IRQHandler ; EXTI Line 1
DCD EXTI2_IRQHandler ; EXTI Line 2
DCD EXTI3_IRQHandler ; EXTI Line 3
DCD EXTI4_IRQHandler ; EXTI Line 4
DCD DMA1_Channel1_IRQHandler ; DMA1 Channel 1
DCD DMA1_Channel2_IRQHandler ; DMA1 Channel 2
DCD DMA1_Channel3_IRQHandler ; DMA1 Channel 3
DCD DMA1_Channel4_IRQHandler ; DMA1 Channel 4
DCD DMA1_Channel5_IRQHandler ; DMA1 Channel 5
DCD DMA1_Channel6_IRQHandler ; DMA1 Channel 6
DCD DMA1_Channel7_IRQHandler ; DMA1 Channel 7
DCD ADC1_2_IRQHandler ; ADC1 and ADC2
DCD CAN1_TX_IRQHandler ; CAN1 TX
DCD CAN1_RX0_IRQHandler ; CAN1 RX0
DCD CAN1_RX1_IRQHandler ; CAN1 RX1
DCD CAN1_SCE_IRQHandler ; CAN1 SCE
DCD EXTI9_5_IRQHandler ; EXTI Line 9..5
DCD TIM1_BRK_IRQHandler ; TIM1 Break
DCD TIM1_UP_IRQHandler ; TIM1 Update
DCD TIM1_TRG_COM_IRQHandler ; TIM1 Trigger and Commutation
DCD TIM1_CC_IRQHandler ; TIM1 Capture Compare
DCD TIM2_IRQHandler ; TIM2
DCD TIM3_IRQHandler ; TIM3
DCD TIM4_IRQHandler ; TIM4
DCD I2C1_EV_IRQHandler ; I2C1 Event
DCD I2C1_ER_IRQHandler ; I2C1 Error
DCD I2C2_EV_IRQHandler ; I2C2 Event
DCD I2C2_ER_IRQHandler ; I2C1 Error
DCD SPI1_IRQHandler ; SPI1
DCD SPI2_IRQHandler ; SPI2
DCD USART1_IRQHandler ; USART1
DCD USART2_IRQHandler ; USART2
DCD USART3_IRQHandler ; USART3
DCD EXTI15_10_IRQHandler ; EXTI Line 15..10
DCD RTCAlarm_IRQHandler ; RTC alarm through EXTI line
DCD OTG_FS_WKUP_IRQHandler ; USB OTG FS Wakeup through EXTI line
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD TIM5_IRQHandler ; TIM5
DCD SPI3_IRQHandler ; SPI3
DCD UART4_IRQHandler ; UART4
DCD UART5_IRQHandler ; UART5
DCD TIM6_IRQHandler ; TIM6
DCD TIM7_IRQHandler ; TIM7
DCD DMA2_Channel1_IRQHandler ; DMA2 Channel1
DCD DMA2_Channel2_IRQHandler ; DMA2 Channel2
DCD DMA2_Channel3_IRQHandler ; DMA2 Channel3
DCD DMA2_Channel4_IRQHandler ; DMA2 Channel4
DCD DMA2_Channel5_IRQHandler ; DMA2 Channel5
DCD ETH_IRQHandler ; Ethernet
DCD ETH_WKUP_IRQHandler ; Ethernet Wakeup through EXTI line
DCD CAN2_TX_IRQHandler ; CAN2 TX
DCD CAN2_RX0_IRQHandler ; CAN2 RX0
DCD CAN2_RX1_IRQHandler ; CAN2 RX1
DCD CAN2_SCE_IRQHandler ; CAN2 SCE
DCD OTG_FS_IRQHandler ; USB OTG FS
__Vectors_End
__Vectors_Size EQU __Vectors_End - __Vectors
AREA |.text|, CODE, READONLY
; Reset handler
Reset_Handler PROC
EXPORT Reset_Handler [WEAK]
IMPORT SystemInit
IMPORT __main
LDR R0, =SystemInit
BLX R0
LDR R0, =__main
BX R0
ENDP
; Dummy Exception Handlers (infinite loops which can be modified)
NMI_Handler PROC
EXPORT NMI_Handler [WEAK]
B .
ENDP
HardFault_Handler\
PROC
EXPORT HardFault_Handler [WEAK]
B .
ENDP
MemManage_Handler\
PROC
EXPORT MemManage_Handler [WEAK]
B .
ENDP
BusFault_Handler\
PROC
EXPORT BusFault_Handler [WEAK]
B .
ENDP
UsageFault_Handler\
PROC
EXPORT UsageFault_Handler [WEAK]
B .
ENDP
SVC_Handler PROC
EXPORT SVC_Handler [WEAK]
B .
ENDP
DebugMon_Handler\
PROC
EXPORT DebugMon_Handler [WEAK]
B .
ENDP
PendSV_Handler PROC
EXPORT PendSV_Handler [WEAK]
B .
ENDP
SysTick_Handler PROC
EXPORT SysTick_Handler [WEAK]
B .
ENDP
Default_Handler PROC
EXPORT WWDG_IRQHandler [WEAK]
EXPORT PVD_IRQHandler [WEAK]
EXPORT TAMPER_IRQHandler [WEAK]
EXPORT RTC_IRQHandler [WEAK]
EXPORT FLASH_IRQHandler [WEAK]
EXPORT RCC_IRQHandler [WEAK]
EXPORT EXTI0_IRQHandler [WEAK]
EXPORT EXTI1_IRQHandler [WEAK]
EXPORT EXTI2_IRQHandler [WEAK]
EXPORT EXTI3_IRQHandler [WEAK]
EXPORT EXTI4_IRQHandler [WEAK]
EXPORT DMA1_Channel1_IRQHandler [WEAK]
EXPORT DMA1_Channel2_IRQHandler [WEAK]
EXPORT DMA1_Channel3_IRQHandler [WEAK]
EXPORT DMA1_Channel4_IRQHandler [WEAK]
EXPORT DMA1_Channel5_IRQHandler [WEAK]
EXPORT DMA1_Channel6_IRQHandler [WEAK]
EXPORT DMA1_Channel7_IRQHandler [WEAK]
EXPORT ADC1_2_IRQHandler [WEAK]
EXPORT CAN1_TX_IRQHandler [WEAK]
EXPORT CAN1_RX0_IRQHandler [WEAK]
EXPORT CAN1_RX1_IRQHandler [WEAK]
EXPORT CAN1_SCE_IRQHandler [WEAK]
EXPORT EXTI9_5_IRQHandler [WEAK]
EXPORT TIM1_BRK_IRQHandler [WEAK]
EXPORT TIM1_UP_IRQHandler [WEAK]
EXPORT TIM1_TRG_COM_IRQHandler [WEAK]
EXPORT TIM1_CC_IRQHandler [WEAK]
EXPORT TIM2_IRQHandler [WEAK]
EXPORT TIM3_IRQHandler [WEAK]
EXPORT TIM4_IRQHandler [WEAK]
EXPORT I2C1_EV_IRQHandler [WEAK]
EXPORT I2C1_ER_IRQHandler [WEAK]
EXPORT I2C2_EV_IRQHandler [WEAK]
EXPORT I2C2_ER_IRQHandler [WEAK]
EXPORT SPI1_IRQHandler [WEAK]
EXPORT SPI2_IRQHandler [WEAK]
EXPORT USART1_IRQHandler [WEAK]
EXPORT USART2_IRQHandler [WEAK]
EXPORT USART3_IRQHandler [WEAK]
EXPORT EXTI15_10_IRQHandler [WEAK]
EXPORT RTCAlarm_IRQHandler [WEAK]
EXPORT OTG_FS_WKUP_IRQHandler [WEAK]
EXPORT TIM5_IRQHandler [WEAK]
EXPORT SPI3_IRQHandler [WEAK]
EXPORT UART4_IRQHandler [WEAK]
EXPORT UART5_IRQHandler [WEAK]
EXPORT TIM6_IRQHandler [WEAK]
EXPORT TIM7_IRQHandler [WEAK]
EXPORT DMA2_Channel1_IRQHandler [WEAK]
EXPORT DMA2_Channel2_IRQHandler [WEAK]
EXPORT DMA2_Channel3_IRQHandler [WEAK]
EXPORT DMA2_Channel4_IRQHandler [WEAK]
EXPORT DMA2_Channel5_IRQHandler [WEAK]
EXPORT ETH_IRQHandler [WEAK]
EXPORT ETH_WKUP_IRQHandler [WEAK]
EXPORT CAN2_TX_IRQHandler [WEAK]
EXPORT CAN2_RX0_IRQHandler [WEAK]
EXPORT CAN2_RX1_IRQHandler [WEAK]
EXPORT CAN2_SCE_IRQHandler [WEAK]
EXPORT OTG_FS_IRQHandler [WEAK]
WWDG_IRQHandler
PVD_IRQHandler
TAMPER_IRQHandler
RTC_IRQHandler
FLASH_IRQHandler
RCC_IRQHandler
EXTI0_IRQHandler
EXTI1_IRQHandler
EXTI2_IRQHandler
EXTI3_IRQHandler
EXTI4_IRQHandler
DMA1_Channel1_IRQHandler
DMA1_Channel2_IRQHandler
DMA1_Channel3_IRQHandler
DMA1_Channel4_IRQHandler
DMA1_Channel5_IRQHandler
DMA1_Channel6_IRQHandler
DMA1_Channel7_IRQHandler
ADC1_2_IRQHandler
CAN1_TX_IRQHandler
CAN1_RX0_IRQHandler
CAN1_RX1_IRQHandler
CAN1_SCE_IRQHandler
EXTI9_5_IRQHandler
TIM1_BRK_IRQHandler
TIM1_UP_IRQHandler
TIM1_TRG_COM_IRQHandler
TIM1_CC_IRQHandler
TIM2_IRQHandler
TIM3_IRQHandler
TIM4_IRQHandler
I2C1_EV_IRQHandler
I2C1_ER_IRQHandler
I2C2_EV_IRQHandler
I2C2_ER_IRQHandler
SPI1_IRQHandler
SPI2_IRQHandler
USART1_IRQHandler
USART2_IRQHandler
USART3_IRQHandler
EXTI15_10_IRQHandler
RTCAlarm_IRQHandler
OTG_FS_WKUP_IRQHandler
TIM5_IRQHandler
SPI3_IRQHandler
UART4_IRQHandler
UART5_IRQHandler
TIM6_IRQHandler
TIM7_IRQHandler
DMA2_Channel1_IRQHandler
DMA2_Channel2_IRQHandler
DMA2_Channel3_IRQHandler
DMA2_Channel4_IRQHandler
DMA2_Channel5_IRQHandler
ETH_IRQHandler
ETH_WKUP_IRQHandler
CAN2_TX_IRQHandler
CAN2_RX0_IRQHandler
CAN2_RX1_IRQHandler
CAN2_SCE_IRQHandler
OTG_FS_IRQHandler
B .
ENDP
ALIGN
;*******************************************************************************
; User Stack and Heap initialization
;*******************************************************************************
IF :DEF:__MICROLIB
EXPORT __initial_sp
EXPORT __heap_base
EXPORT __heap_limit
ELSE
IMPORT __use_two_region_memory
EXPORT __user_initial_stackheap
__user_initial_stackheap
LDR R0, = Heap_Mem
LDR R1, =(Stack_Mem + Stack_Size)
LDR R2, = (Heap_Mem + Heap_Size)
LDR R3, = Stack_Mem
BX LR
ALIGN
ENDIF
END
;******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE*****
@@ -0,0 +1,358 @@
;******************** (C) COPYRIGHT 2011 STMicroelectronics ********************
;* File Name : startup_stm32f10x_hd.s
;* Author : MCD Application Team
;* Version : V3.5.0
;* Date : 11-March-2011
;* Description : STM32F10x High Density Devices vector table for MDK-ARM
;* toolchain.
;* This module performs:
;* - Set the initial SP
;* - Set the initial PC == Reset_Handler
;* - Set the vector table entries with the exceptions ISR address
;* - Configure the clock system and also configure the external
;* SRAM mounted on STM3210E-EVAL board to be used as data
;* memory (optional, to be enabled by user)
;* - Branches to __main in the C library (which eventually
;* calls main()).
;* After Reset the CortexM3 processor is in Thread mode,
;* priority is Privileged, and the Stack is set to Main.
;* <<< Use Configuration Wizard in Context Menu >>>
;*******************************************************************************
; THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
; WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
; AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
; INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
; CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
; INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
;*******************************************************************************
; Amount of memory (in bytes) allocated for Stack
; Tailor this value to your application needs
; <h> Stack Configuration
; <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>
Stack_Size EQU 0x00000400
AREA STACK, NOINIT, READWRITE, ALIGN=3
Stack_Mem SPACE Stack_Size
__initial_sp
; <h> Heap Configuration
; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>
Heap_Size EQU 0x00000200
AREA HEAP, NOINIT, READWRITE, ALIGN=3
__heap_base
Heap_Mem SPACE Heap_Size
__heap_limit
PRESERVE8
THUMB
; Vector Table Mapped to Address 0 at Reset
AREA RESET, DATA, READONLY
EXPORT __Vectors
EXPORT __Vectors_End
EXPORT __Vectors_Size
__Vectors DCD __initial_sp ; Top of Stack
DCD Reset_Handler ; Reset Handler
DCD NMI_Handler ; NMI Handler
DCD HardFault_Handler ; Hard Fault Handler
DCD MemManage_Handler ; MPU Fault Handler
DCD BusFault_Handler ; Bus Fault Handler
DCD UsageFault_Handler ; Usage Fault Handler
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD SVC_Handler ; SVCall Handler
DCD DebugMon_Handler ; Debug Monitor Handler
DCD 0 ; Reserved
DCD PendSV_Handler ; PendSV Handler
DCD SysTick_Handler ; SysTick Handler
; External Interrupts
DCD WWDG_IRQHandler ; Window Watchdog
DCD PVD_IRQHandler ; PVD through EXTI Line detect
DCD TAMPER_IRQHandler ; Tamper
DCD RTC_IRQHandler ; RTC
DCD FLASH_IRQHandler ; Flash
DCD RCC_IRQHandler ; RCC
DCD EXTI0_IRQHandler ; EXTI Line 0
DCD EXTI1_IRQHandler ; EXTI Line 1
DCD EXTI2_IRQHandler ; EXTI Line 2
DCD EXTI3_IRQHandler ; EXTI Line 3
DCD EXTI4_IRQHandler ; EXTI Line 4
DCD DMA1_Channel1_IRQHandler ; DMA1 Channel 1
DCD DMA1_Channel2_IRQHandler ; DMA1 Channel 2
DCD DMA1_Channel3_IRQHandler ; DMA1 Channel 3
DCD DMA1_Channel4_IRQHandler ; DMA1 Channel 4
DCD DMA1_Channel5_IRQHandler ; DMA1 Channel 5
DCD DMA1_Channel6_IRQHandler ; DMA1 Channel 6
DCD DMA1_Channel7_IRQHandler ; DMA1 Channel 7
DCD ADC1_2_IRQHandler ; ADC1 & ADC2
DCD USB_HP_CAN1_TX_IRQHandler ; USB High Priority or CAN1 TX
DCD USB_LP_CAN1_RX0_IRQHandler ; USB Low Priority or CAN1 RX0
DCD CAN1_RX1_IRQHandler ; CAN1 RX1
DCD CAN1_SCE_IRQHandler ; CAN1 SCE
DCD EXTI9_5_IRQHandler ; EXTI Line 9..5
DCD TIM1_BRK_IRQHandler ; TIM1 Break
DCD TIM1_UP_IRQHandler ; TIM1 Update
DCD TIM1_TRG_COM_IRQHandler ; TIM1 Trigger and Commutation
DCD TIM1_CC_IRQHandler ; TIM1 Capture Compare
DCD TIM2_IRQHandler ; TIM2
DCD TIM3_IRQHandler ; TIM3
DCD TIM4_IRQHandler ; TIM4
DCD I2C1_EV_IRQHandler ; I2C1 Event
DCD I2C1_ER_IRQHandler ; I2C1 Error
DCD I2C2_EV_IRQHandler ; I2C2 Event
DCD I2C2_ER_IRQHandler ; I2C2 Error
DCD SPI1_IRQHandler ; SPI1
DCD SPI2_IRQHandler ; SPI2
DCD USART1_IRQHandler ; USART1
DCD USART2_IRQHandler ; USART2
DCD USART3_IRQHandler ; USART3
DCD EXTI15_10_IRQHandler ; EXTI Line 15..10
DCD RTCAlarm_IRQHandler ; RTC Alarm through EXTI Line
DCD USBWakeUp_IRQHandler ; USB Wakeup from suspend
DCD TIM8_BRK_IRQHandler ; TIM8 Break
DCD TIM8_UP_IRQHandler ; TIM8 Update
DCD TIM8_TRG_COM_IRQHandler ; TIM8 Trigger and Commutation
DCD TIM8_CC_IRQHandler ; TIM8 Capture Compare
DCD ADC3_IRQHandler ; ADC3
DCD FSMC_IRQHandler ; FSMC
DCD SDIO_IRQHandler ; SDIO
DCD TIM5_IRQHandler ; TIM5
DCD SPI3_IRQHandler ; SPI3
DCD UART4_IRQHandler ; UART4
DCD UART5_IRQHandler ; UART5
DCD TIM6_IRQHandler ; TIM6
DCD TIM7_IRQHandler ; TIM7
DCD DMA2_Channel1_IRQHandler ; DMA2 Channel1
DCD DMA2_Channel2_IRQHandler ; DMA2 Channel2
DCD DMA2_Channel3_IRQHandler ; DMA2 Channel3
DCD DMA2_Channel4_5_IRQHandler ; DMA2 Channel4 & Channel5
__Vectors_End
__Vectors_Size EQU __Vectors_End - __Vectors
AREA |.text|, CODE, READONLY
; Reset handler
Reset_Handler PROC
EXPORT Reset_Handler [WEAK]
IMPORT __main
IMPORT SystemInit
LDR R0, =SystemInit
BLX R0
LDR R0, =__main
BX R0
ENDP
; Dummy Exception Handlers (infinite loops which can be modified)
NMI_Handler PROC
EXPORT NMI_Handler [WEAK]
B .
ENDP
HardFault_Handler\
PROC
EXPORT HardFault_Handler [WEAK]
B .
ENDP
MemManage_Handler\
PROC
EXPORT MemManage_Handler [WEAK]
B .
ENDP
BusFault_Handler\
PROC
EXPORT BusFault_Handler [WEAK]
B .
ENDP
UsageFault_Handler\
PROC
EXPORT UsageFault_Handler [WEAK]
B .
ENDP
SVC_Handler PROC
EXPORT SVC_Handler [WEAK]
B .
ENDP
DebugMon_Handler\
PROC
EXPORT DebugMon_Handler [WEAK]
B .
ENDP
PendSV_Handler PROC
EXPORT PendSV_Handler [WEAK]
B .
ENDP
SysTick_Handler PROC
EXPORT SysTick_Handler [WEAK]
B .
ENDP
Default_Handler PROC
EXPORT WWDG_IRQHandler [WEAK]
EXPORT PVD_IRQHandler [WEAK]
EXPORT TAMPER_IRQHandler [WEAK]
EXPORT RTC_IRQHandler [WEAK]
EXPORT FLASH_IRQHandler [WEAK]
EXPORT RCC_IRQHandler [WEAK]
EXPORT EXTI0_IRQHandler [WEAK]
EXPORT EXTI1_IRQHandler [WEAK]
EXPORT EXTI2_IRQHandler [WEAK]
EXPORT EXTI3_IRQHandler [WEAK]
EXPORT EXTI4_IRQHandler [WEAK]
EXPORT DMA1_Channel1_IRQHandler [WEAK]
EXPORT DMA1_Channel2_IRQHandler [WEAK]
EXPORT DMA1_Channel3_IRQHandler [WEAK]
EXPORT DMA1_Channel4_IRQHandler [WEAK]
EXPORT DMA1_Channel5_IRQHandler [WEAK]
EXPORT DMA1_Channel6_IRQHandler [WEAK]
EXPORT DMA1_Channel7_IRQHandler [WEAK]
EXPORT ADC1_2_IRQHandler [WEAK]
EXPORT USB_HP_CAN1_TX_IRQHandler [WEAK]
EXPORT USB_LP_CAN1_RX0_IRQHandler [WEAK]
EXPORT CAN1_RX1_IRQHandler [WEAK]
EXPORT CAN1_SCE_IRQHandler [WEAK]
EXPORT EXTI9_5_IRQHandler [WEAK]
EXPORT TIM1_BRK_IRQHandler [WEAK]
EXPORT TIM1_UP_IRQHandler [WEAK]
EXPORT TIM1_TRG_COM_IRQHandler [WEAK]
EXPORT TIM1_CC_IRQHandler [WEAK]
EXPORT TIM2_IRQHandler [WEAK]
EXPORT TIM3_IRQHandler [WEAK]
EXPORT TIM4_IRQHandler [WEAK]
EXPORT I2C1_EV_IRQHandler [WEAK]
EXPORT I2C1_ER_IRQHandler [WEAK]
EXPORT I2C2_EV_IRQHandler [WEAK]
EXPORT I2C2_ER_IRQHandler [WEAK]
EXPORT SPI1_IRQHandler [WEAK]
EXPORT SPI2_IRQHandler [WEAK]
EXPORT USART1_IRQHandler [WEAK]
EXPORT USART2_IRQHandler [WEAK]
EXPORT USART3_IRQHandler [WEAK]
EXPORT EXTI15_10_IRQHandler [WEAK]
EXPORT RTCAlarm_IRQHandler [WEAK]
EXPORT USBWakeUp_IRQHandler [WEAK]
EXPORT TIM8_BRK_IRQHandler [WEAK]
EXPORT TIM8_UP_IRQHandler [WEAK]
EXPORT TIM8_TRG_COM_IRQHandler [WEAK]
EXPORT TIM8_CC_IRQHandler [WEAK]
EXPORT ADC3_IRQHandler [WEAK]
EXPORT FSMC_IRQHandler [WEAK]
EXPORT SDIO_IRQHandler [WEAK]
EXPORT TIM5_IRQHandler [WEAK]
EXPORT SPI3_IRQHandler [WEAK]
EXPORT UART4_IRQHandler [WEAK]
EXPORT UART5_IRQHandler [WEAK]
EXPORT TIM6_IRQHandler [WEAK]
EXPORT TIM7_IRQHandler [WEAK]
EXPORT DMA2_Channel1_IRQHandler [WEAK]
EXPORT DMA2_Channel2_IRQHandler [WEAK]
EXPORT DMA2_Channel3_IRQHandler [WEAK]
EXPORT DMA2_Channel4_5_IRQHandler [WEAK]
WWDG_IRQHandler
PVD_IRQHandler
TAMPER_IRQHandler
RTC_IRQHandler
FLASH_IRQHandler
RCC_IRQHandler
EXTI0_IRQHandler
EXTI1_IRQHandler
EXTI2_IRQHandler
EXTI3_IRQHandler
EXTI4_IRQHandler
DMA1_Channel1_IRQHandler
DMA1_Channel2_IRQHandler
DMA1_Channel3_IRQHandler
DMA1_Channel4_IRQHandler
DMA1_Channel5_IRQHandler
DMA1_Channel6_IRQHandler
DMA1_Channel7_IRQHandler
ADC1_2_IRQHandler
USB_HP_CAN1_TX_IRQHandler
USB_LP_CAN1_RX0_IRQHandler
CAN1_RX1_IRQHandler
CAN1_SCE_IRQHandler
EXTI9_5_IRQHandler
TIM1_BRK_IRQHandler
TIM1_UP_IRQHandler
TIM1_TRG_COM_IRQHandler
TIM1_CC_IRQHandler
TIM2_IRQHandler
TIM3_IRQHandler
TIM4_IRQHandler
I2C1_EV_IRQHandler
I2C1_ER_IRQHandler
I2C2_EV_IRQHandler
I2C2_ER_IRQHandler
SPI1_IRQHandler
SPI2_IRQHandler
USART1_IRQHandler
USART2_IRQHandler
USART3_IRQHandler
EXTI15_10_IRQHandler
RTCAlarm_IRQHandler
USBWakeUp_IRQHandler
TIM8_BRK_IRQHandler
TIM8_UP_IRQHandler
TIM8_TRG_COM_IRQHandler
TIM8_CC_IRQHandler
ADC3_IRQHandler
FSMC_IRQHandler
SDIO_IRQHandler
TIM5_IRQHandler
SPI3_IRQHandler
UART4_IRQHandler
UART5_IRQHandler
TIM6_IRQHandler
TIM7_IRQHandler
DMA2_Channel1_IRQHandler
DMA2_Channel2_IRQHandler
DMA2_Channel3_IRQHandler
DMA2_Channel4_5_IRQHandler
B .
ENDP
ALIGN
;*******************************************************************************
; User Stack and Heap initialization
;*******************************************************************************
IF :DEF:__MICROLIB
EXPORT __initial_sp
EXPORT __heap_base
EXPORT __heap_limit
ELSE
IMPORT __use_two_region_memory
EXPORT __user_initial_stackheap
__user_initial_stackheap
LDR R0, = Heap_Mem
LDR R1, =(Stack_Mem + Stack_Size)
LDR R2, = (Heap_Mem + Heap_Size)
LDR R3, = Stack_Mem
BX LR
ALIGN
ENDIF
END
;******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE*****
@@ -0,0 +1,346 @@
;******************** (C) COPYRIGHT 2011 STMicroelectronics ********************
;* File Name : startup_stm32f10x_hd_vl.s
;* Author : MCD Application Team
;* Version : V3.5.0
;* Date : 11-March-2011
;* Description : STM32F10x High Density Value Line Devices vector table
;* for MDK-ARM toolchain.
;* This module performs:
;* - Set the initial SP
;* - Set the initial PC == Reset_Handler
;* - Set the vector table entries with the exceptions ISR address
;* - Configure the clock system and also configure the external
;* SRAM mounted on STM32100E-EVAL board to be used as data
;* memory (optional, to be enabled by user)
;* - Branches to __main in the C library (which eventually
;* calls main()).
;* After Reset the CortexM3 processor is in Thread mode,
;* priority is Privileged, and the Stack is set to Main.
;* <<< Use Configuration Wizard in Context Menu >>>
;*******************************************************************************
; THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
; WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
; AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
; INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
; CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
; INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
;*******************************************************************************
; Amount of memory (in bytes) allocated for Stack
; Tailor this value to your application needs
; <h> Stack Configuration
; <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>
Stack_Size EQU 0x00000400
AREA STACK, NOINIT, READWRITE, ALIGN=3
Stack_Mem SPACE Stack_Size
__initial_sp
; <h> Heap Configuration
; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>
Heap_Size EQU 0x00000200
AREA HEAP, NOINIT, READWRITE, ALIGN=3
__heap_base
Heap_Mem SPACE Heap_Size
__heap_limit
PRESERVE8
THUMB
; Vector Table Mapped to Address 0 at Reset
AREA RESET, DATA, READONLY
EXPORT __Vectors
EXPORT __Vectors_End
EXPORT __Vectors_Size
__Vectors DCD __initial_sp ; Top of Stack
DCD Reset_Handler ; Reset Handler
DCD NMI_Handler ; NMI Handler
DCD HardFault_Handler ; Hard Fault Handler
DCD MemManage_Handler ; MPU Fault Handler
DCD BusFault_Handler ; Bus Fault Handler
DCD UsageFault_Handler ; Usage Fault Handler
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD SVC_Handler ; SVCall Handler
DCD DebugMon_Handler ; Debug Monitor Handler
DCD 0 ; Reserved
DCD PendSV_Handler ; PendSV Handler
DCD SysTick_Handler ; SysTick Handler
; External Interrupts
DCD WWDG_IRQHandler ; Window Watchdog
DCD PVD_IRQHandler ; PVD through EXTI Line detect
DCD TAMPER_IRQHandler ; Tamper
DCD RTC_IRQHandler ; RTC
DCD FLASH_IRQHandler ; Flash
DCD RCC_IRQHandler ; RCC
DCD EXTI0_IRQHandler ; EXTI Line 0
DCD EXTI1_IRQHandler ; EXTI Line 1
DCD EXTI2_IRQHandler ; EXTI Line 2
DCD EXTI3_IRQHandler ; EXTI Line 3
DCD EXTI4_IRQHandler ; EXTI Line 4
DCD DMA1_Channel1_IRQHandler ; DMA1 Channel 1
DCD DMA1_Channel2_IRQHandler ; DMA1 Channel 2
DCD DMA1_Channel3_IRQHandler ; DMA1 Channel 3
DCD DMA1_Channel4_IRQHandler ; DMA1 Channel 4
DCD DMA1_Channel5_IRQHandler ; DMA1 Channel 5
DCD DMA1_Channel6_IRQHandler ; DMA1 Channel 6
DCD DMA1_Channel7_IRQHandler ; DMA1 Channel 7
DCD ADC1_IRQHandler ; ADC1
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD EXTI9_5_IRQHandler ; EXTI Line 9..5
DCD TIM1_BRK_TIM15_IRQHandler ; TIM1 Break and TIM15
DCD TIM1_UP_TIM16_IRQHandler ; TIM1 Update and TIM16
DCD TIM1_TRG_COM_TIM17_IRQHandler ; TIM1 Trigger and Commutation and TIM17
DCD TIM1_CC_IRQHandler ; TIM1 Capture Compare
DCD TIM2_IRQHandler ; TIM2
DCD TIM3_IRQHandler ; TIM3
DCD TIM4_IRQHandler ; TIM4
DCD I2C1_EV_IRQHandler ; I2C1 Event
DCD I2C1_ER_IRQHandler ; I2C1 Error
DCD I2C2_EV_IRQHandler ; I2C2 Event
DCD I2C2_ER_IRQHandler ; I2C2 Error
DCD SPI1_IRQHandler ; SPI1
DCD SPI2_IRQHandler ; SPI2
DCD USART1_IRQHandler ; USART1
DCD USART2_IRQHandler ; USART2
DCD USART3_IRQHandler ; USART3
DCD EXTI15_10_IRQHandler ; EXTI Line 15..10
DCD RTCAlarm_IRQHandler ; RTC Alarm through EXTI Line
DCD CEC_IRQHandler ; HDMI-CEC
DCD TIM12_IRQHandler ; TIM12
DCD TIM13_IRQHandler ; TIM13
DCD TIM14_IRQHandler ; TIM14
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD TIM5_IRQHandler ; TIM5
DCD SPI3_IRQHandler ; SPI3
DCD UART4_IRQHandler ; UART4
DCD UART5_IRQHandler ; UART5
DCD TIM6_DAC_IRQHandler ; TIM6 and DAC underrun
DCD TIM7_IRQHandler ; TIM7
DCD DMA2_Channel1_IRQHandler ; DMA2 Channel1
DCD DMA2_Channel2_IRQHandler ; DMA2 Channel2
DCD DMA2_Channel3_IRQHandler ; DMA2 Channel3
DCD DMA2_Channel4_5_IRQHandler ; DMA2 Channel4 & Channel5
DCD DMA2_Channel5_IRQHandler ; DMA2 Channel5
__Vectors_End
__Vectors_Size EQU __Vectors_End - __Vectors
AREA |.text|, CODE, READONLY
; Reset handler
Reset_Handler PROC
EXPORT Reset_Handler [WEAK]
IMPORT __main
IMPORT SystemInit
LDR R0, =SystemInit
BLX R0
LDR R0, =__main
BX R0
ENDP
; Dummy Exception Handlers (infinite loops which can be modified)
NMI_Handler PROC
EXPORT NMI_Handler [WEAK]
B .
ENDP
HardFault_Handler\
PROC
EXPORT HardFault_Handler [WEAK]
B .
ENDP
MemManage_Handler\
PROC
EXPORT MemManage_Handler [WEAK]
B .
ENDP
BusFault_Handler\
PROC
EXPORT BusFault_Handler [WEAK]
B .
ENDP
UsageFault_Handler\
PROC
EXPORT UsageFault_Handler [WEAK]
B .
ENDP
SVC_Handler PROC
EXPORT SVC_Handler [WEAK]
B .
ENDP
DebugMon_Handler\
PROC
EXPORT DebugMon_Handler [WEAK]
B .
ENDP
PendSV_Handler PROC
EXPORT PendSV_Handler [WEAK]
B .
ENDP
SysTick_Handler PROC
EXPORT SysTick_Handler [WEAK]
B .
ENDP
Default_Handler PROC
EXPORT WWDG_IRQHandler [WEAK]
EXPORT PVD_IRQHandler [WEAK]
EXPORT TAMPER_IRQHandler [WEAK]
EXPORT RTC_IRQHandler [WEAK]
EXPORT FLASH_IRQHandler [WEAK]
EXPORT RCC_IRQHandler [WEAK]
EXPORT EXTI0_IRQHandler [WEAK]
EXPORT EXTI1_IRQHandler [WEAK]
EXPORT EXTI2_IRQHandler [WEAK]
EXPORT EXTI3_IRQHandler [WEAK]
EXPORT EXTI4_IRQHandler [WEAK]
EXPORT DMA1_Channel1_IRQHandler [WEAK]
EXPORT DMA1_Channel2_IRQHandler [WEAK]
EXPORT DMA1_Channel3_IRQHandler [WEAK]
EXPORT DMA1_Channel4_IRQHandler [WEAK]
EXPORT DMA1_Channel5_IRQHandler [WEAK]
EXPORT DMA1_Channel6_IRQHandler [WEAK]
EXPORT DMA1_Channel7_IRQHandler [WEAK]
EXPORT ADC1_IRQHandler [WEAK]
EXPORT EXTI9_5_IRQHandler [WEAK]
EXPORT TIM1_BRK_TIM15_IRQHandler [WEAK]
EXPORT TIM1_UP_TIM16_IRQHandler [WEAK]
EXPORT TIM1_TRG_COM_TIM17_IRQHandler [WEAK]
EXPORT TIM1_CC_IRQHandler [WEAK]
EXPORT TIM2_IRQHandler [WEAK]
EXPORT TIM3_IRQHandler [WEAK]
EXPORT TIM4_IRQHandler [WEAK]
EXPORT I2C1_EV_IRQHandler [WEAK]
EXPORT I2C1_ER_IRQHandler [WEAK]
EXPORT I2C2_EV_IRQHandler [WEAK]
EXPORT I2C2_ER_IRQHandler [WEAK]
EXPORT SPI1_IRQHandler [WEAK]
EXPORT SPI2_IRQHandler [WEAK]
EXPORT USART1_IRQHandler [WEAK]
EXPORT USART2_IRQHandler [WEAK]
EXPORT USART3_IRQHandler [WEAK]
EXPORT EXTI15_10_IRQHandler [WEAK]
EXPORT RTCAlarm_IRQHandler [WEAK]
EXPORT CEC_IRQHandler [WEAK]
EXPORT TIM12_IRQHandler [WEAK]
EXPORT TIM13_IRQHandler [WEAK]
EXPORT TIM14_IRQHandler [WEAK]
EXPORT TIM5_IRQHandler [WEAK]
EXPORT SPI3_IRQHandler [WEAK]
EXPORT UART4_IRQHandler [WEAK]
EXPORT UART5_IRQHandler [WEAK]
EXPORT TIM6_DAC_IRQHandler [WEAK]
EXPORT TIM7_IRQHandler [WEAK]
EXPORT DMA2_Channel1_IRQHandler [WEAK]
EXPORT DMA2_Channel2_IRQHandler [WEAK]
EXPORT DMA2_Channel3_IRQHandler [WEAK]
EXPORT DMA2_Channel4_5_IRQHandler [WEAK]
EXPORT DMA2_Channel5_IRQHandler [WEAK]
WWDG_IRQHandler
PVD_IRQHandler
TAMPER_IRQHandler
RTC_IRQHandler
FLASH_IRQHandler
RCC_IRQHandler
EXTI0_IRQHandler
EXTI1_IRQHandler
EXTI2_IRQHandler
EXTI3_IRQHandler
EXTI4_IRQHandler
DMA1_Channel1_IRQHandler
DMA1_Channel2_IRQHandler
DMA1_Channel3_IRQHandler
DMA1_Channel4_IRQHandler
DMA1_Channel5_IRQHandler
DMA1_Channel6_IRQHandler
DMA1_Channel7_IRQHandler
ADC1_IRQHandler
EXTI9_5_IRQHandler
TIM1_BRK_TIM15_IRQHandler
TIM1_UP_TIM16_IRQHandler
TIM1_TRG_COM_TIM17_IRQHandler
TIM1_CC_IRQHandler
TIM2_IRQHandler
TIM3_IRQHandler
TIM4_IRQHandler
I2C1_EV_IRQHandler
I2C1_ER_IRQHandler
I2C2_EV_IRQHandler
I2C2_ER_IRQHandler
SPI1_IRQHandler
SPI2_IRQHandler
USART1_IRQHandler
USART2_IRQHandler
USART3_IRQHandler
EXTI15_10_IRQHandler
RTCAlarm_IRQHandler
CEC_IRQHandler
TIM12_IRQHandler
TIM13_IRQHandler
TIM14_IRQHandler
TIM5_IRQHandler
SPI3_IRQHandler
UART4_IRQHandler
UART5_IRQHandler
TIM6_DAC_IRQHandler
TIM7_IRQHandler
DMA2_Channel1_IRQHandler
DMA2_Channel2_IRQHandler
DMA2_Channel3_IRQHandler
DMA2_Channel4_5_IRQHandler
DMA2_Channel5_IRQHandler
B .
ENDP
ALIGN
;*******************************************************************************
; User Stack and Heap initialization
;*******************************************************************************
IF :DEF:__MICROLIB
EXPORT __initial_sp
EXPORT __heap_base
EXPORT __heap_limit
ELSE
IMPORT __use_two_region_memory
EXPORT __user_initial_stackheap
__user_initial_stackheap
LDR R0, = Heap_Mem
LDR R1, =(Stack_Mem + Stack_Size)
LDR R2, = (Heap_Mem + Heap_Size)
LDR R3, = Stack_Mem
BX LR
ALIGN
ENDIF
END
;******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE*****
@@ -0,0 +1,297 @@
;******************** (C) COPYRIGHT 2011 STMicroelectronics ********************
;* File Name : startup_stm32f10x_ld.s
;* Author : MCD Application Team
;* Version : V3.5.0
;* Date : 11-March-2011
;* Description : STM32F10x Low Density Devices vector table for MDK-ARM
;* toolchain.
;* This module performs:
;* - Set the initial SP
;* - Set the initial PC == Reset_Handler
;* - Set the vector table entries with the exceptions ISR address
;* - Configure the clock system
;* - Branches to __main in the C library (which eventually
;* calls main()).
;* After Reset the CortexM3 processor is in Thread mode,
;* priority is Privileged, and the Stack is set to Main.
;* <<< Use Configuration Wizard in Context Menu >>>
;*******************************************************************************
; THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
; WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
; AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
; INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
; CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
; INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
;*******************************************************************************
; Amount of memory (in bytes) allocated for Stack
; Tailor this value to your application needs
; <h> Stack Configuration
; <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>
Stack_Size EQU 0x00000400
AREA STACK, NOINIT, READWRITE, ALIGN=3
Stack_Mem SPACE Stack_Size
__initial_sp
; <h> Heap Configuration
; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>
Heap_Size EQU 0x00000200
AREA HEAP, NOINIT, READWRITE, ALIGN=3
__heap_base
Heap_Mem SPACE Heap_Size
__heap_limit
PRESERVE8
THUMB
; Vector Table Mapped to Address 0 at Reset
AREA RESET, DATA, READONLY
EXPORT __Vectors
EXPORT __Vectors_End
EXPORT __Vectors_Size
__Vectors DCD __initial_sp ; Top of Stack
DCD Reset_Handler ; Reset Handler
DCD NMI_Handler ; NMI Handler
DCD HardFault_Handler ; Hard Fault Handler
DCD MemManage_Handler ; MPU Fault Handler
DCD BusFault_Handler ; Bus Fault Handler
DCD UsageFault_Handler ; Usage Fault Handler
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD SVC_Handler ; SVCall Handler
DCD DebugMon_Handler ; Debug Monitor Handler
DCD 0 ; Reserved
DCD PendSV_Handler ; PendSV Handler
DCD SysTick_Handler ; SysTick Handler
; External Interrupts
DCD WWDG_IRQHandler ; Window Watchdog
DCD PVD_IRQHandler ; PVD through EXTI Line detect
DCD TAMPER_IRQHandler ; Tamper
DCD RTC_IRQHandler ; RTC
DCD FLASH_IRQHandler ; Flash
DCD RCC_IRQHandler ; RCC
DCD EXTI0_IRQHandler ; EXTI Line 0
DCD EXTI1_IRQHandler ; EXTI Line 1
DCD EXTI2_IRQHandler ; EXTI Line 2
DCD EXTI3_IRQHandler ; EXTI Line 3
DCD EXTI4_IRQHandler ; EXTI Line 4
DCD DMA1_Channel1_IRQHandler ; DMA1 Channel 1
DCD DMA1_Channel2_IRQHandler ; DMA1 Channel 2
DCD DMA1_Channel3_IRQHandler ; DMA1 Channel 3
DCD DMA1_Channel4_IRQHandler ; DMA1 Channel 4
DCD DMA1_Channel5_IRQHandler ; DMA1 Channel 5
DCD DMA1_Channel6_IRQHandler ; DMA1 Channel 6
DCD DMA1_Channel7_IRQHandler ; DMA1 Channel 7
DCD ADC1_2_IRQHandler ; ADC1_2
DCD USB_HP_CAN1_TX_IRQHandler ; USB High Priority or CAN1 TX
DCD USB_LP_CAN1_RX0_IRQHandler ; USB Low Priority or CAN1 RX0
DCD CAN1_RX1_IRQHandler ; CAN1 RX1
DCD CAN1_SCE_IRQHandler ; CAN1 SCE
DCD EXTI9_5_IRQHandler ; EXTI Line 9..5
DCD TIM1_BRK_IRQHandler ; TIM1 Break
DCD TIM1_UP_IRQHandler ; TIM1 Update
DCD TIM1_TRG_COM_IRQHandler ; TIM1 Trigger and Commutation
DCD TIM1_CC_IRQHandler ; TIM1 Capture Compare
DCD TIM2_IRQHandler ; TIM2
DCD TIM3_IRQHandler ; TIM3
DCD 0 ; Reserved
DCD I2C1_EV_IRQHandler ; I2C1 Event
DCD I2C1_ER_IRQHandler ; I2C1 Error
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD SPI1_IRQHandler ; SPI1
DCD 0 ; Reserved
DCD USART1_IRQHandler ; USART1
DCD USART2_IRQHandler ; USART2
DCD 0 ; Reserved
DCD EXTI15_10_IRQHandler ; EXTI Line 15..10
DCD RTCAlarm_IRQHandler ; RTC Alarm through EXTI Line
DCD USBWakeUp_IRQHandler ; USB Wakeup from suspend
__Vectors_End
__Vectors_Size EQU __Vectors_End - __Vectors
AREA |.text|, CODE, READONLY
; Reset handler routine
Reset_Handler PROC
EXPORT Reset_Handler [WEAK]
IMPORT __main
IMPORT SystemInit
LDR R0, =SystemInit
BLX R0
LDR R0, =__main
BX R0
ENDP
; Dummy Exception Handlers (infinite loops which can be modified)
NMI_Handler PROC
EXPORT NMI_Handler [WEAK]
B .
ENDP
HardFault_Handler\
PROC
EXPORT HardFault_Handler [WEAK]
B .
ENDP
MemManage_Handler\
PROC
EXPORT MemManage_Handler [WEAK]
B .
ENDP
BusFault_Handler\
PROC
EXPORT BusFault_Handler [WEAK]
B .
ENDP
UsageFault_Handler\
PROC
EXPORT UsageFault_Handler [WEAK]
B .
ENDP
SVC_Handler PROC
EXPORT SVC_Handler [WEAK]
B .
ENDP
DebugMon_Handler\
PROC
EXPORT DebugMon_Handler [WEAK]
B .
ENDP
PendSV_Handler PROC
EXPORT PendSV_Handler [WEAK]
B .
ENDP
SysTick_Handler PROC
EXPORT SysTick_Handler [WEAK]
B .
ENDP
Default_Handler PROC
EXPORT WWDG_IRQHandler [WEAK]
EXPORT PVD_IRQHandler [WEAK]
EXPORT TAMPER_IRQHandler [WEAK]
EXPORT RTC_IRQHandler [WEAK]
EXPORT FLASH_IRQHandler [WEAK]
EXPORT RCC_IRQHandler [WEAK]
EXPORT EXTI0_IRQHandler [WEAK]
EXPORT EXTI1_IRQHandler [WEAK]
EXPORT EXTI2_IRQHandler [WEAK]
EXPORT EXTI3_IRQHandler [WEAK]
EXPORT EXTI4_IRQHandler [WEAK]
EXPORT DMA1_Channel1_IRQHandler [WEAK]
EXPORT DMA1_Channel2_IRQHandler [WEAK]
EXPORT DMA1_Channel3_IRQHandler [WEAK]
EXPORT DMA1_Channel4_IRQHandler [WEAK]
EXPORT DMA1_Channel5_IRQHandler [WEAK]
EXPORT DMA1_Channel6_IRQHandler [WEAK]
EXPORT DMA1_Channel7_IRQHandler [WEAK]
EXPORT ADC1_2_IRQHandler [WEAK]
EXPORT USB_HP_CAN1_TX_IRQHandler [WEAK]
EXPORT USB_LP_CAN1_RX0_IRQHandler [WEAK]
EXPORT CAN1_RX1_IRQHandler [WEAK]
EXPORT CAN1_SCE_IRQHandler [WEAK]
EXPORT EXTI9_5_IRQHandler [WEAK]
EXPORT TIM1_BRK_IRQHandler [WEAK]
EXPORT TIM1_UP_IRQHandler [WEAK]
EXPORT TIM1_TRG_COM_IRQHandler [WEAK]
EXPORT TIM1_CC_IRQHandler [WEAK]
EXPORT TIM2_IRQHandler [WEAK]
EXPORT TIM3_IRQHandler [WEAK]
EXPORT I2C1_EV_IRQHandler [WEAK]
EXPORT I2C1_ER_IRQHandler [WEAK]
EXPORT SPI1_IRQHandler [WEAK]
EXPORT USART1_IRQHandler [WEAK]
EXPORT USART2_IRQHandler [WEAK]
EXPORT EXTI15_10_IRQHandler [WEAK]
EXPORT RTCAlarm_IRQHandler [WEAK]
EXPORT USBWakeUp_IRQHandler [WEAK]
WWDG_IRQHandler
PVD_IRQHandler
TAMPER_IRQHandler
RTC_IRQHandler
FLASH_IRQHandler
RCC_IRQHandler
EXTI0_IRQHandler
EXTI1_IRQHandler
EXTI2_IRQHandler
EXTI3_IRQHandler
EXTI4_IRQHandler
DMA1_Channel1_IRQHandler
DMA1_Channel2_IRQHandler
DMA1_Channel3_IRQHandler
DMA1_Channel4_IRQHandler
DMA1_Channel5_IRQHandler
DMA1_Channel6_IRQHandler
DMA1_Channel7_IRQHandler
ADC1_2_IRQHandler
USB_HP_CAN1_TX_IRQHandler
USB_LP_CAN1_RX0_IRQHandler
CAN1_RX1_IRQHandler
CAN1_SCE_IRQHandler
EXTI9_5_IRQHandler
TIM1_BRK_IRQHandler
TIM1_UP_IRQHandler
TIM1_TRG_COM_IRQHandler
TIM1_CC_IRQHandler
TIM2_IRQHandler
TIM3_IRQHandler
I2C1_EV_IRQHandler
I2C1_ER_IRQHandler
SPI1_IRQHandler
USART1_IRQHandler
USART2_IRQHandler
EXTI15_10_IRQHandler
RTCAlarm_IRQHandler
USBWakeUp_IRQHandler
B .
ENDP
ALIGN
;*******************************************************************************
; User Stack and Heap initialization
;*******************************************************************************
IF :DEF:__MICROLIB
EXPORT __initial_sp
EXPORT __heap_base
EXPORT __heap_limit
ELSE
IMPORT __use_two_region_memory
EXPORT __user_initial_stackheap
__user_initial_stackheap
LDR R0, = Heap_Mem
LDR R1, =(Stack_Mem + Stack_Size)
LDR R2, = (Heap_Mem + Heap_Size)
LDR R3, = Stack_Mem
BX LR
ALIGN
ENDIF
END
;******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE*****
@@ -0,0 +1,304 @@
;******************** (C) COPYRIGHT 2011 STMicroelectronics ********************
;* File Name : startup_stm32f10x_ld_vl.s
;* Author : MCD Application Team
;* Version : V3.5.0
;* Date : 11-March-2011
;* Description : STM32F10x Low Density Value Line Devices vector table
;* for MDK-ARM toolchain.
;* This module performs:
;* - Set the initial SP
;* - Set the initial PC == Reset_Handler
;* - Set the vector table entries with the exceptions ISR address
;* - Configure the clock system
;* - Branches to __main in the C library (which eventually
;* calls main()).
;* After Reset the CortexM3 processor is in Thread mode,
;* priority is Privileged, and the Stack is set to Main.
;* <<< Use Configuration Wizard in Context Menu >>>
;*******************************************************************************
; THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
; WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
; AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
; INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
; CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
; INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
;*******************************************************************************
; Amount of memory (in bytes) allocated for Stack
; Tailor this value to your application needs
; <h> Stack Configuration
; <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>
Stack_Size EQU 0x00000400
AREA STACK, NOINIT, READWRITE, ALIGN=3
Stack_Mem SPACE Stack_Size
__initial_sp
; <h> Heap Configuration
; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>
Heap_Size EQU 0x00000200
AREA HEAP, NOINIT, READWRITE, ALIGN=3
__heap_base
Heap_Mem SPACE Heap_Size
__heap_limit
PRESERVE8
THUMB
; Vector Table Mapped to Address 0 at Reset
AREA RESET, DATA, READONLY
EXPORT __Vectors
EXPORT __Vectors_End
EXPORT __Vectors_Size
__Vectors DCD __initial_sp ; Top of Stack
DCD Reset_Handler ; Reset Handler
DCD NMI_Handler ; NMI Handler
DCD HardFault_Handler ; Hard Fault Handler
DCD MemManage_Handler ; MPU Fault Handler
DCD BusFault_Handler ; Bus Fault Handler
DCD UsageFault_Handler ; Usage Fault Handler
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD SVC_Handler ; SVCall Handler
DCD DebugMon_Handler ; Debug Monitor Handler
DCD 0 ; Reserved
DCD PendSV_Handler ; PendSV Handler
DCD SysTick_Handler ; SysTick Handler
; External Interrupts
DCD WWDG_IRQHandler ; Window Watchdog
DCD PVD_IRQHandler ; PVD through EXTI Line detect
DCD TAMPER_IRQHandler ; Tamper
DCD RTC_IRQHandler ; RTC
DCD FLASH_IRQHandler ; Flash
DCD RCC_IRQHandler ; RCC
DCD EXTI0_IRQHandler ; EXTI Line 0
DCD EXTI1_IRQHandler ; EXTI Line 1
DCD EXTI2_IRQHandler ; EXTI Line 2
DCD EXTI3_IRQHandler ; EXTI Line 3
DCD EXTI4_IRQHandler ; EXTI Line 4
DCD DMA1_Channel1_IRQHandler ; DMA1 Channel 1
DCD DMA1_Channel2_IRQHandler ; DMA1 Channel 2
DCD DMA1_Channel3_IRQHandler ; DMA1 Channel 3
DCD DMA1_Channel4_IRQHandler ; DMA1 Channel 4
DCD DMA1_Channel5_IRQHandler ; DMA1 Channel 5
DCD DMA1_Channel6_IRQHandler ; DMA1 Channel 6
DCD DMA1_Channel7_IRQHandler ; DMA1 Channel 7
DCD ADC1_IRQHandler ; ADC1
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD EXTI9_5_IRQHandler ; EXTI Line 9..5
DCD TIM1_BRK_TIM15_IRQHandler ; TIM1 Break and TIM15
DCD TIM1_UP_TIM16_IRQHandler ; TIM1 Update and TIM16
DCD TIM1_TRG_COM_TIM17_IRQHandler ; TIM1 Trigger and Commutation and TIM17
DCD TIM1_CC_IRQHandler ; TIM1 Capture Compare
DCD TIM2_IRQHandler ; TIM2
DCD TIM3_IRQHandler ; TIM3
DCD 0 ; Reserved
DCD I2C1_EV_IRQHandler ; I2C1 Event
DCD I2C1_ER_IRQHandler ; I2C1 Error
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD SPI1_IRQHandler ; SPI1
DCD 0 ; Reserved
DCD USART1_IRQHandler ; USART1
DCD USART2_IRQHandler ; USART2
DCD 0 ; Reserved
DCD EXTI15_10_IRQHandler ; EXTI Line 15..10
DCD RTCAlarm_IRQHandler ; RTC Alarm through EXTI Line
DCD CEC_IRQHandler ; HDMI-CEC
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD TIM6_DAC_IRQHandler ; TIM6 and DAC underrun
DCD TIM7_IRQHandler ; TIM7
__Vectors_End
__Vectors_Size EQU __Vectors_End - __Vectors
AREA |.text|, CODE, READONLY
; Reset handler
Reset_Handler PROC
EXPORT Reset_Handler [WEAK]
IMPORT __main
IMPORT SystemInit
LDR R0, =SystemInit
BLX R0
LDR R0, =__main
BX R0
ENDP
; Dummy Exception Handlers (infinite loops which can be modified)
NMI_Handler PROC
EXPORT NMI_Handler [WEAK]
B .
ENDP
HardFault_Handler\
PROC
EXPORT HardFault_Handler [WEAK]
B .
ENDP
MemManage_Handler\
PROC
EXPORT MemManage_Handler [WEAK]
B .
ENDP
BusFault_Handler\
PROC
EXPORT BusFault_Handler [WEAK]
B .
ENDP
UsageFault_Handler\
PROC
EXPORT UsageFault_Handler [WEAK]
B .
ENDP
SVC_Handler PROC
EXPORT SVC_Handler [WEAK]
B .
ENDP
DebugMon_Handler\
PROC
EXPORT DebugMon_Handler [WEAK]
B .
ENDP
PendSV_Handler PROC
EXPORT PendSV_Handler [WEAK]
B .
ENDP
SysTick_Handler PROC
EXPORT SysTick_Handler [WEAK]
B .
ENDP
Default_Handler PROC
EXPORT WWDG_IRQHandler [WEAK]
EXPORT PVD_IRQHandler [WEAK]
EXPORT TAMPER_IRQHandler [WEAK]
EXPORT RTC_IRQHandler [WEAK]
EXPORT FLASH_IRQHandler [WEAK]
EXPORT RCC_IRQHandler [WEAK]
EXPORT EXTI0_IRQHandler [WEAK]
EXPORT EXTI1_IRQHandler [WEAK]
EXPORT EXTI2_IRQHandler [WEAK]
EXPORT EXTI3_IRQHandler [WEAK]
EXPORT EXTI4_IRQHandler [WEAK]
EXPORT DMA1_Channel1_IRQHandler [WEAK]
EXPORT DMA1_Channel2_IRQHandler [WEAK]
EXPORT DMA1_Channel3_IRQHandler [WEAK]
EXPORT DMA1_Channel4_IRQHandler [WEAK]
EXPORT DMA1_Channel5_IRQHandler [WEAK]
EXPORT DMA1_Channel6_IRQHandler [WEAK]
EXPORT DMA1_Channel7_IRQHandler [WEAK]
EXPORT ADC1_IRQHandler [WEAK]
EXPORT EXTI9_5_IRQHandler [WEAK]
EXPORT TIM1_BRK_TIM15_IRQHandler [WEAK]
EXPORT TIM1_UP_TIM16_IRQHandler [WEAK]
EXPORT TIM1_TRG_COM_TIM17_IRQHandler [WEAK]
EXPORT TIM1_CC_IRQHandler [WEAK]
EXPORT TIM2_IRQHandler [WEAK]
EXPORT TIM3_IRQHandler [WEAK]
EXPORT I2C1_EV_IRQHandler [WEAK]
EXPORT I2C1_ER_IRQHandler [WEAK]
EXPORT SPI1_IRQHandler [WEAK]
EXPORT USART1_IRQHandler [WEAK]
EXPORT USART2_IRQHandler [WEAK]
EXPORT EXTI15_10_IRQHandler [WEAK]
EXPORT RTCAlarm_IRQHandler [WEAK]
EXPORT CEC_IRQHandler [WEAK]
EXPORT TIM6_DAC_IRQHandler [WEAK]
EXPORT TIM7_IRQHandler [WEAK]
WWDG_IRQHandler
PVD_IRQHandler
TAMPER_IRQHandler
RTC_IRQHandler
FLASH_IRQHandler
RCC_IRQHandler
EXTI0_IRQHandler
EXTI1_IRQHandler
EXTI2_IRQHandler
EXTI3_IRQHandler
EXTI4_IRQHandler
DMA1_Channel1_IRQHandler
DMA1_Channel2_IRQHandler
DMA1_Channel3_IRQHandler
DMA1_Channel4_IRQHandler
DMA1_Channel5_IRQHandler
DMA1_Channel6_IRQHandler
DMA1_Channel7_IRQHandler
ADC1_IRQHandler
EXTI9_5_IRQHandler
TIM1_BRK_TIM15_IRQHandler
TIM1_UP_TIM16_IRQHandler
TIM1_TRG_COM_TIM17_IRQHandler
TIM1_CC_IRQHandler
TIM2_IRQHandler
TIM3_IRQHandler
I2C1_EV_IRQHandler
I2C1_ER_IRQHandler
SPI1_IRQHandler
USART1_IRQHandler
USART2_IRQHandler
EXTI15_10_IRQHandler
RTCAlarm_IRQHandler
CEC_IRQHandler
TIM6_DAC_IRQHandler
TIM7_IRQHandler
B .
ENDP
ALIGN
;*******************************************************************************
; User Stack and Heap initialization
;*******************************************************************************
IF :DEF:__MICROLIB
EXPORT __initial_sp
EXPORT __heap_base
EXPORT __heap_limit
ELSE
IMPORT __use_two_region_memory
EXPORT __user_initial_stackheap
__user_initial_stackheap
LDR R0, = Heap_Mem
LDR R1, =(Stack_Mem + Stack_Size)
LDR R2, = (Heap_Mem + Heap_Size)
LDR R3, = Stack_Mem
BX LR
ALIGN
ENDIF
END
;******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE*****
@@ -0,0 +1,307 @@
;******************** (C) COPYRIGHT 2011 STMicroelectronics ********************
;* File Name : startup_stm32f10x_md.s
;* Author : MCD Application Team
;* Version : V3.5.0
;* Date : 11-March-2011
;* Description : STM32F10x Medium Density Devices vector table for MDK-ARM
;* toolchain.
;* This module performs:
;* - Set the initial SP
;* - Set the initial PC == Reset_Handler
;* - Set the vector table entries with the exceptions ISR address
;* - Configure the clock system
;* - Branches to __main in the C library (which eventually
;* calls main()).
;* After Reset the CortexM3 processor is in Thread mode,
;* priority is Privileged, and the Stack is set to Main.
;* <<< Use Configuration Wizard in Context Menu >>>
;*******************************************************************************
; THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
; WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
; AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
; INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
; CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
; INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
;*******************************************************************************
; Amount of memory (in bytes) allocated for Stack
; Tailor this value to your application needs
; <h> Stack Configuration
; <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>
Stack_Size EQU 0x00000400
AREA STACK, NOINIT, READWRITE, ALIGN=3
Stack_Mem SPACE Stack_Size
__initial_sp
; <h> Heap Configuration
; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>
Heap_Size EQU 0x00000200
AREA HEAP, NOINIT, READWRITE, ALIGN=3
__heap_base
Heap_Mem SPACE Heap_Size
__heap_limit
PRESERVE8
THUMB
; Vector Table Mapped to Address 0 at Reset
AREA RESET, DATA, READONLY
EXPORT __Vectors
EXPORT __Vectors_End
EXPORT __Vectors_Size
__Vectors DCD __initial_sp ; Top of Stack
DCD Reset_Handler ; Reset Handler
DCD NMI_Handler ; NMI Handler
DCD HardFault_Handler ; Hard Fault Handler
DCD MemManage_Handler ; MPU Fault Handler
DCD BusFault_Handler ; Bus Fault Handler
DCD UsageFault_Handler ; Usage Fault Handler
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD SVC_Handler ; SVCall Handler
DCD DebugMon_Handler ; Debug Monitor Handler
DCD 0 ; Reserved
DCD PendSV_Handler ; PendSV Handler
DCD SysTick_Handler ; SysTick Handler
; External Interrupts
DCD WWDG_IRQHandler ; Window Watchdog
DCD PVD_IRQHandler ; PVD through EXTI Line detect
DCD TAMPER_IRQHandler ; Tamper
DCD RTC_IRQHandler ; RTC
DCD FLASH_IRQHandler ; Flash
DCD RCC_IRQHandler ; RCC
DCD EXTI0_IRQHandler ; EXTI Line 0
DCD EXTI1_IRQHandler ; EXTI Line 1
DCD EXTI2_IRQHandler ; EXTI Line 2
DCD EXTI3_IRQHandler ; EXTI Line 3
DCD EXTI4_IRQHandler ; EXTI Line 4
DCD DMA1_Channel1_IRQHandler ; DMA1 Channel 1
DCD DMA1_Channel2_IRQHandler ; DMA1 Channel 2
DCD DMA1_Channel3_IRQHandler ; DMA1 Channel 3
DCD DMA1_Channel4_IRQHandler ; DMA1 Channel 4
DCD DMA1_Channel5_IRQHandler ; DMA1 Channel 5
DCD DMA1_Channel6_IRQHandler ; DMA1 Channel 6
DCD DMA1_Channel7_IRQHandler ; DMA1 Channel 7
DCD ADC1_2_IRQHandler ; ADC1_2
DCD USB_HP_CAN1_TX_IRQHandler ; USB High Priority or CAN1 TX
DCD USB_LP_CAN1_RX0_IRQHandler ; USB Low Priority or CAN1 RX0
DCD CAN1_RX1_IRQHandler ; CAN1 RX1
DCD CAN1_SCE_IRQHandler ; CAN1 SCE
DCD EXTI9_5_IRQHandler ; EXTI Line 9..5
DCD TIM1_BRK_IRQHandler ; TIM1 Break
DCD TIM1_UP_IRQHandler ; TIM1 Update
DCD TIM1_TRG_COM_IRQHandler ; TIM1 Trigger and Commutation
DCD TIM1_CC_IRQHandler ; TIM1 Capture Compare
DCD TIM2_IRQHandler ; TIM2
DCD TIM3_IRQHandler ; TIM3
DCD TIM4_IRQHandler ; TIM4
DCD I2C1_EV_IRQHandler ; I2C1 Event
DCD I2C1_ER_IRQHandler ; I2C1 Error
DCD I2C2_EV_IRQHandler ; I2C2 Event
DCD I2C2_ER_IRQHandler ; I2C2 Error
DCD SPI1_IRQHandler ; SPI1
DCD SPI2_IRQHandler ; SPI2
DCD USART1_IRQHandler ; USART1
DCD USART2_IRQHandler ; USART2
DCD USART3_IRQHandler ; USART3
DCD EXTI15_10_IRQHandler ; EXTI Line 15..10
DCD RTCAlarm_IRQHandler ; RTC Alarm through EXTI Line
DCD USBWakeUp_IRQHandler ; USB Wakeup from suspend
__Vectors_End
__Vectors_Size EQU __Vectors_End - __Vectors
AREA |.text|, CODE, READONLY
; Reset handler
Reset_Handler PROC
EXPORT Reset_Handler [WEAK]
IMPORT __main
IMPORT SystemInit
LDR R0, =SystemInit
BLX R0
LDR R0, =__main
BX R0
ENDP
; Dummy Exception Handlers (infinite loops which can be modified)
NMI_Handler PROC
EXPORT NMI_Handler [WEAK]
B .
ENDP
HardFault_Handler\
PROC
EXPORT HardFault_Handler [WEAK]
B .
ENDP
MemManage_Handler\
PROC
EXPORT MemManage_Handler [WEAK]
B .
ENDP
BusFault_Handler\
PROC
EXPORT BusFault_Handler [WEAK]
B .
ENDP
UsageFault_Handler\
PROC
EXPORT UsageFault_Handler [WEAK]
B .
ENDP
SVC_Handler PROC
EXPORT SVC_Handler [WEAK]
B .
ENDP
DebugMon_Handler\
PROC
EXPORT DebugMon_Handler [WEAK]
B .
ENDP
PendSV_Handler PROC
EXPORT PendSV_Handler [WEAK]
B .
ENDP
SysTick_Handler PROC
EXPORT SysTick_Handler [WEAK]
B .
ENDP
Default_Handler PROC
EXPORT WWDG_IRQHandler [WEAK]
EXPORT PVD_IRQHandler [WEAK]
EXPORT TAMPER_IRQHandler [WEAK]
EXPORT RTC_IRQHandler [WEAK]
EXPORT FLASH_IRQHandler [WEAK]
EXPORT RCC_IRQHandler [WEAK]
EXPORT EXTI0_IRQHandler [WEAK]
EXPORT EXTI1_IRQHandler [WEAK]
EXPORT EXTI2_IRQHandler [WEAK]
EXPORT EXTI3_IRQHandler [WEAK]
EXPORT EXTI4_IRQHandler [WEAK]
EXPORT DMA1_Channel1_IRQHandler [WEAK]
EXPORT DMA1_Channel2_IRQHandler [WEAK]
EXPORT DMA1_Channel3_IRQHandler [WEAK]
EXPORT DMA1_Channel4_IRQHandler [WEAK]
EXPORT DMA1_Channel5_IRQHandler [WEAK]
EXPORT DMA1_Channel6_IRQHandler [WEAK]
EXPORT DMA1_Channel7_IRQHandler [WEAK]
EXPORT ADC1_2_IRQHandler [WEAK]
EXPORT USB_HP_CAN1_TX_IRQHandler [WEAK]
EXPORT USB_LP_CAN1_RX0_IRQHandler [WEAK]
EXPORT CAN1_RX1_IRQHandler [WEAK]
EXPORT CAN1_SCE_IRQHandler [WEAK]
EXPORT EXTI9_5_IRQHandler [WEAK]
EXPORT TIM1_BRK_IRQHandler [WEAK]
EXPORT TIM1_UP_IRQHandler [WEAK]
EXPORT TIM1_TRG_COM_IRQHandler [WEAK]
EXPORT TIM1_CC_IRQHandler [WEAK]
EXPORT TIM2_IRQHandler [WEAK]
EXPORT TIM3_IRQHandler [WEAK]
EXPORT TIM4_IRQHandler [WEAK]
EXPORT I2C1_EV_IRQHandler [WEAK]
EXPORT I2C1_ER_IRQHandler [WEAK]
EXPORT I2C2_EV_IRQHandler [WEAK]
EXPORT I2C2_ER_IRQHandler [WEAK]
EXPORT SPI1_IRQHandler [WEAK]
EXPORT SPI2_IRQHandler [WEAK]
EXPORT USART1_IRQHandler [WEAK]
EXPORT USART2_IRQHandler [WEAK]
EXPORT USART3_IRQHandler [WEAK]
EXPORT EXTI15_10_IRQHandler [WEAK]
EXPORT RTCAlarm_IRQHandler [WEAK]
EXPORT USBWakeUp_IRQHandler [WEAK]
WWDG_IRQHandler
PVD_IRQHandler
TAMPER_IRQHandler
RTC_IRQHandler
FLASH_IRQHandler
RCC_IRQHandler
EXTI0_IRQHandler
EXTI1_IRQHandler
EXTI2_IRQHandler
EXTI3_IRQHandler
EXTI4_IRQHandler
DMA1_Channel1_IRQHandler
DMA1_Channel2_IRQHandler
DMA1_Channel3_IRQHandler
DMA1_Channel4_IRQHandler
DMA1_Channel5_IRQHandler
DMA1_Channel6_IRQHandler
DMA1_Channel7_IRQHandler
ADC1_2_IRQHandler
USB_HP_CAN1_TX_IRQHandler
USB_LP_CAN1_RX0_IRQHandler
CAN1_RX1_IRQHandler
CAN1_SCE_IRQHandler
EXTI9_5_IRQHandler
TIM1_BRK_IRQHandler
TIM1_UP_IRQHandler
TIM1_TRG_COM_IRQHandler
TIM1_CC_IRQHandler
TIM2_IRQHandler
TIM3_IRQHandler
TIM4_IRQHandler
I2C1_EV_IRQHandler
I2C1_ER_IRQHandler
I2C2_EV_IRQHandler
I2C2_ER_IRQHandler
SPI1_IRQHandler
SPI2_IRQHandler
USART1_IRQHandler
USART2_IRQHandler
USART3_IRQHandler
EXTI15_10_IRQHandler
RTCAlarm_IRQHandler
USBWakeUp_IRQHandler
B .
ENDP
ALIGN
;*******************************************************************************
; User Stack and Heap initialization
;*******************************************************************************
IF :DEF:__MICROLIB
EXPORT __initial_sp
EXPORT __heap_base
EXPORT __heap_limit
ELSE
IMPORT __use_two_region_memory
EXPORT __user_initial_stackheap
__user_initial_stackheap
LDR R0, = Heap_Mem
LDR R1, =(Stack_Mem + Stack_Size)
LDR R2, = (Heap_Mem + Heap_Size)
LDR R3, = Stack_Mem
BX LR
ALIGN
ENDIF
END
;******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE*****
@@ -0,0 +1,315 @@
;******************** (C) COPYRIGHT 2011 STMicroelectronics ********************
;* File Name : startup_stm32f10x_md_vl.s
;* Author : MCD Application Team
;* Version : V3.5.0
;* Date : 11-March-2011
;* Description : STM32F10x Medium Density Value Line Devices vector table
;* for MDK-ARM toolchain.
;* This module performs:
;* - Set the initial SP
;* - Set the initial PC == Reset_Handler
;* - Set the vector table entries with the exceptions ISR address
;* - Configure the clock system
;* - Branches to __main in the C library (which eventually
;* calls main()).
;* After Reset the CortexM3 processor is in Thread mode,
;* priority is Privileged, and the Stack is set to Main.
;* <<< Use Configuration Wizard in Context Menu >>>
;*******************************************************************************
; THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
; WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
; AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
; INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
; CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
; INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
;*******************************************************************************
; Amount of memory (in bytes) allocated for Stack
; Tailor this value to your application needs
; <h> Stack Configuration
; <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>
Stack_Size EQU 0x00000400
AREA STACK, NOINIT, READWRITE, ALIGN=3
Stack_Mem SPACE Stack_Size
__initial_sp
; <h> Heap Configuration
; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>
Heap_Size EQU 0x00000200
AREA HEAP, NOINIT, READWRITE, ALIGN=3
__heap_base
Heap_Mem SPACE Heap_Size
__heap_limit
PRESERVE8
THUMB
; Vector Table Mapped to Address 0 at Reset
AREA RESET, DATA, READONLY
EXPORT __Vectors
EXPORT __Vectors_End
EXPORT __Vectors_Size
__Vectors DCD __initial_sp ; Top of Stack
DCD Reset_Handler ; Reset Handler
DCD NMI_Handler ; NMI Handler
DCD HardFault_Handler ; Hard Fault Handler
DCD MemManage_Handler ; MPU Fault Handler
DCD BusFault_Handler ; Bus Fault Handler
DCD UsageFault_Handler ; Usage Fault Handler
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD SVC_Handler ; SVCall Handler
DCD DebugMon_Handler ; Debug Monitor Handler
DCD 0 ; Reserved
DCD PendSV_Handler ; PendSV Handler
DCD SysTick_Handler ; SysTick Handler
; External Interrupts
DCD WWDG_IRQHandler ; Window Watchdog
DCD PVD_IRQHandler ; PVD through EXTI Line detect
DCD TAMPER_IRQHandler ; Tamper
DCD RTC_IRQHandler ; RTC
DCD FLASH_IRQHandler ; Flash
DCD RCC_IRQHandler ; RCC
DCD EXTI0_IRQHandler ; EXTI Line 0
DCD EXTI1_IRQHandler ; EXTI Line 1
DCD EXTI2_IRQHandler ; EXTI Line 2
DCD EXTI3_IRQHandler ; EXTI Line 3
DCD EXTI4_IRQHandler ; EXTI Line 4
DCD DMA1_Channel1_IRQHandler ; DMA1 Channel 1
DCD DMA1_Channel2_IRQHandler ; DMA1 Channel 2
DCD DMA1_Channel3_IRQHandler ; DMA1 Channel 3
DCD DMA1_Channel4_IRQHandler ; DMA1 Channel 4
DCD DMA1_Channel5_IRQHandler ; DMA1 Channel 5
DCD DMA1_Channel6_IRQHandler ; DMA1 Channel 6
DCD DMA1_Channel7_IRQHandler ; DMA1 Channel 7
DCD ADC1_IRQHandler ; ADC1
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD EXTI9_5_IRQHandler ; EXTI Line 9..5
DCD TIM1_BRK_TIM15_IRQHandler ; TIM1 Break and TIM15
DCD TIM1_UP_TIM16_IRQHandler ; TIM1 Update and TIM16
DCD TIM1_TRG_COM_TIM17_IRQHandler ; TIM1 Trigger and Commutation and TIM17
DCD TIM1_CC_IRQHandler ; TIM1 Capture Compare
DCD TIM2_IRQHandler ; TIM2
DCD TIM3_IRQHandler ; TIM3
DCD TIM4_IRQHandler ; TIM4
DCD I2C1_EV_IRQHandler ; I2C1 Event
DCD I2C1_ER_IRQHandler ; I2C1 Error
DCD I2C2_EV_IRQHandler ; I2C2 Event
DCD I2C2_ER_IRQHandler ; I2C2 Error
DCD SPI1_IRQHandler ; SPI1
DCD SPI2_IRQHandler ; SPI2
DCD USART1_IRQHandler ; USART1
DCD USART2_IRQHandler ; USART2
DCD USART3_IRQHandler ; USART3
DCD EXTI15_10_IRQHandler ; EXTI Line 15..10
DCD RTCAlarm_IRQHandler ; RTC Alarm through EXTI Line
DCD CEC_IRQHandler ; HDMI-CEC
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD TIM6_DAC_IRQHandler ; TIM6 and DAC underrun
DCD TIM7_IRQHandler ; TIM7
__Vectors_End
__Vectors_Size EQU __Vectors_End - __Vectors
AREA |.text|, CODE, READONLY
; Reset handler
Reset_Handler PROC
EXPORT Reset_Handler [WEAK]
IMPORT __main
IMPORT SystemInit
LDR R0, =SystemInit
BLX R0
LDR R0, =__main
BX R0
ENDP
; Dummy Exception Handlers (infinite loops which can be modified)
NMI_Handler PROC
EXPORT NMI_Handler [WEAK]
B .
ENDP
HardFault_Handler\
PROC
EXPORT HardFault_Handler [WEAK]
B .
ENDP
MemManage_Handler\
PROC
EXPORT MemManage_Handler [WEAK]
B .
ENDP
BusFault_Handler\
PROC
EXPORT BusFault_Handler [WEAK]
B .
ENDP
UsageFault_Handler\
PROC
EXPORT UsageFault_Handler [WEAK]
B .
ENDP
SVC_Handler PROC
EXPORT SVC_Handler [WEAK]
B .
ENDP
DebugMon_Handler\
PROC
EXPORT DebugMon_Handler [WEAK]
B .
ENDP
PendSV_Handler PROC
EXPORT PendSV_Handler [WEAK]
B .
ENDP
SysTick_Handler PROC
EXPORT SysTick_Handler [WEAK]
B .
ENDP
Default_Handler PROC
EXPORT WWDG_IRQHandler [WEAK]
EXPORT PVD_IRQHandler [WEAK]
EXPORT TAMPER_IRQHandler [WEAK]
EXPORT RTC_IRQHandler [WEAK]
EXPORT FLASH_IRQHandler [WEAK]
EXPORT RCC_IRQHandler [WEAK]
EXPORT EXTI0_IRQHandler [WEAK]
EXPORT EXTI1_IRQHandler [WEAK]
EXPORT EXTI2_IRQHandler [WEAK]
EXPORT EXTI3_IRQHandler [WEAK]
EXPORT EXTI4_IRQHandler [WEAK]
EXPORT DMA1_Channel1_IRQHandler [WEAK]
EXPORT DMA1_Channel2_IRQHandler [WEAK]
EXPORT DMA1_Channel3_IRQHandler [WEAK]
EXPORT DMA1_Channel4_IRQHandler [WEAK]
EXPORT DMA1_Channel5_IRQHandler [WEAK]
EXPORT DMA1_Channel6_IRQHandler [WEAK]
EXPORT DMA1_Channel7_IRQHandler [WEAK]
EXPORT ADC1_IRQHandler [WEAK]
EXPORT EXTI9_5_IRQHandler [WEAK]
EXPORT TIM1_BRK_TIM15_IRQHandler [WEAK]
EXPORT TIM1_UP_TIM16_IRQHandler [WEAK]
EXPORT TIM1_TRG_COM_TIM17_IRQHandler [WEAK]
EXPORT TIM1_CC_IRQHandler [WEAK]
EXPORT TIM2_IRQHandler [WEAK]
EXPORT TIM3_IRQHandler [WEAK]
EXPORT TIM4_IRQHandler [WEAK]
EXPORT I2C1_EV_IRQHandler [WEAK]
EXPORT I2C1_ER_IRQHandler [WEAK]
EXPORT I2C2_EV_IRQHandler [WEAK]
EXPORT I2C2_ER_IRQHandler [WEAK]
EXPORT SPI1_IRQHandler [WEAK]
EXPORT SPI2_IRQHandler [WEAK]
EXPORT USART1_IRQHandler [WEAK]
EXPORT USART2_IRQHandler [WEAK]
EXPORT USART3_IRQHandler [WEAK]
EXPORT EXTI15_10_IRQHandler [WEAK]
EXPORT RTCAlarm_IRQHandler [WEAK]
EXPORT CEC_IRQHandler [WEAK]
EXPORT TIM6_DAC_IRQHandler [WEAK]
EXPORT TIM7_IRQHandler [WEAK]
WWDG_IRQHandler
PVD_IRQHandler
TAMPER_IRQHandler
RTC_IRQHandler
FLASH_IRQHandler
RCC_IRQHandler
EXTI0_IRQHandler
EXTI1_IRQHandler
EXTI2_IRQHandler
EXTI3_IRQHandler
EXTI4_IRQHandler
DMA1_Channel1_IRQHandler
DMA1_Channel2_IRQHandler
DMA1_Channel3_IRQHandler
DMA1_Channel4_IRQHandler
DMA1_Channel5_IRQHandler
DMA1_Channel6_IRQHandler
DMA1_Channel7_IRQHandler
ADC1_IRQHandler
EXTI9_5_IRQHandler
TIM1_BRK_TIM15_IRQHandler
TIM1_UP_TIM16_IRQHandler
TIM1_TRG_COM_TIM17_IRQHandler
TIM1_CC_IRQHandler
TIM2_IRQHandler
TIM3_IRQHandler
TIM4_IRQHandler
I2C1_EV_IRQHandler
I2C1_ER_IRQHandler
I2C2_EV_IRQHandler
I2C2_ER_IRQHandler
SPI1_IRQHandler
SPI2_IRQHandler
USART1_IRQHandler
USART2_IRQHandler
USART3_IRQHandler
EXTI15_10_IRQHandler
RTCAlarm_IRQHandler
CEC_IRQHandler
TIM6_DAC_IRQHandler
TIM7_IRQHandler
B .
ENDP
ALIGN
;*******************************************************************************
; User Stack and Heap initialization
;*******************************************************************************
IF :DEF:__MICROLIB
EXPORT __initial_sp
EXPORT __heap_base
EXPORT __heap_limit
ELSE
IMPORT __use_two_region_memory
EXPORT __user_initial_stackheap
__user_initial_stackheap
LDR R0, = Heap_Mem
LDR R1, =(Stack_Mem + Stack_Size)
LDR R2, = (Heap_Mem + Heap_Size)
LDR R3, = Stack_Mem
BX LR
ALIGN
ENDIF
END
;******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE*****
@@ -0,0 +1,358 @@
;******************** (C) COPYRIGHT 2011 STMicroelectronics ********************
;* File Name : startup_stm32f10x_xl.s
;* Author : MCD Application Team
;* Version : V3.5.0
;* Date : 11-March-2011
;* Description : STM32F10x XL-Density Devices vector table for MDK-ARM
;* toolchain.
;* This module performs:
;* - Set the initial SP
;* - Set the initial PC == Reset_Handler
;* - Set the vector table entries with the exceptions ISR address
;* - Configure the clock system and also configure the external
;* SRAM mounted on STM3210E-EVAL board to be used as data
;* memory (optional, to be enabled by user)
;* - Branches to __main in the C library (which eventually
;* calls main()).
;* After Reset the CortexM3 processor is in Thread mode,
;* priority is Privileged, and the Stack is set to Main.
;* <<< Use Configuration Wizard in Context Menu >>>
;*******************************************************************************
; THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
; WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
; AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
; INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
; CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
; INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
;*******************************************************************************
; Amount of memory (in bytes) allocated for Stack
; Tailor this value to your application needs
; <h> Stack Configuration
; <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>
Stack_Size EQU 0x00000400
AREA STACK, NOINIT, READWRITE, ALIGN=3
Stack_Mem SPACE Stack_Size
__initial_sp
; <h> Heap Configuration
; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>
Heap_Size EQU 0x00000200
AREA HEAP, NOINIT, READWRITE, ALIGN=3
__heap_base
Heap_Mem SPACE Heap_Size
__heap_limit
PRESERVE8
THUMB
; Vector Table Mapped to Address 0 at Reset
AREA RESET, DATA, READONLY
EXPORT __Vectors
EXPORT __Vectors_End
EXPORT __Vectors_Size
__Vectors DCD __initial_sp ; Top of Stack
DCD Reset_Handler ; Reset Handler
DCD NMI_Handler ; NMI Handler
DCD HardFault_Handler ; Hard Fault Handler
DCD MemManage_Handler ; MPU Fault Handler
DCD BusFault_Handler ; Bus Fault Handler
DCD UsageFault_Handler ; Usage Fault Handler
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD SVC_Handler ; SVCall Handler
DCD DebugMon_Handler ; Debug Monitor Handler
DCD 0 ; Reserved
DCD PendSV_Handler ; PendSV Handler
DCD SysTick_Handler ; SysTick Handler
; External Interrupts
DCD WWDG_IRQHandler ; Window Watchdog
DCD PVD_IRQHandler ; PVD through EXTI Line detect
DCD TAMPER_IRQHandler ; Tamper
DCD RTC_IRQHandler ; RTC
DCD FLASH_IRQHandler ; Flash
DCD RCC_IRQHandler ; RCC
DCD EXTI0_IRQHandler ; EXTI Line 0
DCD EXTI1_IRQHandler ; EXTI Line 1
DCD EXTI2_IRQHandler ; EXTI Line 2
DCD EXTI3_IRQHandler ; EXTI Line 3
DCD EXTI4_IRQHandler ; EXTI Line 4
DCD DMA1_Channel1_IRQHandler ; DMA1 Channel 1
DCD DMA1_Channel2_IRQHandler ; DMA1 Channel 2
DCD DMA1_Channel3_IRQHandler ; DMA1 Channel 3
DCD DMA1_Channel4_IRQHandler ; DMA1 Channel 4
DCD DMA1_Channel5_IRQHandler ; DMA1 Channel 5
DCD DMA1_Channel6_IRQHandler ; DMA1 Channel 6
DCD DMA1_Channel7_IRQHandler ; DMA1 Channel 7
DCD ADC1_2_IRQHandler ; ADC1 & ADC2
DCD USB_HP_CAN1_TX_IRQHandler ; USB High Priority or CAN1 TX
DCD USB_LP_CAN1_RX0_IRQHandler ; USB Low Priority or CAN1 RX0
DCD CAN1_RX1_IRQHandler ; CAN1 RX1
DCD CAN1_SCE_IRQHandler ; CAN1 SCE
DCD EXTI9_5_IRQHandler ; EXTI Line 9..5
DCD TIM1_BRK_TIM9_IRQHandler ; TIM1 Break and TIM9
DCD TIM1_UP_TIM10_IRQHandler ; TIM1 Update and TIM10
DCD TIM1_TRG_COM_TIM11_IRQHandler ; TIM1 Trigger and Commutation and TIM11
DCD TIM1_CC_IRQHandler ; TIM1 Capture Compare
DCD TIM2_IRQHandler ; TIM2
DCD TIM3_IRQHandler ; TIM3
DCD TIM4_IRQHandler ; TIM4
DCD I2C1_EV_IRQHandler ; I2C1 Event
DCD I2C1_ER_IRQHandler ; I2C1 Error
DCD I2C2_EV_IRQHandler ; I2C2 Event
DCD I2C2_ER_IRQHandler ; I2C2 Error
DCD SPI1_IRQHandler ; SPI1
DCD SPI2_IRQHandler ; SPI2
DCD USART1_IRQHandler ; USART1
DCD USART2_IRQHandler ; USART2
DCD USART3_IRQHandler ; USART3
DCD EXTI15_10_IRQHandler ; EXTI Line 15..10
DCD RTCAlarm_IRQHandler ; RTC Alarm through EXTI Line
DCD USBWakeUp_IRQHandler ; USB Wakeup from suspend
DCD TIM8_BRK_TIM12_IRQHandler ; TIM8 Break and TIM12
DCD TIM8_UP_TIM13_IRQHandler ; TIM8 Update and TIM13
DCD TIM8_TRG_COM_TIM14_IRQHandler ; TIM8 Trigger and Commutation and TIM14
DCD TIM8_CC_IRQHandler ; TIM8 Capture Compare
DCD ADC3_IRQHandler ; ADC3
DCD FSMC_IRQHandler ; FSMC
DCD SDIO_IRQHandler ; SDIO
DCD TIM5_IRQHandler ; TIM5
DCD SPI3_IRQHandler ; SPI3
DCD UART4_IRQHandler ; UART4
DCD UART5_IRQHandler ; UART5
DCD TIM6_IRQHandler ; TIM6
DCD TIM7_IRQHandler ; TIM7
DCD DMA2_Channel1_IRQHandler ; DMA2 Channel1
DCD DMA2_Channel2_IRQHandler ; DMA2 Channel2
DCD DMA2_Channel3_IRQHandler ; DMA2 Channel3
DCD DMA2_Channel4_5_IRQHandler ; DMA2 Channel4 & Channel5
__Vectors_End
__Vectors_Size EQU __Vectors_End - __Vectors
AREA |.text|, CODE, READONLY
; Reset handler
Reset_Handler PROC
EXPORT Reset_Handler [WEAK]
IMPORT __main
IMPORT SystemInit
LDR R0, =SystemInit
BLX R0
LDR R0, =__main
BX R0
ENDP
; Dummy Exception Handlers (infinite loops which can be modified)
NMI_Handler PROC
EXPORT NMI_Handler [WEAK]
B .
ENDP
HardFault_Handler\
PROC
EXPORT HardFault_Handler [WEAK]
B .
ENDP
MemManage_Handler\
PROC
EXPORT MemManage_Handler [WEAK]
B .
ENDP
BusFault_Handler\
PROC
EXPORT BusFault_Handler [WEAK]
B .
ENDP
UsageFault_Handler\
PROC
EXPORT UsageFault_Handler [WEAK]
B .
ENDP
SVC_Handler PROC
EXPORT SVC_Handler [WEAK]
B .
ENDP
DebugMon_Handler\
PROC
EXPORT DebugMon_Handler [WEAK]
B .
ENDP
PendSV_Handler PROC
EXPORT PendSV_Handler [WEAK]
B .
ENDP
SysTick_Handler PROC
EXPORT SysTick_Handler [WEAK]
B .
ENDP
Default_Handler PROC
EXPORT WWDG_IRQHandler [WEAK]
EXPORT PVD_IRQHandler [WEAK]
EXPORT TAMPER_IRQHandler [WEAK]
EXPORT RTC_IRQHandler [WEAK]
EXPORT FLASH_IRQHandler [WEAK]
EXPORT RCC_IRQHandler [WEAK]
EXPORT EXTI0_IRQHandler [WEAK]
EXPORT EXTI1_IRQHandler [WEAK]
EXPORT EXTI2_IRQHandler [WEAK]
EXPORT EXTI3_IRQHandler [WEAK]
EXPORT EXTI4_IRQHandler [WEAK]
EXPORT DMA1_Channel1_IRQHandler [WEAK]
EXPORT DMA1_Channel2_IRQHandler [WEAK]
EXPORT DMA1_Channel3_IRQHandler [WEAK]
EXPORT DMA1_Channel4_IRQHandler [WEAK]
EXPORT DMA1_Channel5_IRQHandler [WEAK]
EXPORT DMA1_Channel6_IRQHandler [WEAK]
EXPORT DMA1_Channel7_IRQHandler [WEAK]
EXPORT ADC1_2_IRQHandler [WEAK]
EXPORT USB_HP_CAN1_TX_IRQHandler [WEAK]
EXPORT USB_LP_CAN1_RX0_IRQHandler [WEAK]
EXPORT CAN1_RX1_IRQHandler [WEAK]
EXPORT CAN1_SCE_IRQHandler [WEAK]
EXPORT EXTI9_5_IRQHandler [WEAK]
EXPORT TIM1_BRK_TIM9_IRQHandler [WEAK]
EXPORT TIM1_UP_TIM10_IRQHandler [WEAK]
EXPORT TIM1_TRG_COM_TIM11_IRQHandler [WEAK]
EXPORT TIM1_CC_IRQHandler [WEAK]
EXPORT TIM2_IRQHandler [WEAK]
EXPORT TIM3_IRQHandler [WEAK]
EXPORT TIM4_IRQHandler [WEAK]
EXPORT I2C1_EV_IRQHandler [WEAK]
EXPORT I2C1_ER_IRQHandler [WEAK]
EXPORT I2C2_EV_IRQHandler [WEAK]
EXPORT I2C2_ER_IRQHandler [WEAK]
EXPORT SPI1_IRQHandler [WEAK]
EXPORT SPI2_IRQHandler [WEAK]
EXPORT USART1_IRQHandler [WEAK]
EXPORT USART2_IRQHandler [WEAK]
EXPORT USART3_IRQHandler [WEAK]
EXPORT EXTI15_10_IRQHandler [WEAK]
EXPORT RTCAlarm_IRQHandler [WEAK]
EXPORT USBWakeUp_IRQHandler [WEAK]
EXPORT TIM8_BRK_TIM12_IRQHandler [WEAK]
EXPORT TIM8_UP_TIM13_IRQHandler [WEAK]
EXPORT TIM8_TRG_COM_TIM14_IRQHandler [WEAK]
EXPORT TIM8_CC_IRQHandler [WEAK]
EXPORT ADC3_IRQHandler [WEAK]
EXPORT FSMC_IRQHandler [WEAK]
EXPORT SDIO_IRQHandler [WEAK]
EXPORT TIM5_IRQHandler [WEAK]
EXPORT SPI3_IRQHandler [WEAK]
EXPORT UART4_IRQHandler [WEAK]
EXPORT UART5_IRQHandler [WEAK]
EXPORT TIM6_IRQHandler [WEAK]
EXPORT TIM7_IRQHandler [WEAK]
EXPORT DMA2_Channel1_IRQHandler [WEAK]
EXPORT DMA2_Channel2_IRQHandler [WEAK]
EXPORT DMA2_Channel3_IRQHandler [WEAK]
EXPORT DMA2_Channel4_5_IRQHandler [WEAK]
WWDG_IRQHandler
PVD_IRQHandler
TAMPER_IRQHandler
RTC_IRQHandler
FLASH_IRQHandler
RCC_IRQHandler
EXTI0_IRQHandler
EXTI1_IRQHandler
EXTI2_IRQHandler
EXTI3_IRQHandler
EXTI4_IRQHandler
DMA1_Channel1_IRQHandler
DMA1_Channel2_IRQHandler
DMA1_Channel3_IRQHandler
DMA1_Channel4_IRQHandler
DMA1_Channel5_IRQHandler
DMA1_Channel6_IRQHandler
DMA1_Channel7_IRQHandler
ADC1_2_IRQHandler
USB_HP_CAN1_TX_IRQHandler
USB_LP_CAN1_RX0_IRQHandler
CAN1_RX1_IRQHandler
CAN1_SCE_IRQHandler
EXTI9_5_IRQHandler
TIM1_BRK_TIM9_IRQHandler
TIM1_UP_TIM10_IRQHandler
TIM1_TRG_COM_TIM11_IRQHandler
TIM1_CC_IRQHandler
TIM2_IRQHandler
TIM3_IRQHandler
TIM4_IRQHandler
I2C1_EV_IRQHandler
I2C1_ER_IRQHandler
I2C2_EV_IRQHandler
I2C2_ER_IRQHandler
SPI1_IRQHandler
SPI2_IRQHandler
USART1_IRQHandler
USART2_IRQHandler
USART3_IRQHandler
EXTI15_10_IRQHandler
RTCAlarm_IRQHandler
USBWakeUp_IRQHandler
TIM8_BRK_TIM12_IRQHandler
TIM8_UP_TIM13_IRQHandler
TIM8_TRG_COM_TIM14_IRQHandler
TIM8_CC_IRQHandler
ADC3_IRQHandler
FSMC_IRQHandler
SDIO_IRQHandler
TIM5_IRQHandler
SPI3_IRQHandler
UART4_IRQHandler
UART5_IRQHandler
TIM6_IRQHandler
TIM7_IRQHandler
DMA2_Channel1_IRQHandler
DMA2_Channel2_IRQHandler
DMA2_Channel3_IRQHandler
DMA2_Channel4_5_IRQHandler
B .
ENDP
ALIGN
;*******************************************************************************
; User Stack and Heap initialization
;*******************************************************************************
IF :DEF:__MICROLIB
EXPORT __initial_sp
EXPORT __heap_base
EXPORT __heap_limit
ELSE
IMPORT __use_two_region_memory
EXPORT __user_initial_stackheap
__user_initial_stackheap
LDR R0, = Heap_Mem
LDR R1, =(Stack_Mem + Stack_Size)
LDR R2, = (Heap_Mem + Heap_Size)
LDR R3, = Stack_Mem
BX LR
ALIGN
ENDIF
END
;******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE*****
+784
View File
@@ -0,0 +1,784 @@
/**************************************************************************//**
* @file core_cm3.c
* @brief CMSIS Cortex-M3 Core Peripheral Access Layer Source File
* @version V1.30
* @date 30. October 2009
*
* @note
* Copyright (C) 2009 ARM Limited. All rights reserved.
*
* @par
* ARM Limited (ARM) is supplying this software for use with Cortex-M
* processor based microcontrollers. This file can be freely distributed
* within development tools that are supporting such ARM based processors.
*
* @par
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
* CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*
******************************************************************************/
#include <stdint.h>
/* define compiler specific symbols */
#if defined ( __CC_ARM )
#define __ASM __asm /*!< asm keyword for ARM Compiler */
#define __INLINE __inline /*!< inline keyword for ARM Compiler */
#elif defined ( __ICCARM__ )
#define __ASM __asm /*!< asm keyword for IAR Compiler */
#define __INLINE inline /*!< inline keyword for IAR Compiler. Only avaiable in High optimization mode! */
#elif defined ( __GNUC__ )
#define __ASM __asm /*!< asm keyword for GNU Compiler */
#define __INLINE inline /*!< inline keyword for GNU Compiler */
#elif defined ( __TASKING__ )
#define __ASM __asm /*!< asm keyword for TASKING Compiler */
#define __INLINE inline /*!< inline keyword for TASKING Compiler */
#endif
/* ################### Compiler specific Intrinsics ########################### */
#if defined ( __CC_ARM ) /*------------------RealView Compiler -----------------*/
/* ARM armcc specific functions */
/**
* @brief Return the Process Stack Pointer
*
* @return ProcessStackPointer
*
* Return the actual process stack pointer
*/
__ASM uint32_t __get_PSP(void)
{
mrs r0, psp
bx lr
}
/**
* @brief Set the Process Stack Pointer
*
* @param topOfProcStack Process Stack Pointer
*
* Assign the value ProcessStackPointer to the MSP
* (process stack pointer) Cortex processor register
*/
__ASM void __set_PSP(uint32_t topOfProcStack)
{
msr psp, r0
bx lr
}
/**
* @brief Return the Main Stack Pointer
*
* @return Main Stack Pointer
*
* Return the current value of the MSP (main stack pointer)
* Cortex processor register
*/
__ASM uint32_t __get_MSP(void)
{
mrs r0, msp
bx lr
}
/**
* @brief Set the Main Stack Pointer
*
* @param topOfMainStack Main Stack Pointer
*
* Assign the value mainStackPointer to the MSP
* (main stack pointer) Cortex processor register
*/
__ASM void __set_MSP(uint32_t mainStackPointer)
{
msr msp, r0
bx lr
}
/**
* @brief Reverse byte order in unsigned short value
*
* @param value value to reverse
* @return reversed value
*
* Reverse byte order in unsigned short value
*/
__ASM uint32_t __REV16(uint16_t value)
{
rev16 r0, r0
bx lr
}
/**
* @brief Reverse byte order in signed short value with sign extension to integer
*
* @param value value to reverse
* @return reversed value
*
* Reverse byte order in signed short value with sign extension to integer
*/
__ASM int32_t __REVSH(int16_t value)
{
revsh r0, r0
bx lr
}
#if (__ARMCC_VERSION < 400000)
/**
* @brief Remove the exclusive lock created by ldrex
*
* Removes the exclusive lock which is created by ldrex.
*/
__ASM void __CLREX(void)
{
clrex
}
/**
* @brief Return the Base Priority value
*
* @return BasePriority
*
* Return the content of the base priority register
*/
__ASM uint32_t __get_BASEPRI(void)
{
mrs r0, basepri
bx lr
}
/**
* @brief Set the Base Priority value
*
* @param basePri BasePriority
*
* Set the base priority register
*/
__ASM void __set_BASEPRI(uint32_t basePri)
{
msr basepri, r0
bx lr
}
/**
* @brief Return the Priority Mask value
*
* @return PriMask
*
* Return state of the priority mask bit from the priority mask register
*/
__ASM uint32_t __get_PRIMASK(void)
{
mrs r0, primask
bx lr
}
/**
* @brief Set the Priority Mask value
*
* @param priMask PriMask
*
* Set the priority mask bit in the priority mask register
*/
__ASM void __set_PRIMASK(uint32_t priMask)
{
msr primask, r0
bx lr
}
/**
* @brief Return the Fault Mask value
*
* @return FaultMask
*
* Return the content of the fault mask register
*/
__ASM uint32_t __get_FAULTMASK(void)
{
mrs r0, faultmask
bx lr
}
/**
* @brief Set the Fault Mask value
*
* @param faultMask faultMask value
*
* Set the fault mask register
*/
__ASM void __set_FAULTMASK(uint32_t faultMask)
{
msr faultmask, r0
bx lr
}
/**
* @brief Return the Control Register value
*
* @return Control value
*
* Return the content of the control register
*/
__ASM uint32_t __get_CONTROL(void)
{
mrs r0, control
bx lr
}
/**
* @brief Set the Control Register value
*
* @param control Control value
*
* Set the control register
*/
__ASM void __set_CONTROL(uint32_t control)
{
msr control, r0
bx lr
}
#endif /* __ARMCC_VERSION */
#elif (defined (__ICCARM__)) /*------------------ ICC Compiler -------------------*/
/* IAR iccarm specific functions */
#pragma diag_suppress=Pe940
/**
* @brief Return the Process Stack Pointer
*
* @return ProcessStackPointer
*
* Return the actual process stack pointer
*/
uint32_t __get_PSP(void)
{
__ASM("mrs r0, psp");
__ASM("bx lr");
}
/**
* @brief Set the Process Stack Pointer
*
* @param topOfProcStack Process Stack Pointer
*
* Assign the value ProcessStackPointer to the MSP
* (process stack pointer) Cortex processor register
*/
void __set_PSP(uint32_t topOfProcStack)
{
__ASM("msr psp, r0");
__ASM("bx lr");
}
/**
* @brief Return the Main Stack Pointer
*
* @return Main Stack Pointer
*
* Return the current value of the MSP (main stack pointer)
* Cortex processor register
*/
uint32_t __get_MSP(void)
{
__ASM("mrs r0, msp");
__ASM("bx lr");
}
/**
* @brief Set the Main Stack Pointer
*
* @param topOfMainStack Main Stack Pointer
*
* Assign the value mainStackPointer to the MSP
* (main stack pointer) Cortex processor register
*/
void __set_MSP(uint32_t topOfMainStack)
{
__ASM("msr msp, r0");
__ASM("bx lr");
}
/**
* @brief Reverse byte order in unsigned short value
*
* @param value value to reverse
* @return reversed value
*
* Reverse byte order in unsigned short value
*/
uint32_t __REV16(uint16_t value)
{
__ASM("rev16 r0, r0");
__ASM("bx lr");
}
/**
* @brief Reverse bit order of value
*
* @param value value to reverse
* @return reversed value
*
* Reverse bit order of value
*/
uint32_t __RBIT(uint32_t value)
{
__ASM("rbit r0, r0");
__ASM("bx lr");
}
/**
* @brief LDR Exclusive (8 bit)
*
* @param *addr address pointer
* @return value of (*address)
*
* Exclusive LDR command for 8 bit values)
*/
uint8_t __LDREXB(uint8_t *addr)
{
__ASM("ldrexb r0, [r0]");
__ASM("bx lr");
}
/**
* @brief LDR Exclusive (16 bit)
*
* @param *addr address pointer
* @return value of (*address)
*
* Exclusive LDR command for 16 bit values
*/
uint16_t __LDREXH(uint16_t *addr)
{
__ASM("ldrexh r0, [r0]");
__ASM("bx lr");
}
/**
* @brief LDR Exclusive (32 bit)
*
* @param *addr address pointer
* @return value of (*address)
*
* Exclusive LDR command for 32 bit values
*/
uint32_t __LDREXW(uint32_t *addr)
{
__ASM("ldrex r0, [r0]");
__ASM("bx lr");
}
/**
* @brief STR Exclusive (8 bit)
*
* @param value value to store
* @param *addr address pointer
* @return successful / failed
*
* Exclusive STR command for 8 bit values
*/
uint32_t __STREXB(uint8_t value, uint8_t *addr)
{
__ASM("strexb r0, r0, [r1]");
__ASM("bx lr");
}
/**
* @brief STR Exclusive (16 bit)
*
* @param value value to store
* @param *addr address pointer
* @return successful / failed
*
* Exclusive STR command for 16 bit values
*/
uint32_t __STREXH(uint16_t value, uint16_t *addr)
{
__ASM("strexh r0, r0, [r1]");
__ASM("bx lr");
}
/**
* @brief STR Exclusive (32 bit)
*
* @param value value to store
* @param *addr address pointer
* @return successful / failed
*
* Exclusive STR command for 32 bit values
*/
uint32_t __STREXW(uint32_t value, uint32_t *addr)
{
__ASM("strex r0, r0, [r1]");
__ASM("bx lr");
}
#pragma diag_default=Pe940
#elif (defined (__GNUC__)) /*------------------ GNU Compiler ---------------------*/
/* GNU gcc specific functions */
/**
* @brief Return the Process Stack Pointer
*
* @return ProcessStackPointer
*
* Return the actual process stack pointer
*/
uint32_t __get_PSP(void) __attribute__( ( naked ) );
uint32_t __get_PSP(void)
{
uint32_t result=0;
__ASM volatile ("MRS %0, psp\n\t"
"MOV r0, %0 \n\t"
"BX lr \n\t" : "=r" (result) );
return(result);
}
/**
* @brief Set the Process Stack Pointer
*
* @param topOfProcStack Process Stack Pointer
*
* Assign the value ProcessStackPointer to the MSP
* (process stack pointer) Cortex processor register
*/
void __set_PSP(uint32_t topOfProcStack) __attribute__( ( naked ) );
void __set_PSP(uint32_t topOfProcStack)
{
__ASM volatile ("MSR psp, %0\n\t"
"BX lr \n\t" : : "r" (topOfProcStack) );
}
/**
* @brief Return the Main Stack Pointer
*
* @return Main Stack Pointer
*
* Return the current value of the MSP (main stack pointer)
* Cortex processor register
*/
uint32_t __get_MSP(void) __attribute__( ( naked ) );
uint32_t __get_MSP(void)
{
uint32_t result=0;
__ASM volatile ("MRS %0, msp\n\t"
"MOV r0, %0 \n\t"
"BX lr \n\t" : "=r" (result) );
return(result);
}
/**
* @brief Set the Main Stack Pointer
*
* @param topOfMainStack Main Stack Pointer
*
* Assign the value mainStackPointer to the MSP
* (main stack pointer) Cortex processor register
*/
void __set_MSP(uint32_t topOfMainStack) __attribute__( ( naked ) );
void __set_MSP(uint32_t topOfMainStack)
{
__ASM volatile ("MSR msp, %0\n\t"
"BX lr \n\t" : : "r" (topOfMainStack) );
}
/**
* @brief Return the Base Priority value
*
* @return BasePriority
*
* Return the content of the base priority register
*/
uint32_t __get_BASEPRI(void)
{
uint32_t result=0;
__ASM volatile ("MRS %0, basepri_max" : "=r" (result) );
return(result);
}
/**
* @brief Set the Base Priority value
*
* @param basePri BasePriority
*
* Set the base priority register
*/
void __set_BASEPRI(uint32_t value)
{
__ASM volatile ("MSR basepri, %0" : : "r" (value) );
}
/**
* @brief Return the Priority Mask value
*
* @return PriMask
*
* Return state of the priority mask bit from the priority mask register
*/
uint32_t __get_PRIMASK(void)
{
uint32_t result=0;
__ASM volatile ("MRS %0, primask" : "=r" (result) );
return(result);
}
/**
* @brief Set the Priority Mask value
*
* @param priMask PriMask
*
* Set the priority mask bit in the priority mask register
*/
void __set_PRIMASK(uint32_t priMask)
{
__ASM volatile ("MSR primask, %0" : : "r" (priMask) );
}
/**
* @brief Return the Fault Mask value
*
* @return FaultMask
*
* Return the content of the fault mask register
*/
uint32_t __get_FAULTMASK(void)
{
uint32_t result=0;
__ASM volatile ("MRS %0, faultmask" : "=r" (result) );
return(result);
}
/**
* @brief Set the Fault Mask value
*
* @param faultMask faultMask value
*
* Set the fault mask register
*/
void __set_FAULTMASK(uint32_t faultMask)
{
__ASM volatile ("MSR faultmask, %0" : : "r" (faultMask) );
}
/**
* @brief Return the Control Register value
*
* @return Control value
*
* Return the content of the control register
*/
uint32_t __get_CONTROL(void)
{
uint32_t result=0;
__ASM volatile ("MRS %0, control" : "=r" (result) );
return(result);
}
/**
* @brief Set the Control Register value
*
* @param control Control value
*
* Set the control register
*/
void __set_CONTROL(uint32_t control)
{
__ASM volatile ("MSR control, %0" : : "r" (control) );
}
/**
* @brief Reverse byte order in integer value
*
* @param value value to reverse
* @return reversed value
*
* Reverse byte order in integer value
*/
uint32_t __REV(uint32_t value)
{
uint32_t result=0;
__ASM volatile ("rev %0, %1" : "=r" (result) : "r" (value) );
return(result);
}
/**
* @brief Reverse byte order in unsigned short value
*
* @param value value to reverse
* @return reversed value
*
* Reverse byte order in unsigned short value
*/
uint32_t __REV16(uint16_t value)
{
uint32_t result=0;
__ASM volatile ("rev16 %0, %1" : "=r" (result) : "r" (value) );
return(result);
}
/**
* @brief Reverse byte order in signed short value with sign extension to integer
*
* @param value value to reverse
* @return reversed value
*
* Reverse byte order in signed short value with sign extension to integer
*/
int32_t __REVSH(int16_t value)
{
uint32_t result=0;
__ASM volatile ("revsh %0, %1" : "=r" (result) : "r" (value) );
return(result);
}
/**
* @brief Reverse bit order of value
*
* @param value value to reverse
* @return reversed value
*
* Reverse bit order of value
*/
uint32_t __RBIT(uint32_t value)
{
uint32_t result=0;
__ASM volatile ("rbit %0, %1" : "=r" (result) : "r" (value) );
return(result);
}
/**
* @brief LDR Exclusive (8 bit)
*
* @param *addr address pointer
* @return value of (*address)
*
* Exclusive LDR command for 8 bit value
*/
uint8_t __LDREXB(uint8_t *addr)
{
uint8_t result=0;
__ASM volatile ("ldrexb %0, [%1]" : "=r" (result) : "r" (addr) );
return(result);
}
/**
* @brief LDR Exclusive (16 bit)
*
* @param *addr address pointer
* @return value of (*address)
*
* Exclusive LDR command for 16 bit values
*/
uint16_t __LDREXH(uint16_t *addr)
{
uint16_t result=0;
__ASM volatile ("ldrexh %0, [%1]" : "=r" (result) : "r" (addr) );
return(result);
}
/**
* @brief LDR Exclusive (32 bit)
*
* @param *addr address pointer
* @return value of (*address)
*
* Exclusive LDR command for 32 bit values
*/
uint32_t __LDREXW(uint32_t *addr)
{
uint32_t result=0;
__ASM volatile ("ldrex %0, [%1]" : "=r" (result) : "r" (addr) );
return(result);
}
/**
* @brief STR Exclusive (8 bit)
*
* @param value value to store
* @param *addr address pointer
* @return successful / failed
*
* Exclusive STR command for 8 bit values
*/
uint32_t __STREXB(uint8_t value, uint8_t *addr)
{
uint32_t result=0;
__ASM volatile ("strexb %0, %2, [%1]" : "=r" (result) : "r" (addr), "r" (value) );
return(result);
}
/**
* @brief STR Exclusive (16 bit)
*
* @param value value to store
* @param *addr address pointer
* @return successful / failed
*
* Exclusive STR command for 16 bit values
*/
uint32_t __STREXH(uint16_t value, uint16_t *addr)
{
uint32_t result=0;
__ASM volatile ("strexh %0, %2, [%1]" : "=r" (result) : "r" (addr), "r" (value) );
return(result);
}
/**
* @brief STR Exclusive (32 bit)
*
* @param value value to store
* @param *addr address pointer
* @return successful / failed
*
* Exclusive STR command for 32 bit values
*/
uint32_t __STREXW(uint32_t value, uint32_t *addr)
{
uint32_t result=0;
__ASM volatile ("strex %0, %2, [%1]" : "=r" (result) : "r" (addr), "r" (value) );
return(result);
}
#elif (defined (__TASKING__)) /*------------------ TASKING Compiler ---------------------*/
/* TASKING carm specific functions */
/*
* The CMSIS functions have been implemented as intrinsics in the compiler.
* Please use "carm -?i" to get an up to date list of all instrinsics,
* Including the CMSIS ones.
*/
#endif
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,98 @@
/**
******************************************************************************
* @file system_stm32f10x.h
* @author MCD Application Team
* @version V3.5.0
* @date 11-March-2011
* @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Header File.
******************************************************************************
* @attention
*
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*
* <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
******************************************************************************
*/
/** @addtogroup CMSIS
* @{
*/
/** @addtogroup stm32f10x_system
* @{
*/
/**
* @brief Define to prevent recursive inclusion
*/
#ifndef __SYSTEM_STM32F10X_H
#define __SYSTEM_STM32F10X_H
#ifdef __cplusplus
extern "C" {
#endif
/** @addtogroup STM32F10x_System_Includes
* @{
*/
/**
* @}
*/
/** @addtogroup STM32F10x_System_Exported_types
* @{
*/
extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */
/**
* @}
*/
/** @addtogroup STM32F10x_System_Exported_Constants
* @{
*/
/**
* @}
*/
/** @addtogroup STM32F10x_System_Exported_Macros
* @{
*/
/**
* @}
*/
/** @addtogroup STM32F10x_System_Exported_Functions
* @{
*/
extern void SystemInit(void);
extern void SystemCoreClockUpdate(void);
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /*__SYSTEM_STM32F10X_H */
/**
* @}
*/
/**
* @}
*/
/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
@@ -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
@@ -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(); /* 发送启动信号 */
/* 发送设备地址+读写控制bit0 = w 1 = r) bit7 先传 */
i2c_SendByte(_Address | I2C_WR);
ucAck = i2c_WaitAck(); /* 检测设备的ACK应答 */
i2c_Stop(); /* 发送停止信号 */
return ucAck;
}
@@ -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
File diff suppressed because it is too large Load Diff
@@ -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*******************/
@@ -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
@@ -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*******************/
@@ -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*******************/
File diff suppressed because it is too large Load Diff
@@ -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*******************/
File diff suppressed because it is too large Load Diff
@@ -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*******************/
@@ -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通道1d1 = %d, a1 = %d, A1 = %d%%\r\n", outputDistance1, a1, A1);
printf("\r\n通道2d2 = %d, a2 = %d, A2 = %d%%\r\n", outputDistance2, a2, A2);
printf("\r\n通道3d3 = %d, a3 = %d, A3 = %d%%\r\n", outputDistance3, a3, A3);
printf("\r\n通道4d4 = %d, a4 = %d, A4 = %d%%\r\n", outputDistance4, a4, A4);
}
}
/******************** (C) COPYRIGHT 2017 CXHY *****END OF FILE*******************/
@@ -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*******************/
@@ -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*******************/
@@ -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*******************/
@@ -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线路挂起位
}
@@ -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*******************/
@@ -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
}
@@ -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
@@ -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*******************/
@@ -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*******************/
@@ -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*******************/
@@ -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*******************/
File diff suppressed because it is too large Load Diff
@@ -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*******************/
File diff suppressed because it is too large Load Diff
@@ -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*******************/
@@ -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*******************/
@@ -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*******************/
@@ -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*******************/
@@ -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*******************/
@@ -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号和之前的是否相等
*
* : 10
***********************************************************************
*/
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*******************/
@@ -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
* :
*
* : 10
***********************************************************************
*/
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
* :
*
* : 10
***********************************************************************
*/
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*******************/
@@ -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*******************/
@@ -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*******************/
@@ -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*******************/
@@ -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*******************/
@@ -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
@@ -0,0 +1,302 @@
/*************************** (C) COPYRIGHT 2017 YNHB ****************************
* LCD_SDWe.c
* 7LCD串口显示屏驱动程序
* 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*******************/
@@ -0,0 +1,20 @@
/*************************** (C) COPYRIGHT 2017 YNHB ****************************
* LCD_SDWe.h
* 7LCD串口显示屏驱动头文件
* 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*******************/
File diff suppressed because it is too large Load Diff
@@ -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
@@ -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
@@ -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 -> 01
* :
***********************************************************************
*/
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*******************/
@@ -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*******************/
@@ -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); //11111RW(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 -> 01
* :
***********************************************************************
*/
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 -> 01
* :
***********************************************************************
*/
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 -> 08
* 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-45-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*******************/
@@ -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*******************/
@@ -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*******************/
@@ -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*******************/
File diff suppressed because it is too large Load Diff
@@ -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*******************/
@@ -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*******************/
@@ -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*******************/
@@ -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*******************/
@@ -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*******************/
@@ -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*******************/
@@ -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*******************/
@@ -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*******************/
@@ -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*******************/
@@ -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*******************/
@@ -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
@@ -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*******************/
@@ -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*******************/
@@ -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卡解码
*
* : 10
***********************************************************************
*/
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*******************/
@@ -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
* : 161710
*
* :
***********************************************************************
*/
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
* : 161610
*
* :
***********************************************************************
*/
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卡解码
*
* : 10
***********************************************************************
*/
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*******************/
@@ -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*******************/
@@ -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卡解码
*
* : 10
***********************************************************************
*/
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*******************/
@@ -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*******************/

Some files were not shown because too many files have changed in this diff Show More