#i nclude《90s8515.h》
#define uchar unsigned char
#asm
equ __LCD_port=0x18 ;PORTB
#endasm
#i nclude
#i nclude
/************按键功用阐明:0–9为数字键 ********/
#define cEnter 16 //承认键
#define cFunTIon 15 //功用菜单键
#define cDown 14 //上,下选择键
#define cUp 13
#define cRn_Stop 12 //运转/中止切切实实换键
#define cDel 11 //删去
uchar lcd_buffer[33];
uchar getkey(void)
{
uchar key_temp;
PORTC|=0x07; //向PORTC.0–PORTC.2写入高电平
DDRC=0x00; //把PORTA设置为输入形式
key_temp=PINC&0x07; //读取PORTA.0–PORTA.2上的值并屏蔽其它位
/*****假如K0—K6按下,key_temp就为相应的键值,假如K7–K15按下,则读入PINC.0–PINC.2都为高电平,key_temp==7
然后PORTC.0–PORTC.2顺次输出低电平,判别K7–K15那个键按下**********/
if(key_temp==7) //判别K7–K9是否按下
{
DDRC|=0x01; //设置PORTC.0输出0
PORTC&=0xfe;
DDRC&=0x00;
key_temp=PINC&0x07;
key_temp=(key_temp+1)/2+7;
if(key_temp==10) //判别K10–K12是否按下
{
DDRC|=0x02; //设置PORTC.1输出0
PORTC&=0xfd;
DDRC&=0x00;
key_temp=PINC&0x07;
key_temp=(key_temp+1)/2+10;
if(key_temp==13) //判别K13–K15是否按下
{
DDRC|=0x04; //设置PORTC.2输出0
PORTC&=0xfb;
DDRC&=0x00;
key_temp=PINC&0x07;
key_temp+=13;
}
}
}
return key_temp;
}
void init()
{
PORTB=0x00; //PORB的初始化
DDRB=0x00;
DDRC=0x00;
// LCD module iniTIalizaTIon
lcd_init(16);//清屏并把显现坐标设定在0列0行
}
void main()
{
uchar result;
init();
result=getkey();
sprintf(&lcd_buffer[2],“%c”,result);
lcd_gotoxy(0,4);
lcd_putchar(lcd_buffer[2]);
while(1);
}