Discussion in "ARM Development" started by    xmc2330    Feb 11, 2012.
Sat Feb 11 2012, 04:18 pm
#1
ok, hellao gods of ARM programming coming to the point.
i m a M.Sc Electronics Student and now i have been told to interface the keypad on the Dev kit
the board is Called Spirit II from Oasis, it has a LPC2148.
the keypad is a matrix keypad. now whats done here is, its connected to a resistor array and the resistor array has a Vcc given to it.
so.
when i make the rows as input and columns as output
the rows become high by default
if the columns are made input
they become high by default

Algorithm
Set Keypad pins to output
initially clear the port
so now, i make rows high read columns
i mae columns high read rows,
and the result
left shift answer by 2
send value to main
Take the Value and Switch

#include<lpc21xx.h>

#include<lcd.h>

#include<oasis_key.h>

unsigned key;    
char k_value;
int main(void)
{
	PINSEL2=0x00000000;	//mode of operation 
	PINSEL0=0x00000000;	//mode of operation
	IODIR0 |= 0x0000183C;
	make_out_lcd_port();
	lcd_init();	
	clr_lcd_port();delay();
	lcd_cmd(0x00800000);delay();clr_lcd_port();
	lcd_cmd(0x00010000);delay();clr_lcd_port();
	lcd_data('X');delay();clr_lcd_port();
	while(1)
	{
		key=key_read();				
		switch(key)
				{
	case 0x81 : k_value='1';break;
	case 0x82 : k_value='2';break;
	case 0x84 : k_value='3';break;
	case 0x88 : k_value='A';break;
		
	case 0x41 : k_value='4';break;
	case 0x42 : k_value='5';break;
	case 0x44 : k_value='6';break;
	case 0x48 : k_value='B';break;

	case 0x21 : k_value='7';break;
	case 0x22 : k_value='8';break;
	case 0x24 : k_value='9';break;
	case 0x28 : k_value='C';break;
								
	case 0x11 : k_value='*';break;
	case 0x12 : k_value='0';break;
	case 0x14 : k_value='#';break;
	case 0x18 : k_value='D';break;

	case 0x00 : k_value='N';break;
	  }

		lcd_cmd(0x00C00000);delay();clr_lcd_port();
		lcd_data(k_value);delay();clr_lcd_port();
	}
} 
	
//LCD MOdule

#include<lpc21xx.h>

int i;
#define lcd_rs 0x00000800	//defines rs pin
#define lcd_en 0x00001000	//defines en pin
#define lcd_port 0x00FF0000	//defines lcd port
#define make_out_en_rs() IODIR0 |= (lcd_rs | lcd_en)	//makes en,rs output
#define make_out_lcd_port() IODIR1 |= lcd_port		//makes lcd port out
#define clr_lcd_port() IOCLR1 |= lcd_port		//clears lcd port
#define lcd_rs_set() IOSET0 |= lcd_rs
#define lcd_en_set() IOSET0 |= lcd_en
#define lcd_rs_clr() IOCLR0 |= lcd_rs
#define lcd_en_clr() IOCLR0 |= lcd_en
void delay()
{
for(i=0;i<40000;i++);
}
void lcd_cmd(unsigned int value)
{
IODIR0 |= 0x0000183C;
lcd_rs_clr();
IOSET1=value;
lcd_en_set();
lcd_en_clr();
delay();
}

void lcd_data(unsigned char val)
	{
	unsigned result;
	IODIR0 |= 0x0000183C;
	result=val;
	for(i=0;i<16;i++)
		{result=result<<1;}
	lcd_rs_set();
	IOSET1=result;
	lcd_en_set();
	lcd_en_clr();
	delay();
	}

void char_string(char a)
{
lcd_data(a);
clr_lcd_port();delay();
}

void lcd_init()
{
	lcd_cmd(0x00380000);delay();
	clr_lcd_port();

	lcd_cmd(0x000C0000);delay();
	clr_lcd_port();
}

//keypad library
void debounce(void);
int keyread (void);

unsigned key_read(void)
{
	unsigned rows,columns,result;

	IODIR0=0x000003FC;
	IOCLR0=0x00000FFF;
	IOSET0=0x000003C0;
	columns=IOPIN0;
	
	IOCLR0=0x00000FFF;
	IOSET0=0x0000003C;
	rows=IOPIN0;

	debounce();
	result=rows & columns;
	result=result>
>
2;
	result=result & 0x000000FF;
	
	return(result);
	}

void debounce(void)
{
	unsigned int j;
	for (j=0;j<200000;j++)   
	{	
	}	
}




Pin 0.2 ROW1
Pin 0.3 ROW2
Pin 0.4 ROW3
Pin 0.5 ROW4
Pin 0.6 COl1
Pin 0.7 COl2
Pin 0.8 COl3
Pin 0.9 COl4

Pin 0.11 RS
Pin 0.12 EN

Code Is Working, Detecting Keys Fine, i m happy

Present Problem :
Keys are arranged in this fashion

1 2 3 A
4 5 6 B
7 8 9 C
* 0 # D

Keys 1,2,4,5,7,8,*,0 are not Getting Detected zzz

Anyone With Any Suggestions Pls Comment, Any Help will do


[ Edited Wed Feb 15 2012, 11:55 pm ]
Wed Feb 15 2012, 12:41 pm
#2
Help Pl0x

2 Lines are not responding.

i used a multimerer its showing the change but its not showing the output

what works gives a change from 3.3v -> 1.5v
what dosnt give a change is transition of 3.3v -> 0v

any idea what the problem could be guys?


[ Edited Wed Feb 15 2012, 11:55 pm ]
Wed Feb 15 2012, 04:13 pm
#3
@ xmc2330
here less peoples that works on ARM
Ajay can help u as well as Experiment UK
Wed Feb 22 2012, 04:33 am
#4
its more about logic that working on controller here...
can you explain what your key_read() function doing?
Thu Feb 23 2012, 12:08 am
#5
the port is made Output (IOPIN reads high/low irrespective of direction set, its all on the value @ the Pin @ that time)
Columns are made High, Rows are captured
Rows are made high Columns are captured.
The Result is AND'd and a unique value is obtained here, this is returned to the main, the value is the key pressed which is switched.

the problem is
only the 1st 2 lines are not working, other 2 lines are fine. its kinda weird though, if something was wrong, it shouldn't have read the remaining rows correct too, it reads my A,B,C,D and 3,6,8,# correct. my point is if its a problem with the code the mapping should come wrong, but the mapping is coming right, only the other keys are going undetected
Sun Mar 04 2012, 03:33 am
#6
dont you think you need to reset the direction when making rows high in keyread function? or else your IOSET/IOCLR wont take effect.
Sun Mar 04 2012, 05:19 pm
#7
nope dont need to reset. it keeps the previous value,
tried that btw

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

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
ktaletrryp
Fri Apr 26 2024, 10:55 pm
Robertrip
Fri Apr 26 2024, 11:20 am