Created
September 4, 2013 14:12
-
-
Save Embedded-linux/6437489 to your computer and use it in GitHub Desktop.
I/O Port for LPC2148
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
| LPC2148 port acts input for reading data | |
| from P0.28 and P0.29 that connected with push-button switches and resistor pull-up | |
| //————————————————————————————————————————————————————————————————————————// | |
| // Program : Example for test switch | |
| // Description : Test switch at P0.28 and P0.29 for toggle LED at P0.21 and P0.22 | |
| // Frequency : Crystal 12 MHz at PLL 5x(CCLK = 60 MHz),PCLK = 30 MHz | |
| // Filename : switch.c | |
| // C compiler : Keil CARM Compiler | |
| //————————————————————————————————————————————————————————————————————————// | |
| #include “lpc214x.h” // Header file for Phillips LPC2148 controller | |
| //—————————————— 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 read input P0 **/ | |
| char inp0(char _bit) { | |
| unsigned long c; | |
| c = 1<<_bit; | |
| FIO0DIR &= ~c; | |
| return ((FIO0PIN & c)>>_bit); | |
| } | |
| /* Main Function */ | |
| void main() { | |
| init(); | |
| SCS = 0x03; | |
| FIO0DIR |= 0x00600000; | |
| FIOSET |= 0x00600000; | |
| while(1) { | |
| if (inp0(28) == 0) | |
| { | |
| while(inp0(28)==0); | |
| FIO0PIN ^= (1<<21); | |
| } | |
| if (input(29) == 0) | |
| { | |
| while(inp0(29) == 0); | |
| FIO0PIN ^= 1<<22; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment