金牌会员
- 积分
- 2544
- 威望
- 1322
- 贡献
- 564
- 兑换币
- 175
- 注册时间
- 2011-7-12
- 在线时间
- 329 小时
|
2#
楼主 |
发表于 2011-9-30 21:53:10
|
只看该作者
我的原程序中断查询键盘
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
unsigned char a[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F ,0x77,0x7C,0x39,0x5E,0x79,0x71,0x76};
unsigned char flag;
void delay(unsigned char n)
{
unsigned char j;
for(j=1000;j>0;j--)
for(n;n>0;n--);
}
void main(void)
{
TIOS_IOS0=0;
TCTL4=0x01;
TIE_C0I=1;//开通道0,上升沿捕捉
DDRB=0xff;
DDRK=0x0f;
TSCR1_TEN=1;
EnableInterrupts;
for(;;) {
_FEED_COP(); /* feeds the dog */
} /* loop forever */
/* please make sure that you never leave main */
}
#pragma CODE_SEG __NEAR_SEG NON_BANKED
void interrupt 8 tim0()
{
DisableInterrupts;
TFLG1_C0F=1;
PORTK=0x0f;
delay(5);
if(PORTK&0xf0)
{
unsigned char x=0;
unsigned char i,j,temp,tab[]={0xfe,0xfd, 0xfb,0xf7};
flag=0;
for(i=0;i<4;i++)
{
x=0;
temp=0x01;
PORTK=tab[i];
delay(10);
for(j=0;j<4;j++)
{
if(PORTK&temp)
x=i*4+j;
flag=1;
break ;
}
temp=temp<<1;
if(flag=1)
{
break;
}
}
PORTB=a[x];
}
EnableInterrupts;
} |
|