ARM lpc2148 arm7 serial interface

data-send-from-arm7lpc21xx

code
#include<lpc21xx.h>

unsigned char rec;

void pll();

void serial_ini();
void serial_transmit(unsigned char x);

void delay(int x);

int main()
{
PINSEL0 = 0x00000005;
IO0DIR=0XFFFFFFFF;
serial_ini();
pll();
while(1)
{
serial_transmit(‘W’); // call transmit function
delay(100); // calling of delay function
serial_transmit(‘W’); // call transmit function
delay(100); // calling of delay function
serial_transmit(‘W’); // call transmit function
delay(100); // calling of delay function
serial_transmit(‘.’); // call transmit function
delay(100); // calling of delay function
serial_transmit(‘t’); // call transmit function
delay(100); // calling of delay function
serial_transmit(‘r’); // call transmit function
delay(100); // calling of delay function
serial_transmit(‘a’); // call transmit function
delay(100); // calling of delay function
serial_transmit(‘i’); // call transmit function
delay(100); // calling of delay function
serial_transmit(‘n’); // call transmit function
delay(100); // calling of delay function
serial_transmit(‘i’); // call transmit function
delay(100); // calling of delay function
serial_transmit(‘g’); // call transmit function
delay(100); // calling of delay function
serial_transmit(‘l’); // call transmit function
delay(100); // calling of delay function
serial_transmit(‘u’); // call transmit function

serial_transmit(‘d’); // call transmit function
delay(100); // calling of delay function
serial_transmit(‘h’); // call transmit function
delay(100); // calling of delay function
serial_transmit(‘i’); // call transmit function
delay(100); // calling of delay function
serial_transmit(‘a’); // call transmit function
delay(100); // calling of delay function
serial_transmit(‘n’); // call transmit function
delay(100); // calling of delay function
serial_transmit(‘a’); // call transmit function
delay(100); // calling of delay function

delay(100); // calling of delay function
serial_transmit(‘.’); // call transmit function
delay(100); // calling of delay function
serial_transmit(‘i’); // call transmit function
delay(100); // calling of delay function
serial_transmit(‘n’); // call transmit function
delay(100); // calling of delay function

serial_transmit(0x0d); // call transmit function
delay(400);
delay(400);

}
}

void pll()
{
/*PLL IS CONFIGURED TO GET 60HZ pCLK*/
PLLCFG=0X24; // SET PSEL=2 AND MSEL=5
PLLCON=0X01; //PLL IS ACTIVE BUT NOT YET CONNECT
PLLFEED=0XAA; //FEED SEQUENCE
PLLFEED=0X55; //FEED SEQUENCE
while((PLLSTAT & 0X400)==0); //WAIT FOR FEED SEQUENCE TO BE INSERTED
PLLCON=0X03; // PLL HAS BEEN ACTIVE AND BEING CONNECTRD
VPBDIV=0X00; // SET PCLK SAME AS FCCLK
PLLFEED=0XAA; //FEED SEQUENCE
PLLFEED=0X55; //FEED SEQUENCE
}

/* SERIAL INITILIZATION*/

void serial_ini()
{

U0LCR =0x83;
U0DLM=0X00;
U0DLL=0X5e;
U0FDR=0X52;
U0LCR =0x03;
}

void serial_transmit(unsigned char x)
{
U0THR =x; // LOAD DATA IN U0THR REGISTER
while ((U0LSR & 0x40)==0); // WAIT FOR DATA TRANSMISSION
U0LSR|=0X40;
}

void delay(int x)
{
int i,j;
x=x*10;
for(i=0;i<x;i++)
for(j=0;j<350;j++);
}

PROTEUS File for SIMULATION(Password Of RAR file is :-firmcodes.com)
download (1)

_______________________________________________________________________________________________________

2.Program Of RS232 Protocol Of ARM7 (LPC2148) With Lcd
In this program data entered from the hyper terminal of PC or Laptop is appeared on the LCD connected to the controller
/******************************************************
www.firmcodes.com
DEVELOPED BY:- FIRMWARE DEVELOPER
WHAT PROGRAM DO:- DATA SEND FROM PC BY RS232 PROTOCOL IS
DISPLAYED ON LCD CONNECTED WITH ARM7(LPC2148)
******************************************************/

#include<lpc21xx.h>

#define LCD (0xff<<16)
#define RS (1<<13)
#define RW (1<<14)
#define EN (1<<15)

void delay_fv(unsigned int x,int y);

void lcd_display(unsigned int x);
void cmd(unsigned char m);
void lcd_ini();

unsigned char rec;

void pll();

void serial_ini();
char serial_re();

int main()
{
PINSEL0 = 0x00000005;
PINSEL1 = 0x00000000;
IO0DIR=0XFFFFFFFF;
serial_ini();
pll();
lcd_ini();
while(1)
{
serial_re();
lcd_display(rec);
}
}

