shahfenil08
Newbie level 1
#include <mega32.h>
// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x12 ;PORTD
#endasm
#include <lcd.h>
#include<delay.h>
//#include<stdio.h>
#define KB_PORT_OUT PORTB
#define KB_PORT_IN PINB
void main(void)
{
unsigned char upperNibble, keyCode, keyPressed, i;
lcd_init(16);
PORTD=0x00;
DDRD=0xFF;
PORTB=0xff;
DDRB=0xF3;
while (1)
{
//lcd_int(); // display ON
lcd_gotoxy(0,0);
lcd_putsf("welcome");
lcd_gotoxy(0,1);
delay_ms(100);
_lcd_write_data(0x0f);
//moving LCD cursor to second row
upperNibble = 0xff;
for(i=0; i<2; i++)
{
//PORTB &= 0x0f ;
delay_ms(1);
KB_PORT_OUT = ~(0x01 << i);
delay_ms(1); //delay for port o/p settling
upperNibble = KB_PORT_IN | 0x03;
if (upperNibble != 0xff)
{
delay_ms(20); //key debouncing delay
upperNibble = KB_PORT_IN | 0x03;
if(upperNibble == 0x0f) goto OUT;
keyCode = (upperNibble & 0x0c) | (0x03 & ~(0x01 << i));
while (upperNibble != 0xff)
upperNibble = KB_PORT_IN | 0x03;
// PORTB &= 0x0f;
delay_ms(20); //key debouncing delay
switch (keyCode) //generating key characetr to display on LCD
{
case (0x09): keyPressed = '0';
break;
case (0x05): keyPressed = '1';
break;
case (0x0a): keyPressed = '2';
break;
case (0x06): keyPressed = '3';
break;
default : keyPressed = 'X';
}//end of switch
lcd_putchar(keyPressed);
OUT:;
}//end of if
}//end of for*/
}//end of while(1)
}//end of main()
// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x12 ;PORTD
#endasm
#include <lcd.h>
#include<delay.h>
//#include<stdio.h>
#define KB_PORT_OUT PORTB
#define KB_PORT_IN PINB
void main(void)
{
unsigned char upperNibble, keyCode, keyPressed, i;
lcd_init(16);
PORTD=0x00;
DDRD=0xFF;
PORTB=0xff;
DDRB=0xF3;
while (1)
{
//lcd_int(); // display ON
lcd_gotoxy(0,0);
lcd_putsf("welcome");
lcd_gotoxy(0,1);
delay_ms(100);
_lcd_write_data(0x0f);
//moving LCD cursor to second row
upperNibble = 0xff;
for(i=0; i<2; i++)
{
//PORTB &= 0x0f ;
delay_ms(1);
KB_PORT_OUT = ~(0x01 << i);
delay_ms(1); //delay for port o/p settling
upperNibble = KB_PORT_IN | 0x03;
if (upperNibble != 0xff)
{
delay_ms(20); //key debouncing delay
upperNibble = KB_PORT_IN | 0x03;
if(upperNibble == 0x0f) goto OUT;
keyCode = (upperNibble & 0x0c) | (0x03 & ~(0x01 << i));
while (upperNibble != 0xff)
upperNibble = KB_PORT_IN | 0x03;
// PORTB &= 0x0f;
delay_ms(20); //key debouncing delay
switch (keyCode) //generating key characetr to display on LCD
{
case (0x09): keyPressed = '0';
break;
case (0x05): keyPressed = '1';
break;
case (0x0a): keyPressed = '2';
break;
case (0x06): keyPressed = '3';
break;
default : keyPressed = 'X';
}//end of switch
lcd_putchar(keyPressed);
OUT:;
}//end of if
}//end of for*/
}//end of while(1)
}//end of main()