Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

help nxp lpc21xx uart keil help ?

Status
Not open for further replies.

5282604

Full Member level 4
Joined
Dec 19, 2009
Messages
194
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,298
Location
egypt
Activity points
2,404
i have problem with nxp arm lpc uart :sad:
i use this code from nxp . to print "Philips LPC"
**broken link removed**

this my simple code( i only put Initialize() in main) but the code not work give me another value not "Philips LPC" . i use proteus for simulation:lol:



Code:
#include <LPC21xx.H>              /* LPC21xx definitions                      */

/* Macro Definitions */
#define TEMT (1<<6)
#define LINE_FEED 0xA
#define CARRIAGE_RET 0xD
/************************* MAIN *************************/
  int i;
char c[]="Philips LPC";

int main()
{

/* Initialize Pin Select Block for Tx and Rx */
PINSEL0=0x5;
/* Enable FIFO's and reset them */
U0FCR=0x7;
/* Set DLAB and word length set to 8bits */
U0LCR=0x83;
/* Baud rate set to 9600 */
U0DLL=0x10;
U0DLM=0x0;
/* Clear DLAB */
U0LCR=0x3;

/* Keep Transmitting until Null character('\0') is reached */
while(c[i])
{
U0THR=c[i];
i++;
}
U0THR=LINE_FEED;
U0THR=CARRIAGE_RET;
/* Wait till U0THR and U0TSR are both empty */
while(!(U0LSR & TEMT)){}
}

i'm new in arm world
 

Hope it helps:
Code:
#include <LPC21xx.H>                     /* LPC21xx definitions               */
#include "Serial.h"

#define CR     0x0D



/* implementation of putchar (also used by printf function to output data)    */
int sendchar (int ch)  {                 /* Write character to Serial Port    */

  if (ch == '\n')  {
    while (!(U1LSR & 0x20));
    U1THR = CR;                          /* output CR */
  }
  while (!(U1LSR & 0x20));
  return (U1THR = ch);
}


int getkey (void)  {                     /* Read character from Serial Port   */

  while (!(U1LSR & 0x01));

  return (U1RBR);
}

void uart_print_string(char * string, char newline)
{
	while (*string != 0x00){ sendchar(*string++);}
	if (newline!=0){sendchar(13);}
}

void uart_print_value(long val)
{
	char buffer[10] = {0};
	char * head = buffer;
	char cnt=0;
	if (val!=0)
	{
		while( val )
		{
    		*head++ = (val % 10)["0123456789"];
    		val /= 10;
			cnt++;
		}
		while (cnt!=0){ cnt--; sendchar(buffer[cnt]); }
	}
	else
	{
		sendchar('0');
	}
}

void uart_print_hex_value(long val)
{
	char buffer[10] = {0};
	char * head = buffer;
	char cnt=0;
	sendchar('0');
	sendchar('x');
	if (val!=0)
	{
		while( val )
		{
    		*head++ = (val & 0x0F)["0123456789ABCDEF"];
    		val=val>>4;
			cnt++;
		}
		while (cnt!=0){ cnt--; sendchar(buffer[cnt]); }
	}
	else
	{
		sendchar('0');
	}
}
 

thank you
but i not want to use external code for uart
Code:
 #include "Serial.h"
 

serial.h is a header file for serial.c that I posted here. What do you mean exactly?
If you using UART Receiving, you will have to use UART RX Interrupt. For transmit it is enough to use pooling mode.
 

serial.h is a header file for serial.c that I posted here. What do you mean exactly?
If you using UART Receiving, you will have to use UART RX Interrupt. For transmit it is enough to use pooling mode.

i mean i want to include #include <LPC21xx.H> only. i not want to use lib from keil.
like the application note by nxp. in my first post . in the pdf file
 

there is no any libs from keil used in this code
If you not like to use header files for any reason, just delete this string.
:|
 

there is no any libs from keil used in this code
If you not like to use header files for any reason, just delete this string.
:|
thank you but i'm new in arm :roll:. first i want to learn lpc and then the stm32;-)
pls if you have a complete project tell me pls
thank you for helping
 

Well, yes. But it wasn't finished. I didn't realized correct algorithm of 1-Wire Search Rom command in this project. But for education purposes it will be useful. You will see, that high level routines are universal and can be quickly rewritten for any other core. PIC, Atmel, STM for example.
View attachment LPC2101+1-Wire.rar
 
thank you for help me Easyrider83 :p you are agreat man :-D
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top