Sign in

username:

password:



Not a member?

Search lpc2000



Search tips

Subscribe to lpc2000



lpc2000 by Keywords

2106 | ADC | ARM7 | Atmel | Bootloader | CAN | CrossStudio | CrossWorks | DDS | ECos | Ethernet | ETM | FIFO | FLASH | FPGA | GCC | GDB | GNU | GNUARM | GPIO | I2C | IAP | IAR | JTAG | Kickstart | LCD | Linux | LPC | LPC-E2294 | LPC2000 | LPC2100 | LPC2104 | Lpc2106 | Lpc210x | LPC2114 | LPC2119 | LPC2124 | LPC2129 | Lpc2138 | LPC213x | LPC21xx | LPC2210 | LPC2212 | LPC2214 | LPC2292 | LPC2294 | LPC2xxx | LPC3128 | MCB2100 | Olimex | Philips | PWM | Rowley | RTC | RTOS | SPI | SSP | UART | UART0 | UART1 | ULINK | USB | Watchdog | Wiggler


Ads

Discussion Groups

See Also

DSPFPGAElectronics

Discussion Groups | LPC2000 | LPC2368 input port problem...


Advertise Here

Discussion group dedicated to the Philips LPC2000 family of ARM MCUs

LPC2368 input port problem... - "luk...@rocketmail.com" - Mar 22 7:42:01 2009

Hi everyone,

I have been banging my head against a wall trying to figure out what's going wrong with a little program im trying to write. Basically Im taking an analog singal, comparing it to a reference signal input (p0.4~07) from a 4x4 keypad via a MM74C992 keypad decoder IC and outputing a trigger signal on p2.0~7. I have the output port working perfectly, however im having great difficulty getting the input from the keypad decoder IC (4bit binary). Can anyone give me a pointer to how I can go about getting a function to get the keypad input port working?

Inputs:
bit0 = p0.4
bit1 = p0.5
bit2 = p0.6
bit3 = p0.7
data available input pin = p1.20

Returning the input to the main program for comparison to the analog input.

I know this may seem similar to many of the uni students questions but believe me im well past that part of my life... I have been programming assembly using the old HC11+12 uC's for some time and this is my first ARM7 uC with the programming done completely in C (a requirement of the job spec.)

Any help would be greatly appreciated,

Cheers,

Luke

------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )


Re: LPC2368 input port problem... - rtstofer - Mar 22 12:20:35 2009

--- In l...@yahoogroups.com, "lukenyhof@..." wrote:
>
> Hi everyone,
>
> I have been banging my head against a wall trying to figure out what's going wrong with a little program im trying to write. Basically Im taking an analog singal, comparing it to a reference signal input (p0.4~07) from a 4x4 keypad via a MM74C992 keypad decoder IC and outputing a trigger signal on p2.0~7. I have the output port working perfectly, however im having great difficulty getting the input from the keypad decoder IC (4bit binary). Can anyone give me a pointer to how I can go about getting a function to get the keypad input port working?
>
> Inputs:
> bit0 = p0.4
> bit1 = p0.5
> bit2 = p0.6
> bit3 = p0.7
> data available input pin = p1.20
>
> Returning the input to the main program for comparison to the analog input.
>
> I know this may seem similar to many of the uni students questions but believe me im well past that part of my life... I have been programming assembly using the old HC11+12 uC's for some time and this is my first ARM7 uC with the programming done completely in C (a requirement of the job spec.)
>
> Any help would be greatly appreciated,
>
> Cheers,
>
> Luke
>

It's hard for me to tell exactly where you are with the ARM. You might try posting some code.

Maybe something like this would work:

if ( (IOPIN1 & (1<<20)) ) {
val = (I0PIN0 >> 4) & 0x0000000F;
}

You didn't say which device you were using so port names may be different. You might look at the excellent demo code for the LPC2148 at www.jcwren.com/arm Even if you aren't using a 2148, the code will be useful.

