|
本帖最后由 九天星火 于 2018-11-4 17:37 编辑
大学单片机实验,我自己写的,仅供参考
#include<reg51.h>
#include<intrins.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;
uint i;
uint j=0;
void Shift()
{
j++;
if(j==1)
{
LED9=0;
LED10=1;
LED8=1;
LED4=1;
LED7=1;
}
else if(j==2)
{
LED9=1;
LED10=0;
LED8=0;
LED4=1;
LED7=1;
}
else if(j==3)
{
LED9=1;
LED10=1;
LED8=1;
LED4=0;
LED7=0;
j=0;
}
}
void x0_isr()interrupt 0
{
i=0;
TMOD=0x01;
ET0=1;
TH0=0x3c; //65536-50000=15536=3cb0 50ms
TL0=0xb0;
TR0=1;
LED9=0;
LED10=1;
LED8=1;
LED4=1;
LED7=1;
j=1;
}
void main()
{
IT0=1;
EX0=1;
EA=1;
while(1);
}
void Time0(void) interrupt 1
{
i++;
if(i==20)
{
i=0;
Shift();
}
}
|
|