// 直接用寄存器控制灯的亮灭,对stm32入门学习,了解stm32寄存器第一步 ,用的是stm32f10x系列
void soft_delay(unsigned int count)
{
for( ;count!=0;count-- );
}
// 打开 GPIOB 端口的时钟
*( unsigned int * )0x40021018 |= ( (1) << 4 );
// 配置IO口为输出
*( unsigned int * )0x40011000 |= ( (1) << (4*2) );
// 控制 ODR 寄存器
*( unsigned int * )0x4001100C &= ~(1<<2);
while(1)
{
/* 亮 */
*( unsigned int * )0x4001100C &= ~(1<<2);
soft_delay(0xfffff);
/* 灭 */
*( unsigned int * )0x4001100C |= (1<<2);
soft_delay(0xfffff);
}
|