stm32笔记:点亮一个led (精简版)
扫描二维码
随时随地手机看文章
仅包含启动文件 "STM32F10x.s"
C代码
#defineGPIOA_CRL(*(volatileunsignedlong*)(0x40000000+0x10000+0x0800+0x00))
#defineGPIOA_CRH(*(volatileunsignedlong*)(0x40000000+0x10000+0x0800+0x04))
#defineGPIOA_IDR(*(volatileunsignedlong*)(0x40000000+0x10000+0x0800+0x08))
#defineGPIOA_ODR(*(volatileunsignedlong*)(0x40000000+0x10000+0x0800+0x0C))
#defineRCC_APB2ENR(*(volatileunsignedlong*)(0x40000000+0x20000+0x1000+0x18))
voiddelay(unsignedlongi)//超级不精确的软延时
{
intj;
while(i--)
{
for(j=0;j<1500;j++)
{}
}
}
intmain(void)
{
RCC_APB2ENR=1<<2;//打开PA时钟,默认启用内部8M时钟
GPIOA_CRH&=0XFFFFFFF0;//准备配置PA
GPIOA_CRH|=0X00000003;//PA8推挽输出
GPIOA_ODR|=1<<8;//PA8输出高,即先关闭led
while(1)
{
GPIOA_ODR&=0<<8;
delay(3000);
GPIOA_ODR|=1<<8;
delay(3000);
}
}