#include<stm32f10x_lib.h>
#include "sys.h"
#define led PAout(8)
#define int1 PAin(0)
void init_led(void);
void init_usart(void);
void init_PA1_intd(void);
void delay(u16);
u8 num,flag;
int main(void)
{
num = 0;
init_led();
init_usart();
init_PA1_intd();
while(1)
{
if (flag == 1)
{
flag = 0;
USART1->DR = num;
while((USART1->SR & (1 << 6)) == 0);
USART1->SR &= ~(1 << 6);
}
}
}
void init_led(void)
{
RCC->APB2ENR |= 1 << 2;
GPIOA->CRH &= 0xfffffff0;
GPIOA->CRH |= 0x00000003;
}
void init_usart(void)
{
//使能接收发送引脚时钟和串口时钟
RCC->APB2ENR |= 1 << 14 | 1 << 2;
GPIOA->CRH &= 0xfffff000;
GPIOA->CRH |= 0x000008B3;
//复位和清除复位
RCC->APB2RSTR |= 1 << 14;
RCC->APB2RSTR &= ~(1 << 14);
//设置波特率和配置USART1控制寄存器
USART1->BRR = ((8 * 1000000)/(16 * 9600)) << 4;
USART1->CR1 = (1 << 13) | (1 << 8) | (1 << 5) | (1 << 3) | (1 << 2);
//载入中断
MY_NVIC_Init(3,3,USART1_IRQChannel,2);//组2,最低优先级
}
void delay(u16 ms)
{
u16 r1, r2;
for (r1 = 0; r1 < ms; r1++)
for (r2 = 0; r2 < 1150; r2++);
}
void init_PA1_intd(void)
{
RCC->APB2ENR |= 1 << 2;
GPIOA->CRL &= 0xfffffff0;
GPIOA->CRL |= 0x00000008;
// GPIOA->ODR = 1 << 0;
RCC->APB2ENR |= 1 << 1;
AFIO->EXTICR[0] = 0;
EXTI->IMR |= 1 << 0;
EXTI->EMR |= 1 << 0;
EXTI->FTSR |= 1 << 0;
MY_NVIC_Init(2, 2, EXTI0_IRQChannel, 2);
}
void EXTI0_IRQHandler(void)
{
if(int1 == 0)
{
delay(5);
if(int1 == 0)
{
while(!int1);
led = ~led;
num++;
flag = 1;
}
}
}
啊 用JTAG都可以实现,但是全速运行就不能实现、、
|