|
本帖最后由 九天星火 于 2018-11-4 17:43 编辑
大学单片机实验,我自己写的,仅供参考
#include<reg51.h>
#define uint unsigned int
#define uchar unsigned char
sbit SW17=P3^2;
sbit LED9=P2^7;
sbit LED10=P2^6;
sbit LED8=P2^5;
sbit LED4=P2^4;
sbit LED7=P2^3;
uchar flag=0;
void delay()
{
uint i=0;
TMOD=0x01;
TH0=0x3c; //65536-50000=15536=3cb0 50ms
TL0=0xb0;
TR0=1;
while(i<20)
{
if(TF0==1)
{
TF0=0;
i++;
}
}
}
void x0_isr()interrupt 0
{
flag=1;
}
void main()
{
IT0=1;
EX0=1;
EA=1;
flag=0;
while(1)
{
if(flag==1)
{
LED9=0;
LED10=1;
LED8=1;
LED4=1;
LED7=1;
delay();
LED9=1;
LED10=0;
LED8=0;
LED4=1;
LED7=1;
delay();
LED9=1;
LED10=1;
LED8=1;
LED4=0;
LED7=0;
delay();
}
}
}
|
|