三只蓝鲸STM32F103-----小灯闪烁+系统延时

main.c(这个模板我们以后还会继续使用)

#include "main.h"
#include "System.h"	//系统延时
#include "Led.h"		//LED
//#include "Key.h"		//KEY

//#include "UART.h"
//#include "TIMER.h"
//#include "WDOG.h"
//#include "RTC.h"
//#include "ADC.h"
//#include "I2C.h"
//#include "NBIoT.h"

//#define _TST_USART1_EN
#define _TST_LED_EN
//#define _TST_TIMER_EN
//#define _TST_PWM_EN
//#define _TST_USART2_EN
//#define _TST_IWDG_EN                                                                    
//#define _TST_WWDG_EN
//#define _TST_RTC_EN
//#define _TST_ADC_EN
//#define _TST_I2C_EN
//#define _TST_NBIOT_EN
//#define _TST_KEY_LED_EN

//
int  main(void)
{
	int k;
	char rxCh;
	
	//
	tst_Delay_Init();
	tst_LED_Init();
	//tst_USART1_Prt_Init(9600);
	
	/* LED
	 * Main 中翻转LED状态,闪烁
	 */
#ifdef _TST_LED_EN
	tst_LED_OnOff(1);
	tst_Delay_ms(1000);
	tst_LED_OnOff(0);
#endif
	
	/* TIMER
	 * TIMER中断函数中翻转LED状态,闪烁
	 */
#ifdef _TST_TIMER_EN
	tst_TIMER_Pulse_Init();
#endif
	
	/* PWM
	 * 输出4路不同波形,逻辑仪观察
	 */
#ifdef _TST_PWM_EN
	tst_TIMER_PWM_Init();
#endif
	
	/* USART2
	 * 收到以#结束数据后,将小写字母转换成大写后,回送
	 */
#ifdef _TST_USART2_EN
	tst_USART2_Init(115200,tst_USART2_Raw_Handle);
#endif
	
	/* IWDG
	 * 快速闪烁,表示启动事件发生
	 */
#ifdef _TST_IWDG_EN
	for(k=0; k<20;k++)
	{
		tst_LED_Toggle();
		tst_Delay_ms(100);
	}	
	tst_IWDOG_Init();
#endif

	//WWDG
	//快速闪烁,表示启动事件发生
#ifdef _TST_WWDG_EN
	for(k=0; k<20;k++)
	{
		tst_LED_Toggle();
		tst_Delay_ms(100);
	}	
	tst_WWDOG_Init();
#endif
	
	//RTC
	//设置初始时间后,MAIN中定时读取时间,通过调试串口输出
#ifdef _TST_RTC_EN
	tst_RTC_Init();
#endif
	
	//ADC
#ifdef _TST_ADC_EN
	tst_ADC_Init();
#endif
	
	//I2C
#ifdef _TST_I2C_EN
	tst_I2C_Init();
#endif

	//NBIOT
#ifdef _TST_NBIOT_EN
	tst_NBIOT_Init();
#endif

#ifdef _TST_KEY_LED_EN
	tst_KEY_LED_Init();
#endif

	//
	while(1)
	{
		//tst_Delay_ms(500);
		
#ifdef _TST_USART1_EN
		/*
		 * 注意!!WDOG的喂狗间隔很短,输出延时可能导致复位
		 * 打开WDOG时,应屏蔽下列printf语句
		 */
		printf("\r\nInput your choice:\r\n");
		rxCh = getchar();
		if(rxCh == '1')
		{
			printf("\r\nWelcome!\r\n");
		}
		else
		{
			printf("\r\nBye!\r\n");
		}
		tst_Delay_s(1);
#endif	

#ifdef _TST_LED_EN
		tst_LED_Toggle();
		tst_Delay_ms(500);
#endif
		
#ifdef _TST_USART2_EN
		tst_USART2_Raw_Process();
		tst_Delay_ms(50);
#endif
		
#ifdef _TST_IWDG_EN
		//tst_IWDOG_Feed();
		tst_LED_Toggle();
		tst_Delay_ms(500);
#endif
		
#ifdef _TST_WWDG_EN
		//tst_WWDOG_Feed();
		tst_LED_Toggle();
		tst_Delay_ms(20);
#endif
	
#ifdef _TST_RTC_EN
		tst_RTC_GetAndDisp();
		tst_Delay_s(5);
#endif

#ifdef _TST_ADC_EN
		tst_ADC_DispData();
		tst_Delay_s(1);
#endif

#ifdef _TST_I2C_EN
		tst_I2C_Disp();
#endif

#ifdef _TST_NBIOT_EN
		/*
		tst_NBIOT_GetInfo();
		tst_Delay_s(2);
		*/
			
		tst_NBIOT_TCP_TxRx("whaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaat?");
		tst_Delay_s(2);
		
#endif

	}
}