Richard

------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: LPC2368 input port problem... - rtstofer - Mar 22 14:04:44 2009

--- In l...@yahoogroups.com, "rtstofer" wrote:

> It's hard for me to tell exactly where you are with the ARM. You might try posting some code.
>
> Maybe something like this would work:
>
> if ( (IOPIN1 & (1<<20)) ) {
> val = (I0PIN0 >> 4) & 0x0000000F;
> }
>
> You didn't say which device you were using so port names may be different. You might look at the excellent demo code for the LPC2148 at www.jcwren.com/arm Even if you aren't using a 2148, the code will be useful.
>
> Richard
>

OOPS! You did say which device you were using in the Subject line. The code should still work but the register names may be different. They are defined in the lpc.h file. I don't use this device so I have no idea what is in the header file.

Richard

------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: LPC2368 input port problem... - "luk...@rocketmail.com" - Mar 22 19:31:32 2009

Here are a couple of the solutions that I have tried...

Solution A
__________
int main(void)
{
int keyPadNo, firstKeyStroke, currentKey;
int keyTable[FOUR_BIT] = {1,2,3,-1,
4,5,6,-1,
7,8,9,-1,
-1,0,-1,-1};
int keyBit1,keyBit2,keyBit3,keyBit4,keyTemp,key;
key = 0;
lcd_init(); // Initialise LCD

PINSEL10 = 0; // Disable ETM interface, enable LEDs
// P2[0:7] = GPIO Function(xxxx 0000 0000 0000 0000 0000 0000 0000)
PINSEL4 = 0xF0000000;
// Enable Pull-Up P2[0:7] (0101 1111 1111 1111 1111 1111 1111 1111)
PINMODE4 = 0x5FFFFFFF;
// Set GPIO-2[0:7] = Output(xxxx xxxx xxxx xxxx xxxx xxxx 1111 1111)
FIO2DIR = 0x0000000F;

SPEAKER_OFF(); // Default Speaker Status
valve1_OFF(); // Default Valve Status
valve2_OFF(); // Default Valve Status
valve3_OFF(); // Default Valve Status
valve4_OFF(); // Default Valve Status

//ensure that this is the pin for dataAvailable
if ((FIO2PIN & (1<<4)) == 0)
{
OutputEnable_ON();
delay(500);
keyBit1 = (FIO2PIN & (1<<0));
keyBit2 = (FIO2PIN & (1<<1));
keyBit3 = (FIO2PIN & (1<<2));
keyBit4 = (FIO2PIN & (1<<3));
while (i=4;i>0;i--){
keyTemp = (FIO2PIN & (1<<[i]));
if (i>0)
keyTemp = keyTemp << 1;
else
key = (FIO2PIN & (1<<[i]));
}
}
else OutputEnable_OFF();

// now convert the input to a logical and relevent value.
// 0 = 1
// 1 = 2
// 2 = 3
// 3 = A
// 4 = 4
// 5 = 5
// 6 = 6
// 7 = B
// 8 = 7
// 9 = 8
// 10 = 9
// 11 = C
// 12 = *
// 13 = 0
// 14 = #
// 15 = D

}

Solution B
__________

#include "lpc23xx.h"
#include

#define KEYMODE_READ 0x00F00000 // p1.20~1.23(0000 0000 1111 0000 0000 0000 0000 0000)
#define OutputEnable 0x00000030 // p0.4~0.5 (0000 0000 0000 0000 0000 0000 0011 0000)
#define FOUR_BIT 16
#define HASH 14

int main(void)
{

}
int getKeyInput(void)
{
int keyPadNo, firstKeyStroke, currentKey;
int keyTable[FOUR_BIT] = {1,2,3,-1,
4,5,6,-1,
7,8,9,-1,
-1,0,-1,-1};
/*Set Direction of I/O Port 1 pins 20 -> 23 to read*/
FIO1DIR |= KEYMODE_READ;
FIO0DIR |= OutputEnable;
/**Get numbers from keypad until hash is pressed**/
/*Set multiplier to 0*/
firstKeyStroke = 1;
/*For loop to monitor keystrokes*/
while(1)
{
/* Read input bit string */
/*Get key input from FIO Port 1 Register, casting it as an integer*/

currentKey = (int)FIO1PIN0;
/*Check if input bit string is "#" if so break*/
if(currentKey == HASH)
{
break;
}
/*Convert bit number into an integer*/
currentKey = keyTable[currentKey];

/*Check if current letter is not a number*/
if(currentKey > 0)
{
/*Check that this is not the first keystroke*/
if(firstKeyStroke == 1)
{
keyPadNo = currentKey;
firstKeyStroke = 0;
}
else
{
keyPadNo=(keyPadNo*10)+currentKey;
}
}
}
return keyPadNo;
}

------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: LPC2368 input port problem... - rtstofer - Mar 22 20:19:17 2009

--- In l...@yahoogroups.com, "lukenyhof@..." wrote:
>
> Here are a couple of the solutions that I have tried...
>
> Solution A
> __________
> int main(void)
> {
> int keyPadNo, firstKeyStroke, currentKey;
> int keyTable[FOUR_BIT] = {1,2,3,-1,
> 4,5,6,-1,
> 7,8,9,-1,
> -1,0,-1,-1};
> int keyBit1,keyBit2,keyBit3,keyBit4,keyTemp,key;
> key = 0;
> lcd_init(); // Initialise LCD
>
> PINSEL10 = 0; // Disable ETM interface, enable LEDs
> // P2[0:7] = GPIO Function(xxxx 0000 0000 0000 0000 0000 0000 0000)
> PINSEL4 = 0xF0000000;
> // Enable Pull-Up P2[0:7] (0101 1111 1111 1111 1111 1111 1111 1111)
> PINMODE4 = 0x5FFFFFFF;
> // Set GPIO-2[0:7] = Output(xxxx xxxx xxxx xxxx xxxx xxxx 1111 1111)
> FIO2DIR = 0x0000000F;
>
> SPEAKER_OFF(); // Default Speaker Status
> valve1_OFF(); // Default Valve Status
> valve2_OFF(); // Default Valve Status
> valve3_OFF(); // Default Valve Status
> valve4_OFF(); // Default Valve Status
>
> //ensure that this is the pin for dataAvailable
> if ((FIO2PIN & (1<<4)) == 0)
> {
> OutputEnable_ON();
> delay(500);
> keyBit1 = (FIO2PIN & (1<<0));
> keyBit2 = (FIO2PIN & (1<<1));
> keyBit3 = (FIO2PIN & (1<<2));
> keyBit4 = (FIO2PIN & (1<<3));

Repeatedly reading the port may not cause a problem but I would do it once like:

temp = FIO2PIN;
keyBit1 = temp & (1 << 0);

> while (i=4;i>0;i--){
I haven't seen this 'while' syntax before. Are you sure?
> keyTemp = (FIO2PIN & (1<<[i]));
> if (i>0)
> keyTemp = keyTemp << 1;
> else
> key = (FIO2PIN & (1<<[i]));
> }
> }
> else OutputEnable_OFF();

This conversion seems strange. I couldn't follow what was going on with the shifting of keyTemp and so on. Why not just grab the 4 bits, convert to an int and index into an array?

>
> // now convert the input to a logical and relevent value.
> // 0 = 1
> // 1 = 2
> // 2 = 3
> // 3 = A
> // 4 = 4
> // 5 = 5
> // 6 = 6
> // 7 = B
> // 8 = 7
> // 9 = 8
> // 10 = 9
> // 11 = C
> // 12 = *
> // 13 = 0
> // 14 = #
> // 15 = D
>
> }
>
There is no loop in main() so this code either executes once and bombs or it is not fully disclosed.

