Keypad

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

Post Reply
rvogel
Posts: 21
Joined: Mon Sep 18, 2006 11:20 pm
Contact:

Keypad

Post by rvogel »

I am trying to use the Keypad component with a 16F88. I have connected the keypad to port A and an LCD to port B. To use port A, I configured for INTRC_IO so I could use A6 and A7. The component pin connections are set to:

Column1 = Bit0
Column2 = Bit1
Column3 = Bit2
RowA = Bit3
RowB = Bit4
RowC = Bit6
RowD = Bit7

At the beginning of the program I inserted:

Code: Select all

asm __CONFIG _CONFIG1, _INTRC_IO & _DEBUG_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_ON & _PWRTE_ON & _WDT_OFF

Code: Select all

asm __CONFIG _CONFIG2, _IESO_ON & _FCMEN_OFF

Code: Select all

asm osccon = 0x70;/sets internal osc to 8MHz

Then it goes on to:

Declare a variable "NUMBER" =255

Macros- Start and Clear LCD

Macro- PrintASCII("S") to LCD

Begin Loop

Macro- GetKeypadNumber with Return Value "Number"

IF NUMBER<>255 THEN Clear LCD and PrintNumber(NUMBER) to LCD

End Loop

When I run the program on the PIC, The "S" displays for about 1 second then screen clears for a second. After that an 11 displays, flashing in 1 second intervals. Sometimes a 10 displays, but mostly 11. If I press a key on the keypad, that number will eventually flash on the display after a few flashes and in between a 10 or 0.

It seems like this is an OSC and a pin configuration issue. Any ideas?
rvogel

rvogel
Posts: 21
Joined: Mon Sep 18, 2006 11:20 pm
Contact:

Post by rvogel »

I tried swapping around the ports. I set the LCD up on port A and the keypad on port B. The slow update of the LCD is still occuring as it was (the 1 second flashing of the characters.) It now flashes with a 10 and 4. ???

The LCD is on A0-A4 and A6
The keypad is on B0-B6.

Also I am using a different daughter board and a different 16F88 PIC. When I first tested the LCD on port A, it gave me the same output but I hadn't connected the keypad to port B yet.
rvogel

User avatar
Steve
Matrix Staff
Posts: 3422
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Post by Steve »

You did not say what hardware you're using - E-Blocks, or something else?

Also, is the 88 in LVP mode - if it is, then RB3 will be unavailable.

The slow execution speed could be a number of things - have you tried making a simple led flasher with your config and clock settings? Make sure the clock speed setting within FlowCode matches your actual clock speed (i.e. 8MHz).

As for the errors in the values displayed, the keypad's "#" and "*" keys give the values 10 and 11 - are they stuck in any way?

rvogel
Posts: 21
Joined: Mon Sep 18, 2006 11:20 pm
Contact:

Post by rvogel »

Sorry, i forgot to say that I am not using the E-Block keypad, but have wired it the same as the E-Block schematic shows, but rather than it going to DB9, it runs to Port B. And I do have it set to 8MHz under clock speed. The keys appear not to be stuck.
Also, I changed the pins that I am using to B0-B2 and B4-B7, but with the same result as I am not LVP.
I tried the flasher test. At first I thought the LED was just staying on, but it was running so slow that a 1 second delay was taking forever. (I set it to flash on and off in 1 second intervals.) So I changed it to a 20ms delay. It then flashed at a rate of 5 sec on/ 5 sec off.

Thanks.
rvogel

User avatar
Steve
Matrix Staff
Posts: 3422
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Post by Steve »

Your program is running 250 times slower than you would expect (5000/20), so instead of 8MHz, it is more likely running at 31.25kHz - the speed of the INTRC oscillator. You want it to run at 8MHz, which is the INTOSC oscillator - yes, there are 2 different internal oscillators within the 16F88.

Try not using "asm" before the "osccon=0x70;" line. This will probably sort that one out.

rvogel
Posts: 21
Joined: Mon Sep 18, 2006 11:20 pm
Contact:

Post by rvogel »

Ok, I have two things going on here. One is that I think the pinout for my keypad is wrong, or I'm wrong or both. Following what my datasheet says:
Column1=KeyPin3
Column2=KeyPin4
Column3=KeyPin4
RowA=KeyPin1
RowB=KeyPin2
RowC=KeyPin8
RowD=KeyPin7

and KeyPin6=NC

I have 10k Res inline on the Column lines and 100k pullups to ground on Rows. This is how the E-Block Keypad is set up. I had a couple connects wrong and found them this am.

Now the readout flashes "4". When I press the "7" and "10", it flashes "7" and "10" correctly. No other buttons worked.

So I read Port B on the PIC while it was flashing "4" and got:

B0=+5v
B1=0
B2=0
B4=+5v
B5=+5v
B6=0
B7=0

When I pressed "7" B6 went high. So I think I need to swap some wires around. Maybe B1<->B4 and B2<->B5 or some other combination.

I removed the "asm" and it wouldn't post. I then removed the spaces in front and behind the "=" sign and it posted fine.

Running it on the PIC gave me no output. I switched the config from INTRC_IO to INTRC_CLKOUT and the output is a bunch of "D"s and "3"s scrolling across the first line of the display. Faster clock rate, but incorrect.

I will try the flashing LED with this new config.

Thanks for the help. Any ideas?
rvogel

User avatar
Steve
Matrix Staff
Posts: 3422
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Post by Steve »

I'm not sure what's going on with the config stuff.

As for the keypad, it is arranged in a matrix of 4 rows and 3 columns. Basically, when one key is held down, it makes a circuit between the row and column of that key.

When it reads a keypad value, the FlowCode component performs a basic scan. It outputs '1' to each row in turn and reads the voltages present on each row. This way, it can work out which key is pressed.

Hopefully this will help you understand what's going on and should help you solve your problem.

rvogel
Posts: 21
Joined: Mon Sep 18, 2006 11:20 pm
Contact:

Post by rvogel »

Yes, the flasher works at the correct speed. I will play the the KeyPins and see what happens. Thanks again.
rvogel

Post Reply