登录  | 立即注册

游客您好!登录后享受更多精彩

扫一扫,访问微社区

QQ登录

只需一步,快速开始

开启左侧

[寒假笔记] STM32

[复制链接]
发表于 2023-1-8 15:06:27 | 显示全部楼层 |阅读模式
学习笔记
学习科目: 32单片机
学习安排: LED流水灯和蜂鸣器
开始时间: 2023-01-08
结束时间: 2023-01-08
LED流水灯代码
#include "stm32f10x.h"                  // Device header
#include "Delay.h"
int main(void)
{
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,  ENABLE );
       
        GPIO_InitTypeDef GPIO_InitStructure;
        GPIO_InitStructure.GPIO_Mode=  GPIO_Mode_Out_PP ;
        GPIO_InitStructure.GPIO_Pin= GPIO_Pin_All;
        GPIO_InitStructure.GPIO_Speed= GPIO_Speed_50MHz;
        GPIO_Init(GPIOA,&GPIO_InitStructure);
       
       
       
        while (1)
        {
                GPIO_Write(GPIOA,~0x001);//0000 0000 0000 0001
                Delay_ms(300);
                GPIO_Write(GPIOA,~0x002);//0000 0000 0000 0010
                Delay_ms(300);
                GPIO_Write(GPIOA,~0x004);//0000 0000 0000 0100
                Delay_ms(300);
                GPIO_Write(GPIOA,~0x008);//0000 0000 0000 1000
                Delay_ms(300);
                GPIO_Write(GPIOA,~0x010);//0000 0000 0001 0000
                Delay_ms(300);
                GPIO_Write(GPIOA,~0x020);//0000 0000 0010 0000
                Delay_ms(300);
                GPIO_Write(GPIOA,~0x040);//0000 0000 0100 0000
                Delay_ms(300);
                GPIO_Write(GPIOA,~0x080);//0000 0000 1000 0000
                Delay_ms(300);
        }
}


蜂鸣器代码
#include"stm32f10x.h"                  // Device header
#include "Delay.h"
int main(void)
{
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,  ENABLE );
       
        GPIO_InitTypeDef GPIO_InitStructure;
        GPIO_InitStructure.GPIO_Mode=  GPIO_Mode_Out_PP ;
        GPIO_InitStructure.GPIO_Pin= GPIO_Pin_12 ;
        GPIO_InitStructure.GPIO_Speed= GPIO_Speed_50MHz;
        GPIO_Init(GPIOB,&GPIO_InitStructure);
       
       
       
        while (1)
        {
                 GPIO_ResetBits(GPIOB,GPIO_Pin_12);
                 Delay_ms(100);
                 GPIO_SetBits(GPIOB,GPIO_Pin_12);
                 Delay_ms(100);
                 
                 GPIO_ResetBits(GPIOB,GPIO_Pin_12);
                 Delay_ms(100);
                 GPIO_SetBits(GPIOB,GPIO_Pin_12);
                 Delay_ms(700);
        }
}


好懒~~不想说~~~
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表