我是 ARM 编程新手。我正在使用具有 72MHz 时钟的 K20 MK20DX256 MCU 使用周期性中断定时器 0 每 1 秒切换一次 LED。代码编译正常,但 LED 不切换。我发现将定时器与 LED 一起配置不起作用虽然单独的 LED 确实有效,但我在 keil Uvision 中编写了以下代码
#include "MK20D7.h"
#include <stdio.h>
int main(void)
{
SystemInit();
NVIC_EnableIRQ(PIT0_IRQn); //Enable Timer Interrupts
//Configuring Timer 1
PIT->MCR=0x00;
PIT->CHANNEL[0].LDVAL=13888;
PIT->CHANNEL[0].TCTRL=0x3;
//Configure LED
SIM->SCGC5 = (1UL << 11); /* Enable Clock to Port C */
PORTC->PCR[5] = (1UL << 8); /* Pin is GPIO */
PTC->PDDR = (1u<<5);
PTC->PSOR = (1u<<5); //Set PTC5 = 1, turns LED on
while(1){
if(PIT->CHANNEL[0].TFLG ==1)
{
PIT->CHANNEL[0].TFLG =0;
PIT->CHANNEL[0].LDVAL=13888;
if(PTC->PSOR!=(1u<<5))
{
PTC->PSOR = (1u<<5); //Set PTC5 = 1, turns LED on
}
else
{
PTC->PCOR = (1u<<5); //Set PTC5 = 1, turns LED off
}
}
}
}
谁能帮我找出这段代码有什么问题?我发现在调试过程中没有一个寄存器改变它们的值 在 此处输入图像描述