Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Key Matrix scanning delay time

Status
Not open for further replies.

usif

New Member
Hi guys. Im trying to get a simple 4X4 Key matris working, with scanning. Ive read Nigels tutorial about it and though I would Try.

I cant seem to get the delay time between turning each row individually on quite right, so the buttons are being skipped. Can anyone help with getting the delay time correct?

Thanks in advance.

Using BoostC Compiler

Code:
/*    

4X4 KEY MATRIX

PORTCPIN  3  2  1  0              collumns are input pins
														   
 4      O  O  O  O              Rows are output, Scanning
 5      O  O  O  O
 6      O  O  O  O
 7      O  O  O  O 

												
        LCD PIN ARRANGEMENT

	JHD-162A
	
	1    2   3   4  5 6   7  8   9   10  11  12  13   14  15  16
	VSS VCC VEE RS R/W E DB0 DB1 DB2 DB3 DB4 DB5 DB6 DB7 LED+ LED-
	
*/
	

#define LCD_ARGS  0, /* Interface type: mode 0 = 8bit, 1 = 4bit(low nibble), 2 = 4bit(upper nibble) */ \
    0,               /* Use busy signal: 1 = use busy, 0 = use time delays */                          \
    PORTD, TRISD,    /* Data port and data port tris register */                                       \
    PORTA, TRISA,    /* Control port and control port tris register */                                 \
    1,               /* Bit number of control port is connected to RS */                               \
    2,               /* Bit number of control port is connected to RW */                               \
    3                /* Bit number of control port is connected to Enable */





#include <system.h>
#include <lcd_driver.h>
#pragma DATA _CONFIG, _CP_OFF & _PWRTE_OFF & _WDT_OFF & _HS_OSC & _LVP_OFF


#pragma CLOCK_FREQ 20000000

#define col1 portc.3
#define col2 portc.2
#define col3 portc.1
#define col4 portc.0
#define row portc

	
void main()
{

		adcon1 = 0b00000110; //Digital
		trisa = 0x00; // A Output
		trisb = 0xff; // B Input
		trisc = 0x0f; // Portc pin 0-3 input only
		trisd = 0x00; // D Output
	   
	   //initialise LCD
		lcd_setup();
		lcd_clear();
	
		//type in default message
		lcd_gotoxy(0,0);
		lprintf("PRESS A BUTTON");
		
		
		
while(1)
{
			
	for(row=0x10;row != 0x81;row<<=1)
	{
	delay_ms(4);
	
		}
		//portc = 0;
		
		if(row = 0x10 && col1 == 0)
		{
	delay_ms(2);
		lcd_clear();
		lprintf("1");
		}
			if(row = 0x10 && col2 == 0)
		{
		
		delay_ms(2);
		lcd_clear();
		lprintf("2");
		}
		
			if(row = 0x10 && col1 == 0)
		{
		delay_ms(2);
		
		lcd_clear();
		lprintf("3");
		}
		
		if(row = 0x20 && col2 == 0)
		{
		delay_ms(2);
		
		lcd_clear();
		lprintf("4");
		}
		
		delay_ms(20);
		
		
		}
	}
 
Last edited:
I never used a delay for scanning keys if one changed state save it and then delay and check same key for press is how I do it . If not still down go back and keep scanning
 
Status
Not open for further replies.

Latest threads

Back
Top