> Solution B
> __________
>
> #include "lpc23xx.h"
> #include #define KEYMODE_READ 0x00F00000 // p1.20~1.23(0000 0000 1111 0000 0000 0000 0000 0000)
> #define OutputEnable 0x00000030 // p0.4~0.5 (0000 0000 0000 0000 0000 0000 0011 0000)
> #define FOUR_BIT 16
> #define HASH 14
>
> int main(void)
> {
>
I assume the test for data available is in main() and it calls getKeyInput()

> }
> int getKeyInput(void)
> {
> int keyPadNo, firstKeyStroke, currentKey;
> int keyTable[FOUR_BIT] = {1,2,3,-1,
> 4,5,6,-1,
> 7,8,9,-1,
> -1,0,-1,-1};
> /*Set Direction of I/O Port 1 pins 20 -> 23 to read*/
> FIO1DIR |= KEYMODE_READ;
> FIO0DIR |= OutputEnable;
> /**Get numbers from keypad until hash is pressed**/
> /*Set multiplier to 0*/
> firstKeyStroke = 1;
> /*For loop to monitor keystrokes*/
> while(1)
> {
> /* Read input bit string */
> /*Get key input from FIO Port 1 Register, casting it as an integer*/
>
> currentKey = (int)FIO1PIN0;
Maybe currentKey = (int) ( (FIO1PIN0 >> 20) & 0x0F);

> /*Check if input bit string is "#" if so break*/
> if(currentKey == HASH)
> {
> break;
> }
> /*Convert bit number into an integer*/
> currentKey = keyTable[currentKey];
>
> /*Check if current letter is not a number*/
> if(currentKey > 0)
> {
> /*Check that this is not the first keystroke*/
> if(firstKeyStroke == 1)
> {
> keyPadNo = currentKey;
> firstKeyStroke = 0;
> }
> else
> {
> keyPadNo=(keyPadNo*10)+currentKey;
> }
> }
> }
> return keyPadNo;
> }
>
Comments embedded

Ruchard

------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: LPC2368 input port problem... - "luk...@rocketmail.com" - Mar 22 20:28:58 2009

Thanks for your assistance Ruchard, I'll post back when I have made a few alterations.

Cheers,

