按键按下去gpio为1,然后把gpio的数据1通过串口发送出去,然后在串口调试助手中显示1。
一下是我的代码我觉得逻辑没有问题,求大神指点
#include
#include "W7500x_uart.h"
#include "W7500x_gpio.h"
#include "W7500X_crg.h"
#include "print_x.h"__
#include "key.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
GPIO_InitTypeDef GPIO_InitDef;
UART_InitTypeDef UART_InitStructure;
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
void delay_ms(__IO uint32_t nCount);
/**
@retval None
*/
/* GPIO LED(B) Set */
int main()
{
unsigned char s='1';
uint8_t i;
uint16_t num;
char str[10]="";
/*System clock configuration*/
SystemInit();
// *(volatile uint32_t *)(0x41001014) = 0x0060100; //clock setting 48MHz
/* CLK OUT Set */
PAD_AFConfig(PAD_PA,GPIO_Pin_12, PAD_AF1); // PAD Config - CLKOUT used 3nd Function
/* UART0 and UART1 configuration*/
UART_StructInit(&UART_InitStructure);
/* Configure UART0 */
UART_Init(UART1,&UART_InitStructure);
UART_ITConfig(UART1,UART_IT_FLAG_RXI,ENABLE);
S_UART_Init(115200);
//S_UART_SetBaud(115200);
KEY_Init();
/* Retarget functions for GNU Tools for ARM Embedded Processors*/
GPIO_InitDef.GPIO_Pin = GPIO_Pin_12; // Set to Pin_5 (LED(B))
GPIO_InitDef.GPIO_Mode = GPIO_Mode_OUT; // Set to Mode Output
GPIO_Init(GPIOC, &GPIO_InitDef);
PAD_AFConfig(PAD_PC,GPIO_Pin_12, PAD_AF1); // PAD Config - LED used 2nd Function
// GPIO_SetBits(GPIOC, GPIO_Pin_12); // LED(B) Off
while(1)
{
if(KEY_Csan() == 0)
i++;
if(i%2 == 0)
{
GPIO_SetBits(GPIOC, GPIO_Pin_12);
num=GPIO_ReadOutputData(GPIOC);
UART_SendData(UART1,num);
//S_UART_SendData(num);
str[0]=num+48;
prt_str(str);
}
else
{
GPIO_ResetBits(GPIOC, GPIO_Pin_12);
num=GPIO_ReadOutputData(GPIOC);
UART_SendData(UART1,num);
//UART_SendData(num);
str[0]=num+48;
prt_str(str);
}
}
/*
for(;;)
{
S_UART_SendData(s);
printf("UART 1 Test(#1)\r\n");
prt_str("\r\11\r\n");
}
// UartPuts(UART1,"UART 1 Test(#1)\r\n");
*/
}
void delay_ms(__IO uint32_t nCount)
{
volatile uint32_t delay = nCount * 2500; // approximate loops per ms at 24 MHz, Debug config
for(; delay != 0; delay--)
__NOP();
}