嵌入式培训—12.11

① 时钟系统:

                时钟源 — >外部晶振

                锁相环 : 倍频 + 分频

                AHB(关注AHB1),APB(关注APB1,APB2)

② 总线

                AMBA : AHB( 高速总线 ) + APB(外设总线)

③ 时钟树


嵌入式培训—12.11_第1张图片

④ 任务:使用按键控制输入输出

                PA0低电平 未按下   高电平 按下

                //PA0硬件初始化

                时钟源打开

                配置PA0

                输入

                上拉/下拉

                应用

                输入数据寄存器采样(while下 轮训 此寄存器 )

        代码:

#include

#define  Time_Delay 5000

#define RCC_ADDR 0x40023800

#define RCC_AHB1ENR   *((unsigned int *)(RCC_ADDR+0x30))

#define GPIOA_ADDR 0x40020000

#define GPIOA_IDR *((unsigned int *)(GPIOA_ADDR + 0x10))

#define GPIOC_ADDR 0x40020800

#define GPIOC_IDR *((unsigned int *)(GPIOC_ADDR + 0x10))

#define GPIOH_ADDR 0x40021C00

#define GPIOH_MODER *((unsigned int *)(GPIOH_ADDR + 0x00))

#define GPIOH_OTYPER *((unsigned int *)(GPIOH_ADDR + 0x04))

#define GPIOH_OSPEEDER *((unsigned int *)(GPIOH_ADDR + 0x08))

#define GPIOH_PUPDR *((unsigned int *)(GPIOH_ADDR + 0x0C))

#define GPIOH_ODR *((unsigned int *)(GPIOH_ADDR + 0x14))

#define GPIOI_ADDR 0x40022000

#define GPIOI_MODER *((unsigned int *)(GPIOI_ADDR + 0x00))

#define GPIOI_OTYPER *((unsigned int *)(GPIOI_ADDR + 0x04))

#define GPIOI_OSPEEDER *((unsigned int *)(GPIOI_ADDR + 0x08))

#define GPIOI_PUPDR *((unsigned int *)(GPIOI_ADDR + 0x0C))

#define GPIOI_ODR *((unsigned int *)(GPIOI_ADDR + 0x14))

int k=0;

int i[7]={1,2,3,4,5,6,7};

void delay(unsigned int n)

{

unsigned int i,j;

for(i=0;i

for(j=0;j<1000;j++);

}

void Beep()

{

GPIOI_MODER = 0x400000;

GPIOI_OTYPER = 0x00;

GPIOI_PUPDR = 0x400000;

GPIOI_OSPEEDER = 0x00;

GPIOI_ODR = 0x800;

delay(Time_Delay);

GPIOI_ODR = 0x00;

}

void Red()

{

GPIOH_MODER = 0x100000; //Êä³ö

GPIOH_OTYPER = 0x00; //ÍÆÍì

GPIOH_PUPDR = 0x100000; //ÉÏÀ­

GPIOH_OSPEEDER = 0x00; //µÍËÙ

GPIOH_ODR = 0x00; //µÍ

// Beep();

// GPIOH_ODR = 0x400; //¸ß

// delay(Time_Delay);

}

void Yellow()

{

GPIOH_MODER = 0x500000;

GPIOH_OTYPER = 0x00;

GPIOH_PUPDR = 0x500000;

GPIOH_OSPEEDER = 0x00;

GPIOH_ODR = 0x00;

// Beep();

// GPIOH_ODR = 0xC00;

// delay(Time_Delay);

}

void Green()

{

GPIOH_MODER = 0x400000;

GPIOH_OTYPER = 0x00;

GPIOH_PUPDR = 0x400000;

GPIOH_OSPEEDER = 0x00;

GPIOH_ODR = 0x00;

// Beep();

// GPIOH_ODR = 0x800;

// delay(Time_Delay);

}

void Cyan()

{

GPIOH_MODER = 0x1400000;

GPIOH_OTYPER = 0x00;

GPIOH_PUPDR = 0x1400000;

GPIOH_OSPEEDER = 0x00;

GPIOH_ODR = 0x00;

// Beep();

// GPIOH_ODR = 0x1800;

// delay(Time_Delay);

}

void Blue()

{

GPIOH_MODER = 0x1000000;

GPIOH_OTYPER = 0x00;

GPIOH_PUPDR = 0x1000000;

GPIOH_OSPEEDER = 0x00;

GPIOH_ODR = 0x00;

// Beep();

// GPIOH_ODR = 0x1000;

// delay(Time_Delay);

}

void Purple()

{

GPIOH_MODER = 0x1100000;

GPIOH_OTYPER = 0x00;

GPIOH_PUPDR = 0x1100000;

GPIOH_OSPEEDER = 0x00;

GPIOH_ODR = 0x00;

// Beep();

// GPIOH_ODR = 0x1400;

// delay(Time_Delay);

}

void White()

{

GPIOH_MODER = 0x1500000;

GPIOH_OTYPER = 0x00;

GPIOH_PUPDR = 0x1500000;

GPIOH_OSPEEDER = 0x00;

GPIOH_ODR = 0x00;

// Beep();

// GPIOH_ODR = 0x1C00;

// delay(Time_Delay);

}

void Key_1()

{

if((GPIOA_IDR & 0x01) == 0x01)

{

while((GPIOA_IDR & 0x01) == 0x01)

{

switch(i[k])

{

case 1:Red();Beep();break;

case 2:Yellow();Beep();break;

case 3:Green();Beep();break;

case 4:Cyan();Beep();break;

case 5:Blue();Beep();break;

case 6:Purple();Beep();break;

case 7:White();Beep();

}

}

k++;

if(k == 7)

k=0;

}

else

{

switch(i[k])

{

case 2:GPIOH_ODR = 0x400;break;

case 3:GPIOH_ODR = 0xC00;break;

case 4:GPIOH_ODR = 0x800;break;

case 5:GPIOH_ODR = 0x1800;break;

case 6:GPIOH_ODR = 0x1000;break;

case 7:GPIOH_ODR = 0x1400;break;

case 1:GPIOH_ODR = 0x1C00;

}

}

}

void Key_2()

{

if((GPIOC_IDR & 0x2000) == 0x2000)

{

Red();

Beep();

Green();

Beep();

Blue();

Beep();

}

}

int main(void)

{

//ʹÄÜʱÖÓÔ´

RCC_AHB1ENR = 0x00100185; //A,C,H,I

while(1)

{

Key_1();

}

}

你可能感兴趣的:(嵌入式培训—12.11)