/* =============================================================================== Name : main.c Author : Version : Copyright : Copyright (C) Description : main definition =============================================================================== */ #ifdef __USE_CMSIS #include "LPC13xx.h" #endif // TODO: insert other include files here // TODO: insert other definitions and declarations here #define LED_PORTLPC_GPIO0->DATA//FIOPIN for Keil #define LED_DDRLPC_GPIO0->DIR//FIODIR for Keil #define LED(1<<7) #define DLY_MS1000//delay time, in ms volatile unsigned long SysTickCnt=0; /* SysTick Counter */ void SysTick_Handler (void) { /* SysTick Interrupt Handler (1ms) */ SysTickCnt++; } void Delay (unsigned long tick) { /* Delay Function */ unsigned long systick; //unsigned long tick_cnt = tick; systick = SysTickCnt;//systickcnt has the start-up time while ((SysTickCnt - systick) < tick); } void mcu_init(void) { SystemInit();//reset mcu /* Generate interrupt each 1 ms */ SysTick_Config(SystemCoreClock/1000 - 1);//=SystemFrequency for Keil LED_PORT &=~(LED);//clear led LED_DDR |= (LED);//led as output } int main(void) { unsigned char i; mcu_init();//reset mcu while (1) { for (i=0; i<0xff; i++) { LED_PORT ^= (LED); Delay(i<<1);//delay some time } for (i=0xff; i>0x00; i--) { LED_PORT ^= (LED); Delay(i<<1);//delay some time } } } |