I am tring to write a keyboard scanning routine for a 4x4 keypad in C for my FOX11 HC11 trainer board. I am trying to detect when the values on PORTE and PORTD out changed and process the change accourdingly. The I/O map for the keyboard is shown below.
Pin 2 PD2 connects COL0 of the keypad
Pin 3 PD3 connects COL1 of the keypad
Pin 4 PD4 connects COL2 of the keypad
Pin 5 PD5 connects COL3 of the keypad
Pin 6 PE0 connects ROW0 of the keypad
Pin 7 PE1 connects ROW1 of the keypad
Pin 8 PE2 connects ROW2 of the keypad
I have used a default asm program given by the manufacturer to verify that the keyboard physically works. My code is shown below:
/* sample program of mixed C code and asm code */
#include <hc11.h>
#define LED (*(volatile unsigned char*)0x1404)
typedef void (*fnptr)();
#define lcd_ini ((fnptr)0x80f)
void lcd_line1(char, char*);
void lcd_line2(char, char*);
int main()
{
char characterEntered[] = "Key entered ";
// set up the registers
PORTD = 0xFF;
DDRD = 0xFE;
while(1)
{
if((PORTE != 0x8F) || (PORTD != 0x3F))
{
lcd_line1(11, characterEntered);
delay1ms(10000);
lcd_ini();
}
}
return 0;
}
When the value on the pins PD2-PD5 and PE0-PE3 change isn’t the change suppose to be reflected in a change in PORTE and PORTD? If so why aren’t the values of PD or PE changed from their default values 0x8F and 0x3F? Even if I try to assign a new value to PORTE or PORTD they do not change?
#ifndef INV_KEYPADbyte _kbdecoder[4][4]={{0xf,0xb,0x7,0x3},{0xe,0xa,0x6,0x2},{0xd,0x9,0x5,0x1},{0xc,0x8,0x4,0x0},};#else // Use this for dragon12-Plusconst byte _kbdecoder[4][4]={{0xd,0xc,0xb,0xa},{0xe,0x9,0x6,0x3},{0x0,0x8,0x5,0x2},{0xf,0x7,0x4,0x1},};#endif