129 lines
4.7 KiB
C
129 lines
4.7 KiB
C
/********************************** (C) COPYRIGHT *******************************
|
|
* File Name : debug.h
|
|
* Author : WCH
|
|
* Version : V1.0.0
|
|
* Date : 2021/06/06
|
|
* Description : This file contains all the functions prototypes for UART
|
|
* Printf , Delay functions.
|
|
*********************************************************************************
|
|
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
|
* Attention: This software (modified or not) and binary are used for
|
|
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
|
*******************************************************************************/
|
|
#ifndef __DEBUG_H
|
|
#define __DEBUG_H
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#include "stdio.h"
|
|
#include "ch32v30x.h"
|
|
|
|
/* UART Printf Definition */
|
|
#define DEBUG_UART1 1
|
|
#define DEBUG_UART2 2
|
|
#define DEBUG_UART3 3
|
|
|
|
/* DEBUG UATR Definition */
|
|
#ifndef DEBUG
|
|
#define DEBUG DEBUG_UART3
|
|
#endif
|
|
|
|
/* SDI Printf Definition */
|
|
#define SDI_PR_CLOSE 0
|
|
#define SDI_PR_OPEN 1
|
|
|
|
#ifndef SDI_PRINT
|
|
#define SDI_PRINT SDI_PR_CLOSE
|
|
#endif
|
|
|
|
|
|
/* 引脚 定义 */
|
|
#define LED0_GPIO_PORT GPIOB
|
|
#define LED0_GPIO_PIN GPIO_Pin_5
|
|
#define LED0_GPIO_CLK_ENABLE() do{ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); }while(0) /* PB口时钟使能 */
|
|
|
|
#define LED1_GPIO_PORT GPIOB
|
|
#define LED1_GPIO_PIN GPIO_Pin_6
|
|
#define LED1_GPIO_CLK_ENABLE() do{ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); }while(0) /* PB口时钟使能 */
|
|
|
|
#define LED2_GPIO_PORT GPIOB
|
|
#define LED2_GPIO_PIN GPIO_Pin_7
|
|
#define LED2_GPIO_CLK_ENABLE() do{ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); }while(0) /* PC口时钟使能 */
|
|
|
|
#define INPUT_GPIO_PORT GPIOB
|
|
#define INPUT_GPIO_PIN GPIO_Pin_14
|
|
#define INPUT_GPIO_CLK_ENABLE() do{ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); }while(0) /* PA口时钟使能 */
|
|
|
|
#define OUTPUT1_GPIO_PORT GPIOD
|
|
#define OUTPUT1_GPIO_PIN GPIO_Pin_8
|
|
#define OUTPUT1_GPIO_CLK_ENABLE() do{ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE); }while(0) /* PD口时钟使能 */
|
|
|
|
#define OUTPUT2_GPIO_PORT GPIOD
|
|
#define OUTPUT2_GPIO_PIN GPIO_Pin_9
|
|
#define OUTPUT2_GPIO_CLK_ENABLE() do{ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE); }while(0) /* PD口时钟使能 */
|
|
|
|
/******************************************************************************************/
|
|
|
|
/* LED端口定义 */
|
|
#define LED0(x) do{ x ? \
|
|
GPIO_SetBits(LED0_GPIO_PORT,LED0_GPIO_PIN): \
|
|
GPIO_ResetBits(LED0_GPIO_PORT,LED0_GPIO_PIN); \
|
|
}while(0) /* LED0 = BLUE */
|
|
|
|
#define LED1(x) do{ x ? \
|
|
GPIO_SetBits(LED1_GPIO_PORT,LED1_GPIO_PIN): \
|
|
GPIO_ResetBits(LED1_GPIO_PORT,LED1_GPIO_PIN); \
|
|
}while(0) /* LED1 = YELLOW */
|
|
|
|
#define LED2(x) do{ x ? \
|
|
GPIO_SetBits(LED2_GPIO_PORT,LED2_GPIO_PIN): \
|
|
GPIO_ResetBits(LED2_GPIO_PORT,LED2_GPIO_PIN); \
|
|
}while(0) /* LED2 = GREEN */
|
|
|
|
#define INPUT(x) do{ x ? \
|
|
GPIO_SetBits(INPUT_GPIO_PORT,INPUT_GPIO_PIN): \
|
|
GPIO_ResetBits(INPUT_GPIO_PORT,INPUT_GPIO_PIN); \
|
|
}while(0)
|
|
|
|
#define OUTPUT1(x) do{ x ? \
|
|
GPIO_SetBits(OUTPUT1_GPIO_PORT,OUTPUT1_GPIO_PIN): \
|
|
GPIO_ResetBits(OUTPUT1_GPIO_PORT,OUTPUT1_GPIO_PIN); \
|
|
}while(0)
|
|
|
|
#define OUTPUT2(x) do{ x ? \
|
|
GPIO_SetBits(OUTPUT2_GPIO_PORT,OUTPUT2_GPIO_PIN): \
|
|
GPIO_ResetBits(OUTPUT2_GPIO_PORT,OUTPUT2_GPIO_PIN); \
|
|
}while(0)
|
|
|
|
/* LED取反定义 */
|
|
#define LED0_TOGGLE() do{ gpio_toggle_pin(LED0_GPIO_PORT, LED0_GPIO_PIN); }while(0) /* 翻转LED0 */
|
|
#define LED1_TOGGLE() do{ gpio_toggle_pin(LED1_GPIO_PORT, LED1_GPIO_PIN); }while(0) /* 翻转LED1 */
|
|
#define LED2_TOGGLE() do{ gpio_toggle_pin(LED2_GPIO_PORT, LED2_GPIO_PIN); }while(0) /* 翻转LED2 */
|
|
|
|
/******************************************************************************************/
|
|
|
|
void led_init(void); /* 初始化LED */
|
|
|
|
void check_input(void); /*检查PA8口的输入电平*/
|
|
|
|
void set_outpot(uint8_t pd8_state, uint8_t pd9_state); /*设置PD8\PD9输出电平*/
|
|
|
|
|
|
|
|
void Delay_Init(void);
|
|
void Delay_Us (uint32_t n);
|
|
void Delay_Ms (uint32_t n);
|
|
void USART_Printf_Init(uint32_t baudrate);
|
|
void SDI_Printf_Enable(void);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|