#include <iom16v.h>
#include <macros.h>#define uchar unsigned char
#define uint unsigned int unsigned char const dofly[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
uchar keyscan(void);
void delay(uint i);
/*------------------------------------------------
Ö÷º¯Êý
------------------------------------------------*/
void main(void)
{
uchar key;
DDRA = 0xFF;
PORTA = 0xFF;
DDRD = 0xFF;
PORTD = 0xFF;
while(1)
{
key=keyscan();
switch(key)
{
case 0x7e:PORTA=dofly[0];break;//0
case 0x7d:PORTA=dofly[1];break;//1
case 0x7b:PORTA=dofly[2];break;//2
case 0x77:PORTA=dofly[3];break;//3
case 0xbe:PORTA=dofly[4];break;//4
case 0xbd:PORTA=dofly[5];break;//5
case 0xbb:PORTA=dofly[6];break;//6
case 0xb7:PORTA=dofly[7];break;//7
case 0xde:PORTA=dofly[8];break;//8
case 0xdd:PORTA=dofly[9];break;//9
case 0xdb:PORTA=dofly[10];break;//a
case 0xd7:PORTA=dofly[11];break;//b
case 0xee:PORTA=dofly[12];break;//c
case 0xed:PORTA=dofly[13];break;//d
case 0xeb:PORTA=dofly[14];break;//e
case 0xe7:PORTA=dofly[15];break;//f } }
}
/*------------------------------------------------
°´¼üɨÃ躯Êý
------------------------------------------------*/
uchar keyscan(void)
{
uchar cord_h,cord_l;
DDRD=0xF0;
PORTD=0x0f;
delay(100);
cord_h=PIND&0x0f;
if(cord_h!=0x0f)
{
delay(10000);
if(cord_h!=0x0f)
{
cord_h=PIND&0x0f;
DDRD=0x0F;
PORTD=cord_h|0xf0;
delay(100);
cord_l=PIND&0xf0;
return(cord_h+cord_l);
}
}return(0xff);
}
void delay(uint i)
{
while(i--);
}
[
本帖最后由 xisogou 于 2012-6-3 10:29 编辑 ]
此帖出自
小平头技术问答
只是右半部分的8个按键有效,显示2 3 6 7 a b e f
把程序的 D口 换成 B口,就没有问题,不知道为什么?
[ 本帖最后由 xisogou 于 2012-6-3 10:28 编辑 ]一周热门 更多>