4.最终代码
#include "stm32f10x.h" // Device header
//延时
void delay()
{
int i,j;
for (i=0;i<100000;i++)
for (j=0;j<100;j++);
}
void led()
{
}
int main(void)
{
//初始地址GPIOA:0x40010800、GPIOB:0x40010C00、GPIOC:0x40011000
// &= ~用来清0(给某一位单独置0)
// |= 用来给某一位单独置1
//配置复位和时钟控制寄存器(RCC)-使能寄存器APB2
*(unsigned int*)0x40021018|=(0X7<<2);
//配置为推挽输出
*(unsigned int*)0x40010800|=0x00000003;//PA0,低位,偏移地址0x00
*(unsigned int*)0x40010C00|=0x00000003;//PB0,低位,偏移地址0x00
*(unsigned int*)0x40011004|=0x30000000;//PC15,高位,偏移0x04
//配置端口输出数据寄存器ODR,偏移地址0x0Ch
while(1)
{
//全亮
*(unsigned int*)0x4001080C&=~(0x0);
*(unsigned int*)0x40010C0C&=~(0x0);
*(unsigned int*)0x4001100C&=~(0x0<<15);
delay();
//AB亮,C灭
*(unsigned int*)0x4001080C&=~(0x0);
*(unsigned int*)0x40010C0C&=~(0x0);
*(unsigned int*)0x4001100C=0x1<<15;
delay();
//A亮,BC灭
*(unsigned int*)0x4001080C&=~(0x0);
*(unsigned int*)0x40010C0C=0x1<<0;
*(unsigned int*)0x4001100C=0x1<<15;
delay();
//ABC全灭
*(unsigned int*)0x4001080C=0x1;
*(unsigned int*)0x40010C0C=0x1;
*(unsigned int*)0x4001100C=0x1<<15;
delay();
}
}
|