Discussion in "ARM Development" started by    Rakesh hasija    Aug 27, 2009.
Thu Aug 27 2009, 09:54 pm
#1
i want to interface 2x2 keypad with 4x20 lcd using arm controller lpc2109.I Know Interface diagram but i facing problem in programing.i m using C programing.
Since i have four keys i.e k1:menu,k2:UP,k3:Down,K4:enter.BY pressing K1 i enter into Menu MODE and some Parameter are Displayed and that Parameter hav numerical value which should be incremented or decremented by k2 and k3.finally next parameter will cume after pressing k4.i want c routine for that very badly, plz reply as sun as possible
Sun Aug 30 2009, 02:45 pm
#2
post your circuit here.. i would look into it. If you've written any codes for it. do post here.

We all can help but wont be giving out any codes or stuff.. we will make sure you finish your project.

[Topic moved to ARM Development Forum]
Mon Aug 31 2009, 10:09 pm
#3
/* 5 keys interface routines 
K1 	k2	k3	k4	k5
PRG ENT UP  DN
P0.11	P0.12	P0.13	P0.14	P0.15 */



#include <Philips\LPC2138.h>
#include "LCD.h"


#define k1 0x00000800   //P0.11
#define k2 0x00001000   //P0.12
#define k3 0x00002000   //P0.13
#define k4 0x00004000   //P0.14
#define k5 0x00008000   //P0.15



void init_keys()
{
     
    IO0DIR &= (0xFFFF07FF); //INPUT - 0
}
int key_pressed(){
    unsigned long val;
      val = IO0PIN;
      
      if (!(val&k1)){
            return 1;
      }
       
      if (!(val&k2)){
            return 2;
      }
       
      if (!(val&k3)){
            return 3;
      }
       
      if (!(val&k4)){
            return 4;
      }
      
      if (!(val&k5)){
            return 5;
      }
      return 0;
}

void keypad()
{
int i;
 while(1){
        i=key_pressed();
       	     
              lcd_clrscr ();
               if(i=1)      /*program mode*/
                {
                  program();
                  if(i=2)
                  enter();
                  if(i=3)
                  up();
                  if(i=4)
                  down();
                 }
              
 }
 void program()
 {
        DisplayRow(1,l8);
		DisplayRow(2,l6);
		DisplayRow(3,l7);
	    lcd_setpos(2,4);
	    cur_on();
	    cur_blink();
  
 }
 void enter()
 {
 int i; 
        DisplayRow(1,l8);
		DisplayRow(2,l6);
		DisplayRow(3,l7);
        lcd_setpos(2,4);
	    cur_on();
	    cur_blink();
	    i=key_pressed();
	     if(i=2)
	     {
	      lcd_setpos(2,9);
	     cur_on();
	     cur_blink();
	     }

}
void up()
{
DisplayRow(1,l8);
		DisplayRow(2,l6);
		DisplayRow(3,l7);
        lcd_setpos(2,4);
	     cur_on();
	     cur_blink();
 }  
 void down()
 {
        DisplayRow(1,l8);
		DisplayRow(2,l6);
		DisplayRow(3,l7);
        lcd_setpos(2,4);
	     cur_on();
	     cur_blink();
	     }
}


[ Edited Wed Sep 02 2009, 05:57 pm ]
Mon Aug 31 2009, 10:11 pm
#4
Dis is my code for key control.plz check it n help me in controlling parameter up/down.
Mon Nov 02 2009, 10:41 am
#5
something wrong here

:

if(i=1) /*program mode*/
{
program();
if(i=2)
enter();
if(i=3)
up();
if(i=4)
down();
}

the above code will wok only if you get more than one values i.e. 1 and 2,3,4 etc...
which i beleive is not possible..
check the routine ...
Tue Nov 03 2009, 02:43 pm
#6
code will run very fast, in while(1) loop if you have pressed key1, then you will continue to clear screen again and again and will not be able to see anything.

also you cannot press two keys at the same time so

following part of code will never execute..

if(i=1) /*program mode*/
{
program();
if(i=2) //this
enter();
if(i=3)//this
up();
if(i=4)//and this
down();
}

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Clydehet
Wed May 01 2024, 06:44 pm
Davidoried
Wed May 01 2024, 06:11 pm
KevinTab
Sun Apr 28 2024, 05:35 am
Tumergix
Sun Apr 28 2024, 12:59 am
StevenDrulk
Sat Apr 27 2024, 08:47 pm
StephenHauct
Sat Apr 27 2024, 09:38 am
Adamsaf
Sat Apr 27 2024, 07:12 am
Robertphype
Sat Apr 27 2024, 12:23 am