LPC2138 Program Execution Issue

Hello everybody,

I am using Keil microvision IDE (EVALUATION copy) for my project testing. I am burning hex file through flash magic software using ISP mode.

Initially i wrote simple serial port (uart0) example code.Also added few lines to toggle LED connected to pin P1.24.

Now when i compiled code in Microvision V5 (keil MDK), its serial message showing in my PC hyper terminal. Bit LED (related port pin) state not changed to show blinking.

Hence i copy code & compiled in Microvision Keil 4 IDE, But there nither serial messaging nor led blinking happened.

when i retested same in Keil MDK again serail message shows but not LED, why so ?

I tested all parameters well again & again ( FOSC,CCLK,PCLK  settings, UART0 & port settings). All are correct.

Anybody  has any idea whether my controller is not executing well?

have some found similar issue?

Author:-    Embedded Laboratory

FOSC = 10MHz
CCLK = 60MHz
PCLK = 15MHz
#include <LPC213X.H>

void initClocks(void);
void initGPIO(void);
void toggle_led(void);
void delay_100ms(unsigned char ii);

#define REL_EN       (0x01<<22)   //p0.22
#define LED1          (0x01<<24)   //p1.24
//#define LED2          (0x01<<26)   //p1.26

char String[]="Welcome to LPC!!! \n\r\n";
unsigned int delay;
/**************Function Prototypes************/
void UART0_Init(void);
void UART0_Write(unsigned char value);
void UART0_Write_Text(unsigned char msg[]);
unsigned char UART0_Read(void);

unsigned char msg[] = "Embedded Laboratory\r\n";
unsigned char echo_test[] = "Echo Test\r\n";
int main()

/****************Function Definition**********/
void initClocks(void)

	PLLCON = 0x01;   //Enable PLL
	//PLLCFG = 0x24;   //Multiplier and divider setup	//12mhz crystal
	PLLCFG = 0x25;   //Multiplier and divider setup		//10mhz crystal
	PLLFEED = 0xAA;  //Feed sequence
	PLLFEED = 0x55;
		while(!(PLLSTAT & 0x00000400)); //is locked?
	PLLCON = 0x03;   //Connect PLL after PLL is locked
	PLLFEED = 0xAA;  //Feed sequence
	PLLFEED = 0x55;
//	VPBDIV = 0x01;    // PCLK is same as CCLK i.e.60 MHz
	VPBDIV = 0x00;    // PCLK =15mhz is same as 1/4th of CCLK i.e.60 MHz

/***************UART-0 Functions**************/
void UART0_Init(void)
    PINSEL0 = 0x00000005;                //P0.0 as TX0 and P0.1 as RX0
    U0LCR = 0x83;                                //Enable access to Divisor Latches
    //and Set 8 bit Character Length with 1 Stop bit and Parity Disabled
    //Access to Divisor Latches is Enabled, in order to write Baud Rate Generator Registers
    //Values to be written in Baud Rate Registers U0DLM and U0LL
    Formula is
    Baud_Rate = PCLK*MulVal / [(16*(256*U0DLM+U0DLL)*(MulVal + DivAddVal))]
    MulVal = 1;
    DivAddVal = 0;
    Baud_Rate = 9600;
    PCLK = 15MHz
    U0DLM = 0;
    U0DLL = 15000000/(9600*16) = 97.65625 = 98
    U0DLL = 98 = 0x62
    U0DLM = 0x00;
    U0DLL = 0x62;                                    //Baud Rate of 9600
    U0LCR = 0x03;                                    //Disable Access to Divisor Latches

void toggle_led(void)
		IOCLR1 = LED1;
		//IOCLR1 = LED2;
		IOSET1 = LED1;  
		//IOSET1 = LED2;    

//delay of 100 msec
void delay_100ms(unsigned char ii)
    unsigned i,j;
    i = 648117;
    j = i * ii;
        ii = 0;
void initGPIO(void)
	PINSEL1 = 0x00000000;
    PINSEL2 = 0x00000000;

    IODIR1 = 0xFFFF0000;

void UART0_Write(unsigned char value)
    THRE bit can be extracted by this U0LSR & 0x20
    THRE = 0 means data is present.
    THRE = 1 means register is empty.
    In order to transmit data, we have to wait will the THRE = 1,
    then only we can transmit data.
    while(!(U0LSR&0x20));                        //THRE = 0 stay here
    U0THR = value;

void UART0_Write_Text(unsigned char msg[])

unsigned char UART0_Read(void)
    Receiver Data Ready = U0LSR.0 bit
    RDR bit can be extracted by this U0LSR & 0x01
    RDR = 0 means no Data is Received in U0RBR
    RDR = 1 means that Data is present in U0RBR
    while(!(U0LSR & 0x01));                        //RDR = 0 stay here
    return (U0RBR);

Please guide me.

Regards & thanks,


More questions in this forum