Luke
--- In l...@yahoogroups.com, "rtstofer" wrote:
>
> --- In l...@yahoogroups.com, "lukenyhof@" wrote:
> >
> > Here are a couple of the solutions that I have tried...
> >
> > Solution A
> > __________
> > int main(void)
> > {
> > int keyPadNo, firstKeyStroke, currentKey;
> > int keyTable[FOUR_BIT] = {1,2,3,-1,
> > 4,5,6,-1,
> > 7,8,9,-1,
> > -1,0,-1,-1};
> > int keyBit1,keyBit2,keyBit3,keyBit4,keyTemp,key;
> > key = 0;
> > lcd_init(); // Initialise LCD
> >
> > PINSEL10 = 0; // Disable ETM interface, enable LEDs
> > // P2[0:7] = GPIO Function(xxxx 0000 0000 0000 0000 0000 0000 0000)
> > PINSEL4 = 0xF0000000;
> > // Enable Pull-Up P2[0:7] (0101 1111 1111 1111 1111 1111 1111 1111)
> > PINMODE4 = 0x5FFFFFFF;
> > // Set GPIO-2[0:7] = Output(xxxx xxxx xxxx xxxx xxxx xxxx 1111 1111)
> > FIO2DIR = 0x0000000F;
> >
> > SPEAKER_OFF(); // Default Speaker Status
> > valve1_OFF(); // Default Valve Status
> > valve2_OFF(); // Default Valve Status
> > valve3_OFF(); // Default Valve Status
> > valve4_OFF(); // Default Valve Status
> >
> > //ensure that this is the pin for dataAvailable
> > if ((FIO2PIN & (1<<4)) == 0)
> > {
> > OutputEnable_ON();
> > delay(500);
> > keyBit1 = (FIO2PIN & (1<<0));
> > keyBit2 = (FIO2PIN & (1<<1));
> > keyBit3 = (FIO2PIN & (1<<2));
> > keyBit4 = (FIO2PIN & (1<<3));
>
> Repeatedly reading the port may not cause a problem but I would do it once like:
>
> temp = FIO2PIN;
> keyBit1 = temp & (1 << 0);
>
> > while (i=4;i>0;i--){
> I haven't seen this 'while' syntax before. Are you sure?
> > keyTemp = (FIO2PIN & (1<<[i]));
> > if (i>0)
> > keyTemp = keyTemp << 1;
> > else
> > key = (FIO2PIN & (1<<[i]));
> > }
> > }
> > else OutputEnable_OFF();
>
> This conversion seems strange. I couldn't follow what was going on with the shifting of keyTemp and so on. Why not just grab the 4 bits, convert to an int and index into an array?
>
> >
> > // now convert the input to a logical and relevent value.
> > // 0 = 1
> > // 1 = 2
> > // 2 = 3
> > // 3 = A
> > // 4 = 4
> > // 5 = 5
> > // 6 = 6
> > // 7 = B
> > // 8 = 7
> > // 9 = 8
> > // 10 = 9
> > // 11 = C
> > // 12 = *
> > // 13 = 0
> > // 14 = #
> > // 15 = D
> >
> > }
> >
> There is no loop in main() so this code either executes once and bombs or it is not fully disclosed.
>
> >
> >
> > Solution B
> > __________
> >
> > #include "lpc23xx.h"
> > #include
> >
> > #define KEYMODE_READ 0x00F00000 // p1.20~1.23(0000 0000 1111 0000 0000 0000 0000 0000)
> > #define OutputEnable 0x00000030 // p0.4~0.5 (0000 0000 0000 0000 0000 0000 0011 0000)
> > #define FOUR_BIT 16
> > #define HASH 14
> >
> > int main(void)
> > {
> >
> I assume the test for data available is in main() and it calls getKeyInput()
>
> > }
> >
> >
> > int getKeyInput(void)
> > {
> > int keyPadNo, firstKeyStroke, currentKey;
> > int keyTable[FOUR_BIT] = {1,2,3,-1,
> > 4,5,6,-1,
> > 7,8,9,-1,
> > -1,0,-1,-1};
> > /*Set Direction of I/O Port 1 pins 20 -> 23 to read*/
> > FIO1DIR |= KEYMODE_READ;
> > FIO0DIR |= OutputEnable;
> >
> >
> > /**Get numbers from keypad until hash is pressed**/
> > /*Set multiplier to 0*/
> > firstKeyStroke = 1;
> > /*For loop to monitor keystrokes*/
> > while(1)
> > {
> > /* Read input bit string */
> > /*Get key input from FIO Port 1 Register, casting it as an integer*/
> >
> > currentKey = (int)FIO1PIN0;
> Maybe currentKey = (int) ( (FIO1PIN0 >> 20) & 0x0F);
>
>
> > /*Check if input bit string is "#" if so break*/
> > if(currentKey == HASH)
> > {
> > break;
> > }
> > /*Convert bit number into an integer*/
> > currentKey = keyTable[currentKey];
> >
> > /*Check if current letter is not a number*/
> > if(currentKey > 0)
> > {
> > /*Check that this is not the first keystroke*/
> > if(firstKeyStroke == 1)
> > {
> > keyPadNo = currentKey;
> > firstKeyStroke = 0;
> > }
> > else
> > {
> > keyPadNo=(keyPadNo*10)+currentKey;
> > }
> > }
> > }
> > return keyPadNo;
> > }
> >
> Comments embedded
>
> Ruchard
>

------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )