刚刚入门学习单片机,请高手们多提一些意见,小弟不胜感激.
#include<reg52.h> //头文件
void isr_int (void ); //中断服务函数声明
unsigned char scan_num;
void delay(unsigned int ms)// 延时函数
{
unsigned char k;
while(ms--)
{
for(k=0;k<100;k++);
}
}
void main (void ) //主函数
{
unsigned char i;
P1=0xff;
IT0=0; //设置INT0低电平触发方式
EA=1; //开CPU中断
EX0=1; //开EX0中断
while (1)
{
scan_num = 0xfe;
for(i=0;i<7;i++)
{
P1 = scan_num;
scan_num = (scan_num<<1)|0x01;
delay(1000);
}
for(i=0;i<7;i++)
{
P1 = scan_num;
scan_num = (scan_num>>1)|0x80;
delay(1000);
}
}
}
void isr_int (void) interrupt 0 //中断服务函数
{
unsigned int f;
EX0=0;
for(f=0;f<50000;f++);
{
delay(1000);
}
EX0=1;
} |