Created
September 4, 2013 14:23
-
-
Save Embedded-linux/6437659 to your computer and use it in GitHub Desktop.
LED Blink for LPC 2148
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| This experiment is testing output port function of LPC2148 to drive 2 LED at P0.21 and P0.22 | |
| //——————————————————————————————————————————————————————————————————// | |
| // Program : Example for display LED | |
| // Description : LED Blink toggle at P0.21 and P0.22 | |
| // Frequency : Crystal 12 MHz at PLL 5x(CCLK = 60 MHz),PCLK = 30 MHz | |
| // Filename : led.c | |
| // C compiler : Keil CARM Compiler | |
| //——————————————————————————————————————————————————————————————————// | |
| #include “lpc214x.h” // Header file for Phillips LPC2148 controller | |
| #define LED2_ON FIO0CLR = 0x00200000 // Red led 0.21 on | |
| #define LED2_OFF FIO0SET = 0x00200000 // Red led 0.21 off | |
| //—————————————— Function for Initial system clock ————————————————// | |
| void init() | |
| { | |
| PLL0CFG=0x24; // MSEL = 4,PSEL = 2 | |
| PLL0FEED=0xAA; // Feed process | |
| PLL0FEED=0x55; | |
| PLL0CON=0x1; | |
| PLL0FEED=0xAA; // Feed process | |
| PLL0FEED=0x55; | |
| while(!(PLL0STAT & 0x400)); // Wait until PLL Locked | |
| PLL0CON=0x3; // Connect the PLL as the clock source | |
| PLL0FEED=0xAA; // Feed process | |
| PLL0FEED=0x55; | |
| MAMCR=0x2; // Enabling MAM and setting number of clocks used | |
| // for Flash memory fetch (4 cclks in this case) | |
| MAMTIM=0x4; | |
| VPBDIV=0x02; // PCLK at 30 MHz | |
| } | |
| //————————————————— Function delay ———————————————————————// | |
| void delay_ms(long ms) // delay 1 ms per count @ CCLK 60 MHz | |
| { | |
| long i,j; | |
| for (i = 0; i < ms; i++ ) | |
| for (j = 0; j < 6659; j++ ); | |
| } | |
| //————————————————— Main Program ————————————————————————// | |
| void main() | |
| { | |
| init(); | |
| SCS = 0x03; | |
| FIO0DIR |= 0x00600000; | |
| while(1) { | |
| LED1_ON; | |
| LED2_OFF; | |
| delay_ms(50); | |
| LED2_ON; | |
| LED1_OFF; | |
| delay_ms(50); | |
| } | |
| } | |
| ******************************************************************************************************************** | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment