#include<stm32f10x_lib.h>
#include "sys.h"
#include "delay.h"
#define led PAout(8)
u8 flag;
u8 num;
void init_pin(void);
void init_uart(void);
int main(void)
{
Stm32_Clock_Init(9);
init_pin();
init_uart();
while(1)
{
if (flag == 1)
{
flag = 0;
led = !led;
num = USART1->DR;
while((USART1->SR & (1 << 6)) == 0);
USART1 -> SR &= ~(1<<6);
}
}
}
void init_pin(void)
{
RCC->APB2ENR = 1 << 2 | 1 << 14;
GPIOA->CRH &= 0xfffff000;
GPIOA->CRH |= 0x000008B3;
}
void init_uart(void)
{
RCC->APB2RSTR = 1 << 14;
RCC->APB2RSTR &= ~(1 << 14);
USART1->BRR = ((72*1000000)/(9600*16)) << 4;
USART1->CR1 = 1 << 13 | 1 << 8 | 1 << 5 | 1 << 3 | 1 << 2;
MY_NVIC_Init(3, 3, USART1_IRQChannel, 2);
}
void USART1_IRQHandler(void)
{
flag = 1;
num = USART1 -> DR;
USART1 -> SR &= ~(1<<5);
}
帮帮我嘛 我用JTAG还是不知道错在哪里、、 |