Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

lcd keypad of lpc 2148 arm

Status
Not open for further replies.

bhoomi_29

Newbie level 5
Joined
Jul 6, 2012
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,350
I am doing lcd keypad interface on arm lpc 2148...my code takes some random value and displays that.it is not taking key pressed value...I am attaching code.please help me in this.
Code:
#include <LPC214X.H>
void init_keyb(void);
void init_lcd(void);
unsigned char read_key(void);
unsigned char decode(int, int);
int get_row(int);
int get_col(int);
unsigned char mat(int, int);
void cmd(unsigned char);
void datal(unsigned char);
void delay(int);

int main ()
 { 

 

  unsigned char f=0xFF;			  //for unpressed key


  // PINSEL0 = 0x00000000;		// Enable GPIO on all pins
// PINSEL1 = 0x00000000;
// PINSEL2 = 0x00000000;


  init_keyb();
  init_lcd();
  
  while (1)
   {
	f = read_key();
    if (f!=0xFF)				  //if no key is pressed then continue polling
    datal(f);
	else
	continue;
   }
 }


void init_keyb(void)
 {
  IODIR1 = 0x00000000;			  //making rows as I/P and columns as O/P
 }

void init_lcd(void)
 {
  IODIR0 = 0x007F0000;

  cmd(0x28);
  cmd(0x01);
  cmd(0x02);
  cmd(0x06);
  cmd(0x0C);

 }

unsigned char read_key()
 {
  int row=0,col=0,i;
  unsigned char f=0xFF;
  
  IOSET1 = 0x01E00000;		      //making rows as I/P and columns as O/P

  row = IOPIN1 & 0x001E0000;

  IOSET1 = 0x001E0000;			  //making rows as O/P and columns as I/P

  col = IOPIN1 & 0x01E00000;

  IOSET1 = 0x01E00000;			  //making rows as I/P and columns as O/P

  f = decode(row,col);

  return (f);
 }


unsigned char decode(int row, int col)
 {
  int r=0,c=0;
  unsigned char f=0xFF;

  r=get_row(row);

  c=get_col(col);

  if (r!=0xFF && c!=0xFF)
     f=mat(r,c);
  else
     f=0xFF;
  return (f);
 }

unsigned char mat(int r, int c)
 {
  unsigned char m[4][4]={{'A','B','C','D'},
                         {'E','F','G','H'},
						 {'I','J','K','L'},
						 {'M','N','O','P'},
                        };
  unsigned char f;
  f=m[r][c];
  return (f);
 }

int get_row(int row)
 {
  int r=0xff;
  
  switch (row ^ 0x001E0000)
   {
    case 0x00020000:
	     r=0;
	     break;

	case 0x00040000:
	     r=1;
		 break;

	case 0x00080000:
	     r=2;
		 break;

	case 0x00100000:
	     r=3;
		 break;

	default:
	  	 break;
   }
  return (r);
 }

int get_col (int col)
 {
  int c=0xff;
  
  switch (col ^ 0x01E00000)
   {
    
	case 0x00200000:
	     c=0;
		 break;

	case 0x00400000:
	     c=1;
		 break;

	case 0x00800000:
	     c=2;
		 break;

	case 0x01000000:
	     c=3;
		 break;

	default:
	     break;
   }
  return (c);
 }

void cmd(unsigned char com)
 {
  int a=0;
  a=com&0xF0;
  a=a<<15;

  IOCLR0 = 0x007f0000;
  IOSET0 = 0x00010000;
  
  IOSET0 = a;
  delay(10000);

  IOCLR0 = 0x00010000;
  
  a=com&0x0F;
  a=a<<19;

  IOCLR0 = 0x007f00;
  IOSET0 = 0x00040000;

  IOSET0 = a;
  delay(10000);

  IOCLR0 = 0x00040000;
 }

void datal(unsigned char d)
 {
  int b=0;
  b=d&0xF0;
  b=b<<15;

  IOCLR0 = 0x007f0000;
  IOSET0 = 0x00050000;

  IOSET0 = b;
  delay(10000);

  IOCLR0 = 0x00040000;

  b=d&0x0F;
  b=b<<19;

  IOCLR0 = 0x007f00;
  IOSET0 = 0x00070000;

  IOSET0 = b;
  delay(10000);

  IOCLR0 = 0x00040000;
 }

void delay(int count)
 {
  int i=0,j=0;
  for (i=0;i<count;i++)
     for (j=0;j<35;j++);
 }
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top