0% found this document useful (0 votes)
0 views9 pages

Ex8-ESL[1][1]

The document outlines the process of establishing RS232 serial communication using the ARM7 LPC2148 microcontroller. It details the hardware and software requirements, explains the theory behind RS-232 communication, and provides a program for implementation. Additionally, it includes information on configuring I2C for a seven-segment display and demonstrates how to write data to it using I2C communication.

Uploaded by

nandhiniec21
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views9 pages

Ex8-ESL[1][1]

The document outlines the process of establishing RS232 serial communication using the ARM7 LPC2148 microcontroller. It details the hardware and software requirements, explains the theory behind RS-232 communication, and provides a program for implementation. Additionally, it includes information on configuring I2C for a seven-segment display and demonstrates how to write data to it using I2C communication.

Uploaded by

nandhiniec21
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

SERIAL COMMUNICATION

Aim : To establish RS232 serial communication using ARM7 LPC2148.

Hardware Requirements:

1. Desktop Computer
2. ARM7 LPC2148

Software Requirements:

1. IAR Embedded Workbench


2. Flash Magic
3. Wincap

THEORY:

RS-232 COMMUNICATION

Serial port is a serial communication physical interface through which information transfers
in or out one bit at a time (contrast parallel port). The name "serial" comes from the fact that
a serial port "serializes" data. That is, it takes a byte of data and transmits the 8 bits in the
byte one at a time. The advantage is that a serial port needs only one wire to transmit the 8
bits (while a parallel port needs 8). The disadvantage is that it takes 8 times longer to transmit
the data than it would if there were 8 wires. Serial ports lower cable costs and make cables
smaller.

There are two basic types of serial communications, synchronous and asynchronous. With
synchronous communications, the two devices initially synchronize themselves to each other,
and then continually send characters to stay in sync. Even when data is not really being sent,
a constant flow of bits allows each device to know where the other is at any given time. That
is, each character that is sent is either actual data or an idle character. Synchronous
communications allows faster data transfer rates than asynchronous methods, because
additional bits to mark the beginning and end of each data byte are not required.

NANDHINI P 20EC1058
PROGRAM:

// BAUD RATE CALCULATION


// DIVISOR = (PCLK/(16*DESIRED_BAUDRATE))
// For Example
// Peripheral Clock Frequency (PCLK) = 12 Mhz
// Desired Baud Rate = 19200 bps
// Divisor = (12000000/(16*19200)) = 39

#include<NXP/iolpc2148.h>
#define DESIRED_BAUDRATE 19200
#define CRYSTAL_FREQUENCY_IN_HZ 12000000
#define PCLK CRYSTAL_FREQUENCY_IN_HZ // since VPBDIV=0x01
#define DIVISOR (PCLK/(16*DESIRED_BAUDRATE))
char arr[]=" \n\r Vimicro system Pvt ltd. Chennai - 96. " ;
char serial_tr(char ch)
{
if (ch=='\n')
{
while (!(U0LSR&0x20)); //wait until Transmit Holding Register is empty
U0THR='\r'; //then store to Transmit Holding Register
}
while (!(U0LSR&0x20)) {} //wait until Transmit Holding Register is
U0THR=ch; //then store to Transmit Holding Register
return ch;
} void Arm_Uart0_Init(void)
{
PINSEL0 = 0x00000005; // (probably not necessary: PINSELs default to zero).
// (lower 4bit selected for UART0 and remaining all bits selected for GPIO's)
// (frist LSB 2bit(0 and 1 bits) selected 01b for UART0 Tx).
// ( LSB bit(2 and 3 bits) selected 01b for UART0 Rx).

U0LCR=0x83; / / U0LCR: UART0 Line Control Register.


// 0x83: enable Divisor Latch access, set 8-bit word
// 1 stop bit, no parity, disable break transmission.
VPBDIV=0x01; // VPBDIV: VPB bus clock divider 0x01:
U0DLL=DIVISOR&0xFF; // U0DLL: UART0 Divisor Latch (LSB).
U0DLM=DIVISOR>>8; // U0DLM: UART0 Divisor Latch (MSB).

NANDHINI P 20EC1058
Asynchronous means "no synchronization", and thus does not require sending and receiving
idle characters. However, the beginning and end of each byte of data must be identified by
start and stop bits. The start bit indicates when the data byte is about to begin and the stop bit
signals when it ends. The requirement to send these additional two bits causes asynchronous
communication to be slightly slower than synchronous however it has the advantage that the
processor does not have to deal with the additional idle characters.

An asynchronous line that is idle is identified with a value of 1 (also called a mark state). By
using this value to indicate that no data is currently being sent, the devices are able to
distinguish between an idle state and a disconnected line. When a character is about to be
transmitted, a start bit is sent. A start bit has a value of 0 (also called a space state). Thus,
when the line switches from a value of 1 to a value of 0, the receiver is alerted that a data
character is about to be sent.

One of the LPC2148s many powerful features is its integrated UART, otherwise known as a
serial port. The fact that the LPC2148 has an integrated serial port means that you may very
easily read and write values to the serial port. If it were not for the integrated serial port,
writing a byte to a serial line would be a rather tedious process-requiring turning on and off
one of the I/O lines in rapid succession to properly "clock out" each individual bit, including
start bits, stop bits, and parity bits. However, we do not have to do this. Instead, we simply
need to configure the serial ports operation mode and baud rate. Once configured, all we have
to do is write to an SFR to write a value to the serial port or read the same SFR to read a
value from the serial port.

The LPC2148 will automatically let us know when it has finished sending the character we
wrote and will also let us know whenever it has received a byte so that we can process it. We
do not have to worry about transmission at the bit level--which saves us quite a bit of coding
and processing time.

NANDHINI P 20EC1058
U0LCR=0x03 ; // U0LCR: UART0 Line Control Register
// 0x03: disable Divisor Latch access.
U0FCR=0x05 ; // U0FCR: UART0 FIFO Control Register
// 0x05: Clear Tx FIFO and enable Rx and Tx FIFOs
}

