|
![](static/image/common/ico_lz.png)
楼主 |
发表于 2007-11-14 16:00:48
|
显示全部楼层
谢谢,我已经下载看了,您写的我看懂了,只是为什么我这个思路就不行呢?这是我参考别人写的一个程序, 很想知道为什么不能工作,希望您能指点一下.
下面的程序是我改动过的:
#include <iom16v.h>
#include <macros.h>
unsigned char table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf,0xf8,0x80,0x90,0xbf,0xf8,0x80};
unsigned char t,i;
void main(void)
{
DDRC=0XFF;
PORTC=0X00;
while(1)
{
unsigned char i,code,l;
DDRA = 0x00;/*获取列地址 */
PORTA = 0xf0;
DDRA = 0x0f;
i = PINA;
DDRA = 0x00;/*获取行地址 */
PORTA = 0x0f;
DDRA = 0xf0;
l= PINA;
i=i|l;
DDRA = 0x00;/*输出复位 */
PORTA = 0xFF;
if (i!=0X00)
{delay();
i=PINA;
if (i!=0x00)
{ code=key_read();
display(code);
delay();
}
else ;
}
else ;
};
}
unsigned char key_read(void)
{
unsigned char m,n;
DDRA = 0x00;/*获取列地址 */
PORTA = 0xf0;
DDRA = 0x0f;
m = PINA;
DDRA = 0x00;/*获取行地址 */
PORTA = 0x0f;
DDRA = 0xf0;
n= PINA;
m=m|n;
DDRA = 0x00;/*输出复位 */
PORTA = 0xFF;
switch (m)
{ /*将按键码转换成键值 */
case 0xee: return 1;break;
case 0xde: return 2;break;
case 0xbe: return 3;break;
case 0x7e: return 4;break;
case 0xed: return 5;break;
case 0xdd: return 6;break;
case 0xbd: return 7;break;
case 0x7d: return 8;break;
case 0xeb: return 9;break;
case 0xdb: return 10;break;
case 0xbb: return 11;break;
case 0x7b: return 12;break;
case 0xe7: return 13;break;
case 0xd7: return 14;break;
case 0xb7: return 15;break;
case 0x77: return 16;break;
default : return 0;break;
}
}
void display(code)
{
PORTC=table[code];
}
void delay()
{
int t;
for(t=100;t>0;t--)
;
} |
|