野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 19994|回复: 2

请教一下,为什么我这个程序不能令STM32指南板的灯闪烁,...

[复制链接]
发表于 2021-10-24 15:27:44 | 显示全部楼层 |阅读模式
#include "stm32f103.h"
#define Giob_clock *(unsigned int*)(0x40021018)
#define Giob_define *(unsigned int*)(0x40010c00)
#define Giob_output *(unsigned int*)(0x40010c0c)
void delay_cnt( int num)
{
        for(;num !=0;num--)
        {
               
        }
}

int main()
{

        #if 1
        Giob_clock |=(1<<3);
        Giob_define |=(1<<0);
        //int temp=0xfffffff;
       
        Giob_output &=~(1<<0);    //GIOB的dro亮灯
        delay_cnt(0xFFFFFFFF);    //延时
       
        Giob_output |=(1<<0);     //GIOB的dro灭灯
        delay_cnt(0xFFFFFFFF);   //延时
       
       
        #else
        *(unsigned int*)(0x40021018) |=(1<<3);
        //*(unsigned int*)(0x40010C00) &=(0xf<<0);
        *(unsigned int*)(0x40010C00) |=(1<<0);
        *(unsigned int*)(0x40010C0C) &=~(1<<0);
       
        #endif
       
        return 0;
}

回复

使用道具 举报

发表于 2021-10-25 09:20:16 | 显示全部楼层
单片机里的main函数最后不能return,需要有个死循环防止跳出main
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-10-25 13:38:53 | 显示全部楼层
你好,删除了return,增加了循环,但还是不闪。
        while(1)
        {
       
        GPIO_SetBits(GPIOB,GPIO_pin_0);   //灭灯
       
        delay_cnt(0xFFFFF);
       
        GPIO_RestBits(GPIOB,GPIO_pin_0);//亮灯
       
        delay_cnt(0xFFFFF);
        }
       
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2025-12-6 07:06 , Processed in 0.035059 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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