void main ()
{
int i;
Arm_Uart0_Init();
while(1)
{
for(i=0;arr[i]!='\0';i++) //arr[] value is send to serial port
{
serial_tr(arr[i]);
}
}
}

NANDHINI P 20EC1058
UART or Serial ports, also called communication (COM) ports, RS-232 ports are bi-
directional. The LPC2148 contain two UARTs. In addition to standard transmit and receive
data lines, the UART1 also provides a full modem control handshake interface.

RESULT:
Thus RS232 serial communication using ARM7 LPC2148 is estabilashed.

NANDHINI P 20EC1058
PROGRAM:
#include <nxp\iolpc2148.h>
#define counter_delay 0x4ffff // Counter Delay ( 1 second approx. )
void delay(unsigned int k)
{
for(int i=0;i<k;i++);
}
void i2c_config(void)
{
PINSEL0|=0X00000050; // To select the Port pins p0.2 and p0.3 as i2c configurable
I2C0CONCLR=0X6C; // To clear all bits in the i2c0 register
I2C0CONSET=0X40; // To enable the i2c
I2C0SCLH=70;
I2C0SCLL=50; // To set clock rate as 100 KHZ
}
void i2c_write(char address,char data)
{
I2C0CONSET=0X20;
delay(50);
while(I2C0STAT!=0x08);
I2C0CONCLR=0X28;

// To send a slave address


I2C0DAT=address;
delay(50);
while(I2C0STAT!=0x18);
I2C0CONCLR=0x08;

//Data has been written to appropriate address


I2C0DAT=data;
delay(50);
while(I2C0STAT!=0x28);

//stop condition
I2C0CONSET=0X10;
I2C0CONCLR=0x08;
delay(50);
}
void counter()
{
unsigned char data[10]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
unsigned char s=0;
int cnt;
for(s=0;s<10;s++) // loop to run the counter
{
i2c_write(0x40,data[s]); // writing data to 1st digit (LSB)
i2c_write(0x42,data[s]); // writing data to 2nd digit
i2c_write(0x44,data[s]); // writing data to 3rd digit
i2c_write(0x46,data[s]); // writing data to 4th digit (MSB)
i2c_write(0x48,data[s]);

NANDHINI P 20EC1058
SERIAL COMMUNICATION

Aim : To establish RS232 serial communication using ARM7 LPC2148.

Hardware Requirements:

1. Desktop Computer
2. ARM7 LPC2148

Software Requirements:

1. IAR Embedded Workbench


2. Flash Magic

THEORY:
SEVEN SEGMENT DISPLAY

A seven-segment display, less commonly known as a seven-segment indicator, is a form of


display device that is an alternative to the more complex dot-matrix displays. Seven-segment
displays are commonly used in electronics as a method of displaying decimal numeric
feedback on the internal operations of devices.

A seven-segment display, as its name indicates, is composed of seven elements. Individually


on or off, they can be combined to produce simplified representations of the Hindu-Arabic
numerals. Each of the numbers and may be represented by two or more different glyphs on
seven-segment displays.

The seven segments are arranged as a rectangle of two vertical segments on each side with
one horizontal segment on the top and bottom. Additionally, the seventh segment bisects the
rectangle horizontally. There are also fourteen-segment displays and sixteen-segment
displays (for full alphanumeric); however, these have mostly been replaced by dot-matrix
displays. Often the seven segments are arranged in an oblique, or italic, arrangement, which
aids readability.

The letters A to G refers to the segments of a 7-segment display.

i2c_write(0x4A,data[s]);

NANDHINI P 20EC1058
delay(counter_delay); // Counter Delay ( 1 second approx. )
}
}
void main(void)
{
unsigned char i,address[6]={0x40,0x42, 0x44, 0x46, 0x48, 0x4A};
i2c_config(); // confugring I2C for 7 segment driver .
for(i=0;i<6;i++) {i2c_write(address[i],0x00);} // making all 7 segment blank.
while(1)
{
counter();
} // counting upto cunnting limit.
// Here counting limit is 110.
}

NANDHINI P 20EC1058
RESULT:

Thus RS232 Serial Communication using ARM7 LPC2148 is estabilashed.

NANDHINI P 20EC1058

You might also like