📄 main.c
字号:
#include <iom8515v.h>
#include"ForATmega8515.h"
#define C0 0x04
#define C1 0x08
#define C2 0x10
#define R0 0x40
#define R1 0x80
void delay(uint ticks);//严时
uchar GetKey(void);
uchar temp;
void main()
{
uchar shuma=0;
uchar key=0;
init_devices();
while(1)
{
temp=GetKey();
key=temp;
if((key&0x10)!=0) //第一列有键按下
{
if((temp&0x01)==0)shuma=1;
else if((temp&0x02)==0)shuma=3;
else if((temp&0x04)==0)shuma=5;
}
else if((key&0x20)!=0)//第二列有键按下
{
if((temp&0x01)==0)shuma=2;
else if((temp&0x02)==0)shuma=4;
else if((temp&0x04)==0)shuma=6;
}
PORTA=Tab[shuma];
}
}
void delay(uint ticks)
{
uchar i;
for(;ticks!=0;ticks--)for(i=200;i!=0;i--);
}
////////////////////////////////////////////////
uchar GetKey(void)
{
uchar key;
uchar temp;
//temp的高4位是按下的列
//temp低4位是按下的行
DDRD&=~(C0+C1+C2);//C0,C1,C2设置为输入
DDRD|=R0+R1;//R0,R1设置为输出
PORTD&=~(R0+R1);//R0,R1输出0
key=PIND; //读取引脚
key>>=2;
key&=0x07;
if(key!=0x07) //如果有键盘按下
{
delay(1); //延时,软件滤波
key=PIND; //读取引脚
key>>=2;
key&=0x07;
if(key!=0x07)
{
//确实有键按下
temp=key;
DDRD|=C0+C1+C2;////C0,C1,C2设置为输出
DDRD&=~(R0+R1);//R0,R1设置为输入
PORTD|=C0+C1+C2;
key=PIND; //读取引脚
key>>=2;
key&=0x30;
temp+=key;
return temp;
}
}
return 0xff;//没有键按下
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -