Vous êtes sur la page 1sur 6

/* Interface program for LCD Interface for MCB2140 board */ #include <LPC21xx.H> //#include <stdio.

h> #define CR 0xd unsigned char mess[] = {'I','S',' ','T','Y','P','E','D',0x00}; unsigned char disp1[] = {'T','H','I','S',' ','I','S',' ','C','L','O','C','K',0x0 0}; unsigned char disp2[] = {'60',' ','S','E','C','O','N','D',' ','C','M','P','T',0x 00}; /*Function to dislay a character on the Console (Hyperterminal)*/ int putchar(int ch) { if(ch == '\n') { while(!(U1LSR & 0x20)); U1THR = CR; } while(!(U1LSR & 0x20)); return (U1THR = ch); } /*Function to send a string to Console (Hyperterminal) */ void sendstr(char *p) { while(*p) { putchar(*p++); } } /* Function to read a character from Keyboard through Serial Port */ 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 ++)

{} } } /* Function to display the character entered from the keyboard */ void Disp_Key(unsigned long c) { unsigned int x; unsigned long l; l = c << 16; IOCLR1 = 0x00FF0000; IOSET1 = l; IOCLR0 = 0x003F8000; IOSET0 = 0xfa << 15; IOCLR0 = 0x003F8000; IOSET0 = 0xf9 << 15; IOCLR0 = 0x003F8000; IOSET0 = 0xfd << 15; IOCLR0 = 0x003F8000; IOSET0 = 0xf9 << 15; IOCLR0 = 0x003F8000; x = 0x50; delay(x); }

/* E /* 0 /* 0 /* 1 /* 0

R/W* RS */ 1 0 */ 0 0 0 1 */ 1 */ 1 */

/* Function to issue the series of commands to the LCD module */ void Command_Write(unsigned long com_word) { unsigned int x; IOCLR1 = 0x00FF0000; IOSET1 = com_word; LCD through GPIO1 */ IOCLR0 = 0x003F8000; IOSET0 = 0xfb << 15; IOCLR0 = 0x003F8000; IOSET0 = 0xf8 << 15; IOCLR0 = 0x003F8000; IOSET0 = 0xfc << 15; IOCLR0 = 0x003F8000; IOSET0 = 0xf8 << 15; IOCLR0 = 0x003F8000; x = 0x50; delay(x); }

/* Send commands to the /* E /* 0 /* 0 /* 1 /* 0 R/W* RS */ 1 1 */ 0 0 0 0 */ 0 */ 0 */

/* 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 ++; }

} void Disp_String2(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; given for the voltage rise from 0V to 5V */ delay(j); command = 0x38 << 16; for the LCD module */ Command_Write(command); j = 0x13F; delay(j); command = 0x38 << 16; line 5*7 font */ Command_Write(command); command = 0x0c << 16; l. Diplay on, cursor off, */ Command_Write(command); command = 0x10<< 16; */ Command_Write(command); command = 0x01 << 16; */ Command_Write(command); } 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 = 0x30,h=0x00,z=0x00, q=0x3a,w,e,d,q1=0x3a,r,t; T0PR = 0x000002ee0; /* Delay /* Issue software reset

/* Function set 8-bit, 1 /* Display on off contro /* blink off */ /* Clear the LCD display /* Clear the LCD display

T0MR0= 0x000003e7; T0MCR = 0x00000002; T0EMR = 0x0020; PINSEL0 = 0x00050000; PINSEL1 = 0x00000000; PINSEL2 = 0x00000004; IODIR0 = 0x007FB0FC; and GPIO1 as O/P ports */ IODIR1 = 0x00FF0000; U1LCR = 0x83; U1DLL = 97; U1LCR = 0x03; /* Initialize LCD module */ LCD_init(); com_word = 0x80 << 16; Command_Write(com_word); //LCD related work //while(1); T0TCR = 0x01;

/* Enable RxD1 and TxD1 */ /* Configure the GPIO0 /* 8 bits, no Parity, 1 Stop bit */ /* 9600 Baud Rate @ 15MHz VPB Clock */

while(!(T0EMR & 0X01)); T0EMR &= 0xFFFE; com_word = 0x80 << 16; Command_Write(com_word); Disp_String1(); while(!(T0EMR & 0X01)); T0EMR &= 0xFFFE; com_word = 0x8d << 16; g the cursor to the home location */ Command_Write(com_word); Disp_Key(q); } delay1(); delay1(); G FOR KEY" message on LCD */ // sendstr("\nEnter any key to clear the display : "); c = getchar(); com_word = 0x01 << 16; ay */ Command_Write(com_word); com_word = 0x80 << 16; the home location */ Command_Write(com_word); /* T0TCR = 0x01; //delay1(); T0TCR = 0x01; while(1) { /* Clears the LCD Displ /* Bring the cursor to /* Brin

/* Displays the "WAITIN

for(r=0x30;r<=0x32;r++) { while(!(T0EMR & 0X01)); T0EMR &= 0xFFFE; com_word = 0xc0 << 16; g the cursor to the home location */ /* Command_Write(com_word); Disp_Key(r); for(t=0x30;t<=0x33;t++) { while(!(T0EMR & 0X01)); T0EMR &= 0xFFFE; com_word = 0xc1 << 16; g the cursor to the home location */ /* Command_Write(com_word); Disp_Key(t); for(w=0x30;w<=0x35;w++) { while(!(T0EMR & 0X01)); T0EMR &= 0xFFFE; com_word = 0xc3 << 16; g the cursor to the home location */ Command_Write(com_word); /* Disp_Key(w); for(e=0x30;e<=0x39;e++) { while(!(T0EMR & 0X01)); T0EMR &= 0xFFFE; com_word = 0xc4 << 16; g the cursor to the home location */ Command_Write(com_word); Disp_Key(e); for(z=0x30;z<=0x35;z++) { while(!(T0EMR & 0X01)); T0EMR &= 0xFFFE; com_word = 0xc6 << 16; g the cursor to the home location */ Command_Write(com_word); Disp_Key(z); for(c=0x30;c<=0x39;c++) { while(!(T0EMR & 0X01)); T0EMR &= 0xFFFE; com_word = 0xc7 << 16; g the cursor to the home location */ Command_Write(com_word); Disp_Key(c); com_word = 0xc5 << 16; g the cursor to the home location */ Command_Write(com_word); Disp_Key(q); com_word = 0xc2 << 16; /* Bring the cursor to the home location */ Command_Write(com_word); /* Brin /* Brin

/* Brin

/* Brin

/* Brin

/* Brin

/* Brin

Disp_Key(q1); } } } } } } sendstr("\nEnter Key : "); layed on the display */ c = getchar(); Disp_Key(c); key entered */ com_word = 0xc0 << 16; Command_Write(com_word); Disp_Message(); "IS TYPED" message on LCD */ com_word = 0x02 << 16; Command_Write(com_word); x = 10; delay(x); } }

/* Enter the key to be disp /* Displays the

/* Displays the

Vous aimerez peut-être aussi