Interfacing with LED, LCD, GLCD, KEYPAD

Updated on 2017/06/21 11:06

Syllabus

Interfacing with LED, LCD, GLCD, KEYPAD

LED Interfacing with LPC2148

Schematic Diagram

LED.png

Interfacing Description

Port Pin No.LED 
P0.15D1
P0.16D2
P0.17D3
P0.18D4
P0.19D5
P0.20D6
P0.21D7
P0.22D8

Embedded C code for the Interfacing

#include<lpc21xx.h> 
void delay_lcd(void);
void delay(void)
{
unsigned int j;  
for(j=0;j<1000000;j++);
return;
}
int main (void)
{
IODIR0 = 0x007F8000; //configure P0.16 to P0.22 as output pins
while (1)                            //Loop forever   
{     
IOSET0=0x007F8000; //turn LEDs ON by setting P0.16 to P0.22 as High   
delay();
IOCLR0=0x007F8000; //turn LEDs Off by setting P0.16 to P0.22 as Low
delay();   
}
}

LCD Interfacing with LPC2148

Schematic Diagram

LCD.png

Interfacing Description

LPC2148 Port Pin No.LCD Pins
P1.16D0
P1.17D1
P1.18D2
P1.19D3
P1.20D4
P1.21D5
P1.22D6
P1.23D7
P1.25RS
P0.29EN
P0.10BC

Embedded C code for the Interfacing

#include<lpc21xx.h>
void lcdcmd(unsigned int cmd);
void lcddata(unsigned int data);
void delay(unsigned int itime);
int main()
{
  PINSEL0=0X00000000;
  PINSEL1=0X00000000;
  PINSEL2=0X00000000;
  IODIR0=0X20000400;
  IODIR1=0X02FF0000;
  IOCLR0=0X00000400;
  lcdcmd(0x38);
  delay(100);
  lcdcmd(0x06);
  delay(100);
  lcdcmd(0x01);
  delay(100);
  lcdcmd(0x0e);
  delay(100);
  lcdcmd(0x80);
  delay(100);
 unsigned char array[]="SKNCOE PUNE";
 unsigned int i=0;
 for(i=0;i<6;i++)
  {
    lcddata(array[i]);
    delay(1000);
   
  }
  lcdcmd(0xc0);
  delay(100);
 for(i=7;i<11;i++)
  {
   lcddata(array[i]);
    delay(1000);
  }
 return 0;
}
void delay(unsigned int itime)
{
 int i,j;
 for(i=0;i<itime;i++)
 for(j=0;j<200;j++);
}
void lcdcmd(unsigned int cmd )
{
 IOCLR1=0X00FF0000;
 cmd=cmd<<16;
 IOSET1=cmd;
 IOCLR1=0X02000000;
 IOSET0=0X20000000;
 delay(100);
 IOCLR0=0X20000000;
}
void lcddata(unsigned int data )
{
 IOCLR1=0X00FF0000;
 data=data<<16;
 IOSET1=data;
 IOCLR1=0X02000000;
 IOSET0=0X20000000;
 delay(100);
 IOCLR0=0X20000000;
}

Keypad Interfacing with LPC2148

Schematic Diagram

keyboard_interfacing.png

Interfacing Description

LPC2148 Port Pin No.LCD Pins
P1.16D0
P1.17D1
P1.18D2
P1.19D3
P1.20D4
P1.21D5
P1.22D6
P1.23D7
P0.28RS
P0.29EN
P0.10BC
LPC2148 Port Pin No.Keyboard connection

P0.2,P0.3,P0.4,P0.5

Column Read Lines
 P0.6,P0.7,P0.8,P0.9Row Scan Lines

Embedded C program for the Interfacing

void lcdcmd(unsigned int);
void lcddata(unsigned int);
void delay_lcd(void);
int main(void)
{
   while(1)
{  
 IODIR1=0x00ff0000;
 IODIR0=0x300003c0;
 lcdcmd(0x38);
 lcdcmd(0x0e);
 lcdcmd(0x01);
 lcdcmd(0x06);
 lcdcmd(0x83);
 lcdcmd(0xC0);
IO0PIN=0x00000380;// First Scan Line(row status)
if(( IO0PIN & 0x0000003c )!= 0x0000003c))////(row & column)
{
switch(IO0PIN & 0x0000003c)
 {
case 0x00000038 : lcddata("C");break;
case 0x00000034 : lcddata("D");break;
case 0x0000002c : lcddata("E");break;
case 0x0000001c : lcddata("F");break;
 }
 }
 IO0PIN=0x00000340;// Second Scan Line(row status)
if(( IO0PIN & 0x0000003c )!= 0x0000003c) )////(row & column)
{
switch(IO0PIN & 0x0000003c)
 {
case 0x00000038 : lcddata("8");break;
case 0x00000034 : lcddata("9");break;
case 0x0000002c : lcddata("A");break;
case 0x0000001c : lcddata("B");break;
 }
 }
        IO0PIN=0x000002c0;// Third Scan Line(row)
if(( IO0PIN & 0x0000003c )!= 0x0000003c)////(row & column
{
switch(IO0PIN & 0x0000003c)
 {
case 0x00000038 : lcddata("4");break;
case 0x00000034 : lcddata("5");break;
case 0x0000002c : lcddata("6");break;
case 0x0000001c : lcddata("7");break;
 }
 }
 IO0PIN=0x000001c0; // Four Scan Line(row)
 if(( IO0PIN & 0x0000003c )!= 0x0000003c)////(row & column)
{
switch(IO0PIN & 0x0000003c)
 {
case 0x00000038 : lcddata("0");break;
case 0x00000034 : lcddata("1");break;
case 0x0000002c : lcddata("2");break;
case 0x0000001c : lcddata("3");break;
 }
 }
 delay_lcd();
}
}
void lcdcmd(unsigned int cmddata)
{
 IOCLR1=0x00ff0000;
 IOCLR0=0x10000000;
 cmddata=cmddata<<16;
 IOSET1=cmddata;
 IOSET0=0x20000000;
 delay_lcd();
 IOCLR0=0x20000000;
 delay_lcd();
return;
}
void lcddata(unsigned int outdata)
{
 IOCLR1=0x00ff0000;
 IOSET0=0x10000000;
 outdata=outdata<<16;
 IOSET1=outdata;
 IOSET0=0x20000000;
 delay_lcd();
 IOCLR0=0x20000000;
 delay_lcd();
return;
}
void delay_lcd(void)
{
int j;
for(j=0;j<10000;j++);
return;
}

References

  • WikiNote Foundation
  • Prof. Sujit Wagh
Tags:
Created by 1stVolunteer on 2017/06/21 11:06