Water lamp-stm32

Water lamp and buzzer

insert image description here
insert image description here
insert image description here
insert image description here

#include "stm32f10x.h"                  // Device header
#include "Delay.h"
int main(void)
{
	//开启GPIO时钟
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
	//GPIO初始化
	GPIO_InitTypeDef GPIO_InitStruct;
	GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
	GPIO_InitStruct.GPIO_Pin = GPIO_Pin_All;//定义所有的端口GPIO_Pin_0~GPIO_Pin_16
	GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_Init(GPIOA,&GPIO_InitStruct);
	//GPIO电平初始化
//	GPIO_SetBits(GPIOA,GPIO_Pin_0);//设置为高电平
//	GPIO_ResetBits(GPIOA,GPIO_Pin_0);//设置为低电平
//	GPIO_WriteBit(GPIOA,GPIO_Pin_0,Bit_SET);//设置为高电平
//	GPIO_WriteBit(GPIOA,GPIO_Pin_0,Bit_RESET);//设置为低电平
	GPIO_Write(GPIOA,0x0001);//0000 0000 0000 0001
	while(1)
	{
		//流水灯的效果
		GPIO_Write(GPIOA,0x0001);//0000 0000 0000 0001
		Delay_ms(100);
		GPIO_Write(GPIOA,0x0002);//0000 0000 0000 0010
		Delay_ms(100);
		GPIO_Write(GPIOA,0x0004);//0000 0000 0000 0100
		Delay_ms(100);
		GPIO_Write(GPIOA,0x0008);//0000 0000 0000 1000
		Delay_ms(100);
		GPIO_Write(GPIOA,0x0010);//0000 0000 0001 0000
		Delay_ms(100);
		GPIO_Write(GPIOA,0x0020);//0000 0000 0010 0000
		Delay_ms(100);
		GPIO_Write(GPIOA,0x0040);//0000 0000 0100 0000
		Delay_ms(100);
		GPIO_Write(GPIOA,0x0080);//0000 0000 1000 0000
		Delay_ms(100);
	}
}

The method of using library functions
First open the end of .h to see what functions are there; then right-click to switch to the definition of the function to see the usage of the parameters of the function.

Refer to the library function manual.

Guess you like

Origin blog.csdn.net/qq_45159887/article/details/130331444