neillsun
Junior Member level 2
- Joined
- Jul 12, 2007
- Messages
- 20
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Location
- London, UK
- Activity points
- 1,442
I am pulling my hair out with this one...
I have a 4x4 matrix ketpad connected to pins RC0 thru RC7 (RC0-RC3 are columns and RC4 thru RC7 are rows).
I have connected RC4-7 to ground through 10k resistors, and I am using the following code (PICCLite in MPLAB IDE) which I got from http://www.rs232pro.com/keypad_hardware.htm, I also copied the basic circuit, but I am relying on the internat OSC, so I haven't added the XTAL:
If I have it correct, the LED connected to RA3 should briefly switch off when a key is pressed, but nothing happens!!
Please can somebody point me in the correct direction??
Thanks.
I have a 4x4 matrix ketpad connected to pins RC0 thru RC7 (RC0-RC3 are columns and RC4 thru RC7 are rows).
I have connected RC4-7 to ground through 10k resistors, and I am using the following code (PICCLite in MPLAB IDE) which I got from http://www.rs232pro.com/keypad_hardware.htm, I also copied the basic circuit, but I am relying on the internat OSC, so I haven't added the XTAL:
Code:
#include <pic.h>
#include "delay.h"
#define INPUT 1
#define OUTPUT 0
void main()
{
const unsigned char keypad[]= {0x11,0x21,0x41,0x81,0x12,0x22,0x42,0x82,0x14,0x24,0x44,0x84,0x18,0x28,0x48,0x88};
const unsigned char character[] = {'1','2','3','A','4','5','6','B','7','8','9','C','*','0','#','D'};
unsigned char i,ii;
TRISA3=OUTPUT;
TRISC=0xFF;
PORTC=0xF0;
RA3=1;
while(1)
{
PORTC=0x0F; /* init/re-init port */
while(PORTC==0x0F); /* wait for key press */
DelayUs(10);
if(PORTC!=0x0F)
{
for(i=0;i<4;i++)
{
PORTC=1<<i;
for(ii=0;ii<16;ii++)
{
if(PORTC==keypad[ii])
{
RA3=0; /* led */
DelayUs(200);
DelayUs(200);
RA3=1;
i=4;
break;
}
}
}
}
}
}
If I have it correct, the LED connected to RA3 should briefly switch off when a key is pressed, but nothing happens!!
Please can somebody point me in the correct direction??
Thanks.