小白分享直接操作寄存器代码

2019-08-19 16:41发布

别的话就不说了,直接上代码了。

#include "sys.h"

//ALIENTEK ì½Ë÷ÕßSTM32F407¿a·¢°å êμÑé4
//′®¿úí¨DÅêμÑé  
//¼¼êõÖ§3Ö£owww.openedv.com
//1ãÖYêDDÇòíμç×ó¿Æ¼¼óDÏT1«
#define        GPFMOD                (*(volatile unsigned long *)0x40021400)
#define        GPFODR                (*(volatile unsigned long *)0x40021414)
#define GPFBSRR     (*(volatile unsigned long *)0x40021418)
#define AHB1ENABLE     (*(volatile unsigned long *)0x40023830)
#define        GPF9_out        (1<<(9*2))
#define        GPF10_out        (1<<(10*2))
void  wait(volatile unsigned long dly)
{
        for(; dly > 0; dly--);
}
int main(void)
{      
         Stm32_Clock_Init(336,8,2,7);//éè&#214;&#195;ê±&#214;ó,168Mhz                   
         AHB1ENABLE|=0x0020;
         GPFMOD=GPF9_out|GPF10_out;
        while(1)
        {  
      GPFBSRR=0x00000600;       
          wait(10000000);
          GPFBSRR=0x06000000;       
          wait(10000000);
        }
}

如此就能实现原子哥讲的跑马灯的实验了
我有一个不明白的问题,不是说M4内核差不多是一点几MIPS的速度吗,但是为什么执行延时时的速度这么快,我可是写了1000万啊,但是一秒钟循环一次啊,这么快,按理说应该是10多秒执行一个循环啊,为什么这么快


















友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。