新手上路
- 积分
- 39
- 金钱
- 39
- 注册时间
- 2015-2-5
- 在线时间
- 0 小时
|
5金钱
PORTA.8 有波动 而PORTD.2不波动,我代码如下:
test.c
#include "sys.h"
#include "usart.h"
#include "delay.h"
#include "led.h"
int main(void)
{
Stm32_Clock_Init(9);
delay_init(72);
LED_Init();
while(1)
{
LED0=0;
LED1=1;
delay_ms(300);
LED0=1;
LED1=0;
delay_ms(300);
}
}
led.c
#include "led.h"
//
//
void LED_Init(void)
{
RCC->APB2ENR|=1<<2; //使能PORTA时钟
RCC->APB2ENR|=1<<5; //使能PORTD时钟
GPIOA->CRH&=0XFFFFFFF0;
GPIOA->CRH|=0X00000003;
GPIOA->ODR|=1<<8;
GPIOA->CRL&=0XFFFFF0FF;
GPIOA->CRL|=0X00000300;
GPIOA->ODR|=1<<2;
}
led.h
#ifndef __LED_H
#define __LED_H
#include "sys.h"
//LED端口定义
#define LED0 PAout(8) //PA8
#define LED1 PDout(2) //PD2
void LED_Init(void); //初始化
#endif
PS:《例说STM32》P96 第一行 中居然让我添加PORTB.5和PORTE.5!!! |
|