This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

UART

I am new to ARM I have written a code for recieving the character from UART then Display it on the LCD for LPC2148 but when i run it in the proteus then LCD initialises correctly but when it comes to receive data it continuously runs my code is as Follows

#include<lpc214x.h>

#define RS (1<<16)
#define RW (1<<17)
#define EN (1<<18)
#define data_pins (0xF<<19)

void UART0_init(void);
void UART0_TX(unsigned int x);
unsigned int UART0_RX(void);
void lcd_cmd(unsigned char d);
void lcd_data(unsigned char d);
void lcd_init(void);
void lcd_string(unsigned char *d);
void delay(void);

unsigned char s;

int main(void)
{ UART0_init(); IO0DIR|=RS|EN|RW|data_pins; IO0CLR|=RW; lcd_init(); lcd_string("Initializng..."); while(1) { s=UART0_RX(); lcd_data(s); delay(); lcd_cmd(0xc0); //UART0_TX(s); }
} void UART0_init(void)
{ PINSEL0|=(1<<0)|(1<<2); U0LCR=(1<<0)|(1<<1)|(1<<7); U0DLM=0; U0DLL=0x4E; U0LCR=0x03; U0FCR=(1<<0);
} void UART0_TX(unsigned int x)
{ //U0TER=(1<<7); U0THR=x; while(!(U0LSR&(1<<5))); U0LSR=(1<<5);
} unsigned int UART0_RX(void)
{ unsigned int x; while(!(U0LSR&(1<<0))); x=U0RBR; U0LSR=(1<<0); return x;
} unsigned char usart_rx(void)
{ unsigned char d; while(!(U0LSR & 0x01)); d=U0RBR; return d;
} void lcd_init(void)
{ lcd_cmd(0x02); lcd_cmd(0x28); lcd_cmd(0x28); lcd_cmd(0x06); lcd_cmd(0x01); lcd_cmd(0x0E); lcd_cmd(0x80);
} void lcd_data(unsigned char d)
{ IO0CLR|=data_pins; IO0SET|=data_pins&(d<<15); IO0SET|=RS; IO0SET|=EN; delay(); IO0CLR|=EN;

IO0CLR|=data_pins; IO0SET|=data_pins&(d<<19); IO0SET|=EN; delay(); IO0CLR|=EN;
} void lcd_cmd(unsigned char d)
{ IO0CLR|=data_pins; IO0SET|=data_pins&(d<<15); IO0CLR|=RS; IO0SET|=EN; delay(); IO0CLR|=EN;

IO0CLR|=data_pins; IO0SET|=data_pins&(d<<19); IO0SET|=EN; delay(); IO0CLR|=EN;
} void lcd_string(unsigned char *d)
{ while(d!='\0') { lcd_data(*d); d++; }
} void delay(void)
{ int i,j; for(i=0;i<50;i++) { for(j=0;j<500;j++); }
} i think recieve function goes to recursion condition but how to stop it i am unable to Find

Parents Reply Children