📄 61c22(arm).txt
字号:
这是一个用ARM写的程序,很简单。可能我们的目的不一样,但是应该差不多。
unsigned char Get_key() // get the value of the optical encoders
{
unsigned char ch=0;
ch=rPDATC&0x0007; 读三个口的状态
return ch;
}
unsigned char Detect_key() // the program for detecting optical encoders
{
unsigned char key1=0,key2=0,k1=0,k2=0,k3=0;
Begin: key1=Get_key(); //obtain the key value
Delay_W(600000);
key2=Get_key(); //obtain the key value again
while(key1==key2) //if the key value different from the last time, then there is a input
{
key2=Get_key();
Delay_W(600000);
}
k1=key1&0x03; //acquire the former state
k2=key2&0x03; //acquire the current state
k3=key2&0x04; // to see if the enter is pressed
if(k3==0) //enter has the highest PRI
return 0;
else if(((k1==0)&&(k2==1))||((k1==1)&&(k2==3))||((k1==3)&&(k2==2))||((k1==2)&&(k2==0))) // turn left
return 2;
else if(((k1==0)&&(k2==2))||((k1==2)&&(k2==3))||((k1==3)&&(k2==1))||((k1==1)&&(k2==0))) // turn right
return 3;
else
goto Begin;
}
我这个程序是查询式的, 就是说如果没有键按下,就会一直在这里等待。
还有就是除了函数:unsigned char Get_key() 外,其他的都跟单片机一样,你只需要把这个函数改写成用
单片机的IO口读就可以了。
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -