matt reister

HC11 keyboard scanning routine HELP!

Discussion created by matt reister on Apr 6, 2008
Latest reply on Apr 6, 2008 by matt reister

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?

Outcomes