Created
September 4, 2013 14:04
-
-
Save Embedded-linux/6437385 to your computer and use it in GitHub Desktop.
UART 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
| //—————————————————————————————————————————————————————————————————————————// | |
| // Program : UART example | |
| // Description : Example for test UART1 interrupt mode | |
| // Frequency : Crystal 12 MHz at PLL 5x(CCLK = 60 MHz),PCLK = 30 MHz | |
| // Filename : uart_int.c | |
| // C compiler : Keil CARM Compiler | |
| //—————————————————————————————————————————————————————————————————————————// | |
| #include “lpc214x.h” // Header file for Phillips LPC2148 controller | |
| #include “uart.h” // Library for use module UART0,UART1 | |
| #include “stdio.h” // Library for use puts function(For UART1) | |
| //—————————————— 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 | |
| } | |
| //—————————————— Interrupt service routine for UART1 ———————————————// | |
| void isr_uart1(void) __irq | |
| { | |
| char msg; | |
| if(((msg = U1IIR) & 0x01) == 0) // Check status flag communication | |
| { | |
| switch (msg & 0x0E) // Filter message | |
| { | |
| case 0x04: while(!(U1LSR & 0x20)); // Receive Data Available | |
| U1THR = U1RBR; // Echo character | |
| break; | |
| case 0x02: break; // Their Interrupt | |
| default: break; // Other | |
| } | |
| } | |
| VICVectAddr = 0; // Acknowledge Interrupt | |
| } | |
| Note: "uart.h" is defined in previous post | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment