RCC->APB2ENR|=1<<2;
AFIO->MAPR = AFIO_MAPR_SWJ_CFG_JTAGDISABLE;
GPIOA->CRH&=0X0FFFFFFF;
GPIOA->CRH|=0X80000000;
GPIOA->ODR &=0x7FFF;
1. IO状态设置
GPIOA->CRH&=0X0FFFFFFF;
GPIOA->CRH|=0X80000000;
2.下拉
GPIOA->ODR &=0x7FFF;
GPIOA->ODR|=1<<5; //PA5输出高 GPIOB->ODR &= 0XFF07; //PB3,PB4,PB5,PB6,PB7输出低
3.例1:
void LED_Init(void)
{
RCC->APB2ENR|=1<<2;
AFIO->MAPR = AFIO_MAPR_SWJ_CFG_JTAGDISABLE;
GPIOA->CRL&=0X00000000;
GPIOA->CRL|=0X22222222;
GPIOA->CRH&=0X0FF00000;
GPIOA->CRH|=0X20022222;
GPIOA->ODR|=0<<8;
GPIOA->ODR|=0<<9;
GPIOA->ODR|=0<<10;
GPIOA->ODR|=0<<11;
GPIOA->ODR|=0<<12;
GPIOA->ODR|=0<<15;
RCC->APB2ENR|=1<<3;
GPIOB->CRL&=0X00000000;
GPIOB->CRL|=0X22222222;
GPIOB->CRH&=0X00000000;
GPIOB->CRH|=0X22222222;
GPIOB->ODR|=0;
RCC->APB2ENR|=1<<4;
GPIOC->CRH&=0XFFF00000;
GPIOC->CRH|=0X22200000;
}
main.c
#include "sys.h"
#include "usart.h"
#include "delay.h"
#include "led.h"
#include "control.h"
#include <math.h>
#include <stdlib.h>
int main(void)
{
Stm32_Clock_Init(9);
delay_init(72);
LED_Init();
while(1)
{
}
}
|