void delay_fv(unsigned int x,int y)
{
unsigned int i,j;
for(i=0;i<x;i++)
for(j=0;j<y;j++);
}

void lcd_display(unsigned int x)
{
IO0CLR|=(RS|RW|EN|LCD);
IO0SET|=(x<<16);
IO0SET|=RS;
IO0CLR|=RW;
IO0SET|=EN;
delay_fv(100,10);
IO0CLR|=EN;
delay_fv(10,10);
}

void cmd(unsigned char m)
{
IO0CLR|=(RS|RW|EN|LCD);
IO0SET|=(m<<16);
IO0CLR|=RS;
IO0CLR|=RW;
IO0SET|=EN;
delay_fv(100,100);
IO0CLR|=EN;
delay_fv(100,10);
}

void lcd_ini()
{
cmd(0X38);
cmd(0X0e);
cmd(0X06);
cmd(0X01);
cmd(0X80);
}

void pll()
{
/*PLL IS CONFIGURED TO GET 60HZ pCLK*/
PLLCFG=0X24; // SET PSEL=2 AND MSEL=5
PLLCON=0X01; //PLL IS ACTIVE BUT NOT YET CONNECT
PLLFEED=0XAA; //FEED SEQUENCE
PLLFEED=0X55; //FEED SEQUENCE
while((PLLSTAT & 0X400)==0); //WAIT FOR FEED SEQUENCE TO BE INSERTED
PLLCON=0X03; // PLL HAS BEEN ACTIVE AND BEING CONNECTRD
VPBDIV=0X00; // SET PCLK SAME AS FCCLK
PLLFEED=0XAA; //FEED SEQUENCE
PLLFEED=0X55; //FEED SEQUENCE
}

void serial_ini()
{

U0LCR =0x83;
U0DLM=0X00;
U0DLL=0X5e;
U0FDR=0X52;
U0LCR =0x03;
}

char serial_re()
{
while ((U0LSR & 0x01)==0); // wait untill complete data is received
rec=U0RBR;
return rec;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/******************************************************
www.firmcodes.com
DEVELOPED BY:- FIRMWARE DEVELOPER
WHAT PROGRAM DO:- DATA SEND FROM PC BY RS232 PROTOCOL IS
DISPLAYED ON LCD CONNECTED WITH ARM7(LPC2148)
******************************************************/

#include<lpc21xx.h>

#define LCD (0xff<<16)
#define RS (1<<13)
#define RW (1<<14)
#define EN (1<<15)

void delay_fv(unsigned int x,int y);

void lcd_display(unsigned int x);
void cmd(unsigned char m);
void lcd_ini();

unsigned char rec;

void pll();

void serial_ini();
char serial_re();

int main()
{
PINSEL0 = 0x00000005;
PINSEL1 = 0x00000000;
IO0DIR=0XFFFFFFFF;
serial_ini();
pll();
lcd_ini();
while(1)
{
serial_re();
lcd_display(rec);
}
}

void delay_fv(unsigned int x,int y)
{
unsigned int i,j;
for(i=0;i<x;i++)
for(j=0;j<y;j++);
}

void lcd_display(unsigned int x)
{
IO0CLR|=(RS|RW|EN|LCD);
IO0SET|=(x<<16);
IO0SET|=RS;
IO0CLR|=RW;
IO0SET|=EN;
delay_fv(100,10);
IO0CLR|=EN;
delay_fv(10,10);
}

void cmd(unsigned char m)
{
IO0CLR|=(RS|RW|EN|LCD);
IO0SET|=(m<<16);
IO0CLR|=RS;
IO0CLR|=RW;
IO0SET|=EN;
delay_fv(100,100);
IO0CLR|=EN;
delay_fv(100,10);
}

void lcd_ini()
{
cmd(0X38);
cmd(0X0e);
cmd(0X06);
cmd(0X01);
cmd(0X80);
}

void pll()
{
/*PLL IS CONFIGURED TO GET 60HZ pCLK*/
PLLCFG=0X24; // SET PSEL=2 AND MSEL=5
PLLCON=0X01; //PLL IS ACTIVE BUT NOT YET CONNECT
PLLFEED=0XAA; //FEED SEQUENCE
PLLFEED=0X55; //FEED SEQUENCE
while((PLLSTAT & 0X400)==0); //WAIT FOR FEED SEQUENCE TO BE INSERTED
PLLCON=0X03; // PLL HAS BEEN ACTIVE AND BEING CONNECTRD
VPBDIV=0X00; // SET PCLK SAME AS FCCLK
PLLFEED=0XAA; //FEED SEQUENCE
PLLFEED=0X55; //FEED SEQUENCE
}

void serial_ini()
{

U0LCR =0x83;
U0DLM=0X00;
U0DLL=0X5e;
U0FDR=0X52;
U0LCR =0x03;
}

char serial_re()
{
while ((U0LSR & 0x01)==0); // wait untill complete data is received
rec=U0RBR;
return rec;
}

Leave a Reply

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