I am newbie in arm programming. I am using teensy 3.2 which has MK20DX256 microcontroller chip .and led is connected to PTC5 of MC.
i have written this code to blink LED
The project builds without error but hex file does not blink led. i am using teensyloader to program the board with hex file
here is my code
////////////////////////////////////////////////////////////////////////////////////////////////
# include "MK20D7.h"void delay(unsigned int );
int main(void){ SystemCoreClockUpdate(); /* Get Core Clock Frequency */ SysTick_Config(SystemCoreClock/1000); /* Generate interrupt each 1 ms */
PORTC->PCR[5]= 256; //declared as GPIO PTC->PDDR=0x00000010; while(1) { PTC->PDOR=0x00000010; delay(500); PTC->PDOR=0x00000000; delay(500); } }
void delay(unsigned int ms){ unsigned int i,j;
for(i=0;i<ms;i++) for(j=0;j<20000;j++);
}
////////////////////////////
please help me in finding what is wrong with this code
No i am using a simulator
But my code works now
# include "MK20D7.h" void delay(unsigned int); void delay(unsigned int ms) { volatile unsigned int i,j; for(i=0;i<ms;i++) for(j=0;j<2000;j++); } int main(void) { SIM->SCGC5 = (1UL << 11); /* Enable Clock to Port C */ PORTC->PCR[5] = (1UL << 8); /* Pin is GPIO */ PTC->PDDR = (1u<<5); while(1) { PTC->PSOR = (1u<<5); //Set PTC5 = 1, turns LED on delay(500); //Burn some time PTC->PCOR = (1u<<5); //Set PTC5 = 1, turns LED off delay(500); //Burn some time } }