作者kinkipikachu (提琴手的無弦之聲)
看板ASM
標題[請益] 4X4的 keyboard 寫法
時間Tue Feb 9 13:25:16 2010
小弟知道網路上跟書上有很多,我自己試寫了一個
用 keil c 寫的 keypad 程式,但是七段就是不會亮,
請大大指點一下我錯誤的觀念,我不知錯再哪裡?
硬體架構:
OUTPUT 接收
89S51 P0.0 P0.1 P0.2 P0.3 P0.4 P0.5 P0.6 P0.7
採用低態驅動
P2 接 7段顯示器
程式:
#include <AT89X51.H>
char keypad(void);
code char
table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,
0x83,0xc6,0xa1,0x86,0x8e,0xff};
main()
{
char n;
while(1)
{
n=table[keypad()];
P2=~n;
}
}
char keypad(void)
{
char key=16;
if (P0==0x77)
{
key=0;
return key;
}
else if (P0==0x7b)
{
key=1;
return key;
}
else if (P0==0x7c)
{
key=2;
return key;
}
else if (P0==0x7e)
{
key=3;
return key;
}
else if (P0==0xb7)
{
key=4;
return key;
}
else if (P0==0xbb)
{
key=5;
return key;
}
else if (P0==0xbc)
{
key=6;
return key;
}
else if (P0==0xbe)
{
key=7;
return key;
}
else if (P0==0xc7)
{
key=8;
return key;
}
else if (P0==0xcb)
{
key=9;
return key;
}
else if (P0==0xce)
{
key=10;
return key;
}
else if (P0==0xc7)
{
key=11;
return key;
}
else if (P0==0xe7)
{
key=12;
return key;
}
else if (P0==0xeb)
{
key=13;
return key;
}
else if (P0==0xec)
{
key=14;
return key;
}
else if (P0==0xee)
{
key=15;
return key;
}
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 203.72.21.230
推 ruemann:因為你的keypad程序是不會work的…… 02/09 19:02
→ ruemann:簡單講就是P0可能恒為1(有pull-high)或恒為0(沒有pull-h 02/09 19:03
→ ya88552200:會是P0沒接提昇電阻嗎? 02/10 00:06