Page 1 of 1

EB006 with PIC16F88 - Keypad problem

Posted: Tue Apr 10, 2012 3:53 pm
by Phaenix
I think I may just be doing it wrong, but I've been breaking my head over it for a while now... I was using this for this configuration/testing strategy: Keypad Board C & Assembly Strategy

Code: Select all

#include <system.h>

void setup_hardware(void)
{
	trisb = 0xF0;
	trisa = 0xE0;
	porta = 0x00;
}

void main(void)
{
	setup_hardware();

	while (1)
	{
		portb = 0x01;

		if ((portb & 0x10) > 0)
		{
			porta = 0x01;
		}
		else if ((portb & 0x20) > 0)
		{
			porta = 0x04;
		}
		else if ((portb & 0x40) > 0)
		{
			porta = 0x03;
		}
		else if ((portb & 0x80) > 0)
		{
			porta = 0x05; // '*' is pressed
		}
		
		portb = 0x02;
		
		if ((portb & 0x10) > 0)
		{
			porta = 0x02;
		}
		else if ((portb & 0x20) > 0)
		{
			porta = 0x05;
		}
		else if ((portb & 0x40) > 0)
		{
			porta = 0x08;
		}
		else if ((portb & 0x80) > 0)
		{
			porta = 0x00;
		}
		
		portb = 0x04;
		
		if ((portb & 0x10) > 0)
		{
			porta = 0x03;
		}
		else if ((portb & 0x20) > 0)
		{
			porta = 0x06;
		}
		else if ((portb & 0x40) > 0)
		{
			porta = 0x09;
		}
		else if ((portb & 0x80) > 0)
		{
			porta = 0x0B; // '+' is pressed
		}
	}
}
Only buttons 1 - 6 are being read, and buttons 1, 2 and 3 don't always read exactly right.

Re: EB006 with PIC16F88 - Keypad problem

Posted: Wed Apr 11, 2012 12:29 pm
by Puddy32
Hi
Just a possibility, have you a ground wire on keypad
if you are getting different readings then some of your connection could be floating.

Re: EB006 with PIC16F88 - Keypad problem

Posted: Wed Apr 11, 2012 1:49 pm
by Phaenix
There are no connectors on the keypad to ground it, not like the switch board has.

Re: EB006 with PIC16F88 - Keypad problem

Posted: Fri Apr 13, 2012 8:54 am
by Phaenix
Does anyone know...? :(

Re: EB006 with PIC16F88 - Keypad problem

Posted: Fri Apr 13, 2012 9:36 am
by Benj
Hello,

Your not giving us much to go on. When you say don't always read exactly right how do you mean?

Are you using a Matrix Keypad E-block or your own hardware?

Re: EB006 with PIC16F88 - Keypad problem

Posted: Fri Apr 13, 2012 9:56 am
by Phaenix
I'm using the Matrix keypad. When I press a button, the corresponding LEDs are supposed to light up. It only does that when I press buttons 1 through 6, 7 to # don't work at all.

When I press buttons 1, 2 or 3 the LEDs lit up, but sometimes they're not the right ones, or too many lit up.

I'm sorry if I'm being confusing... :(

EDIT: this program's purpose was to test the functionality of the keypad. To see if all buttons were working, and to see how they worked exactly. I think I'm doing something wrong.

Re: EB006 with PIC16F88 - Keypad problem

Posted: Fri Apr 13, 2012 10:58 am
by Benj
Hello,

Please refer to the attached C file and it should help you to get the keypad working. I have replicated your setup with the keypad on PortB and the Digits being shown on PortA.

Re: EB006 with PIC16F88 - Keypad problem

Posted: Fri Apr 13, 2012 11:22 am
by Phaenix
Sorry to be a nuisance, but my school hasn't provided me with Flowcode and I don't think they're going to give me one of the licenses they have. Is it possible for you to give me a solution that doesn't require Flowcode headers?

Re: EB006 with PIC16F88 - Keypad problem

Posted: Fri Apr 13, 2012 11:50 am
by Benj
Hello,

The C file is just for an example so you can design your own functions. No Flowcode headers are required anywhere in the actual code.

Re: EB006 with PIC16F88 - Keypad problem

Posted: Fri Apr 13, 2012 11:52 am
by Phaenix
Ah, alright. Thanks a lot!