/*
4X4 KEY MATRIX
PORTCPIN 3 2 1 0 collumns are input pins
4 O O O O
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 DATA _CONFIG, _PWRTE_OFF & _BODEN_OFF & _WDT_OFF & _LVP_OFF & _CPD_OFF & _DEBUG_OFF & _XT_OSC & _CP_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 writing
lcd_gotoxy(0,0);
lprintf("PRESS A BUTTON");
char row;
while(1 == 1)
{
/*if(col1 == 0)
{
lprintf("tstin123");
}*/
for(row=0x10;row != 0x80;row<<=1)
{
portc = row;
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 = 0x20 && col1 == 0)
{
delay_ms(2);
lcd_clear();
lprintf("3");
}
if(row = 0x20 && col2 == 0)
{
delay_ms(2);
lcd_clear();
lprintf("4");
}
delay_ms(20);
}
}