|
#include <reg51.h>
#define uchar unsigned char
#define uint unsigned int
#define out P2
sbit pos=P0^0;
sbit neg=P0^1;
void delayms (uint);
uchar code turn[]={0x02,0x06,0x04,0x0c,0x08,0x09,0x01,0x03};
void main(void)
{
uchar i;
out=0x03;
while(1)
{
if(!pos)
{
i=i<8?i+1:0;
out=turn;
delayms(50);
}
else if(!neg)
{
i=i>0?i-1:7;
out=turn;
delayms(50);
}
}
|
|