智能车制作
标题:
想把51上的矩阵键盘程序该用飞思卡尔的做一遍,发现不行了,至今还不知道哪里有问题
[打印本页]
作者:
抓住指間の落寞.
时间:
2013-2-27 14:55
标题:
想把51上的矩阵键盘程序该用飞思卡尔的做一遍,发现不行了,至今还不知道哪里有问题
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
#define uchar unsigned char
#define uint unsigned int
#define dula PORTK_PK0
#define wela PORTK_PK1
#define dula_dir DDRK_DDRK1
#define wela_dir DDRK_DDRK0
#define DATA PORTA
#define DATA_dir DDRA
#define KEY PORTB
#define KEY_dir DDRB
byte shuma[20]={
0x03,0x9f,0x25,0x0d,
0x99,0x49,0x41,0x1f,
0x01,0x09
};
/*************************************************************/
/* 延时函数 */
/*************************************************************/
void delay(uint xms)
{
uint i,j;
for(j=xms;j>0;j--)
for(i=110;i>0;i--);
}
/*************************************************************/
void display(uchar num) {
DATA=shuma[num];
dula=1;
dula=0;
}
/*************************************************************/
void keyscan() {
uchar temp,n;
KEY = 0Xfe;
temp = KEY;
temp =temp&0xf0;
if(temp!=0xf0)
{
delay(10) ;
temp = KEY;
switch(temp)
{ case 0xee :n=0;break;
case 0xde :n=1;break;
case 0xbe :n=2;break;
case 0x7e :n=3;break;
}
while(temp!=0xf0)
{
temp = KEY;
temp =temp&0xf0;
}
display(n);
}
KEY = 0Xfd;
temp = KEY;
temp =temp&0xf0;
if(temp!=0xf0)
{
delay(10) ;
temp = KEY;
switch(temp)
{ case 0xed :n=4;break;
case 0xdd :n=5;break;
case 0xbd :n=6;break;
case 0x7d :n=7;break;
}
while(temp!=0xf0)
{
temp = KEY;
temp =temp&0xf0;
}
display(n);
}
KEY = 0Xfb;
temp = KEY;
temp =temp&0xf0;
if(temp!=0xf0)
{
delay(10) ;
temp = KEY;
switch(temp)
{ case 0xeb :n=8;break;
case 0xdb :n=9;break;
case 0xbb :n=10;break;
case 0x7b :n=11;break;
}
while(temp!=0xf0)
{
temp = KEY;
temp =temp&0xf0;
}
display(n);
}
KEY = 0Xf7;
temp = KEY;
temp =temp&0xf0;
if(temp!=0xf0)
{
delay(10) ;
temp = KEY;
switch(temp)
{ case 0xe7 :n=12;break;
case 0xd7 :n=13;break;
case 0xb7 :n=14;break;
case 0x77 :n=15;break;
}
while(temp!=0xf0)
{
temp = KEY;
temp =temp&0xf0;
}
display(n);
}
}
/*************************************************************/
void init()
{
dula_dir = 1;
wela_dir = 1;
DATA_dir = 0xff;
KEY_dir = 0xff;
}
/*************************************************************/
void main(void) {
init();
dula = 1;
DATA = 0xff;
dula = 0;
wela = 1;
DATA = 0xff;
wela = 0;
for(;;)
{
keyscan();
}
}
作者:
抓住指間の落寞.
时间:
2013-2-27 16:46
还是出不来 好纠结啊 希望有高手指教指教
:'(
欢迎光临 智能车制作 (http://111.231.132.190/)
Powered by Discuz! X3.2