I am new to ARM programming .I am using K20 MK20DX256 MCU with 72MHz Clock to toggle an LED every 1second with Periodic Interrupt Timer 0. The code compiles Fine but LED does not toggle .I found out that configuring Timer together with LED does not work while LED alone does work I have written the following code in 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
}
}
}
}
Can anyone help me in finding out what is wrong with this code? I found out that none of the registers change their value during debugging enter image description here