|
請教各位前輩 以下是朋友的程式 小弟我看不懂 希望可以聽各位大大的講解
int i;
int led[]={2,3,4,5,6,7,8,9};
unsigned char dataD;
unsigned char dataB;
void setup()
{
//DDRD = B00000011;
//DDRB = B11111100;
Serial.begin(9600);
for(i=0;i<8;i++)
pinMode(led[i],OUTPUT);
for(i=0;i<8;i++)
digitalWrite(led[i],LOW);
}
void loop()
{
if(Serial.available()>0)
{
unsigned char data = Serial.read();
PORTD = data<<2;
PORTB = data>>6;
dataD = PORTD;
dataD = dataD&0x03;
//dataD = dataD|(data<<2);
dataB = PORTB;
dataB = dataB&0xFC;
dataD = dataD|(data<<2);
dataB = dataB|(data<<6);
delay(2000);
PORTD = PORTD&0x03;
PORTB = PORTB&0xFC;
}
} |
|