#include<reg51.h>
sbit s1 = P3^2;
sbit s2 = P3^3;
void delay(unsigned int n)
{
while(n--);
}
void yanshi(unsigned char a)
{
unsigned char b;
for(b = 0;b<a;b++)
{
TH0 =(65536 - 50000)/256;
TL0 = (65536 - 50000)%256;
TR0 = 1;
while(!TF0);
TF0 = 0;
}
}
void zuo()
{
unsigned char c = 0x01;
unsigned char *h;
unsigned char f;
h = &c;
for(f = 0;f<8;f++)
{
P1 = ~c;
delay(20000);
*c = *c<<1;
if(c == 0)
{
c = 0x01;
}
}
}
void you()
{
unsigned char e = 0x80;
unsigned char *p;
unsigned char b;
p = &e;
for(b = 0;b<8;b++)
{
P1 = ~e;
yanshi(4);
*e = *e>>1;
if(e ==0x00)
{
e = 0x80;
}
}
}
void main()
{
TMOD = 0x01;
EX0 = 1;
IT0 = 1;
PX0 = 1;
EX1 = 1;
IT1 = 0;
EA = 1;
while(1)
{
zuo();
}
}
void zd()interrupt 0
{
unsigned char j;
j = P1;
you();
P1 = j;
}
void zhongduan() interrupt 2
{
unsigned char j,i;
j = P1;
for( i = 0; i<3;i++)
{
P1 = 0x00;
yanshi(10);
P1 = 0xff;
yanshi(10);
}
while(!s2);
P1 = j;
}
|