mian.h

#ifndef __MAIN_H
#define __MAIN_H

//
#include "stdio.h"

#include "stm32f10x.h"

//
#endif

Led.c

#include "Led.h"

//LED PB5
#define _TST_LED_CLK	RCC_APB2Periph_GPIOB
#define _TST_LED_PORT	GPIOB
#define _TST_LED_PIN	GPIO_Pin_5

//
void tst_LED_Init(void)
{
	
	GPIO_InitTypeDef  GPIO_InitStructure;
  
	/* Enable the GPIO_LED Clock */
	RCC_APB2PeriphClockCmd(_TST_LED_CLK, ENABLE);

	/* Configure the GPIO_LED pin */
	GPIO_InitStructure.GPIO_Pin = _TST_LED_PIN;
  /*GPIO_Mode*/
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
	/*GPIO_Speed*/
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	/*初始化GPIO*/
	GPIO_Init(_TST_LED_PORT, &GPIO_InitStructure);
	
	//默认打开
	GPIO_SetBits(_TST_LED_PORT,_TST_LED_PIN);	
}


void tst_LED_OnOff(uint8_t onOff)
{
	if(onOff)
	{
		/*关闭*/
		GPIO_ResetBits(_TST_LED_PORT,_TST_LED_PIN);
	}
	else
	{
		/*打开*/
		GPIO_SetBits(_TST_LED_PORT,_TST_LED_PIN);
	}
}

/*小灯闪烁*/
void tst_LED_Toggle(void)
{
	/*获取LedPB5的状态*/
	uint8_t ioSet = GPIO_ReadOutputDataBit(_TST_LED_PORT,_TST_LED_PIN);
	
	if(ioSet == Bit_SET)//Bit_SET = 1
	{
		tst_LED_OnOff(1);
	}
	else
	{
		tst_LED_OnOff(0);
	}
	
}

Led.h

#include "Led.h"

//LED PB5
#define _TST_LED_CLK	RCC_APB2Periph_GPIOB
#define _TST_LED_PORT	GPIOB
#define _TST_LED_PIN	GPIO_Pin_5

//
void tst_LED_Init(void)
{
	
	GPIO_InitTypeDef  GPIO_InitStructure;
  
	/* Enable the GPIO_LED Clock */
	RCC_APB2PeriphClockCmd(_TST_LED_CLK, ENABLE);

	/* Configure the GPIO_LED pin */
	GPIO_InitStructure.GPIO_Pin = _TST_LED_PIN;
  /*GPIO_Mode*/
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
	/*GPIO_Speed*/
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	/*初始化GPIO*/
	GPIO_Init(_TST_LED_PORT, &GPIO_InitStructure);
	
	//默认打开
	GPIO_SetBits(_TST_LED_PORT,_TST_LED_PIN);	
}


void tst_LED_OnOff(uint8_t onOff)
{
	if(onOff)
	{
		/*关闭*/
		GPIO_ResetBits(_TST_LED_PORT,_TST_LED_PIN);
	}
	else
	{
		/*打开*/
		GPIO_SetBits(_TST_LED_PORT,_TST_LED_PIN);
	}
}

/*小灯闪烁*/
void tst_LED_Toggle(void)
{
	/*获取LedPB5的状态*/
	uint8_t ioSet = GPIO_ReadOutputDataBit(_TST_LED_PORT,_TST_LED_PIN);
	
	if(ioSet == Bit_SET)//Bit_SET = 1
	{
		tst_LED_OnOff(1);
	}
	else
	{
		tst_LED_OnOff(0);
	}
	
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值