This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

KEYBOARD AND LCD INTERFACING

This is keyboard interfacing with lcd.
it works perfect with logic analyzer, when i dump on to kit its not working.
can anyone suggest me some modifications.

#include<reg51.h>

void lcd_cmd(char);
void lcd_init();
void lcd_data(char);
void delay(int);
void row(unsigned int rowloc);
void column(unsigned int colloc);
void MSDelay(unsigned int value);

sbit rs = P0^7;
sbit rw = P0^6;
sbit oe = P0^5;

sbit r1 = P1^0;
sbit r2 = P1^1;
sbit r3 = P1^2;
sbit r4 = P1^3;
sbit r5 = P1^4;
sbit r6 = P1^5;

sbit c1 = P0^0;
sbit c2 = P0^1;
sbit c3 = P0^2;

int x, y;
unsigned int rowloc, colloc;
char num[6][3] = { {'1','2','3'}, {'4','5','6'}, {'7','8','9'}, {'*','0','#'}, {'A','B','C'}, {'D','E','F'}
};

void column(unsigned int colloc)
{ colloc = ((~colloc) & 0x07); if(colloc == 1) x = 0; if(colloc == 2) x = 1; if(colloc == 4) x = 2;
} void row(unsigned int rowloc)
{ rowloc &= 0x3F ; if( rowloc == 1) y = 0; if( rowloc == 2) y = 1; if( rowloc == 4) y = 2; if( rowloc == 8) y = 3; if( rowloc == 16) y = 4; if( rowloc == 32) y = 5;
} void lcd_cmd(char x)
{ P2 = x; rs = 0; oe = 1; //creating a pulse rw = 0; delay(1); oe = 0;
} void lcd_init()
{ lcd_cmd(0x38); lcd_cmd(0x0E); lcd_cmd(0x01); lcd_cmd(0x06); lcd_cmd(0x80);
} void delay(int n)
{ int i=0; for(i=0;i<n;i++) { TR0=1; while(TF0!=1); TF0=0; TR0=0; }
} void lcd_data(char x)
{ P2 = x; rs = 1; oe = 1; rw = 0; delay(1); oe = 0;
} void main()
{ char c;

r1 = r2 = r3 = r4 = r5 = r6 = 0; c1 = c2 = c3 = 1;

P2 = 0x00; TMOD = 0x01; lcd_init();

while(1) { while(c1 == 1 && c2 == 1 && c3 == 1); MSDelay(20); colloc = P0 ; rowloc = P1; column(colloc); MSDelay(20); row(rowloc); c = num[y][x]; while( c1 == 0 || c2 == 0 || c3 ==0 ); r1 = r2 = r3 = r4 = r5 = r6 = 0; lcd_data(c); }
} void MSDelay(unsigned int value)
{ unsigned int x, y; for(x = 0; x < 1275; x++) for(y = 0; y < value; y++);
}

  • I think you forgot to read how to post formatted source code. Clearly visible directly about the message input box.

    Works perfect with logic analyzer? You mean the simulator in Keil? How do you know it works perfect? The simulator don't have real hardware so can't tell you if it really works perfectly - have you tried real bouncy keyboard input? Have you verified timing etc of every signal for the LCD?

    Doesn't work for real hardware? Don't you have any more information than that? How doesn't it work? What have you done to figure out if it fails to read keyboard presses? How/if it fails to send out LCD data? Have you checked all signals etc?

    First step is for you to post enough info that we really know what you have done and exactly what you have deduced (and how you came to the conclusions).