Sie sind auf Seite 1von 5

EXPERIMENT NO.

3 Date :

AIM OF THE EXPERIMENT:

To display name on the LCD Module in ‘C’ programming using Keil software and to interface it
with MCB2140 board.
REQUIREMENT:

1. Keil MCB 2140 Board


2. Serial Com cable
3. Keil uVision4
4. Flash Magic Version 5.4
5. Power supply
6. LCD module.

PROCEDURE:

1. The board was connected to the system .The power to system was provided using a USB
cable. The system serial port's baud rate was set in accordance with the board.
2. The program for displaying name using LCD was written using Keil uVision4 in C
language.
3. The program was compiled and then the hex file was generated.
4. The Flash Magic was opened and it was initialized by selecting proper settings.
5. Then the hex file was downloaded into the board using Flash Magic Version 5.4.
6. The LCD module was connected to the board and the power supply was given to it.

PROGRAM:
#include <LPC21xx.H>
//#include <stdio.h>
#define CR 0xd
unsigned char disp1[] = {'S','H','R','E','E','T','A ',M' ,' ','S','O','A',0x00};
int putchar(int ch)
{
if(ch == '\n')
{
while(!(U1LSR & 0x20));
U1THR = CR;
}
while(!(U1LSR & 0x20));
return (U1THR = ch);
}
void sendstr(char *p)
{
while(*p)
{
putchar(*p++);
EXPERIMENT NO. 3 Date :

}
}
int getchar (void)
{
while (!(U1LSR & 0x01));
return (U1RBR);
}
void delay(unsigned int x)
{
unsigned int i,j;
for(i = 0; i < 10; i ++)
{
for(j = 0; j < x; j ++)
{}
}
}
void delay1()
{
unsigned int i,j;
for(i = 0; i < 0x50; i ++)
{
for(j = 0; j < 0x4fb; j ++)
{}
}
}
void Disp_Key(unsigned long c)
{
unsigned int x;
unsigned long l;
l = c << 16;
IOCLR1 = 0x00FF0000;
IOSET1 = l;
IOCLR0 = 0x003F8000; /* E R/W* RS */
IOSET0 = 0xfa << 15; /* 0 1 0 */
IOCLR0 = 0x003F8000;
IOSET0 = 0xf9 << 15; /* 0 0 1 */
IOCLR0 = 0x003F8000;
IOSET0 = 0xfd << 15; /* 1 0 1 */
IOCLR0 = 0x003F8000;
IOSET0 = 0xf9 << 15; /* 0 0 1 */
IOCLR0 = 0x003F8000;
x = 0x50;
delay(x);
}
/* Function to issue the series of commands to the LCD module */
void Command_Write(unsigned long com_word)
EXPERIMENT NO. 3 Date :

{
unsigned int x;
IOCLR1 = 0x00FF0000;
IOSET1 = com_word; /* Send commands to the LCD
through GPIO1 */
IOCLR0 = 0x003F8000; /* E R/W* RS */
IOSET0 = 0xfb << 15; /* 0 1 1 */
IOCLR0 = 0x003F8000;
IOSET0 = 0xf8 << 15; /* 0 0 0 */
IOCLR0 = 0x003F8000;
IOSET0 = 0xfc << 15; /* 1 0 0 */
IOCLR0 = 0x003F8000;
IOSET0 = 0xf8 << 15; /* 0 0 0 */
IOCLR0 = 0x003F8000;
x = 0x50;
delay(x);
}
/* Function to read characters from a string and displaying the same by calling the
Disp_key fucntion */
void Disp_String1(void)
{
int i;
i = 0;
while(disp1[i] != 0x00)
{
Disp_Key(disp1[i]);
i ++;
}
}
/* Function to initialize the LCD module */
void LCD_init(void)
{
int j;
unsigned long command;
j = 0x9f; /* Delay given for the voltage rise from 0V to 5V */
delay(j);
command = 0x38 << 16; /* Issue software reset for the LCD module */
Command_Write(command);
j = 0x13F;
delay(j);
command = 0x38 << 16; /* Function set 8-bit, 1 line 5*7 font*/
Command_Write(command);
command = 0x0c << 16; /* Display on off control. Diplay on, cursor off, */
Command_Write(command); /* blink off */
command = 0x01 << 16; ?* Clear the LCD display */
Command_Write(command);
EXPERIMENT NO. 3 Date :

}
void Disp_Message(void)
{
int i;
i = 0;
while(mess[i] != 0x00)
{
Disp_Key(mess[i]);
i ++;
}
}

int main()
{
unsigned long com_word;
unsigned char x;
unsigned char c;
PINSEL0 = 0x00050000; /* Enable RxD1 and TxD1 */
PINSEL1 = 0x00000000;
PINSEL2 = 0x00000004;
IODIR0 = 0x007FB0FC; /* Configure the GPIO0 and GPIO1 as O/P ports */
IODIR1 = 0x00FF0000;
U1LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
U1DLL = 97; /* 9600 Baud Rate @ 15MHz VPB Clock */
U1LCR = 0x03; /* Initialize LCD module */
LCD_init();
com_word = 0x80 << 16;
Command_Write(com_word);
delay1();
delay1();
Disp_String1();
sendstr("\nEnter any key to clear the display : ");
c = getchar();
com_word = 0x01 << 16; /* Clears the LCD Display */
Command_Write(com_word);
com_word = 0x80 << 16; /* Bring the cursor to the home location */
Command_Write(com_word);
while(1)
{
sendstr("\nEnter Key : "); /* Enter the key to be displayed on the display */
c = getchar();
Disp_Key(c); /* Displays the key entered */
delay1();
com_word = 0xc0 << 16;
Command_Write(com_word);
Disp_Message(); /* Displays the "IS TYPED" message on LCD */
EXPERIMENT NO. 3 Date :

com_word = 0x02 << 16;


Command_Write(com_word);
x = 10;
delay(x);
}
}

CONCLUSION:
The LCD registers and its connections were understood and the connections with the micro
controller with the board. The name was used as data for displaying and it was displayed
successfully.

Shreetam Behera
M.Tech 1st year AEI
Regd No.1051015014

Das könnte Ihnen auch gefallen