单片机外部中断实验 p1口接八个发光二极管,实现:s1加1键,s2减1键(INT0'INT1) )

要求:八个灯一开始全灭,每按一次加一键灯就多亮一盏,八个灯全亮后每按一次减一键灯就灭一盏。谢谢

#include <reg51.h>

#define uchar unsigned char 

uchar code table[]={0xff,0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00};

uchar i;

void main()

{

  IT0=1;

  EX0=1;

  IT1=1;

  EX1=1;

  EA=1;

  while(1)

  {

   P2=table[i];

  

  }

}

void t0()interrupt 0  

{

  i++;

  if(i==9)

  i=0;

}

void t1()interrupt 2

{

 i--;

 if(i==255)

 i=8;

}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-04-13
这个不用中断做吧
第2个回答  2011-04-13
你是想要源程序还是想要搭个外围电路?
相似回答