ARM : Example Setting PLL for LPC2148


As on last page we have finished all theoretical procedure…lets try our hands to write a program

#include<stdio.h>
#include<LPC21xx.h>
#include<stdlib.h>
#define THRE 0x20
#define TEMT 0x40
#define DR 0x01
#define CAR_RET 0x0D
#define LINE_FEED 0x0A

void pll_init( intcfg )
{
	intloop_ctr;
	// Step 1: Set CFG and CON
	PLL0CFG = cfg;
	PLL0CON = 0x01; // PLL Enable
	// Step 2: Security measure: feed
	pll_feed();
// Step 3: Wait for the lock into the new frequency
	loop_ctr = 10000;
	while( ((PLL0STAT&(1<<10))==0) && (loop_ctr>0) ) loop_ctr--;
	// if PLL0STAT & (1<<10) does not hold, we have an issue...
	// Step 4: Connect the PLL
	PLL0CON |= 0x03;
	// Step 5: Security measure: feed
	pll_feed();
}

static void pll_feed( void )
{
	PLL0FEED = 0xAA;
	PLL0FEED = 0x55;
}

void inituart1()
{
	PINSEL0 |= 0x00050000;

	U1LCR = 0x83;
	U1FDR = 0x00000010;
	U1DLL = 0x01;
	U1DLM = 0x00;
	U1LCR = 0x03;

	U1IER = 0x0000007;
	U1FCR = 0x01;
}

void put_char1(unsigned char ch)
{
	while(!(U1LSR & THRE));
	U1THR=ch;
}

unsigned char get_char1(void)
{
	while(!(U1LSR & DR));
	return(U1RBR);
}

int main( void )
{
	unsigned char a;

	pll_init(0x24); // legal/suitable  values: 60, 41, 42, 23, 24

	inituart1();
	put_char1('d');
	while(1)
	{
		a= get_char1();
		put_char1(a);
	}

	while(1); // infinite loop
}

 

 

Related posts:

About author

This article was written by admin

Admin has over twenty years experience in the electronics industry, largely dedicated to embedded software. A frequent presenter at conferences and seminars and author of numerous technical articles. Working presently as Development Manager in India. A firm Believer in Knowledge grows when it shared.

Comments

Comments (6)
  1. sukumaran says - Posted: April 8, 2013

    hi sir,, is baud rate correct?

  2. admin says - Posted: April 9, 2013

    Hi my friend ….where did you find baud rate? can you be please more specific about it?

  3. ankush says - Posted: September 26, 2013

    sir please send me your mail id…

  4. ankush says - Posted: September 26, 2013

    send me basic program of arm7 in c

  5. Ambuj Maurya says - Posted: December 25, 2015

    Hello, Sir will u help me out in interfacing M45PE16 with ARM LPC2148

  6. bhavesh says - Posted: April 20, 2016

    sir please explain me step 3 of the above program. why do we use (PLL0STAT & (1<<10)) and then && with loop_ctr. please explain in etail

Leave your comment

Your email address will not be published. Required fields are marked *