Вы находитесь на странице: 1из 1

/*

***********************************************************************************
**********************
* (c) Copyright 03/09/2017,Pune, India
* All Rights Reserved
* File : APCUART.H
* Descripton : This is header file for Serial Comuunication using UART0 of ARM7.
* TXD of ARM: P0.0
* Cotains Clocks_Ini, UART0_Ini and Send_Byte functions give following
functionality
* Clocks_Ini : To set CPU Clock(CCLK) and Peripheral Clock(PCLK) to
60MHz given 10MHz crystal
* connected to microcontroller
* UART0_Ini : To initialize the UART0 for serial communication with
baud rate of 9600
* Send_Byte : To send 8 bit data through UART0 pin
* By :
* E&TC Engineer,Pune
* Date : 10/09/2017
* Tested on Proteus 8.1 with lpc2138.
* Have Fun!!!
***********************************************************************************
**********************
*/
#include<lpc21xx.h>
void Clocks_Ini(void)
{
PLL0CON = 0x01; //Enable PLL
PLL0CFG = 0x25; //Multiplier and divider setup
PLL0FEED = 0xAA; //Feed sequence
PLL0FEED = 0x55;
while(!(PLL0STAT & 0x00000400)); //is locked?
PLL0CON = 0x03; //Connect PLL after PLL is locked
PLL0FEED = 0xAA; //Feed sequence
PLL0FEED = 0x55;
VPBDIV = 0x01; // PCLK is same as CCLK i.e.60 MHz For 10 MHz crystal Frequecy
}

void UART0_Ini(void)
{
PINSEL0 = 0x00000001; /* Select TxD for P0.0 and RxD for P0.1 */
U0LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit | DLAB set to 1 */
U0DLL = 135;
U0DLM = 1;
U0FDR = 0xF0; /* MULVAL=15(bits - 7:4) , DIVADDVAL=0(bits - 3:0)*/
U0LCR &= 0x0F; // Set DLAB=0 to lock MULVAL and DIVADDVAL
//BaudRate is now ~9600 and we are ready for UART communication!
}

void Send_Byte(unsigned char apc)


{
while (!(U0LSR & (1<<5))); // wait till the THR is empty
U0THR = apc; // now we can write to the Tx FIFO
}

Вам также может понравиться