Tuesday, 29 September 2015

UART RECEIVER IN ARM7(LPC2129/38)

#include<lpc21xx.h>
void cmd(int);
void cmd1(int);
void data(char);
void delay();
int main()
{
char s;
PINSEL0=0X00000004;
IO1DIR=0XFFFFFFFF;
cmd(0x30);
cmd(0x30);
cmd(0x30);
cmd(0x20);
cmd1(0x28);
cmd1(0x01);
cmd1(0x06);
cmd1(0x0e);
cmd1(0x80);

U0LCR=0X83;
U0DLL=0X51;
U0DLM=0X00;
U0LCR=0X03;

while(1)
{
while((U0LSR&0X01)==0);
s=U0RBR;
data(s);
 }
 }

 void cmd(int b)
{
unsigned int s;
s=b&0xf0;
IO1SET=s<<16;
IO1CLR=0X000F0000;
IO1SET|=0X00080000;
delay();
IO1CLR=0X00080000;
IO1CLR=0XFFFFFFFF;
}
void cmd1(int a)
{


unsigned int s;
s=a&0xf0;
IO1SET=s<<16;
IO1CLR=0X000F0000;
IO1SET|=0X00080000;
delay();
IO1CLR=0X00080000;
IO1CLR=0XFFFFFFFF;


s=a&0x0f;
IO1SET=s<<20;
IO1CLR=0X000F0000;
IO1SET|=0X00080000;
delay();
IO1CLR=0X00080000;
delay();
IO1CLR=0XFFFFFFFF;
}
void data(char a)
{

char s;
s=a&0xf0;
IO1SET=s<<16;
IO1CLR=0X000F0000;
IO1SET|=0X000A0000;
delay();
IO1CLR=0X00080000;
IO1CLR=0XFFFFFFFF;


s=a&0x0f;
IO1SET=s<<20;
IO1CLR=0X000F0000;
IO1SET|=0X000A0000;
delay();
IO1CLR=0X00080000;
delay();
IO1CLR=0XFFFFFFFF;
}
void delay()
{
int i;
for(i=0;i<10000;i++);
}

No comments:

Post a Comment