#include <pic.h>
__CONFIG(XT&WDTDIS);
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
uchar c;
void delay(uint x)
{
uint a,b;
for(a=x;a>0;a--)
for(b=110;b>0;b--);
}
void init(void)
{
PORTA=0X00;
TRISA=0XFF;
PORTB=0X00;
TRISB=0X00;
PORTC=0XFF;
TRISC=0XFF;
PORTD=0X00;
TRISD=0X00;
}
void move(void)
{
uint dat;
uchar y;
dat=0x20;
for(y=0;y<7;y++)
{
PORTB=dat;
if(RA1==0)
{
delay(100);
dat=dat>>1;
}
else
{
RD7=1;
delay(250);
RD7=0;
}
}
}
void key(void)
{
if(RC2==0)
{
c=1;
}
}
void test(void)
{
key();
if(c==1)
{
c=0;
move();
}
}
void main()
{
init();
while(1)
{
test();
}
} |